function current_screen() { // validate screen if (!acf_is_screen('edit-acf-field-group')) { return; } /* customize post stats (draft -> disabled)? global $wp_post_statuses; $wp_post_statuses['draft']->label = 'Disabled'; $wp_post_statuses['draft']->label_count[0] = 'Disabled (%s)'; $wp_post_statuses['draft']->label_count[1] = 'Disabled (%s)'; $wp_post_statuses['draft']->label_count['singular'] = 'Disabled (%s)'; $wp_post_statuses['draft']->label_count['plural'] = 'Disabled (%s)'; $post_states = apply_filters( 'display_post_states', $post_states, $post ); */ // check stuff $this->check_duplicate(); $this->check_sync(); // actions add_action('admin_footer', array($this, 'admin_footer')); // columns add_filter('manage_edit-acf-field-group_columns', array($this, 'field_group_columns'), 10, 1); add_action('manage_acf-field-group_posts_custom_column', array($this, 'field_group_columns_html'), 10, 2); }
function current_screen() { // validate screen if (!acf_is_screen('acf-field-group')) { return; } // disable JSON to avoid conflicts between DB and JSON acf_disable_local(); // actions add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts')); add_action('admin_head', array($this, 'admin_head')); }
function admin_enqueue_scripts() { // validate screen if (acf_is_screen('widgets') || acf_is_screen('customize')) { // valid } else { return; } // load acf scripts acf_enqueue_scripts(); // actions add_action('acf/input/admin_footer', array($this, 'admin_footer')); }
function current_screen() { // validate screen if (!acf_is_screen('edit-acf-field-group')) { return; } // check stuff $this->check_duplicate(); $this->check_sync(); // actions add_action('admin_footer', array($this, 'admin_footer')); // columns add_filter('manage_edit-acf-field-group_columns', array($this, 'field_group_columns'), 10, 1); add_action('manage_acf-field-group_posts_custom_column', array($this, 'field_group_columns_html'), 10, 2); }
function current_screen() { // validate screen if (!acf_is_screen('acf-field-group')) { return; } // disable JSON to avoid conflicts between DB and JSON acf_disable_local(); // enqueue scripts acf_enqueue_scripts(); // actions add_action('acf/input/admin_enqueue_scripts', array($this, 'admin_enqueue_scripts')); add_action('acf/input/admin_head', array($this, 'admin_head')); add_action('acf/input/form_data', array($this, 'form_data')); add_action('acf/input/admin_footer', array($this, 'admin_footer')); add_action('acf/input/admin_footer_js', array($this, 'admin_footer_js')); // filters add_filter('acf/input/admin_l10n', array($this, 'admin_l10n')); }
function current_screen() { // validate screen if (!acf_is_screen('acf-field-group')) { return; } // disable filters to ensure ACF loads raw data from DB acf_disable_filters(); // enqueue scripts acf_enqueue_scripts(); // actions add_action('acf/input/admin_enqueue_scripts', array($this, 'admin_enqueue_scripts')); add_action('acf/input/admin_head', array($this, 'admin_head')); add_action('acf/input/form_data', array($this, 'form_data')); add_action('acf/input/admin_footer', array($this, 'admin_footer')); add_action('acf/input/admin_footer_js', array($this, 'admin_footer_js')); // filters add_filter('acf/input/admin_l10n', array($this, 'admin_l10n')); }
function current_screen() { // validate screen if (!acf_is_screen('edit-acf-field-group')) { return; } // customize post_status global $wp_post_statuses; // modify publish post status $wp_post_statuses['publish']->label_count = _n_noop('Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', 'acf'); // reorder trash to end $wp_post_statuses['trash'] = acf_extract_var($wp_post_statuses, 'trash'); // check stuff $this->check_duplicate(); $this->check_sync(); // actions add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts')); add_action('admin_footer', array($this, 'admin_footer')); // columns add_filter('manage_edit-acf-field-group_columns', array($this, 'field_group_columns'), 10, 1); add_action('manage_acf-field-group_posts_custom_column', array($this, 'field_group_columns_html'), 10, 2); }
function admin_footer() { ?> <script type="text/javascript"> (function($) { acf.add_filter('get_fields', function( $fields ){ // widgets $fields = $fields.not('#available-widgets .acf-field'); // customizer $fields = $fields.not('.widget-tpl .acf-field'); // return return $fields; }); $('#widgets-right').on('click', '.widget-control-save', function( e ){ // vars var $form = $(this).closest('form'); // bail early if not active if( !acf.validation.active ) { return true; } // ignore validation (only ignore once) if( acf.validation.ignore ) { acf.validation.ignore = 0; return true; } // bail early if this form does not contain ACF data if( !$form.find('#acf-form-data').exists() ) { return true; } // stop WP JS validation e.stopImmediatePropagation(); // store submit trigger so it will be clicked if validation is passed acf.validation.$trigger = $(this); // run validation acf.validation.fetch( $form ); // stop all other click events on this input return false; }); $(document).on('click', '.widget-top', function(){ var $el = $(this).parent().children('.widget-inside'); setTimeout(function(){ acf.get_fields('', $el).each(function(){ acf.do_action('show_field', $(this)); }); }, 250); }); $(document).on('widget-added', function( e, $widget ){ acf.do_action('append', $widget ); }); $(document).on('widget-saved widget-updated', function( e, $widget ){ // unlock form acf.validation.toggle( $widget, 'unlock' ); // submit acf.do_action('submit', $widget ); }); <?php if (acf_is_screen('customize')) { ?> // customizer saves widget on any input change, so unload is not needed acf.unload.active = 0; <?php } ?> })(jQuery); </script> <?php }
/** * Get field group filters based on active screen. */ public function get_acf_field_group_filters() { global $post, $pagenow, $typenow, $plugin_page; $filter = array(); if ($pagenow === 'post.php' || $pagenow === 'post-new.php') { if ($typenow !== 'acf') { $filter['post_id'] = $post->ID; $filter['post_type'] = $typenow; } } elseif ($pagenow === 'admin.php' && isset($plugin_page)) { if (acf_get_options_page($plugin_page)) { $filter['post_id'] = acf_get_valid_post_id('options'); } } elseif ($pagenow === 'edit-tags.php' && isset($_GET['taxonomy'])) { $filter['taxonomy'] = filter_var($_GET['taxonomy'], FILTER_SANITIZE_STRING); } elseif ($pagenow === 'profile.php') { $filter['user_id'] = get_current_user_id(); $filter['user_form'] = 'edit'; } elseif ($pagenow === 'user-edit.php' && isset($_GET['user_id'])) { $filter['user_id'] = filter_var($_GET['user_id'], FILTER_SANITIZE_NUMBER_INT); $filter['user_form'] = 'edit'; } elseif ($pagenow === 'user-new.php') { $filter['user_id'] = 'new'; $filter['user_form'] = 'edit'; } elseif ($pagenow === 'media.php' || $pagenow === 'upload.php') { $filter['attachment'] = 'All'; } elseif (acf_is_screen('widgets') || acf_is_screen('customize')) { $filter['widget'] = 'all'; } return $filter; }
function admin_notices() { // bail ealry if already on update page if (acf_is_screen('custom-fields_page_acf-upgrade')) { return; } // view $view = array('button_text' => __("Upgrade Database", 'acf'), 'button_url' => admin_url('edit.php?post_type=acf-field-group&page=acf-upgrade')); // load view acf_get_view('update-notice', $view); }
function admin_footer() { ?> <script type="text/javascript"> (function($) { acf.add_filter('get_fields', function( $fields ){ // widgets $fields = $fields.not('#available-widgets .acf-field'); // customizer $fields = $fields.not('.widget-tpl .acf-field'); // return return $fields; }); $('#widgets-right').on('click', '.widget-control-save', function( e ){ // vars var $form = $(this).closest('form'); // bail early if not active if( !acf.validation.active ) { return true; } // ignore validation (only ignore once) if( acf.validation.ignore ) { acf.validation.ignore = 0; return true; } // bail early if this form does not contain ACF data if( !$form.find('#acf-form-data').exists() ) { return true; } // stop WP JS validation e.stopImmediatePropagation(); // store submit trigger so it will be clicked if validation is passed acf.validation.$trigger = $(this); // run validation acf.validation.fetch( $form ); // stop all other click events on this input return false; }); $(document).on('click', '.widget-top', function(){ var $el = $(this).parent().children('.widget-inside'); setTimeout(function(){ acf.get_fields('', $el).each(function(){ acf.do_action('show_field', $(this)); }); }, 250); }); $(document).on('widget-added', function( e, $widget ){ // - use delay to avoid rendering issues with customizer (ensures div is visible) setTimeout(function(){ acf.do_action('append', $widget ); }, 100); }); $(document).on('widget-saved widget-updated', function( e, $widget ){ // unlock form acf.validation.toggle( $widget, 'unlock' ); // submit acf.do_action('submit', $widget ); }); <?php if (acf_is_screen('customize')) { ?> // customizer saves widget on any input change, so unload is not needed acf.unload.active = 0; // hack customizer function to remove bug caused by WYSIWYG field using aunique ID // customizer compares returned AJAX HTML with the HTML of the widget form. // the _getInputsSignature() function is used to generate a string based of input name + id. // because ACF generates a unique ID on the WYSIWYG field, this string will not match causing the preview function to bail. // an attempt was made to remove the WYSIWYG unique ID, but this caused multiple issues in the wp-admin and altimately doesn't make sense with the tinymce rule that all editors must have a unique ID. // source: wp-admin/js/customize-widgets.js // vars var WidgetControl = wp.customize.Widgets.WidgetControl.prototype; // backup functions WidgetControl.__getInputsSignature = WidgetControl._getInputsSignature; WidgetControl.__setInputState = WidgetControl._setInputState; // modify __getInputsSignature WidgetControl._getInputsSignature = function( inputs ) { // vars var signature = this.__getInputsSignature( inputs ); safe = []; // split signature = signature.split(';'); // loop for( var i in signature ) { // vars var bit = signature[i]; // bail ealry if acf is found if( bit.indexOf('acf') !== -1 ) continue; // append safe.push( bit ); } // update signature = safe.join(';'); // return return signature; }; // modify _setInputState // this function deosn't seem to run on widget title/content, only custom fields // either way, this function is not needed and will break ACF fields WidgetControl._setInputState = function( input, state ) { return true; }; <?php } ?> })(jQuery); </script> <?php }
function wp_post_revision_fields($fields, $post = null) { // validate page if (acf_is_screen('revision') || acf_is_ajax('get-revision-diffs')) { // allow } else { // bail early (most likely saving a post) return $fields; } // vars $append = array(); $order = array(); $post_id = acf_maybe_get($post, 'ID'); // compatibility with WP < 4.5 (test) if (!$post_id) { global $post; $post_id = $post->ID; } // get all postmeta $meta = get_post_meta($post_id); // bail early if no meta if (!$meta) { return $fields; } // loop foreach ($meta as $name => $value) { // attempt to find key value $key = acf_maybe_get($meta, '_' . $name); // bail ealry if no key if (!$key) { continue; } // update vars $value = $value[0]; $key = $key[0]; // bail early if $key is a not a field_key if (!acf_is_field_key($key)) { continue; } // get field $field = acf_get_field($key); $field_title = $field['label'] . ' (' . $name . ')'; $field_order = $field['menu_order']; $ancestors = acf_get_field_ancestors($field); // ancestors if (!empty($ancestors)) { // vars $count = count($ancestors); $oldest = acf_get_field($ancestors[$count - 1]); // update vars $field_title = str_repeat('- ', $count) . $field_title; $field_order = $oldest['menu_order'] . '.1'; } // append $append[$name] = $field_title; $order[$name] = $field_order; // hook into specific revision field filter and return local value add_filter("_wp_post_revision_field_{$name}", array($this, 'wp_post_revision_field'), 10, 4); } // append if (!empty($append)) { // vars $prefix = '_'; // add prefix $append = acf_add_array_key_prefix($append, $prefix); $order = acf_add_array_key_prefix($order, $prefix); // sort by name (orders sub field values correctly) array_multisort($order, $append); // remove prefix $append = acf_remove_array_key_prefix($append, $prefix); // append $fields = $fields + $append; } // return return $fields; }