Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Define a constant for the ACF group key
- define('WBCOM_ACF_BUSINESS_INFO_GROUP_KEY', 'group_66d6cf54cb672');
- /**
- * Get ACF Business Information group fields
- *
- * @return array|false
- */
- function wbcom_get_business_info_group_fields() {
- $fields = acf_get_fields( WBCOM_ACF_BUSINESS_INFO_GROUP_KEY );
- return is_array( $fields ) ? $fields : false;
- }
- /**
- * Display ACF Business Information fields in the contact tab
- *
- * @return void
- */
- function wbcom_display_business_info_fields_in_contact() {
- acf_form_head();
- $fields = wbcom_get_business_info_group_fields();
- if ( !empty( $fields ) ) {
- acf_render_fields( $fields, get_the_ID() );
- } else {
- // Handle the case where no fields are found or an error occurred
- echo '<p>No fields available to display.</p>';
- }
- }
- add_action( 'business_profile_after_contact_info', 'wbcom_display_business_info_fields_in_contact' );
- /**
- * Save ACF Business Information fields
- *
- * @param int $post_id
- * @return void
- */
- function wbcom_save_business_info_fields( $post_id ) {
- if ( isset( $_POST['acf'] ) && ! empty( $_POST['acf'] ) ) {
- foreach ( $_POST['acf'] as $field_key => $field_value ) {
- $field = get_field_object($field_key);
- if( $field ) {
- switch( $field['type'] ) {
- case 'text':
- case 'textarea':
- case 'email':
- case 'url':
- update_field( $field_key, sanitize_text_field( $field_value ), $post_id );
- break;
- case 'number':
- update_field( $field_key, floatval( $field_value ), $post_id );
- break;
- default:
- update_field( $field_key, $field_value, $post_id );
- break;
- }
- }
- }
- }
- }
- add_action( 'save_post', 'wbcom_save_business_info_fields', 99, 1 );
- /**
- * Show ACF Business Information fields in the about section
- *
- * @return void
- */
- function wbcom_show_business_info_fields_in_about_section() {
- $fields = wbcom_get_business_info_group_fields();
- if ( !empty( $fields ) ) {
- foreach ( $fields as $field ) {
- $value = get_field( $field['name'], get_the_ID() );
- if ( !empty( $value ) ) {
- echo '<h2>' . esc_html( $field['label'] ) . '</h2>';
- switch( $field['type'] ) {
- case 'url':
- echo '<p><a href="' . esc_url( $value ) . '" target="_blank">' . esc_html( $value ) . '</a></p>';
- break;
- default:
- echo '<p>' . esc_html( $value ) . '</p>';
- break;
- }
- }
- }
- }
- }
- add_action( 'bp_business_profile_after_render_contact_info', 'wbcom_show_business_info_fields_in_about_section' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement