add_field_advanced_settings($fields); // Remove acfe_form }else{ $this->add_field_advanced_settings($fields, false); } } /* * Add Field Advanced Settings */ function add_field_advanced_settings($fields, $add = true){ if(empty($fields)) return; foreach($fields as $field){ // bypass clone if($field['type'] === 'clone') continue; // Group / Clone if(isset($field['sub_fields']) && !empty($field['sub_fields'])){ $this->add_field_advanced_settings($field['sub_fields'], $add); } // Flexible Content elseif(isset($field['layouts']) && !empty($field['layouts'])){ foreach($field['layouts'] as $layout){ if(isset($layout['sub_fields']) && !empty($layout['sub_fields'])){ $this->add_field_advanced_settings($layout['sub_fields'], $add); } } } // Add if($add){ if(acf_maybe_get($field, 'acfe_form')) continue; $field['acfe_form'] = true; // Remove }else{ if(!acf_maybe_get($field, 'acfe_form')) continue; acfe_unset($field, 'acfe_form'); acfe_unset($field, 'acfe_settings'); acfe_unset($field, 'acfe_validate'); } acf_update_field($field); } } /* * Advanced Settings */ function render_field_group_advanced_settings($field_group){ // Form settings acf_render_field_wrap(array( 'label' => __('Advanced settings'), 'name' => 'acfe_form', 'prefix' => 'acf_field_group', 'type' => 'true_false', 'ui' => 1, 'instructions' => __('Enable advanced fields settings & validation'), 'value' => (isset($field_group['acfe_form'])) ? $field_group['acfe_form'] : '', 'required' => false, 'wrapper' => array( 'data-after' => 'active' ) )); } /** * Metabox */ function render_field_group_settings(){ add_meta_box('acf-field-group-acfe', __('Field group', 'acf'), array($this, 'render_field_group_setting_metabox'), 'acf-field-group', 'normal'); add_meta_box('acf-field-group-acfe-side', __('Advanced Settings', 'acfe'), array($this, 'render_field_group_setting_sidebar_metabox'), 'acf-field-group', 'side'); } function render_field_group_setting_metabox(){ global $field_group; // Meta acf_render_field_wrap(array( 'label' => __('Custom meta data'), 'name' => 'acfe_meta', 'key' => 'acfe_meta', 'instructions' => __('Add custom meta data to the field group. Can be retrived using acf_get_field_group()'), 'prefix' => 'acf_field_group', 'type' => 'repeater', 'button_label' => __('+ Meta'), 'required' => false, 'layout' => 'table', 'value' => (isset($field_group['acfe_meta'])) ? $field_group['acfe_meta'] : array(), 'sub_fields' => array( array( 'ID' => false, 'label' => __('Key'), 'name' => 'acfe_meta_key', 'key' => 'acfe_meta_key', 'prefix' => '', '_name' => '', '_prepare' => '', 'type' => 'text', 'instructions' => false, 'required' => false, 'wrapper' => array( 'width' => '', 'class' => '', 'id' => '', ), ), array( 'ID' => false, 'label' => __('Value'), 'name' => 'acfe_meta_value', 'key' => 'acfe_meta_value', 'prefix' => '', '_name' => '', '_prepare' => '', 'type' => 'text', 'instructions' => false, 'required' => false, 'wrapper' => array( 'width' => '', 'class' => '', 'id' => '', ), ), ) )); // Data acf_render_field_wrap(array( 'label' => __('Field group data'), 'instructions' => __('View raw field group data, for development use'), 'type' => 'acfe_dynamic_message', 'name' => 'acfe_data', 'prefix' => 'acf_field_group', 'value' => $field_group['key'], )); // Note acf_render_field_wrap(array( 'label' => __('Note'), 'name' => 'acfe_note', 'prefix' => 'acf_field_group', 'type' => 'textarea', 'instructions' => __('Add personal note. Only visible to administrators'), 'value' => (isset($field_group['acfe_note'])) ? $field_group['acfe_note'] : '', 'required' => false, )); ?> __('Display title', 'acfe'), 'instructions' => __('Render this title on edit post screen', 'acfe'), 'type' => 'text', 'name' => 'acfe_display_title', 'prefix' => 'acf_field_group', 'value' => acf_maybe_get($field_group, 'acfe_display_title'), 'placeholder' => '', 'prepend' => '', 'append' => '' )); /* * Sync available */ if(acfe_is_sync_available($field_group)){ $json_already_active = 0; if(in_array('json', acf_maybe_get($field_group, 'acfe_autosync', array()))) $json_already_active = 1; ?>

acf_get_instance('ACFE_Field_Groups')->get_php_data($field_group), 'json' => acf_get_instance('ACFE_Field_Groups')->get_json_data($field_group), ); acf_disable_filter('local'); $choices = array( 'php' => 'PHP', 'json' => 'Json', ); global $pagenow; foreach($data as $type => $info){ $wrapper = array( 'class' => 'acf-js-tooltip', 'title' => $info['file'], ); if($info['class']) $wrapper['class'] .= ' ' . $info['class']; if($info['message']){ $wrapper['title'] = $info['message']; } $icons = array(); if($info['warning'] && $pagenow !== 'post-new.php') $icons[] = ''; ob_start(); ?> > __('Auto Sync'), 'instructions' => '', 'type' => 'checkbox', 'name' => 'acfe_autosync', 'prefix' => 'acf_field_group', 'value' => acf_maybe_get($field_group, 'acfe_autosync', array()), 'choices' => array( 'php' => $choices['php'], 'json' => $choices['json'], ) )); /* * Permissions */ acf_render_field_wrap(array( 'label' => __('Permissions'), 'name' => 'acfe_permissions', 'prefix' => 'acf_field_group', 'type' => 'checkbox', 'instructions' => __('Select user roles that are allowed to view and edit this field group in post edition'), 'required' => false, 'default_value' => false, 'choices' => acfe_get_roles(), 'value' => acf_maybe_get($field_group, 'acfe_permissions', array()), 'layout' => 'vertical' )); ?> post_type !== 'acf-field-group') return; global $field_group; ?>
Export: PHP Json
' . __('Data') . ''; return; } echo '' . __('Data') . ''; echo '
' . print_r($field_group, true) . '
' . print_r($field_group_raw, true) . '
'; } /** * Alternative Title */ function render_field_group_alternative_title($field_groups){ if(!is_admin()) return $field_groups; if(acfe_is_admin_screen()) return $field_groups; foreach($field_groups as &$field_group){ if(!acf_maybe_get($field_group, 'acfe_display_title')) continue; $field_group['title'] = $field_group['acfe_display_title']; } return $field_groups; } /** * Permissions */ function render_field_group_permissions($field_groups){ if(!is_admin()) return $field_groups; if(acfe_is_admin_screen()) return $field_groups; $current_user_roles = acfe_get_current_user_roles(); foreach($field_groups as $key => $field_group){ if(!acf_maybe_get($field_group, 'acfe_permissions')) continue; $render_field_group = false; foreach($current_user_roles as $current_user_role){ foreach($field_group['acfe_permissions'] as $field_group_role){ if($current_user_role !== $field_group_role) continue; $render_field_group = true; break; } if($render_field_group) break; } if(!$render_field_group) unset($field_groups[$key]); } return $field_groups; } /* * Instructions */ function render_field_group_instructions_settings($field){ $field['choices'] = array_merge($field['choices'], array('acfe_instructions_tooltip' => 'Tooltip')); return $field; } /** * Default AutoSync */ function render_field_group_default_autosync($field_group){ // Only new field groups if(!acf_maybe_get($field_group, 'location')){ // Default label placement: Left $field_group['label_placement'] = 'left'; // AutoSync $acfe_autosync = array(); if(acf_get_setting('acfe/json_found', false)){ $acfe_autosync[] = 'json'; } if(acf_get_setting('acfe/php_found', false)){ $acfe_autosync[] = 'php'; } if(!empty($acfe_autosync)){ $field_group['acfe_autosync'] = $acfe_autosync; } } return $field_group; } /** * Hide on Screen Settings */ function render_field_group_hide_on_screen_settings($field){ $choices = array(); foreach($field['choices'] as $key => $value){ if($key == 'the_content'){ $choices['block_editor'] = __('Block Editor'); } $choices[$key] = $value; } $field['choices'] = $choices; return $field; } /* * Prepare Export Categories */ function prepare_field_group_export_categories($field_group){ $_field_group = acf_get_field_group($field_group['key']); if(empty($_field_group)) return $field_group; if(!acf_maybe_get($_field_group, 'ID')) return $field_group; $categories = get_the_terms($_field_group['ID'], 'acf-field-group-category'); if(empty($categories) || is_wp_error($categories)) return $field_group; $field_group['acfe_categories'] = array(); foreach($categories as $term){ $field_group['acfe_categories'][$term->slug] = $term->name; } return $field_group; } function prepare_field_group_import_categories($field_group){ if(!$categories = acf_maybe_get($field_group, 'acfe_categories')) return; foreach($categories as $term_slug => $term_name){ $new_term_id = false; $get_term = get_term_by('slug', $term_slug, 'acf-field-group-category'); // Term doesn't exists if(empty($get_term)){ $new_term = wp_insert_term($term_name, 'acf-field-group-category', array( 'slug' => $term_slug )); if(!is_wp_error($new_term)){ $new_term_id = $new_term['term_id']; } // Term already exists }else{ $new_term_id = $get_term->term_id; } if($new_term_id){ wp_set_post_terms($field_group['ID'], array($new_term_id), 'acf-field-group-category', true); } } } function render_disable_block_editor(){ // globals global $typenow; // Restrict $restricted = array('acf-field-group', 'attachment'); if(in_array($typenow, $restricted)) return; $post_type = $typenow; $post_id = 0; if ( isset( $_GET['post'] ) ) { $post_id = (int) $_GET['post']; } elseif ( isset( $_POST['post_ID'] ) ) { $post_id = (int) $_POST['post_ID']; } $field_groups = acf_get_field_groups(array( 'post_id' => $post_id, 'post_type' => $post_type )); $hide_block_editor = false; foreach($field_groups as $field_group){ $hide_on_screen = acf_get_array($field_group['hide_on_screen']); if(!in_array('block_editor', $hide_on_screen)) continue; $hide_block_editor = true; break; } if($hide_block_editor){ add_filter('use_block_editor_for_post_type', '__return_false'); } } function prepare_repeater($field){ $field['prefix'] = str_replace('row-', '', $field['prefix']); $field['name'] = str_replace('row-', '', $field['name']); return $field; } } acf_new_instance('ACFE_Field_Group'); endif;