diff --git a/acf.php b/acf.php index 2a71eb4..a945f50 100644 --- a/acf.php +++ b/acf.php @@ -3,655 +3,665 @@ Plugin Name: Advanced Custom Fields PRO Plugin URI: https://www.advancedcustomfields.com Description: Customize WordPress with powerful, professional and intuitive fields. -Version: 5.9.9 +Version: 5.10.2 Author: Delicious Brains Author URI: https://www.advancedcustomfields.com Text Domain: acf Domain Path: /lang */ -if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly - -if( ! class_exists('ACF') ) : - -class ACF { - - /** @var string The plugin version number. */ - var $version = '5.9.9'; - - /** @var array The plugin settings array. */ - var $settings = array(); - - /** @var array The plugin data array. */ - var $data = array(); - - /** @var array Storage for class instances. */ - var $instances = array(); - - /** - * __construct - * - * A dummy constructor to ensure ACF is only setup once. - * - * @date 23/06/12 - * @since 5.0.0 - * - * @param void - * @return void - */ - function __construct() { - // Do nothing. - } - - /** - * initialize - * - * Sets up the ACF plugin. - * - * @date 28/09/13 - * @since 5.0.0 - * - * @param void - * @return void - */ - function initialize() { - - // Define constants. - $this->define( 'ACF', true ); - $this->define( 'ACF_PATH', plugin_dir_path( __FILE__ ) ); - $this->define( 'ACF_BASENAME', plugin_basename( __FILE__ ) ); - $this->define( 'ACF_VERSION', $this->version ); - $this->define( 'ACF_MAJOR_VERSION', 5 ); - - // Define settings. - $this->settings = array( - 'name' => __('Advanced Custom Fields', 'acf'), - 'slug' => dirname( ACF_BASENAME ), - 'version' => ACF_VERSION, - 'basename' => ACF_BASENAME, - 'path' => ACF_PATH, - 'file' => __FILE__, - 'url' => plugin_dir_url( __FILE__ ), - 'show_admin' => true, - 'show_updates' => true, - 'stripslashes' => false, - 'local' => true, - 'json' => true, - 'save_json' => '', - 'load_json' => array(), - 'default_language' => '', - 'current_language' => '', - 'capability' => 'manage_options', - 'uploader' => 'wp', - 'autoload' => false, - 'l10n' => true, - 'l10n_textdomain' => '', - 'google_api_key' => '', - 'google_api_client' => '', - 'enqueue_google_maps' => true, - 'enqueue_select2' => true, - 'enqueue_datepicker' => true, - 'enqueue_datetimepicker' => true, - 'select2_version' => 4, - 'row_index_offset' => 1, - 'remove_wp_meta_box' => true - ); - - // Include utility functions. - include_once( ACF_PATH . 'includes/acf-utility-functions.php'); - - // Include previous API functions. - acf_include('includes/api/api-helpers.php'); - acf_include('includes/api/api-template.php'); - acf_include('includes/api/api-term.php'); - - // Include classes. - acf_include('includes/class-acf-data.php'); - acf_include('includes/fields/class-acf-field.php'); - acf_include('includes/locations/abstract-acf-legacy-location.php'); - acf_include('includes/locations/abstract-acf-location.php'); - - // Include functions. - acf_include('includes/acf-helper-functions.php'); - acf_include('includes/acf-hook-functions.php'); - acf_include('includes/acf-field-functions.php'); - acf_include('includes/acf-field-group-functions.php'); - acf_include('includes/acf-form-functions.php'); - acf_include('includes/acf-meta-functions.php'); - acf_include('includes/acf-post-functions.php'); - acf_include('includes/acf-user-functions.php'); - acf_include('includes/acf-value-functions.php'); - acf_include('includes/acf-input-functions.php'); - acf_include('includes/acf-wp-functions.php'); - - // Include core. - acf_include('includes/fields.php'); - acf_include('includes/locations.php'); - acf_include('includes/assets.php'); - acf_include('includes/compatibility.php'); - acf_include('includes/deprecated.php'); - acf_include('includes/l10n.php'); - acf_include('includes/local-fields.php'); - acf_include('includes/local-meta.php'); - acf_include('includes/local-json.php'); - acf_include('includes/loop.php'); - acf_include('includes/media.php'); - acf_include('includes/revisions.php'); - acf_include('includes/updates.php'); - acf_include('includes/upgrades.php'); - acf_include('includes/validation.php'); - - // Include ajax. - acf_include('includes/ajax/class-acf-ajax.php'); - acf_include('includes/ajax/class-acf-ajax-check-screen.php'); - acf_include('includes/ajax/class-acf-ajax-user-setting.php'); - acf_include('includes/ajax/class-acf-ajax-upgrade.php'); - acf_include('includes/ajax/class-acf-ajax-query.php'); - acf_include('includes/ajax/class-acf-ajax-query-users.php'); - acf_include('includes/ajax/class-acf-ajax-local-json-diff.php'); - - // Include forms. - acf_include('includes/forms/form-attachment.php'); - acf_include('includes/forms/form-comment.php'); - acf_include('includes/forms/form-customizer.php'); - acf_include('includes/forms/form-front.php'); - acf_include('includes/forms/form-nav-menu.php'); - acf_include('includes/forms/form-post.php'); - acf_include('includes/forms/form-gutenberg.php'); - acf_include('includes/forms/form-taxonomy.php'); - acf_include('includes/forms/form-user.php'); - acf_include('includes/forms/form-widget.php'); - - // Include admin. - if( is_admin() ) { - acf_include('includes/admin/admin.php'); - acf_include('includes/admin/admin-field-group.php'); - acf_include('includes/admin/admin-field-groups.php'); - acf_include('includes/admin/admin-notices.php'); - acf_include('includes/admin/admin-tools.php'); - acf_include('includes/admin/admin-upgrade.php'); - } - - // Include legacy. - acf_include('includes/legacy/legacy-locations.php'); - - // Include PRO. - acf_include('pro/acf-pro.php'); - - // Include tests. - if( defined('ACF_DEV') && ACF_DEV ) { - acf_include('tests/tests.php'); - } - - // Add actions. - add_action( 'init', array($this, 'init'), 5 ); - add_action( 'init', array($this, 'register_post_types'), 5 ); - add_action( 'init', array($this, 'register_post_status'), 5 ); - - // Add filters. - add_filter( 'posts_where', array($this, 'posts_where'), 10, 2 ); - } - - /** - * init - * - * Completes the setup process on "init" of earlier. - * - * @date 28/09/13 - * @since 5.0.0 - * - * @param void - * @return void - */ - function init() { - - // Bail early if called directly from functions.php or plugin file. - if( !did_action('plugins_loaded') ) { - return; - } - - // This function may be called directly from template functions. Bail early if already did this. - if( acf_did('init') ) { - return; - } - - // Update url setting. Allows other plugins to modify the URL (force SSL). - acf_update_setting( 'url', plugin_dir_url( __FILE__ ) ); - - // Load textdomain file. - acf_load_textdomain(); - - // Include 3rd party compatiblity. - acf_include('includes/third-party.php'); - - // Include wpml support. - if( defined('ICL_SITEPRESS_VERSION') ) { - acf_include('includes/wpml.php'); - } - - // Include fields. - acf_include('includes/fields/class-acf-field-text.php'); - acf_include('includes/fields/class-acf-field-textarea.php'); - acf_include('includes/fields/class-acf-field-number.php'); - acf_include('includes/fields/class-acf-field-range.php'); - acf_include('includes/fields/class-acf-field-email.php'); - acf_include('includes/fields/class-acf-field-url.php'); - acf_include('includes/fields/class-acf-field-password.php'); - acf_include('includes/fields/class-acf-field-image.php'); - acf_include('includes/fields/class-acf-field-file.php'); - acf_include('includes/fields/class-acf-field-wysiwyg.php'); - acf_include('includes/fields/class-acf-field-oembed.php'); - acf_include('includes/fields/class-acf-field-select.php'); - acf_include('includes/fields/class-acf-field-checkbox.php'); - acf_include('includes/fields/class-acf-field-radio.php'); - acf_include('includes/fields/class-acf-field-button-group.php'); - acf_include('includes/fields/class-acf-field-true_false.php'); - acf_include('includes/fields/class-acf-field-link.php'); - acf_include('includes/fields/class-acf-field-post_object.php'); - acf_include('includes/fields/class-acf-field-page_link.php'); - acf_include('includes/fields/class-acf-field-relationship.php'); - acf_include('includes/fields/class-acf-field-taxonomy.php'); - acf_include('includes/fields/class-acf-field-user.php'); - acf_include('includes/fields/class-acf-field-google-map.php'); - acf_include('includes/fields/class-acf-field-date_picker.php'); - acf_include('includes/fields/class-acf-field-date_time_picker.php'); - acf_include('includes/fields/class-acf-field-time_picker.php'); - acf_include('includes/fields/class-acf-field-color_picker.php'); - acf_include('includes/fields/class-acf-field-message.php'); - acf_include('includes/fields/class-acf-field-accordion.php'); - acf_include('includes/fields/class-acf-field-tab.php'); - acf_include('includes/fields/class-acf-field-group.php'); - - /** - * Fires after field types have been included. - * - * @date 28/09/13 - * @since 5.0.0 - * - * @param int $major_version The major version of ACF. - */ - do_action( 'acf/include_field_types', ACF_MAJOR_VERSION ); - - // Include locations. - acf_include('includes/locations/class-acf-location-post-type.php'); - acf_include('includes/locations/class-acf-location-post-template.php'); - acf_include('includes/locations/class-acf-location-post-status.php'); - acf_include('includes/locations/class-acf-location-post-format.php'); - acf_include('includes/locations/class-acf-location-post-category.php'); - acf_include('includes/locations/class-acf-location-post-taxonomy.php'); - acf_include('includes/locations/class-acf-location-post.php'); - acf_include('includes/locations/class-acf-location-page-template.php'); - acf_include('includes/locations/class-acf-location-page-type.php'); - acf_include('includes/locations/class-acf-location-page-parent.php'); - acf_include('includes/locations/class-acf-location-page.php'); - acf_include('includes/locations/class-acf-location-current-user.php'); - acf_include('includes/locations/class-acf-location-current-user-role.php'); - acf_include('includes/locations/class-acf-location-user-form.php'); - acf_include('includes/locations/class-acf-location-user-role.php'); - acf_include('includes/locations/class-acf-location-taxonomy.php'); - acf_include('includes/locations/class-acf-location-attachment.php'); - acf_include('includes/locations/class-acf-location-comment.php'); - acf_include('includes/locations/class-acf-location-widget.php'); - acf_include('includes/locations/class-acf-location-nav-menu.php'); - acf_include('includes/locations/class-acf-location-nav-menu-item.php'); - - /** - * Fires after location types have been included. - * - * @date 28/09/13 - * @since 5.0.0 - * - * @param int $major_version The major version of ACF. - */ - do_action( 'acf/include_location_rules', ACF_MAJOR_VERSION ); - - /** - * Fires during initialization. Used to add local fields. - * - * @date 28/09/13 - * @since 5.0.0 - * - * @param int $major_version The major version of ACF. - */ - do_action( 'acf/include_fields', ACF_MAJOR_VERSION ); - - /** - * Fires after ACF is completely "initialized". - * - * @date 28/09/13 - * @since 5.0.0 - * - * @param int $major_version The major version of ACF. - */ - do_action( 'acf/init', ACF_MAJOR_VERSION ); - } - - /** - * register_post_types - * - * Registers the ACF post types. - * - * @date 22/10/2015 - * @since 5.3.2 - * - * @param void - * @return void - */ - function register_post_types() { - - // Vars. - $cap = acf_get_setting('capability'); - - // Register the Field Group post type. - register_post_type('acf-field-group', array( - 'labels' => array( - 'name' => __( 'Field Groups', 'acf' ), - 'singular_name' => __( 'Field Group', 'acf' ), - 'add_new' => __( 'Add New' , 'acf' ), - 'add_new_item' => __( 'Add New Field Group' , 'acf' ), - 'edit_item' => __( 'Edit Field Group' , 'acf' ), - 'new_item' => __( 'New Field Group' , 'acf' ), - 'view_item' => __( 'View Field Group', 'acf' ), - 'search_items' => __( 'Search Field Groups', 'acf' ), - 'not_found' => __( 'No Field Groups found', 'acf' ), - 'not_found_in_trash' => __( 'No Field Groups found in Trash', 'acf' ), - ), - 'public' => false, - 'hierarchical' => true, - 'show_ui' => true, - 'show_in_menu' => false, - '_builtin' => false, - 'capability_type' => 'post', - 'capabilities' => array( - 'edit_post' => $cap, - 'delete_post' => $cap, - 'edit_posts' => $cap, - 'delete_posts' => $cap, - ), - 'supports' => array('title'), - 'rewrite' => false, - 'query_var' => false, - )); - - - // Register the Field post type. - register_post_type('acf-field', array( - 'labels' => array( - 'name' => __( 'Fields', 'acf' ), - 'singular_name' => __( 'Field', 'acf' ), - 'add_new' => __( 'Add New' , 'acf' ), - 'add_new_item' => __( 'Add New Field' , 'acf' ), - 'edit_item' => __( 'Edit Field' , 'acf' ), - 'new_item' => __( 'New Field' , 'acf' ), - 'view_item' => __( 'View Field', 'acf' ), - 'search_items' => __( 'Search Fields', 'acf' ), - 'not_found' => __( 'No Fields found', 'acf' ), - 'not_found_in_trash' => __( 'No Fields found in Trash', 'acf' ), - ), - 'public' => false, - 'hierarchical' => true, - 'show_ui' => false, - 'show_in_menu' => false, - '_builtin' => false, - 'capability_type' => 'post', - 'capabilities' => array( - 'edit_post' => $cap, - 'delete_post' => $cap, - 'edit_posts' => $cap, - 'delete_posts' => $cap, - ), - 'supports' => array('title'), - 'rewrite' => false, - 'query_var' => false, - )); - } - - /** - * register_post_status - * - * Registers the ACF post statuses. - * - * @date 22/10/2015 - * @since 5.3.2 - * - * @param void - * @return void - */ - function register_post_status() { - - // Register the Disabled post status. - register_post_status('acf-disabled', array( - 'label' => _x( 'Disabled', 'post status', 'acf' ), - 'public' => true, - 'exclude_from_search' => false, - 'show_in_admin_all_list' => true, - 'show_in_admin_status_list' => true, - 'label_count' => _n_noop( 'Disabled (%s)', 'Disabled (%s)', 'acf' ), - )); - } - - /** - * posts_where - * - * Filters the $where clause allowing for custom WP_Query args. - * - * @date 31/8/19 - * @since 5.8.1 - * - * @param string $where The WHERE clause. - * @return WP_Query $wp_query The query object. - */ - function posts_where( $where, $wp_query ) { - global $wpdb; - - // Add custom "acf_field_key" arg. - if( $field_key = $wp_query->get('acf_field_key') ) { - $where .= $wpdb->prepare(" AND {$wpdb->posts}.post_name = %s", $field_key ); - } - - // Add custom "acf_field_name" arg. - if( $field_name = $wp_query->get('acf_field_name') ) { - $where .= $wpdb->prepare(" AND {$wpdb->posts}.post_excerpt = %s", $field_name ); - } - - // Add custom "acf_group_key" arg. - if( $group_key = $wp_query->get('acf_group_key') ) { - $where .= $wpdb->prepare(" AND {$wpdb->posts}.post_name = %s", $group_key ); - } - - // Return. - return $where; - } - - /** - * define - * - * Defines a constant if doesnt already exist. - * - * @date 3/5/17 - * @since 5.5.13 - * - * @param string $name The constant name. - * @param mixed $value The constant value. - * @return void - */ - function define( $name, $value = true ) { - if( !defined($name) ) { - define( $name, $value ); - } - } - - /** - * has_setting - * - * Returns true if a setting exists for this name. - * - * @date 2/2/18 - * @since 5.6.5 - * - * @param string $name The setting name. - * @return boolean - */ - function has_setting( $name ) { - return isset($this->settings[ $name ]); - } - - /** - * get_setting - * - * Returns a setting or null if doesn't exist. - * - * @date 28/09/13 - * @since 5.0.0 - * - * @param string $name The setting name. - * @return mixed - */ - function get_setting( $name ) { - return isset($this->settings[ $name ]) ? $this->settings[ $name ] : null; - } - - /** - * update_setting - * - * Updates a setting for the given name and value. - * - * @date 28/09/13 - * @since 5.0.0 - * - * @param string $name The setting name. - * @param mixed $value The setting value. - * @return true - */ - function update_setting( $name, $value ) { - $this->settings[ $name ] = $value; - return true; - } - - /** - * get_data - * - * Returns data or null if doesn't exist. - * - * @date 28/09/13 - * @since 5.0.0 - * - * @param string $name The data name. - * @return mixed - */ - function get_data( $name ) { - return isset($this->data[ $name ]) ? $this->data[ $name ] : null; - } - - /** - * set_data - * - * Sets data for the given name and value. - * - * @date 28/09/13 - * @since 5.0.0 - * - * @param string $name The data name. - * @param mixed $value The data value. - * @return void - */ - function set_data( $name, $value ) { - $this->data[ $name ] = $value; - } - - /** - * get_instance - * - * Returns an instance or null if doesn't exist. - * - * @date 13/2/18 - * @since 5.6.9 - * - * @param string $class The instance class name. - * @return object - */ - function get_instance( $class ) { - $name = strtolower($class); - return isset($this->instances[ $name ]) ? $this->instances[ $name ] : null; - } - - /** - * new_instance - * - * Creates and stores an instance of the given class. - * - * @date 13/2/18 - * @since 5.6.9 - * - * @param string $class The instance class name. - * @return object - */ - function new_instance( $class ) { - $instance = new $class(); - $name = strtolower($class); - $this->instances[ $name ] = $instance; - return $instance; - } - - /** - * Magic __isset method for backwards compatibility. - * - * @date 24/4/20 - * @since 5.9.0 - * - * @param string $key Key name. - * @return bool - */ - public function __isset( $key ) { - return in_array( $key, array( 'locations', 'json' ) ); - } - - /** - * Magic __get method for backwards compatibility. - * - * @date 24/4/20 - * @since 5.9.0 - * - * @param string $key Key name. - * @return mixed - */ - public function __get( $key ) { - switch ( $key ) { - case 'locations': - return acf_get_instance( 'ACF_Legacy_Locations' ); - case 'json': - return acf_get_instance( 'ACF_Local_JSON' ); - } - return null; - } +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly } -/* - * acf - * - * The main function responsible for returning the one true acf Instance to functions everywhere. - * Use this function like you would a global variable, except without needing to declare the global. - * - * Example: - * - * @date 4/09/13 - * @since 4.3.0 - * - * @param void - * @return ACF - */ -function acf() { - global $acf; - - // Instantiate only once. - if( !isset($acf) ) { - $acf = new ACF(); - $acf->initialize(); - } - return $acf; -} +if ( ! class_exists( 'ACF' ) ) : -// Instantiate. -acf(); + class ACF { + + /** @var string The plugin version number. */ + var $version = '5.10.2'; + + /** @var array The plugin settings array. */ + var $settings = array(); + + /** @var array The plugin data array. */ + var $data = array(); + + /** @var array Storage for class instances. */ + var $instances = array(); + + /** + * __construct + * + * A dummy constructor to ensure ACF is only setup once. + * + * @date 23/06/12 + * @since 5.0.0 + * + * @param void + * @return void + */ + function __construct() { + // Do nothing. + } + + /** + * initialize + * + * Sets up the ACF plugin. + * + * @date 28/09/13 + * @since 5.0.0 + * + * @param void + * @return void + */ + function initialize() { + + // Define constants. + $this->define( 'ACF', true ); + $this->define( 'ACF_PATH', plugin_dir_path( __FILE__ ) ); + $this->define( 'ACF_BASENAME', plugin_basename( __FILE__ ) ); + $this->define( 'ACF_VERSION', $this->version ); + $this->define( 'ACF_MAJOR_VERSION', 5 ); + + // Define settings. + $this->settings = array( + 'name' => __( 'Advanced Custom Fields', 'acf' ), + 'slug' => dirname( ACF_BASENAME ), + 'version' => ACF_VERSION, + 'basename' => ACF_BASENAME, + 'path' => ACF_PATH, + 'file' => __FILE__, + 'url' => plugin_dir_url( __FILE__ ), + 'show_admin' => true, + 'show_updates' => true, + 'stripslashes' => false, + 'local' => true, + 'json' => true, + 'save_json' => '', + 'load_json' => array(), + 'default_language' => '', + 'current_language' => '', + 'capability' => 'manage_options', + 'uploader' => 'wp', + 'autoload' => false, + 'l10n' => true, + 'l10n_textdomain' => '', + 'google_api_key' => '', + 'google_api_client' => '', + 'enqueue_google_maps' => true, + 'enqueue_select2' => true, + 'enqueue_datepicker' => true, + 'enqueue_datetimepicker' => true, + 'select2_version' => 4, + 'row_index_offset' => 1, + 'remove_wp_meta_box' => true, + ); + + // Include utility functions. + include_once ACF_PATH . 'includes/acf-utility-functions.php'; + + // Include previous API functions. + acf_include( 'includes/api/api-helpers.php' ); + acf_include( 'includes/api/api-template.php' ); + acf_include( 'includes/api/api-term.php' ); + + // Include classes. + acf_include( 'includes/class-acf-data.php' ); + acf_include( 'includes/fields/class-acf-field.php' ); + acf_include( 'includes/locations/abstract-acf-legacy-location.php' ); + acf_include( 'includes/locations/abstract-acf-location.php' ); + + // Include functions. + acf_include( 'includes/acf-helper-functions.php' ); + acf_include( 'includes/acf-hook-functions.php' ); + acf_include( 'includes/acf-field-functions.php' ); + acf_include( 'includes/acf-field-group-functions.php' ); + acf_include( 'includes/acf-form-functions.php' ); + acf_include( 'includes/acf-meta-functions.php' ); + acf_include( 'includes/acf-post-functions.php' ); + acf_include( 'includes/acf-user-functions.php' ); + acf_include( 'includes/acf-value-functions.php' ); + acf_include( 'includes/acf-input-functions.php' ); + acf_include( 'includes/acf-wp-functions.php' ); + + // Include core. + acf_include( 'includes/fields.php' ); + acf_include( 'includes/locations.php' ); + acf_include( 'includes/assets.php' ); + acf_include( 'includes/compatibility.php' ); + acf_include( 'includes/deprecated.php' ); + acf_include( 'includes/l10n.php' ); + acf_include( 'includes/local-fields.php' ); + acf_include( 'includes/local-meta.php' ); + acf_include( 'includes/local-json.php' ); + acf_include( 'includes/loop.php' ); + acf_include( 'includes/media.php' ); + acf_include( 'includes/revisions.php' ); + acf_include( 'includes/updates.php' ); + acf_include( 'includes/upgrades.php' ); + acf_include( 'includes/validation.php' ); + + // Include ajax. + acf_include( 'includes/ajax/class-acf-ajax.php' ); + acf_include( 'includes/ajax/class-acf-ajax-check-screen.php' ); + acf_include( 'includes/ajax/class-acf-ajax-user-setting.php' ); + acf_include( 'includes/ajax/class-acf-ajax-upgrade.php' ); + acf_include( 'includes/ajax/class-acf-ajax-query.php' ); + acf_include( 'includes/ajax/class-acf-ajax-query-users.php' ); + acf_include( 'includes/ajax/class-acf-ajax-local-json-diff.php' ); + + // Include forms. + acf_include( 'includes/forms/form-attachment.php' ); + acf_include( 'includes/forms/form-comment.php' ); + acf_include( 'includes/forms/form-customizer.php' ); + acf_include( 'includes/forms/form-front.php' ); + acf_include( 'includes/forms/form-nav-menu.php' ); + acf_include( 'includes/forms/form-post.php' ); + acf_include( 'includes/forms/form-gutenberg.php' ); + acf_include( 'includes/forms/form-taxonomy.php' ); + acf_include( 'includes/forms/form-user.php' ); + acf_include( 'includes/forms/form-widget.php' ); + + // Include admin. + if ( is_admin() ) { + acf_include( 'includes/admin/admin.php' ); + acf_include( 'includes/admin/admin-field-group.php' ); + acf_include( 'includes/admin/admin-field-groups.php' ); + acf_include( 'includes/admin/admin-notices.php' ); + acf_include( 'includes/admin/admin-tools.php' ); + acf_include( 'includes/admin/admin-upgrade.php' ); + } + + // Include legacy. + acf_include( 'includes/legacy/legacy-locations.php' ); + + // Include PRO. + acf_include( 'pro/acf-pro.php' ); + + // Include tests. + if ( defined( 'ACF_DEV' ) && ACF_DEV ) { + acf_include( 'tests/tests.php' ); + } + + // Add actions. + add_action( 'init', array( $this, 'init' ), 5 ); + add_action( 'init', array( $this, 'register_post_types' ), 5 ); + add_action( 'init', array( $this, 'register_post_status' ), 5 ); + + // Add filters. + add_filter( 'posts_where', array( $this, 'posts_where' ), 10, 2 ); + } + + /** + * init + * + * Completes the setup process on "init" of earlier. + * + * @date 28/09/13 + * @since 5.0.0 + * + * @param void + * @return void + */ + function init() { + + // Bail early if called directly from functions.php or plugin file. + if ( ! did_action( 'plugins_loaded' ) ) { + return; + } + + // This function may be called directly from template functions. Bail early if already did this. + if ( acf_did( 'init' ) ) { + return; + } + + // Update url setting. Allows other plugins to modify the URL (force SSL). + acf_update_setting( 'url', plugin_dir_url( __FILE__ ) ); + + // Load textdomain file. + acf_load_textdomain(); + + // Include 3rd party compatiblity. + acf_include( 'includes/third-party.php' ); + + // Include wpml support. + if ( defined( 'ICL_SITEPRESS_VERSION' ) ) { + acf_include( 'includes/wpml.php' ); + } + + // Include fields. + acf_include( 'includes/fields/class-acf-field-text.php' ); + acf_include( 'includes/fields/class-acf-field-textarea.php' ); + acf_include( 'includes/fields/class-acf-field-number.php' ); + acf_include( 'includes/fields/class-acf-field-range.php' ); + acf_include( 'includes/fields/class-acf-field-email.php' ); + acf_include( 'includes/fields/class-acf-field-url.php' ); + acf_include( 'includes/fields/class-acf-field-password.php' ); + acf_include( 'includes/fields/class-acf-field-image.php' ); + acf_include( 'includes/fields/class-acf-field-file.php' ); + acf_include( 'includes/fields/class-acf-field-wysiwyg.php' ); + acf_include( 'includes/fields/class-acf-field-oembed.php' ); + acf_include( 'includes/fields/class-acf-field-select.php' ); + acf_include( 'includes/fields/class-acf-field-checkbox.php' ); + acf_include( 'includes/fields/class-acf-field-radio.php' ); + acf_include( 'includes/fields/class-acf-field-button-group.php' ); + acf_include( 'includes/fields/class-acf-field-true_false.php' ); + acf_include( 'includes/fields/class-acf-field-link.php' ); + acf_include( 'includes/fields/class-acf-field-post_object.php' ); + acf_include( 'includes/fields/class-acf-field-page_link.php' ); + acf_include( 'includes/fields/class-acf-field-relationship.php' ); + acf_include( 'includes/fields/class-acf-field-taxonomy.php' ); + acf_include( 'includes/fields/class-acf-field-user.php' ); + acf_include( 'includes/fields/class-acf-field-google-map.php' ); + acf_include( 'includes/fields/class-acf-field-date_picker.php' ); + acf_include( 'includes/fields/class-acf-field-date_time_picker.php' ); + acf_include( 'includes/fields/class-acf-field-time_picker.php' ); + acf_include( 'includes/fields/class-acf-field-color_picker.php' ); + acf_include( 'includes/fields/class-acf-field-message.php' ); + acf_include( 'includes/fields/class-acf-field-accordion.php' ); + acf_include( 'includes/fields/class-acf-field-tab.php' ); + acf_include( 'includes/fields/class-acf-field-group.php' ); + + /** + * Fires after field types have been included. + * + * @date 28/09/13 + * @since 5.0.0 + * + * @param int $major_version The major version of ACF. + */ + do_action( 'acf/include_field_types', ACF_MAJOR_VERSION ); + + // Include locations. + acf_include( 'includes/locations/class-acf-location-post-type.php' ); + acf_include( 'includes/locations/class-acf-location-post-template.php' ); + acf_include( 'includes/locations/class-acf-location-post-status.php' ); + acf_include( 'includes/locations/class-acf-location-post-format.php' ); + acf_include( 'includes/locations/class-acf-location-post-category.php' ); + acf_include( 'includes/locations/class-acf-location-post-taxonomy.php' ); + acf_include( 'includes/locations/class-acf-location-post.php' ); + acf_include( 'includes/locations/class-acf-location-page-template.php' ); + acf_include( 'includes/locations/class-acf-location-page-type.php' ); + acf_include( 'includes/locations/class-acf-location-page-parent.php' ); + acf_include( 'includes/locations/class-acf-location-page.php' ); + acf_include( 'includes/locations/class-acf-location-current-user.php' ); + acf_include( 'includes/locations/class-acf-location-current-user-role.php' ); + acf_include( 'includes/locations/class-acf-location-user-form.php' ); + acf_include( 'includes/locations/class-acf-location-user-role.php' ); + acf_include( 'includes/locations/class-acf-location-taxonomy.php' ); + acf_include( 'includes/locations/class-acf-location-attachment.php' ); + acf_include( 'includes/locations/class-acf-location-comment.php' ); + acf_include( 'includes/locations/class-acf-location-widget.php' ); + acf_include( 'includes/locations/class-acf-location-nav-menu.php' ); + acf_include( 'includes/locations/class-acf-location-nav-menu-item.php' ); + + /** + * Fires after location types have been included. + * + * @date 28/09/13 + * @since 5.0.0 + * + * @param int $major_version The major version of ACF. + */ + do_action( 'acf/include_location_rules', ACF_MAJOR_VERSION ); + + /** + * Fires during initialization. Used to add local fields. + * + * @date 28/09/13 + * @since 5.0.0 + * + * @param int $major_version The major version of ACF. + */ + do_action( 'acf/include_fields', ACF_MAJOR_VERSION ); + + /** + * Fires after ACF is completely "initialized". + * + * @date 28/09/13 + * @since 5.0.0 + * + * @param int $major_version The major version of ACF. + */ + do_action( 'acf/init', ACF_MAJOR_VERSION ); + } + + /** + * register_post_types + * + * Registers the ACF post types. + * + * @date 22/10/2015 + * @since 5.3.2 + * + * @param void + * @return void + */ + function register_post_types() { + + // Vars. + $cap = acf_get_setting( 'capability' ); + + // Register the Field Group post type. + register_post_type( + 'acf-field-group', + array( + 'labels' => array( + 'name' => __( 'Field Groups', 'acf' ), + 'singular_name' => __( 'Field Group', 'acf' ), + 'add_new' => __( 'Add New', 'acf' ), + 'add_new_item' => __( 'Add New Field Group', 'acf' ), + 'edit_item' => __( 'Edit Field Group', 'acf' ), + 'new_item' => __( 'New Field Group', 'acf' ), + 'view_item' => __( 'View Field Group', 'acf' ), + 'search_items' => __( 'Search Field Groups', 'acf' ), + 'not_found' => __( 'No Field Groups found', 'acf' ), + 'not_found_in_trash' => __( 'No Field Groups found in Trash', 'acf' ), + ), + 'public' => false, + 'hierarchical' => true, + 'show_ui' => true, + 'show_in_menu' => false, + '_builtin' => false, + 'capability_type' => 'post', + 'capabilities' => array( + 'edit_post' => $cap, + 'delete_post' => $cap, + 'edit_posts' => $cap, + 'delete_posts' => $cap, + ), + 'supports' => array( 'title' ), + 'rewrite' => false, + 'query_var' => false, + ) + ); + + // Register the Field post type. + register_post_type( + 'acf-field', + array( + 'labels' => array( + 'name' => __( 'Fields', 'acf' ), + 'singular_name' => __( 'Field', 'acf' ), + 'add_new' => __( 'Add New', 'acf' ), + 'add_new_item' => __( 'Add New Field', 'acf' ), + 'edit_item' => __( 'Edit Field', 'acf' ), + 'new_item' => __( 'New Field', 'acf' ), + 'view_item' => __( 'View Field', 'acf' ), + 'search_items' => __( 'Search Fields', 'acf' ), + 'not_found' => __( 'No Fields found', 'acf' ), + 'not_found_in_trash' => __( 'No Fields found in Trash', 'acf' ), + ), + 'public' => false, + 'hierarchical' => true, + 'show_ui' => false, + 'show_in_menu' => false, + '_builtin' => false, + 'capability_type' => 'post', + 'capabilities' => array( + 'edit_post' => $cap, + 'delete_post' => $cap, + 'edit_posts' => $cap, + 'delete_posts' => $cap, + ), + 'supports' => array( 'title' ), + 'rewrite' => false, + 'query_var' => false, + ) + ); + } + + /** + * register_post_status + * + * Registers the ACF post statuses. + * + * @date 22/10/2015 + * @since 5.3.2 + * + * @param void + * @return void + */ + function register_post_status() { + + // Register the Disabled post status. + register_post_status( + 'acf-disabled', + array( + 'label' => _x( 'Disabled', 'post status', 'acf' ), + 'public' => true, + 'exclude_from_search' => false, + 'show_in_admin_all_list' => true, + 'show_in_admin_status_list' => true, + 'label_count' => _n_noop( 'Disabled (%s)', 'Disabled (%s)', 'acf' ), + ) + ); + } + + /** + * posts_where + * + * Filters the $where clause allowing for custom WP_Query args. + * + * @date 31/8/19 + * @since 5.8.1 + * + * @param string $where The WHERE clause. + * @return WP_Query $wp_query The query object. + */ + function posts_where( $where, $wp_query ) { + global $wpdb; + + // Add custom "acf_field_key" arg. + if ( $field_key = $wp_query->get( 'acf_field_key' ) ) { + $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $field_key ); + } + + // Add custom "acf_field_name" arg. + if ( $field_name = $wp_query->get( 'acf_field_name' ) ) { + $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_excerpt = %s", $field_name ); + } + + // Add custom "acf_group_key" arg. + if ( $group_key = $wp_query->get( 'acf_group_key' ) ) { + $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $group_key ); + } + + // Return. + return $where; + } + + /** + * define + * + * Defines a constant if doesnt already exist. + * + * @date 3/5/17 + * @since 5.5.13 + * + * @param string $name The constant name. + * @param mixed $value The constant value. + * @return void + */ + function define( $name, $value = true ) { + if ( ! defined( $name ) ) { + define( $name, $value ); + } + } + + /** + * has_setting + * + * Returns true if a setting exists for this name. + * + * @date 2/2/18 + * @since 5.6.5 + * + * @param string $name The setting name. + * @return boolean + */ + function has_setting( $name ) { + return isset( $this->settings[ $name ] ); + } + + /** + * get_setting + * + * Returns a setting or null if doesn't exist. + * + * @date 28/09/13 + * @since 5.0.0 + * + * @param string $name The setting name. + * @return mixed + */ + function get_setting( $name ) { + return isset( $this->settings[ $name ] ) ? $this->settings[ $name ] : null; + } + + /** + * update_setting + * + * Updates a setting for the given name and value. + * + * @date 28/09/13 + * @since 5.0.0 + * + * @param string $name The setting name. + * @param mixed $value The setting value. + * @return true + */ + function update_setting( $name, $value ) { + $this->settings[ $name ] = $value; + return true; + } + + /** + * get_data + * + * Returns data or null if doesn't exist. + * + * @date 28/09/13 + * @since 5.0.0 + * + * @param string $name The data name. + * @return mixed + */ + function get_data( $name ) { + return isset( $this->data[ $name ] ) ? $this->data[ $name ] : null; + } + + /** + * set_data + * + * Sets data for the given name and value. + * + * @date 28/09/13 + * @since 5.0.0 + * + * @param string $name The data name. + * @param mixed $value The data value. + * @return void + */ + function set_data( $name, $value ) { + $this->data[ $name ] = $value; + } + + /** + * get_instance + * + * Returns an instance or null if doesn't exist. + * + * @date 13/2/18 + * @since 5.6.9 + * + * @param string $class The instance class name. + * @return object + */ + function get_instance( $class ) { + $name = strtolower( $class ); + return isset( $this->instances[ $name ] ) ? $this->instances[ $name ] : null; + } + + /** + * new_instance + * + * Creates and stores an instance of the given class. + * + * @date 13/2/18 + * @since 5.6.9 + * + * @param string $class The instance class name. + * @return object + */ + function new_instance( $class ) { + $instance = new $class(); + $name = strtolower( $class ); + $this->instances[ $name ] = $instance; + return $instance; + } + + /** + * Magic __isset method for backwards compatibility. + * + * @date 24/4/20 + * @since 5.9.0 + * + * @param string $key Key name. + * @return bool + */ + public function __isset( $key ) { + return in_array( $key, array( 'locations', 'json' ) ); + } + + /** + * Magic __get method for backwards compatibility. + * + * @date 24/4/20 + * @since 5.9.0 + * + * @param string $key Key name. + * @return mixed + */ + public function __get( $key ) { + switch ( $key ) { + case 'locations': + return acf_get_instance( 'ACF_Legacy_Locations' ); + case 'json': + return acf_get_instance( 'ACF_Local_JSON' ); + } + return null; + } + } + + /* + * acf + * + * The main function responsible for returning the one true acf Instance to functions everywhere. + * Use this function like you would a global variable, except without needing to declare the global. + * + * Example: + * + * @date 4/09/13 + * @since 4.3.0 + * + * @param void + * @return ACF + */ + function acf() { + global $acf; + + // Instantiate only once. + if ( ! isset( $acf ) ) { + $acf = new ACF(); + $acf->initialize(); + } + return $acf; + } + + // Instantiate. + acf(); endif; // class_exists check diff --git a/assets/build/css/acf-field-group.css b/assets/build/css/acf-field-group.css index d0afe76..7ba8696 100644 --- a/assets/build/css/acf-field-group.css +++ b/assets/build/css/acf-field-group.css @@ -255,7 +255,6 @@ } .rule-groups .rule-group { margin: 0 0 5px; - /* Don't allow user to delete the first field group */ } .rule-groups .rule-group h4 { margin: 0 0 3px; @@ -279,12 +278,13 @@ .rule-groups .rule-group tr:hover td.remove a { visibility: visible; } -.rule-groups .rule-group:first-child tr:first-child td.remove a { - visibility: hidden !important; -} .rule-groups .rule-group select:empty { background: #f8f8f8; } +.rule-groups:not(.rule-groups-multiple) .rule-group:first-child tr:first-child td.remove a { + /* Don't allow user to delete the only rule group */ + visibility: hidden !important; +} /*--------------------------------------------------------------------------------------------- * diff --git a/assets/build/css/acf-field-group.min.css b/assets/build/css/acf-field-group.min.css index 0484ca2..292cee4 100644 --- a/assets/build/css/acf-field-group.min.css +++ b/assets/build/css/acf-field-group.min.css @@ -1 +1 @@ -#acf-field-group-fields>.inside,#acf-field-group-locations>.inside,#acf-field-group-options>.inside{padding:0;margin:0}.postbox .handle-order-higher,.postbox .handle-order-lower{display:none}#minor-publishing-actions,#misc-publishing-actions #visibility,#misc-publishing-actions .edit-timestamp{display:none}#minor-publishing{border-bottom:0 none}#misc-pub-section{border-bottom:0 none}#misc-publishing-actions .misc-pub-section{border-bottom-color:#f5f5f5}#acf-field-group-fields{border:0 none;box-shadow:none}#acf-field-group-fields>.handlediv,#acf-field-group-fields>.hndle,#acf-field-group-fields>.postbox-header{display:none}#acf-field-group-fields a{text-decoration:none}#acf-field-group-fields a:active,#acf-field-group-fields a:focus{outline:0;box-shadow:none}#acf-field-group-fields .li-field-order{width:20%}#acf-field-group-fields .li-field-label{width:30%}#acf-field-group-fields .li-field-name{width:25%}#acf-field-group-fields .li-field-type{width:25%}#acf-field-group-fields .li-field-key{display:none}#acf-field-group-fields.show-field-keys .li-field-key,#acf-field-group-fields.show-field-keys .li-field-label,#acf-field-group-fields.show-field-keys .li-field-name,#acf-field-group-fields.show-field-keys .li-field-type{width:20%}#acf-field-group-fields.show-field-keys .li-field-key{display:block}#acf-field-group-fields .acf-field-list-wrap{border:#ccd0d4 solid 1px}#acf-field-group-fields .acf-field-list{background:#f5f5f5;margin-top:-1px}#acf-field-group-fields .acf-field-list .no-fields-message{padding:15px 15px;background:#fff;display:none}#acf-field-group-fields .acf-field-list.-empty .no-fields-message{display:block}.acf-admin-3-8 #acf-field-group-fields .acf-field-list-wrap{border-color:#dfdfdf}.acf-field-object{border-top:#eee solid 1px;background:#fff}.acf-field-object.ui-sortable-helper{border-top-color:#fff;box-shadow:0 0 0 1px #dfdfdf,0 1px 4px rgba(0,0,0,.1)}.acf-field-object.ui-sortable-placeholder{box-shadow:0 -1px 0 0 #dfdfdf;visibility:visible!important;background:#f9f9f9;border-top-color:transparent;min-height:54px}.acf-field-object.ui-sortable-placeholder:after,.acf-field-object.ui-sortable-placeholder:before{visibility:hidden}.acf-field-object>.meta{display:none}.acf-field-object>.handle a{-webkit-transition:none;-moz-transition:none;-o-transition:none;transition:none}.acf-field-object>.handle li{padding-top:10px;padding-bottom:10px;word-wrap:break-word}.acf-field-object>.handle .acf-icon{margin:1px 0 0;cursor:move;background:0 0;float:left;height:28px;line-height:26px;width:28px;font-size:13px;color:#444;position:relative;z-index:1}.acf-field-object>.handle strong{display:block;padding-bottom:6px;font-size:14px;line-height:14px;min-height:14px}.acf-field-object>.handle .row-options{visibility:hidden}.acf-field-object>.handle .row-options a{margin-right:4px}.acf-field-object>.handle .row-options a.delete-field{color:#a00}.acf-field-object>.handle .row-options a.delete-field:hover{color:red}.acf-field-object.open+.acf-field-object{border-top-color:#e1e1e1}.acf-field-object.open>.handle{background:#2a9bd9;border:#2696d3 solid 1px;text-shadow:#268fbb 0 1px 0;color:#fff;position:relative;margin:-1px -1px 0 -1px}.acf-field-object.open>.handle a{color:#fff!important}.acf-field-object.open>.handle a:hover{text-decoration:underline!important}.acf-field-object.open>.handle .acf-icon{border-color:#fff;color:#fff}.acf-field-object.open>.handle .acf-required{color:#fff}.acf-field-object.-hover>.handle .row-options,.acf-field-object:hover>.handle .row-options{visibility:visible}.acf-field-object>.settings{display:none;width:100%}.acf-field-object>.settings>.acf-table{border:none}.acf-field-object .rule-groups{margin-top:20px}.rule-groups h4{margin:3px 0}.rule-groups .rule-group{margin:0 0 5px}.rule-groups .rule-group h4{margin:0 0 3px}.rule-groups .rule-group td.param{width:35%}.rule-groups .rule-group td.operator{width:20%}.rule-groups .rule-group td.add{width:40px}.rule-groups .rule-group td.remove{width:28px;vertical-align:middle}.rule-groups .rule-group td.remove a{visibility:hidden}.rule-groups .rule-group tr:hover td.remove a{visibility:visible}.rule-groups .rule-group:first-child tr:first-child td.remove a{visibility:hidden!important}.rule-groups .rule-group select:empty{background:#f8f8f8}#acf-field-group-options tr[data-name=hide_on_screen] li{float:left;width:33%}@media (max-width:1100px){#acf-field-group-options tr[data-name=hide_on_screen] li{width:50%}}table.conditional-logic-rules{background:0 0;border:0 none;border-radius:0}table.conditional-logic-rules tbody td{background:0 0;border:0 none!important;padding:5px 2px!important}.acf-field-object-accordion .acf-field-setting-instructions,.acf-field-object-accordion .acf-field-setting-name,.acf-field-object-accordion .acf-field-setting-required,.acf-field-object-accordion .acf-field-setting-warning,.acf-field-object-accordion .acf-field-setting-wrapper,.acf-field-object-tab .acf-field-setting-instructions,.acf-field-object-tab .acf-field-setting-name,.acf-field-object-tab .acf-field-setting-required,.acf-field-object-tab .acf-field-setting-warning,.acf-field-object-tab .acf-field-setting-wrapper{display:none}.acf-field-object-accordion .li-field-name,.acf-field-object-tab .li-field-name{visibility:hidden}.acf-field-object+.acf-field-object-accordion:before,.acf-field-object+.acf-field-object-tab:before{display:block;content:"";height:5px;width:100%;background:#f5f5f5;border-top:#e1e1e1 solid 1px;border-bottom:#e1e1e1 solid 1px;margin-top:-1px}.acf-admin-3-8 .acf-field-object+.acf-field-object-accordion:before,.acf-admin-3-8 .acf-field-object+.acf-field-object-tab:before{border-color:#e5e5e5}.acf-field-object-accordion p:first-child,.acf-field-object-tab p:first-child{margin:.5em 0}.acf-field-object-accordion .acf-field-setting-instructions{display:table-row}.acf-field-object-message tr[data-name=instructions],.acf-field-object-message tr[data-name=name],.acf-field-object-message tr[data-name=required]{display:none!important}.acf-field-object-message .li-field-name{visibility:hidden}.acf-field-object-message textarea{height:175px!important}.acf-field-object-separator tr[data-name=instructions],.acf-field-object-separator tr[data-name=name],.acf-field-object-separator tr[data-name=required]{display:none!important}.acf-field-object-date-picker .acf-radio-list li,.acf-field-object-date-time-picker .acf-radio-list li,.acf-field-object-time-picker .acf-radio-list li{line-height:25px}.acf-field-object-date-picker .acf-radio-list span,.acf-field-object-date-time-picker .acf-radio-list span,.acf-field-object-time-picker .acf-radio-list span{display:inline-block;min-width:10em}.acf-field-object-date-picker .acf-radio-list input[type=text],.acf-field-object-date-time-picker .acf-radio-list input[type=text],.acf-field-object-time-picker .acf-radio-list input[type=text]{width:100px}.acf-field-object-date-time-picker .acf-radio-list span{min-width:15em}.acf-field-object-date-time-picker .acf-radio-list input[type=text]{width:200px}#slugdiv .inside{padding:12px;margin:0}#slugdiv input[type=text]{width:100%;height:28px;font-size:14px}html[dir=rtl] .acf-field-object.open>.handle{margin:-1px -1px 0}html[dir=rtl] .acf-field-object.open>.handle .acf-icon{float:right}html[dir=rtl] .acf-field-object.open>.handle .li-field-order{padding-left:0!important;padding-right:15px!important}@media only screen and (max-width:850px){td.acf-input,td.acf-label,tr.acf-field{display:block!important;width:auto!important;border:0 none!important}tr.acf-field{border-top:#ededed solid 1px!important;margin-bottom:0!important}td.acf-label{background:0 0!important;padding-bottom:0!important}} \ No newline at end of file +#acf-field-group-fields>.inside,#acf-field-group-locations>.inside,#acf-field-group-options>.inside{padding:0;margin:0}.postbox .handle-order-higher,.postbox .handle-order-lower{display:none}#minor-publishing-actions,#misc-publishing-actions #visibility,#misc-publishing-actions .edit-timestamp{display:none}#minor-publishing{border-bottom:0 none}#misc-pub-section{border-bottom:0 none}#misc-publishing-actions .misc-pub-section{border-bottom-color:#f5f5f5}#acf-field-group-fields{border:0 none;box-shadow:none}#acf-field-group-fields>.handlediv,#acf-field-group-fields>.hndle,#acf-field-group-fields>.postbox-header{display:none}#acf-field-group-fields a{text-decoration:none}#acf-field-group-fields a:active,#acf-field-group-fields a:focus{outline:0;box-shadow:none}#acf-field-group-fields .li-field-order{width:20%}#acf-field-group-fields .li-field-label{width:30%}#acf-field-group-fields .li-field-name{width:25%}#acf-field-group-fields .li-field-type{width:25%}#acf-field-group-fields .li-field-key{display:none}#acf-field-group-fields.show-field-keys .li-field-key,#acf-field-group-fields.show-field-keys .li-field-label,#acf-field-group-fields.show-field-keys .li-field-name,#acf-field-group-fields.show-field-keys .li-field-type{width:20%}#acf-field-group-fields.show-field-keys .li-field-key{display:block}#acf-field-group-fields .acf-field-list-wrap{border:#ccd0d4 solid 1px}#acf-field-group-fields .acf-field-list{background:#f5f5f5;margin-top:-1px}#acf-field-group-fields .acf-field-list .no-fields-message{padding:15px 15px;background:#fff;display:none}#acf-field-group-fields .acf-field-list.-empty .no-fields-message{display:block}.acf-admin-3-8 #acf-field-group-fields .acf-field-list-wrap{border-color:#dfdfdf}.acf-field-object{border-top:#eee solid 1px;background:#fff}.acf-field-object.ui-sortable-helper{border-top-color:#fff;box-shadow:0 0 0 1px #dfdfdf,0 1px 4px rgba(0,0,0,.1)}.acf-field-object.ui-sortable-placeholder{box-shadow:0 -1px 0 0 #dfdfdf;visibility:visible!important;background:#f9f9f9;border-top-color:transparent;min-height:54px}.acf-field-object.ui-sortable-placeholder:after,.acf-field-object.ui-sortable-placeholder:before{visibility:hidden}.acf-field-object>.meta{display:none}.acf-field-object>.handle a{-webkit-transition:none;-moz-transition:none;-o-transition:none;transition:none}.acf-field-object>.handle li{padding-top:10px;padding-bottom:10px;word-wrap:break-word}.acf-field-object>.handle .acf-icon{margin:1px 0 0;cursor:move;background:0 0;float:left;height:28px;line-height:26px;width:28px;font-size:13px;color:#444;position:relative;z-index:1}.acf-field-object>.handle strong{display:block;padding-bottom:6px;font-size:14px;line-height:14px;min-height:14px}.acf-field-object>.handle .row-options{visibility:hidden}.acf-field-object>.handle .row-options a{margin-right:4px}.acf-field-object>.handle .row-options a.delete-field{color:#a00}.acf-field-object>.handle .row-options a.delete-field:hover{color:red}.acf-field-object.open+.acf-field-object{border-top-color:#e1e1e1}.acf-field-object.open>.handle{background:#2a9bd9;border:#2696d3 solid 1px;text-shadow:#268fbb 0 1px 0;color:#fff;position:relative;margin:-1px -1px 0 -1px}.acf-field-object.open>.handle a{color:#fff!important}.acf-field-object.open>.handle a:hover{text-decoration:underline!important}.acf-field-object.open>.handle .acf-icon{border-color:#fff;color:#fff}.acf-field-object.open>.handle .acf-required{color:#fff}.acf-field-object.-hover>.handle .row-options,.acf-field-object:hover>.handle .row-options{visibility:visible}.acf-field-object>.settings{display:none;width:100%}.acf-field-object>.settings>.acf-table{border:none}.acf-field-object .rule-groups{margin-top:20px}.rule-groups h4{margin:3px 0}.rule-groups .rule-group{margin:0 0 5px}.rule-groups .rule-group h4{margin:0 0 3px}.rule-groups .rule-group td.param{width:35%}.rule-groups .rule-group td.operator{width:20%}.rule-groups .rule-group td.add{width:40px}.rule-groups .rule-group td.remove{width:28px;vertical-align:middle}.rule-groups .rule-group td.remove a{visibility:hidden}.rule-groups .rule-group tr:hover td.remove a{visibility:visible}.rule-groups .rule-group select:empty{background:#f8f8f8}.rule-groups:not(.rule-groups-multiple) .rule-group:first-child tr:first-child td.remove a{visibility:hidden!important}#acf-field-group-options tr[data-name=hide_on_screen] li{float:left;width:33%}@media (max-width:1100px){#acf-field-group-options tr[data-name=hide_on_screen] li{width:50%}}table.conditional-logic-rules{background:0 0;border:0 none;border-radius:0}table.conditional-logic-rules tbody td{background:0 0;border:0 none!important;padding:5px 2px!important}.acf-field-object-accordion .acf-field-setting-instructions,.acf-field-object-accordion .acf-field-setting-name,.acf-field-object-accordion .acf-field-setting-required,.acf-field-object-accordion .acf-field-setting-warning,.acf-field-object-accordion .acf-field-setting-wrapper,.acf-field-object-tab .acf-field-setting-instructions,.acf-field-object-tab .acf-field-setting-name,.acf-field-object-tab .acf-field-setting-required,.acf-field-object-tab .acf-field-setting-warning,.acf-field-object-tab .acf-field-setting-wrapper{display:none}.acf-field-object-accordion .li-field-name,.acf-field-object-tab .li-field-name{visibility:hidden}.acf-field-object+.acf-field-object-accordion:before,.acf-field-object+.acf-field-object-tab:before{display:block;content:"";height:5px;width:100%;background:#f5f5f5;border-top:#e1e1e1 solid 1px;border-bottom:#e1e1e1 solid 1px;margin-top:-1px}.acf-admin-3-8 .acf-field-object+.acf-field-object-accordion:before,.acf-admin-3-8 .acf-field-object+.acf-field-object-tab:before{border-color:#e5e5e5}.acf-field-object-accordion p:first-child,.acf-field-object-tab p:first-child{margin:.5em 0}.acf-field-object-accordion .acf-field-setting-instructions{display:table-row}.acf-field-object-message tr[data-name=instructions],.acf-field-object-message tr[data-name=name],.acf-field-object-message tr[data-name=required]{display:none!important}.acf-field-object-message .li-field-name{visibility:hidden}.acf-field-object-message textarea{height:175px!important}.acf-field-object-separator tr[data-name=instructions],.acf-field-object-separator tr[data-name=name],.acf-field-object-separator tr[data-name=required]{display:none!important}.acf-field-object-date-picker .acf-radio-list li,.acf-field-object-date-time-picker .acf-radio-list li,.acf-field-object-time-picker .acf-radio-list li{line-height:25px}.acf-field-object-date-picker .acf-radio-list span,.acf-field-object-date-time-picker .acf-radio-list span,.acf-field-object-time-picker .acf-radio-list span{display:inline-block;min-width:10em}.acf-field-object-date-picker .acf-radio-list input[type=text],.acf-field-object-date-time-picker .acf-radio-list input[type=text],.acf-field-object-time-picker .acf-radio-list input[type=text]{width:100px}.acf-field-object-date-time-picker .acf-radio-list span{min-width:15em}.acf-field-object-date-time-picker .acf-radio-list input[type=text]{width:200px}#slugdiv .inside{padding:12px;margin:0}#slugdiv input[type=text]{width:100%;height:28px;font-size:14px}html[dir=rtl] .acf-field-object.open>.handle{margin:-1px -1px 0}html[dir=rtl] .acf-field-object.open>.handle .acf-icon{float:right}html[dir=rtl] .acf-field-object.open>.handle .li-field-order{padding-left:0!important;padding-right:15px!important}@media only screen and (max-width:850px){td.acf-input,td.acf-label,tr.acf-field{display:block!important;width:auto!important;border:0 none!important}tr.acf-field{border-top:#ededed solid 1px!important;margin-bottom:0!important}td.acf-label{background:0 0!important;padding-bottom:0!important}} \ No newline at end of file diff --git a/assets/build/js/acf-field-group.js b/assets/build/js/acf-field-group.js index 50c0de6..1b0c8c2 100644 --- a/assets/build/js/acf-field-group.js +++ b/assets/build/js/acf-field-group.js @@ -1266,6 +1266,36 @@ acf.registerFieldSetting( TimePickerDisplayFormatFieldSetting ); acf.registerFieldSetting( TimePickerReturnFormatFieldSetting ); + /** + * Color Picker Settings. + * + * @date 16/12/20 + * @since 5.9.4 + * + * @param type $var Description. Default. + * @return type Description. + */ + var ColorPickerReturnFormat = acf.FieldSetting.extend({ + type: 'color_picker', + name: 'enable_opacity', + render: function(){ + var $return_format_setting = this.fieldObject.$setting('return_format'); + var $default_value_setting = this.fieldObject.$setting('default_value'); + var $labelText = $return_format_setting.find('input[type="radio"][value="string"]').parent('label').contents().last(); + var $defaultPlaceholder = $default_value_setting.find('input[type="text"]'); + var l10n = acf.get('colorPickerL10n'); + + if( this.field.val() ) { + $labelText.replaceWith( l10n.rgba_string ); + $defaultPlaceholder.attr('placeholder', 'rgba(255,255,255,0.8)'); + } else { + $labelText.replaceWith( l10n.hex_string ); + $defaultPlaceholder.attr('placeholder', '#FFFFFF'); + } + } + }); + acf.registerFieldSetting( ColorPickerReturnFormat ); + })(jQuery); (function($, undefined){ @@ -2166,6 +2196,7 @@ initialize: function(){ this.$el = $('#acf-field-group-locations'); + this.updateGroupsClass(); }, onClickAddRule: function( e, $el ){ @@ -2186,6 +2217,7 @@ addRule: function( $tr ){ acf.duplicate( $tr ); + this.updateGroupsClass(); }, removeRule: function( $tr ){ @@ -2194,6 +2226,13 @@ } else { $tr.remove(); } + + // Update h4 + var $group = this.$('.rule-group:first'); + $group.find('h4').text( acf.__('Show this field group if') ); + + + this.updateGroupsClass(); }, changeRule: function( $rule ){ @@ -2238,7 +2277,24 @@ // remove all tr's except the first one $group2.find('tr').not(':first').remove(); - } + + // update the groups class + this.updateGroupsClass(); + }, + + updateGroupsClass: function () { + var $group = this.$(".rule-group:last"); + + var $ruleGroups = $group.closest(".rule-groups"); + + var rows_count = $ruleGroups.find(".acf-table tr").length; + + if (rows_count > 1) { + $ruleGroups.addClass("rule-groups-multiple"); + } else { + $ruleGroups.removeClass("rule-groups-multiple"); + } + }, }); })(jQuery); diff --git a/assets/build/js/acf-field-group.min.js b/assets/build/js/acf-field-group.min.js index 41a03a0..d38b9cc 100644 --- a/assets/build/js/acf-field-group.min.js +++ b/assets/build/js/acf-field-group.min.js @@ -1 +1 @@ -!function(n){new acf.Model({id:"fieldGroupManager",events:{"submit #post":"onSubmit",'click a[href="#"]':"onClick","click .submitdelete":"onClickTrash"},filters:{find_fields_args:"filterFindFieldArgs"},onSubmit:function(e,t){var i=n("#titlewrap #title");i.val()||(e.preventDefault(),acf.unlockForm(t),alert(acf.__("Field group title is required")),i.trigger("focus"))},onClick:function(e){e.preventDefault()},onClickTrash:function(e){confirm(acf.__("Move to trash. Are you sure?"))||e.preventDefault()},filterFindFieldArgs:function(e){return e.visible=!0,e}}),new acf.Model({id:"screenOptionsManager",wait:"prepare",events:{change:"onChange"},initialize:function(){var e=n("#adv-settings"),t=n("#acf-append-show-on-screen");e.find(".metabox-prefs").append(t.html()),e.find(".metabox-prefs br").remove(),t.remove(),this.$el=n("#acf-field-key-hide"),this.render()},isChecked:function(){return this.$el.prop("checked")},onChange:function(e,t){var i=this.isChecked()?1:0;acf.updateUserSetting("show_field_keys",i),this.render()},render:function(){this.isChecked()?n("#acf-field-group-fields").addClass("show-field-keys"):n("#acf-field-group-fields").removeClass("show-field-keys")}}),new acf.Model({actions:{new_field:"onNewField"},onNewField:function(e){var t,i;e.has("append")&&(i=e.get("append"),(t=e.$el.siblings('[data-name="'+i+'"]').first()).length&&((t=(i=t.children(".acf-input")).children("ul")).length||(i.wrapInner(''),t=i.children("ul")),i=e.$(".acf-input").html(),i=n("
  • "+i+"
  • "),t.append(i),t.attr("data-cols",t.children().length),e.remove()))}})}(jQuery),function(r){acf.FieldObject=acf.Model.extend({eventScope:".acf-field-object",events:{"click .edit-field":"onClickEdit","click .delete-field":"onClickDelete","click .duplicate-field":"duplicate","click .move-field":"move","change .field-type":"onChangeType","change .field-required":"onChangeRequired","blur .field-label":"onChangeLabel","blur .field-name":"onChangeName",change:"onChange",changed:"onChanged"},data:{id:0,key:"",type:""},setup:function(e){this.$el=e,this.inherit(e),this.prop("ID"),this.prop("parent"),this.prop("menu_order")},$input:function(e){return r("#"+this.getInputId()+"-"+e)},$meta:function(){return this.$(".meta:first")},$handle:function(){return this.$(".handle:first")},$settings:function(){return this.$(".settings:first")},$setting:function(e){return this.$(".acf-field-settings:first > .acf-field-setting-"+e)},getParent:function(){return acf.getFieldObjects({child:this.$el,limit:1}).pop()},getParents:function(){return acf.getFieldObjects({child:this.$el})},getFields:function(){return acf.getFieldObjects({parent:this.$el})},getInputName:function(){return"acf_fields["+this.get("id")+"]"},getInputId:function(){return"acf_fields-"+this.get("id")},newInput:function(e,t){var i=this.getInputId(),n=this.getInputName();e&&(i+="-"+e,n+="["+e+"]");t=r("").attr({id:i,name:n,value:t});return this.$("> .meta").append(t),t},getProp:function(e){if(this.has(e))return this.get(e);var t=this.$input(e),t=t.length?t.val():null;return this.set(e,t,!0),t},setProp:function(e,t){var i=this.$input(e);i.val();return i.length||(i=this.newInput(e,t)),null===t?i.remove():i.val(t),this.has(e)?this.set(e,t):this.set(e,t,!0),this},prop:function(e,t){return void 0!==t?this.setProp(e,t):this.getProp(e)},props:function(t){Object.keys(t).map(function(e){this.setProp(e,t[e])},this)},getLabel:function(){var e=this.prop("label");return e=""===e?acf.__("(no label)"):e},getName:function(){return this.prop("name")},getType:function(){return this.prop("type")},getTypeLabel:function(){var e=this.prop("type"),t=acf.get("fieldTypes");return t[e]?t[e].label:e},getKey:function(){return this.prop("key")},initialize:function(){this.addProFields()},addProFields:function(){var e;acf.data.fieldTypes.hasOwnProperty("clone")||((e=r(".field-type").not(".acf-free-field-type")).find('optgroup option[value="group"]').parent().append('"),e.find('optgroup option[value="image"]').parent().append('"),e.addClass("acf-free-field-type"))},render:function(){var e=this.$(".handle:first"),t=this.prop("menu_order"),i=this.getLabel(),n=this.prop("name"),a=this.getTypeLabel(),l=this.prop("key"),o=this.$input("required").prop("checked");e.find(".acf-icon").html(parseInt(t)+1),o&&(i+=' *'),e.find(".li-field-label strong a").html(i),e.find(".li-field-name").text(n),e.find(".li-field-type").text(a),e.find(".li-field-key").text(l),acf.doAction("render_field_object",this)},refresh:function(){acf.doAction("refresh_field_object",this)},isOpen:function(){return this.$el.hasClass("open")},onClickEdit:function(e){this.isOpen()?this.close():this.open()},open:function(){var e=this.$el.children(".settings");e.slideDown(),this.$el.addClass("open"),acf.doAction("open_field_object",this),this.trigger("openFieldObject"),acf.doAction("show",e)},close:function(){var e=this.$el.children(".settings");e.slideUp(),this.$el.removeClass("open"),acf.doAction("close_field_object",this),this.trigger("closeFieldObject"),acf.doAction("hide",e)},serialize:function(){return acf.serialize(this.$el,this.getInputName())},save:function(e){e=e||"settings","settings"!==this.getProp("save")&&(this.setProp("save",e),this.$el.attr("data-save",e),acf.doAction("save_field_object",this,e))},submit:function(){var e=this.getInputName(),t=this.get("save");this.isOpen()&&this.close(),"settings"==t||("meta"==t?this.$('> .settings [name^="'+e+'"]'):this.$('[name^="'+e+'"]')).remove(),acf.doAction("submit_field_object",this)},onChange:function(e,t){this.save(),acf.doAction("change_field_object",this)},onChanged:function(e,t,i,n){"save"!=i&&(-1<["menu_order","parent"].indexOf(i)?this.save("meta"):this.save(),-1<["menu_order","label","required","name","type","key"].indexOf(i)&&this.render(),acf.doAction("change_field_object_"+i,this,n))},onChangeLabel:function(e,t){t=t.val();this.set("label",t),""==this.prop("name")&&(t=acf.applyFilters("generate_field_object_name",acf.strSanitize(t),this),this.prop("name",t))},onChangeName:function(e,t){t=t.val();this.set("name",t),"field_"===t.substr(0,6)&&alert(acf.__('The string "field_" may not be used at the start of a field name'))},onChangeRequired:function(e,t){t=t.prop("checked")?1:0;this.set("required",t)},delete:function(e){e=acf.parseArgs(e,{animate:!0});var t,i=this.prop("ID");i&&(i=(t=r("#_acf_delete_fields")).val()+"|"+i,t.val(i)),acf.doAction("delete_field_object",this),e.animate?this.removeAnimate():this.remove()},onClickDelete:function(e,t){if(e.shiftKey)return this.delete();this.$el.addClass("-hover");acf.newTooltip({confirmRemove:!0,target:t,context:this,confirm:function(){this.delete()},cancel:function(){this.$el.removeClass("-hover")}})},removeAnimate:function(){var e=this,t=this.$el.parent(),i=acf.findFieldObjects({sibling:this.$el});acf.remove({target:this.$el,endHeight:i.length?0:50,complete:function(){e.remove(),acf.doAction("removed_field_object",e,t)}}),acf.doAction("remove_field_object",e,t)},duplicate:function(){var e=acf.uniqid("field_"),t=acf.duplicate({target:this.$el,search:this.get("id"),replace:e});t.attr("data-key",e);var i=acf.getFieldObject(t);this.isOpen()?this.close():i.open();var n=i.$setting("label input");setTimeout(function(){n.trigger("focus")},251);var a,l=i.prop("label"),o=i.prop("name"),c=o.split("_").pop(),t=acf.__("copy");acf.isNumeric(c)?(l=l.replace(c,a=+c+1),o=o.replace(c,a)):0===c.indexOf(t)?(a=+c.replace(t,""),l=l.replace(c,t+(a=a?a+1:2)),o=o.replace(c,t+a)):(l+=" ("+t+")",o+="_"+t),i.prop("ID",0),i.prop("label",l),i.prop("name",o),i.prop("key",e),acf.doAction("duplicate_field_object",this,i),acf.doAction("append_field_object",i)},wipe:function(){var e=this.get("id"),t=this.get("key"),i=acf.uniqid("field_");acf.rename({target:this.$el,search:e,replace:i}),this.set("id",i),this.set("prevId",e),this.set("prevKey",t),this.prop("key",i),this.prop("ID",0),this.$el.attr("data-key",i),this.$el.attr("data-id",i),acf.doAction("wipe_field_object",this)},move:function(){function t(e){return"settings"==e.get("save")}var i,n,a,l,o,c,d=t(this);d||acf.getFieldObjects({parent:this.$el}).map(function(e){d=t(e)||e.changed}),d?alert(acf.__("This field cannot be moved until its changes have been saved")):(i=this.prop("ID"),n=this,a=!1,l=function(e){a.loading(!1),a.content(e),a.on("submit","form",o)},o=function(e,t){e.preventDefault(),acf.startButtonLoading(a.$(".button"));e={action:"acf/field_group/move_field",field_id:i,field_group_id:a.$("select").val()};r.ajax({url:acf.get("ajaxurl"),data:acf.prepareForAjax(e),type:"post",dataType:"html",success:c})},c=function(e){a.content(e),n.removeAnimate()},function(){a=acf.newPopup({title:acf.__("Move Custom Field"),loading:!0,width:"300px"});var e={action:"acf/field_group/move_field",field_id:i};r.ajax({url:acf.get("ajaxurl"),data:acf.prepareForAjax(e),type:"post",dataType:"html",success:l})}())},onChangeType:function(e,t){this.changeTimeout&&clearTimeout(this.changeTimeout),this.changeTimeout=this.setTimeout(function(){this.changeType(t.val())},300)},changeType:function(e){var t=this.prop("type"),i=acf.strSlugify("acf-field-object-"+t),n=acf.strSlugify("acf-field-object-"+e);this.$el.removeClass(i).addClass(n),this.$el.attr("data-type",e),this.$el.data("type",e),this.has("xhr")&&this.get("xhr").abort();var a=this.$("> .settings > table > tbody"),n=a.children('[data-setting="'+t+'"]');if(this.set("settings-"+t,n),n.detach(),this.has("settings-"+e)){var l=this.get("settings-"+e);return this.$setting("conditional_logic").before(l),void this.set("type",e)}var o=r('
    ');this.$setting("conditional_logic").before(o);l={action:"acf/field_group/render_field_settings",field:this.serialize(),prefix:this.getInputName()},l=r.ajax({url:acf.get("ajaxurl"),data:acf.prepareForAjax(l),type:"post",dataType:"html",context:this,success:function(e){e&&(o.after(e),acf.doAction("append",a))},complete:function(){o.remove(),this.set("type",e)}});this.set("xhr",l)},updateParent:function(){var e=acf.get("post_id"),t=this.getParent();t&&(e=parseInt(t.prop("ID"))||t.prop("key")),this.prop("parent",e)}})}(jQuery),function(i){function n(e){return acf.strPascalCase(e||"")+"FieldSetting"}acf.registerFieldSetting=function(e){var t=e.prototype,t=n(t.type+" "+t.name);this.models[t]=e},acf.newFieldSetting=function(e){var t=e.get("setting")||"",i=e.get("name")||"",i=n(t+" "+i),i=acf.models[i]||null;return null!==i&&new i(e)},acf.getFieldSetting=function(e){return(e=e instanceof jQuery?acf.getField(e):e).setting};new acf.Model({actions:{new_field:"onNewField"},onNewField:function(e){e.setting=acf.newFieldSetting(e)}});acf.FieldSetting=acf.Model.extend({field:!1,type:"",name:"",wait:"ready",eventScope:".acf-field",events:{change:"render"},setup:function(e){var t=e.$el;this.$el=t,this.field=e,this.$fieldObject=t.closest(".acf-field-object"),this.fieldObject=acf.getFieldObject(this.$fieldObject),i.extend(this.data,e.data)},initialize:function(){this.render()},render:function(){}});var e=acf.FieldSetting.extend({type:"",name:"",render:function(){var e=this.$('input[type="radio"]:checked');"other"!=e.val()&&this.$('input[type="text"]').val(e.val())}}),t=e.extend({type:"date_picker",name:"display_format"}),a=e.extend({type:"date_picker",name:"return_format"});acf.registerFieldSetting(t),acf.registerFieldSetting(a);t=e.extend({type:"date_time_picker",name:"display_format"}),a=e.extend({type:"date_time_picker",name:"return_format"});acf.registerFieldSetting(t),acf.registerFieldSetting(a);a=e.extend({type:"time_picker",name:"display_format"}),e=e.extend({name:"return_format"});acf.registerFieldSetting(a),acf.registerFieldSetting(e)}(jQuery),function(l){var e=acf.FieldSetting.extend({type:"",name:"conditional_logic",events:{"change .conditions-toggle":"onChangeToggle","click .add-conditional-group":"onClickAddGroup","focus .condition-rule-field":"onFocusField","change .condition-rule-field":"onChangeField","change .condition-rule-operator":"onChangeOperator","click .add-conditional-rule":"onClickAdd","click .remove-conditional-rule":"onClickRemove"},$rule:!1,scope:function(e){return this.$rule=e,this},ruleData:function(e,t){return this.$rule.data.apply(this.$rule,arguments)},$input:function(e){return this.$rule.find(".condition-rule-"+e)},$td:function(e){return this.$rule.find("td."+e)},$toggle:function(){return this.$(".conditions-toggle")},$control:function(){return this.$(".rule-groups")},$groups:function(){return this.$(".rule-group")},$rules:function(){return this.$(".rule")},open:function(){var e=this.$control();e.show(),acf.enable(e)},close:function(){var e=this.$control();e.hide(),acf.disable(e)},render:function(){this.$toggle().prop("checked")?(this.renderRules(),this.open()):this.close()},renderRules:function(){var e=this;this.$rules().each(function(){e.renderRule(l(this))})},renderRule:function(e){this.scope(e),this.renderField(),this.renderOperator(),this.renderValue()},renderField:function(){var i=[],n=this.fieldObject.cid,e=this.$input("field");acf.getFieldObjects().map(function(e){var t={id:e.getKey(),text:e.getLabel()};e.cid===n&&(t.text+=acf.__("(this field)"),t.disabled=!0),acf.getConditionTypes({fieldType:e.getType()}).length||(t.disabled=!0);e=e.getParents().length;t.text="- ".repeat(e)+t.text,i.push(t)}),i.length||i.push({id:"",text:acf.__("No toggle fields available")}),acf.renderSelect(e,i),this.ruleData("field",e.val())},renderOperator:function(){var e,t,i;this.ruleData("field")&&((e=this.$input("operator")).val(),t=[],null===e.val()&&acf.renderSelect(e,[{id:this.ruleData("operator"),text:""}]),i=acf.findFieldObject(this.ruleData("field")),i=acf.getFieldObject(i),acf.getConditionTypes({fieldType:i.getType()}).map(function(e){t.push({id:e.prototype.operator,text:e.prototype.label})}),acf.renderSelect(e,t),this.ruleData("operator",e.val()))},renderValue:function(){var t,e,i,n,a;this.ruleData("field")&&this.ruleData("operator")&&(t=this.$input("value"),e=this.$td("value"),i=t.val(),n=acf.findFieldObject(this.ruleData("field")),n=acf.getFieldObject(n),(n=acf.getConditionTypes({fieldType:n.getType(),operator:this.ruleData("operator")})[0].prototype.choices(n))instanceof Array?(a=l(""),acf.renderSelect(a,n)):a=l(n),t.detach(),e.html(a),setTimeout(function(){["class","name","id"].map(function(e){a.attr(e,t.attr(e))})},0),a.prop("disabled")||acf.val(a,i,!0),this.ruleData("value",a.val()))},onChangeToggle:function(){this.render()},onClickAddGroup:function(e,t){this.addGroup()},addGroup:function(){var e=this.$(".rule-group:last"),e=acf.duplicate(e);e.find("h4").text(acf.__("or")),e.find("tr").not(":first").remove(),this.fieldObject.save()},onFocusField:function(e,t){this.renderField()},onChangeField:function(e,t){this.scope(t.closest(".rule")),this.ruleData("field",t.val()),this.renderOperator(),this.renderValue()},onChangeOperator:function(e,t){this.scope(t.closest(".rule")),this.ruleData("operator",t.val()),this.renderValue()},onClickAdd:function(e,t){t=acf.duplicate(t.closest(".rule"));this.renderRule(t)},onClickRemove:function(e,t){t=t.closest(".rule");this.fieldObject.save(),0==t.siblings(".rule").length&&t.closest(".rule-group").remove(),t.remove()}});acf.registerFieldSetting(e);new acf.Model({actions:{duplicate_field_objects:"onDuplicateFieldObjects"},onDuplicateFieldObjects:function(e,t,i){var n={},a=l();e.map(function(e){n[e.get("prevKey")]=e.get("key"),a=a.add(e.$(".condition-rule-field"))}),a.each(function(){var e=l(this),t=e.val();t&&n[t]&&(e.find("option:selected").attr("value",n[t]),e.val(n[t]))})}})}(jQuery),function(l){acf.findFieldObject=function(e){return acf.findFieldObjects({key:e,limit:1})},acf.findFieldObjects=function(e){e=e||{};var t=".acf-field-object",i=!1;return(e=acf.parseArgs(e,{id:"",key:"",type:"",limit:!1,list:null,parent:!1,sibling:!1,child:!1})).id&&(t+='[data-id="'+e.id+'"]'),e.key&&(t+='[data-key="'+e.key+'"]'),e.type&&(t+='[data-type="'+e.type+'"]'),i=e.list?e.list.children(t):e.parent?e.parent.find(t):e.sibling?e.sibling.siblings(t):e.child?e.child.parents(t):l(t),i=e.limit?i.slice(0,e.limit):i},acf.getFieldObject=function(e){return(e="string"==typeof e?acf.findFieldObject(e):e).data("acf")||acf.newFieldObject(e)},acf.getFieldObjects=function(e){var e=acf.findFieldObjects(e),t=[];return e.each(function(){var e=acf.getFieldObject(l(this));t.push(e)}),t},acf.newFieldObject=function(e){e=new acf.FieldObject(e);return acf.doAction("new_field_object",e),e};new acf.Model({priority:5,initialize:function(){["prepare","ready","append","remove"].map(function(e){this.addFieldActions(e)},this)},addFieldActions:function(e){var n=e+"_field_objects",a=e+"_field_object",l=e+"FieldObject";acf.addAction(e,function(e){var t,i=acf.getFieldObjects({parent:e});i.length&&((t=acf.arrayArgs(arguments)).splice(0,1,n,i),acf.doAction.apply(null,t))},5),acf.addAction(n,function(e){var t=acf.arrayArgs(arguments);t.unshift(a),e.map(function(e){t[1]=e,acf.doAction.apply(null,t)})},5),acf.addAction(a,function(t){var i=acf.arrayArgs(arguments);i.unshift(a);["type","name","key"].map(function(e){i[0]=a+"/"+e+"="+t.get(e),acf.doAction.apply(null,i)}),i.splice(0,2),t.trigger(l,i)},5)}}),new acf.Model({id:"fieldManager",events:{"submit #post":"onSubmit","mouseenter .acf-field-list":"onHoverSortable","click .add-field":"onClickAdd"},actions:{removed_field_object:"onRemovedField",sortstop_field_object:"onReorderField",delete_field_object:"onDeleteField",change_field_object_type:"onChangeFieldType",duplicate_field_object:"onDuplicateField"},onSubmit:function(e,t){acf.getFieldObjects().map(function(e){e.submit()})},setFieldMenuOrder:function(e){this.renderFields(e.$el.parent())},onHoverSortable:function(e,n){n.hasClass("ui-sortable")||n.sortable({handle:".acf-sortable-handle",connectWith:".acf-field-list",start:function(e,t){var i=acf.getFieldObject(t.item);t.placeholder.height(t.item.height()),acf.doAction("sortstart_field_object",i,n)},update:function(e,t){t=acf.getFieldObject(t.item);acf.doAction("sortstop_field_object",t,n)}})},onRemovedField:function(e,t){this.renderFields(t)},onReorderField:function(e,t){e.updateParent(),this.renderFields(t)},onDeleteField:function(e){e.getFields().map(function(e){e.delete({animate:!1})})},onChangeFieldType:function(e){},onDuplicateField:function(e,t){var i=t.getFields();i.length&&(i.map(function(e){e.wipe(),e.updateParent()}),acf.doAction("duplicate_field_objects",i,t,e)),this.setFieldMenuOrder(t)},renderFields:function(e){var t=acf.getFieldObjects({list:e});t.length?(e.removeClass("-empty"),t.map(function(e,t){e.prop("menu_order",t)})):e.addClass("-empty")},onClickAdd:function(e,t){t=t.closest(".acf-tfoot").siblings(".acf-field-list");this.addField(t)},addField:function(i){var e=l("#tmpl-acf-field").html(),t=l(e),n=t.data("id"),e=acf.uniqid("field_"),t=acf.duplicate({target:t,search:n,replace:e,append:function(e,t){i.append(t)}}),n=acf.getFieldObject(t);n.prop("key",e),n.prop("ID",0),n.prop("label",""),n.prop("name",""),t.attr("data-key",e),t.attr("data-id",e),n.updateParent();var a=n.$input("label");setTimeout(function(){a.trigger("focus")},251),n.open(),this.renderFields(i),acf.doAction("add_field_object",n),acf.doAction("append_field_object",n)}})}(jQuery),function(a){new acf.Model({id:"locationManager",wait:"ready",events:{"click .add-location-rule":"onClickAddRule","click .add-location-group":"onClickAddGroup","click .remove-location-rule":"onClickRemoveRule","change .refresh-location-rule":"onChangeRemoveRule"},initialize:function(){this.$el=a("#acf-field-group-locations")},onClickAddRule:function(e,t){this.addRule(t.closest("tr"))},onClickRemoveRule:function(e,t){this.removeRule(t.closest("tr"))},onChangeRemoveRule:function(e,t){this.changeRule(t.closest("tr"))},onClickAddGroup:function(e,t){this.addGroup()},addRule:function(e){acf.duplicate(e)},removeRule:function(e){(0==e.siblings("tr").length?e.closest(".rule-group"):e).remove()},changeRule:function(t){var e=t.closest(".rule-group"),i=t.find("td.param select").attr("name").replace("[param]",""),n={action:"acf/field_group/render_location_rule"};n.rule=acf.serialize(t,i),n.rule.id=t.data("id"),n.rule.group=e.data("id"),acf.disable(t.find("td.value")),a.ajax({url:acf.get("ajaxurl"),data:acf.prepareForAjax(n),type:"post",dataType:"html",success:function(e){e&&t.replaceWith(e)}})},addGroup:function(){var e=this.$(".rule-group:last");$group2=acf.duplicate(e),$group2.find("h4").text(acf.__("or")),$group2.find("tr").not(":first").remove()}})}(jQuery),function(l){var e=acf.getCompatibility(acf);e.field_group={save_field:function(e,t){t=void 0!==t?t:"settings",acf.getFieldObject(e).save(t)},delete_field:function(e,t){t=void 0===t||t,acf.getFieldObject(e).delete({animate:t})},update_field_meta:function(e,t,i){acf.getFieldObject(e).prop(t,i)},delete_field_meta:function(e,t){acf.getFieldObject(e).prop(t,null)}},e.field_group.field_object=acf.model.extend({type:"",o:{},$field:null,$settings:null,tag:function(e){var t=this.type,i=e.split("_");return i.splice(1,0,"field"),e=i.join("_"),t&&(e+="/type="+t),e},selector:function(){var e=".acf-field-object",t=this.type;return t&&(e+="-"+t,e=acf.str_replace("_","-",e)),e},_add_action:function(e,t){var i=this;acf.add_action(this.tag(e),function(e){i.set("$field",e),i[t].apply(i,arguments)})},_add_filter:function(e,t){var i=this;acf.add_filter(this.tag(e),function(e){i.set("$field",e),i[t].apply(i,arguments)})},_add_event:function(e,t){var i=this,n=e.substr(0,e.indexOf(" ")),a=e.substr(e.indexOf(" ")+1),e=this.selector();l(document).on(n,e+" "+a,function(e){e.$el=l(this),e.$field=e.$el.closest(".acf-field-object"),i.set("$field",e.$field),i[t].apply(i,[e])})},_set_$field:function(){this.o=this.$field.data(),this.$settings=this.$field.find("> .settings > table > tbody"),this.focus()},focus:function(){},setting:function(e){return this.$settings.find("> .acf-field-setting-"+e)}});new acf.Model({actions:{open_field_object:"onOpenFieldObject",close_field_object:"onCloseFieldObject",add_field_object:"onAddFieldObject",duplicate_field_object:"onDuplicateFieldObject",delete_field_object:"onDeleteFieldObject",change_field_object_type:"onChangeFieldObjectType",change_field_object_label:"onChangeFieldObjectLabel",change_field_object_name:"onChangeFieldObjectName",change_field_object_parent:"onChangeFieldObjectParent",sortstop_field_object:"onChangeFieldObjectParent"},onOpenFieldObject:function(e){acf.doAction("open_field",e.$el),acf.doAction("open_field/type="+e.get("type"),e.$el),acf.doAction("render_field_settings",e.$el),acf.doAction("render_field_settings/type="+e.get("type"),e.$el)},onCloseFieldObject:function(e){acf.doAction("close_field",e.$el),acf.doAction("close_field/type="+e.get("type"),e.$el)},onAddFieldObject:function(e){acf.doAction("add_field",e.$el),acf.doAction("add_field/type="+e.get("type"),e.$el)},onDuplicateFieldObject:function(e){acf.doAction("duplicate_field",e.$el),acf.doAction("duplicate_field/type="+e.get("type"),e.$el)},onDeleteFieldObject:function(e){acf.doAction("delete_field",e.$el),acf.doAction("delete_field/type="+e.get("type"),e.$el)},onChangeFieldObjectType:function(e){acf.doAction("change_field_type",e.$el),acf.doAction("change_field_type/type="+e.get("type"),e.$el),acf.doAction("render_field_settings",e.$el),acf.doAction("render_field_settings/type="+e.get("type"),e.$el)},onChangeFieldObjectLabel:function(e){acf.doAction("change_field_label",e.$el),acf.doAction("change_field_label/type="+e.get("type"),e.$el)},onChangeFieldObjectName:function(e){acf.doAction("change_field_name",e.$el),acf.doAction("change_field_name/type="+e.get("type"),e.$el)},onChangeFieldObjectParent:function(e){acf.doAction("update_field_parent",e.$el)}})}(jQuery); \ No newline at end of file +!function(n){new acf.Model({id:"fieldGroupManager",events:{"submit #post":"onSubmit",'click a[href="#"]':"onClick","click .submitdelete":"onClickTrash"},filters:{find_fields_args:"filterFindFieldArgs"},onSubmit:function(e,t){var i=n("#titlewrap #title");i.val()||(e.preventDefault(),acf.unlockForm(t),alert(acf.__("Field group title is required")),i.trigger("focus"))},onClick:function(e){e.preventDefault()},onClickTrash:function(e){confirm(acf.__("Move to trash. Are you sure?"))||e.preventDefault()},filterFindFieldArgs:function(e){return e.visible=!0,e}}),new acf.Model({id:"screenOptionsManager",wait:"prepare",events:{change:"onChange"},initialize:function(){var e=n("#adv-settings"),t=n("#acf-append-show-on-screen");e.find(".metabox-prefs").append(t.html()),e.find(".metabox-prefs br").remove(),t.remove(),this.$el=n("#acf-field-key-hide"),this.render()},isChecked:function(){return this.$el.prop("checked")},onChange:function(e,t){var i=this.isChecked()?1:0;acf.updateUserSetting("show_field_keys",i),this.render()},render:function(){this.isChecked()?n("#acf-field-group-fields").addClass("show-field-keys"):n("#acf-field-group-fields").removeClass("show-field-keys")}}),new acf.Model({actions:{new_field:"onNewField"},onNewField:function(e){var t,i;e.has("append")&&(i=e.get("append"),(t=e.$el.siblings('[data-name="'+i+'"]').first()).length&&((t=(i=t.children(".acf-input")).children("ul")).length||(i.wrapInner(''),t=i.children("ul")),i=e.$(".acf-input").html(),i=n("
  • "+i+"
  • "),t.append(i),t.attr("data-cols",t.children().length),e.remove()))}})}(jQuery),function(r){acf.FieldObject=acf.Model.extend({eventScope:".acf-field-object",events:{"click .edit-field":"onClickEdit","click .delete-field":"onClickDelete","click .duplicate-field":"duplicate","click .move-field":"move","change .field-type":"onChangeType","change .field-required":"onChangeRequired","blur .field-label":"onChangeLabel","blur .field-name":"onChangeName",change:"onChange",changed:"onChanged"},data:{id:0,key:"",type:""},setup:function(e){this.$el=e,this.inherit(e),this.prop("ID"),this.prop("parent"),this.prop("menu_order")},$input:function(e){return r("#"+this.getInputId()+"-"+e)},$meta:function(){return this.$(".meta:first")},$handle:function(){return this.$(".handle:first")},$settings:function(){return this.$(".settings:first")},$setting:function(e){return this.$(".acf-field-settings:first > .acf-field-setting-"+e)},getParent:function(){return acf.getFieldObjects({child:this.$el,limit:1}).pop()},getParents:function(){return acf.getFieldObjects({child:this.$el})},getFields:function(){return acf.getFieldObjects({parent:this.$el})},getInputName:function(){return"acf_fields["+this.get("id")+"]"},getInputId:function(){return"acf_fields-"+this.get("id")},newInput:function(e,t){var i=this.getInputId(),n=this.getInputName();e&&(i+="-"+e,n+="["+e+"]");t=r("").attr({id:i,name:n,value:t});return this.$("> .meta").append(t),t},getProp:function(e){if(this.has(e))return this.get(e);var t=this.$input(e),t=t.length?t.val():null;return this.set(e,t,!0),t},setProp:function(e,t){var i=this.$input(e);i.val();return i.length||(i=this.newInput(e,t)),null===t?i.remove():i.val(t),this.has(e)?this.set(e,t):this.set(e,t,!0),this},prop:function(e,t){return void 0!==t?this.setProp(e,t):this.getProp(e)},props:function(t){Object.keys(t).map(function(e){this.setProp(e,t[e])},this)},getLabel:function(){var e=this.prop("label");return e=""===e?acf.__("(no label)"):e},getName:function(){return this.prop("name")},getType:function(){return this.prop("type")},getTypeLabel:function(){var e=this.prop("type"),t=acf.get("fieldTypes");return t[e]?t[e].label:e},getKey:function(){return this.prop("key")},initialize:function(){this.addProFields()},addProFields:function(){var e;acf.data.fieldTypes.hasOwnProperty("clone")||((e=r(".field-type").not(".acf-free-field-type")).find('optgroup option[value="group"]').parent().append('"),e.find('optgroup option[value="image"]').parent().append('"),e.addClass("acf-free-field-type"))},render:function(){var e=this.$(".handle:first"),t=this.prop("menu_order"),i=this.getLabel(),n=this.prop("name"),a=this.getTypeLabel(),l=this.prop("key"),o=this.$input("required").prop("checked");e.find(".acf-icon").html(parseInt(t)+1),o&&(i+=' *'),e.find(".li-field-label strong a").html(i),e.find(".li-field-name").text(n),e.find(".li-field-type").text(a),e.find(".li-field-key").text(l),acf.doAction("render_field_object",this)},refresh:function(){acf.doAction("refresh_field_object",this)},isOpen:function(){return this.$el.hasClass("open")},onClickEdit:function(e){this.isOpen()?this.close():this.open()},open:function(){var e=this.$el.children(".settings");e.slideDown(),this.$el.addClass("open"),acf.doAction("open_field_object",this),this.trigger("openFieldObject"),acf.doAction("show",e)},close:function(){var e=this.$el.children(".settings");e.slideUp(),this.$el.removeClass("open"),acf.doAction("close_field_object",this),this.trigger("closeFieldObject"),acf.doAction("hide",e)},serialize:function(){return acf.serialize(this.$el,this.getInputName())},save:function(e){e=e||"settings","settings"!==this.getProp("save")&&(this.setProp("save",e),this.$el.attr("data-save",e),acf.doAction("save_field_object",this,e))},submit:function(){var e=this.getInputName(),t=this.get("save");this.isOpen()&&this.close(),"settings"==t||("meta"==t?this.$('> .settings [name^="'+e+'"]'):this.$('[name^="'+e+'"]')).remove(),acf.doAction("submit_field_object",this)},onChange:function(e,t){this.save(),acf.doAction("change_field_object",this)},onChanged:function(e,t,i,n){"save"!=i&&(-1<["menu_order","parent"].indexOf(i)?this.save("meta"):this.save(),-1<["menu_order","label","required","name","type","key"].indexOf(i)&&this.render(),acf.doAction("change_field_object_"+i,this,n))},onChangeLabel:function(e,t){t=t.val();this.set("label",t),""==this.prop("name")&&(t=acf.applyFilters("generate_field_object_name",acf.strSanitize(t),this),this.prop("name",t))},onChangeName:function(e,t){t=t.val();this.set("name",t),"field_"===t.substr(0,6)&&alert(acf.__('The string "field_" may not be used at the start of a field name'))},onChangeRequired:function(e,t){t=t.prop("checked")?1:0;this.set("required",t)},delete:function(e){e=acf.parseArgs(e,{animate:!0});var t,i=this.prop("ID");i&&(i=(t=r("#_acf_delete_fields")).val()+"|"+i,t.val(i)),acf.doAction("delete_field_object",this),e.animate?this.removeAnimate():this.remove()},onClickDelete:function(e,t){if(e.shiftKey)return this.delete();this.$el.addClass("-hover");acf.newTooltip({confirmRemove:!0,target:t,context:this,confirm:function(){this.delete()},cancel:function(){this.$el.removeClass("-hover")}})},removeAnimate:function(){var e=this,t=this.$el.parent(),i=acf.findFieldObjects({sibling:this.$el});acf.remove({target:this.$el,endHeight:i.length?0:50,complete:function(){e.remove(),acf.doAction("removed_field_object",e,t)}}),acf.doAction("remove_field_object",e,t)},duplicate:function(){var e=acf.uniqid("field_"),t=acf.duplicate({target:this.$el,search:this.get("id"),replace:e});t.attr("data-key",e);var i=acf.getFieldObject(t);this.isOpen()?this.close():i.open();var n=i.$setting("label input");setTimeout(function(){n.trigger("focus")},251);var a,l=i.prop("label"),o=i.prop("name"),c=o.split("_").pop(),t=acf.__("copy");acf.isNumeric(c)?(l=l.replace(c,a=+c+1),o=o.replace(c,a)):0===c.indexOf(t)?(a=+c.replace(t,""),l=l.replace(c,t+(a=a?a+1:2)),o=o.replace(c,t+a)):(l+=" ("+t+")",o+="_"+t),i.prop("ID",0),i.prop("label",l),i.prop("name",o),i.prop("key",e),acf.doAction("duplicate_field_object",this,i),acf.doAction("append_field_object",i)},wipe:function(){var e=this.get("id"),t=this.get("key"),i=acf.uniqid("field_");acf.rename({target:this.$el,search:e,replace:i}),this.set("id",i),this.set("prevId",e),this.set("prevKey",t),this.prop("key",i),this.prop("ID",0),this.$el.attr("data-key",i),this.$el.attr("data-id",i),acf.doAction("wipe_field_object",this)},move:function(){function t(e){return"settings"==e.get("save")}var i,n,a,l,o,c,d=t(this);d||acf.getFieldObjects({parent:this.$el}).map(function(e){d=t(e)||e.changed}),d?alert(acf.__("This field cannot be moved until its changes have been saved")):(i=this.prop("ID"),n=this,a=!1,l=function(e){a.loading(!1),a.content(e),a.on("submit","form",o)},o=function(e,t){e.preventDefault(),acf.startButtonLoading(a.$(".button"));e={action:"acf/field_group/move_field",field_id:i,field_group_id:a.$("select").val()};r.ajax({url:acf.get("ajaxurl"),data:acf.prepareForAjax(e),type:"post",dataType:"html",success:c})},c=function(e){a.content(e),n.removeAnimate()},function(){a=acf.newPopup({title:acf.__("Move Custom Field"),loading:!0,width:"300px"});var e={action:"acf/field_group/move_field",field_id:i};r.ajax({url:acf.get("ajaxurl"),data:acf.prepareForAjax(e),type:"post",dataType:"html",success:l})}())},onChangeType:function(e,t){this.changeTimeout&&clearTimeout(this.changeTimeout),this.changeTimeout=this.setTimeout(function(){this.changeType(t.val())},300)},changeType:function(e){var t=this.prop("type"),i=acf.strSlugify("acf-field-object-"+t),n=acf.strSlugify("acf-field-object-"+e);this.$el.removeClass(i).addClass(n),this.$el.attr("data-type",e),this.$el.data("type",e),this.has("xhr")&&this.get("xhr").abort();var a=this.$("> .settings > table > tbody"),n=a.children('[data-setting="'+t+'"]');if(this.set("settings-"+t,n),n.detach(),this.has("settings-"+e)){var l=this.get("settings-"+e);return this.$setting("conditional_logic").before(l),void this.set("type",e)}var o=r('
    ');this.$setting("conditional_logic").before(o);l={action:"acf/field_group/render_field_settings",field:this.serialize(),prefix:this.getInputName()},l=r.ajax({url:acf.get("ajaxurl"),data:acf.prepareForAjax(l),type:"post",dataType:"html",context:this,success:function(e){e&&(o.after(e),acf.doAction("append",a))},complete:function(){o.remove(),this.set("type",e)}});this.set("xhr",l)},updateParent:function(){var e=acf.get("post_id"),t=this.getParent();t&&(e=parseInt(t.prop("ID"))||t.prop("key")),this.prop("parent",e)}})}(jQuery),function(i){function n(e){return acf.strPascalCase(e||"")+"FieldSetting"}acf.registerFieldSetting=function(e){var t=e.prototype,t=n(t.type+" "+t.name);this.models[t]=e},acf.newFieldSetting=function(e){var t=e.get("setting")||"",i=e.get("name")||"",i=n(t+" "+i),i=acf.models[i]||null;return null!==i&&new i(e)},acf.getFieldSetting=function(e){return(e=e instanceof jQuery?acf.getField(e):e).setting};new acf.Model({actions:{new_field:"onNewField"},onNewField:function(e){e.setting=acf.newFieldSetting(e)}});acf.FieldSetting=acf.Model.extend({field:!1,type:"",name:"",wait:"ready",eventScope:".acf-field",events:{change:"render"},setup:function(e){var t=e.$el;this.$el=t,this.field=e,this.$fieldObject=t.closest(".acf-field-object"),this.fieldObject=acf.getFieldObject(this.$fieldObject),i.extend(this.data,e.data)},initialize:function(){this.render()},render:function(){}});var e=acf.FieldSetting.extend({type:"",name:"",render:function(){var e=this.$('input[type="radio"]:checked');"other"!=e.val()&&this.$('input[type="text"]').val(e.val())}}),t=e.extend({type:"date_picker",name:"display_format"}),a=e.extend({type:"date_picker",name:"return_format"});acf.registerFieldSetting(t),acf.registerFieldSetting(a);t=e.extend({type:"date_time_picker",name:"display_format"}),a=e.extend({type:"date_time_picker",name:"return_format"});acf.registerFieldSetting(t),acf.registerFieldSetting(a);a=e.extend({type:"time_picker",name:"display_format"}),e=e.extend({name:"return_format"});acf.registerFieldSetting(a),acf.registerFieldSetting(e);e=acf.FieldSetting.extend({type:"color_picker",name:"enable_opacity",render:function(){var e=this.fieldObject.$setting("return_format"),t=this.fieldObject.$setting("default_value"),i=e.find('input[type="radio"][value="string"]').parent("label").contents().last(),e=t.find('input[type="text"]'),t=acf.get("colorPickerL10n");this.field.val()?(i.replaceWith(t.rgba_string),e.attr("placeholder","rgba(255,255,255,0.8)")):(i.replaceWith(t.hex_string),e.attr("placeholder","#FFFFFF"))}});acf.registerFieldSetting(e)}(jQuery),function(l){var e=acf.FieldSetting.extend({type:"",name:"conditional_logic",events:{"change .conditions-toggle":"onChangeToggle","click .add-conditional-group":"onClickAddGroup","focus .condition-rule-field":"onFocusField","change .condition-rule-field":"onChangeField","change .condition-rule-operator":"onChangeOperator","click .add-conditional-rule":"onClickAdd","click .remove-conditional-rule":"onClickRemove"},$rule:!1,scope:function(e){return this.$rule=e,this},ruleData:function(e,t){return this.$rule.data.apply(this.$rule,arguments)},$input:function(e){return this.$rule.find(".condition-rule-"+e)},$td:function(e){return this.$rule.find("td."+e)},$toggle:function(){return this.$(".conditions-toggle")},$control:function(){return this.$(".rule-groups")},$groups:function(){return this.$(".rule-group")},$rules:function(){return this.$(".rule")},open:function(){var e=this.$control();e.show(),acf.enable(e)},close:function(){var e=this.$control();e.hide(),acf.disable(e)},render:function(){this.$toggle().prop("checked")?(this.renderRules(),this.open()):this.close()},renderRules:function(){var e=this;this.$rules().each(function(){e.renderRule(l(this))})},renderRule:function(e){this.scope(e),this.renderField(),this.renderOperator(),this.renderValue()},renderField:function(){var i=[],n=this.fieldObject.cid,e=this.$input("field");acf.getFieldObjects().map(function(e){var t={id:e.getKey(),text:e.getLabel()};e.cid===n&&(t.text+=acf.__("(this field)"),t.disabled=!0),acf.getConditionTypes({fieldType:e.getType()}).length||(t.disabled=!0);e=e.getParents().length;t.text="- ".repeat(e)+t.text,i.push(t)}),i.length||i.push({id:"",text:acf.__("No toggle fields available")}),acf.renderSelect(e,i),this.ruleData("field",e.val())},renderOperator:function(){var e,t,i;this.ruleData("field")&&((e=this.$input("operator")).val(),t=[],null===e.val()&&acf.renderSelect(e,[{id:this.ruleData("operator"),text:""}]),i=acf.findFieldObject(this.ruleData("field")),i=acf.getFieldObject(i),acf.getConditionTypes({fieldType:i.getType()}).map(function(e){t.push({id:e.prototype.operator,text:e.prototype.label})}),acf.renderSelect(e,t),this.ruleData("operator",e.val()))},renderValue:function(){var t,e,i,n,a;this.ruleData("field")&&this.ruleData("operator")&&(t=this.$input("value"),e=this.$td("value"),i=t.val(),n=acf.findFieldObject(this.ruleData("field")),n=acf.getFieldObject(n),(n=acf.getConditionTypes({fieldType:n.getType(),operator:this.ruleData("operator")})[0].prototype.choices(n))instanceof Array?(a=l(""),acf.renderSelect(a,n)):a=l(n),t.detach(),e.html(a),setTimeout(function(){["class","name","id"].map(function(e){a.attr(e,t.attr(e))})},0),a.prop("disabled")||acf.val(a,i,!0),this.ruleData("value",a.val()))},onChangeToggle:function(){this.render()},onClickAddGroup:function(e,t){this.addGroup()},addGroup:function(){var e=this.$(".rule-group:last"),e=acf.duplicate(e);e.find("h4").text(acf.__("or")),e.find("tr").not(":first").remove(),this.fieldObject.save()},onFocusField:function(e,t){this.renderField()},onChangeField:function(e,t){this.scope(t.closest(".rule")),this.ruleData("field",t.val()),this.renderOperator(),this.renderValue()},onChangeOperator:function(e,t){this.scope(t.closest(".rule")),this.ruleData("operator",t.val()),this.renderValue()},onClickAdd:function(e,t){t=acf.duplicate(t.closest(".rule"));this.renderRule(t)},onClickRemove:function(e,t){t=t.closest(".rule");this.fieldObject.save(),0==t.siblings(".rule").length&&t.closest(".rule-group").remove(),t.remove()}});acf.registerFieldSetting(e);new acf.Model({actions:{duplicate_field_objects:"onDuplicateFieldObjects"},onDuplicateFieldObjects:function(e,t,i){var n={},a=l();e.map(function(e){n[e.get("prevKey")]=e.get("key"),a=a.add(e.$(".condition-rule-field"))}),a.each(function(){var e=l(this),t=e.val();t&&n[t]&&(e.find("option:selected").attr("value",n[t]),e.val(n[t]))})}})}(jQuery),function(l){acf.findFieldObject=function(e){return acf.findFieldObjects({key:e,limit:1})},acf.findFieldObjects=function(e){e=e||{};var t=".acf-field-object",i=!1;return(e=acf.parseArgs(e,{id:"",key:"",type:"",limit:!1,list:null,parent:!1,sibling:!1,child:!1})).id&&(t+='[data-id="'+e.id+'"]'),e.key&&(t+='[data-key="'+e.key+'"]'),e.type&&(t+='[data-type="'+e.type+'"]'),i=e.list?e.list.children(t):e.parent?e.parent.find(t):e.sibling?e.sibling.siblings(t):e.child?e.child.parents(t):l(t),i=e.limit?i.slice(0,e.limit):i},acf.getFieldObject=function(e){return(e="string"==typeof e?acf.findFieldObject(e):e).data("acf")||acf.newFieldObject(e)},acf.getFieldObjects=function(e){var e=acf.findFieldObjects(e),t=[];return e.each(function(){var e=acf.getFieldObject(l(this));t.push(e)}),t},acf.newFieldObject=function(e){e=new acf.FieldObject(e);return acf.doAction("new_field_object",e),e};new acf.Model({priority:5,initialize:function(){["prepare","ready","append","remove"].map(function(e){this.addFieldActions(e)},this)},addFieldActions:function(e){var n=e+"_field_objects",a=e+"_field_object",l=e+"FieldObject";acf.addAction(e,function(e){var t,i=acf.getFieldObjects({parent:e});i.length&&((t=acf.arrayArgs(arguments)).splice(0,1,n,i),acf.doAction.apply(null,t))},5),acf.addAction(n,function(e){var t=acf.arrayArgs(arguments);t.unshift(a),e.map(function(e){t[1]=e,acf.doAction.apply(null,t)})},5),acf.addAction(a,function(t){var i=acf.arrayArgs(arguments);i.unshift(a);["type","name","key"].map(function(e){i[0]=a+"/"+e+"="+t.get(e),acf.doAction.apply(null,i)}),i.splice(0,2),t.trigger(l,i)},5)}}),new acf.Model({id:"fieldManager",events:{"submit #post":"onSubmit","mouseenter .acf-field-list":"onHoverSortable","click .add-field":"onClickAdd"},actions:{removed_field_object:"onRemovedField",sortstop_field_object:"onReorderField",delete_field_object:"onDeleteField",change_field_object_type:"onChangeFieldType",duplicate_field_object:"onDuplicateField"},onSubmit:function(e,t){acf.getFieldObjects().map(function(e){e.submit()})},setFieldMenuOrder:function(e){this.renderFields(e.$el.parent())},onHoverSortable:function(e,n){n.hasClass("ui-sortable")||n.sortable({handle:".acf-sortable-handle",connectWith:".acf-field-list",start:function(e,t){var i=acf.getFieldObject(t.item);t.placeholder.height(t.item.height()),acf.doAction("sortstart_field_object",i,n)},update:function(e,t){t=acf.getFieldObject(t.item);acf.doAction("sortstop_field_object",t,n)}})},onRemovedField:function(e,t){this.renderFields(t)},onReorderField:function(e,t){e.updateParent(),this.renderFields(t)},onDeleteField:function(e){e.getFields().map(function(e){e.delete({animate:!1})})},onChangeFieldType:function(e){},onDuplicateField:function(e,t){var i=t.getFields();i.length&&(i.map(function(e){e.wipe(),e.updateParent()}),acf.doAction("duplicate_field_objects",i,t,e)),this.setFieldMenuOrder(t)},renderFields:function(e){var t=acf.getFieldObjects({list:e});t.length?(e.removeClass("-empty"),t.map(function(e,t){e.prop("menu_order",t)})):e.addClass("-empty")},onClickAdd:function(e,t){t=t.closest(".acf-tfoot").siblings(".acf-field-list");this.addField(t)},addField:function(i){var e=l("#tmpl-acf-field").html(),t=l(e),n=t.data("id"),e=acf.uniqid("field_"),t=acf.duplicate({target:t,search:n,replace:e,append:function(e,t){i.append(t)}}),n=acf.getFieldObject(t);n.prop("key",e),n.prop("ID",0),n.prop("label",""),n.prop("name",""),t.attr("data-key",e),t.attr("data-id",e),n.updateParent();var a=n.$input("label");setTimeout(function(){a.trigger("focus")},251),n.open(),this.renderFields(i),acf.doAction("add_field_object",n),acf.doAction("append_field_object",n)}})}(jQuery),function(a){new acf.Model({id:"locationManager",wait:"ready",events:{"click .add-location-rule":"onClickAddRule","click .add-location-group":"onClickAddGroup","click .remove-location-rule":"onClickRemoveRule","change .refresh-location-rule":"onChangeRemoveRule"},initialize:function(){this.$el=a("#acf-field-group-locations"),this.updateGroupsClass()},onClickAddRule:function(e,t){this.addRule(t.closest("tr"))},onClickRemoveRule:function(e,t){this.removeRule(t.closest("tr"))},onChangeRemoveRule:function(e,t){this.changeRule(t.closest("tr"))},onClickAddGroup:function(e,t){this.addGroup()},addRule:function(e){acf.duplicate(e),this.updateGroupsClass()},removeRule:function(e){(0==e.siblings("tr").length?e.closest(".rule-group"):e).remove(),this.$(".rule-group:first").find("h4").text(acf.__("Show this field group if")),this.updateGroupsClass()},changeRule:function(t){var e=t.closest(".rule-group"),i=t.find("td.param select").attr("name").replace("[param]",""),n={action:"acf/field_group/render_location_rule"};n.rule=acf.serialize(t,i),n.rule.id=t.data("id"),n.rule.group=e.data("id"),acf.disable(t.find("td.value")),a.ajax({url:acf.get("ajaxurl"),data:acf.prepareForAjax(n),type:"post",dataType:"html",success:function(e){e&&t.replaceWith(e)}})},addGroup:function(){var e=this.$(".rule-group:last");$group2=acf.duplicate(e),$group2.find("h4").text(acf.__("or")),$group2.find("tr").not(":first").remove(),this.updateGroupsClass()},updateGroupsClass:function(){var e=this.$(".rule-group:last").closest(".rule-groups");1 .settings > table > tbody"),this.focus()},focus:function(){},setting:function(e){return this.$settings.find("> .acf-field-setting-"+e)}});new acf.Model({actions:{open_field_object:"onOpenFieldObject",close_field_object:"onCloseFieldObject",add_field_object:"onAddFieldObject",duplicate_field_object:"onDuplicateFieldObject",delete_field_object:"onDeleteFieldObject",change_field_object_type:"onChangeFieldObjectType",change_field_object_label:"onChangeFieldObjectLabel",change_field_object_name:"onChangeFieldObjectName",change_field_object_parent:"onChangeFieldObjectParent",sortstop_field_object:"onChangeFieldObjectParent"},onOpenFieldObject:function(e){acf.doAction("open_field",e.$el),acf.doAction("open_field/type="+e.get("type"),e.$el),acf.doAction("render_field_settings",e.$el),acf.doAction("render_field_settings/type="+e.get("type"),e.$el)},onCloseFieldObject:function(e){acf.doAction("close_field",e.$el),acf.doAction("close_field/type="+e.get("type"),e.$el)},onAddFieldObject:function(e){acf.doAction("add_field",e.$el),acf.doAction("add_field/type="+e.get("type"),e.$el)},onDuplicateFieldObject:function(e){acf.doAction("duplicate_field",e.$el),acf.doAction("duplicate_field/type="+e.get("type"),e.$el)},onDeleteFieldObject:function(e){acf.doAction("delete_field",e.$el),acf.doAction("delete_field/type="+e.get("type"),e.$el)},onChangeFieldObjectType:function(e){acf.doAction("change_field_type",e.$el),acf.doAction("change_field_type/type="+e.get("type"),e.$el),acf.doAction("render_field_settings",e.$el),acf.doAction("render_field_settings/type="+e.get("type"),e.$el)},onChangeFieldObjectLabel:function(e){acf.doAction("change_field_label",e.$el),acf.doAction("change_field_label/type="+e.get("type"),e.$el)},onChangeFieldObjectName:function(e){acf.doAction("change_field_name",e.$el),acf.doAction("change_field_name/type="+e.get("type"),e.$el)},onChangeFieldObjectParent:function(e){acf.doAction("update_field_parent",e.$el)}})}(jQuery); \ No newline at end of file diff --git a/assets/build/js/acf-input.js b/assets/build/js/acf-input.js index 37aec7b..2c763b6 100644 --- a/assets/build/js/acf-input.js +++ b/assets/build/js/acf-input.js @@ -7729,10 +7729,25 @@ placeholder: this.get('placeholder'), multiple: this.get('multiple'), data: [], - escapeMarkup: function( string ){ - return acf.escHtml( string ); - }, + escapeMarkup: function( markup ) { + if (typeof markup !== 'string') { + return markup; + } + return acf.escHtml( markup ); + } }; + + // Only use the template if SelectWoo is not loaded to work around https://github.com/woocommerce/woocommerce/pull/30473 + if ( ! acf.isset(window, 'jQuery', 'fn', 'selectWoo') ) { + + options.templateSelection = function( selection ) { + var $selection = $(''); + $selection.html( acf.escHtml( selection.text ) ); + $selection.data('element', selection.element); + return $selection; + }; + + } // multiple if( options.multiple ) { @@ -7788,8 +7803,12 @@ // loop $ul.find('.select2-selection__choice').each(function() { - // vars - var $option = $( $(this).data('data').element ); + // Attempt to use .data if it exists (select2 version < 4.0.6) or use our template data instead. + if ( $(this).data('data') ) { + var $option = $( $(this).data('data').element ); + } else { + var $option = $( $(this).children('span.acf-selection').data('element') ); + } // detach and re-append to end $option.detach().appendTo( $select ); @@ -9656,7 +9675,7 @@ var lastPostStatus = ''; wp.data.subscribe(function() { var postStatus = editorSelect.getEditedPostAttribute( 'status' ); - useValidation = ( postStatus === 'publish' ); + useValidation = ( postStatus === 'publish' || postStatus === 'future' ); lastPostStatus = ( postStatus !== 'publish' ) ? postStatus : lastPostStatus; }); @@ -9676,7 +9695,7 @@ return resolve( 'Validation ignored (autosave).' ); } - // Bail early if validation is not neeed. + // Bail early if validation is not needed. if( !useValidation ) { return resolve( 'Validation ignored (draft).' ); } @@ -9728,6 +9747,8 @@ } }).then(function(){ return savePost.apply(_this, _args); + }).catch(function(err){ + // Nothing to do here, user is alerted of validation issues. }); }; } diff --git a/assets/build/js/acf-input.min.js b/assets/build/js/acf-input.min.js index fd1d9f4..f7a16b1 100644 --- a/assets/build/js/acf-input.min.js +++ b/assets/build/js/acf-input.min.js @@ -1 +1 @@ -!function(e,i){var a=[];acf.Field=acf.Model.extend({type:"",eventScope:".acf-field",wait:"ready",setup:function(t){this.$el=t,this.inherit(t),this.inherit(this.$control())},val:function(t){return t!==i?this.setValue(t):this.prop("disabled")?null:this.getValue()},getValue:function(){return this.$input().val()},setValue:function(t){return acf.val(this.$input(),t)},__:function(t){return acf._e(this.type,t)},$control:function(){return!1},$input:function(){return this.$("[name]:first")},$inputWrap:function(){return this.$(".acf-input:first")},$labelWrap:function(){return this.$(".acf-label:first")},getInputName:function(){return this.$input().attr("name")||""},parent:function(){var t=this.parents();return!!t.length&&t[0]},parents:function(){var t=this.$el.parents(".acf-field");return acf.getFields(t)},show:function(t,e){t=acf.show(this.$el,t);return t&&(this.prop("hidden",!1),acf.doAction("show_field",this,e)),t},hide:function(t,e){t=acf.hide(this.$el,t);return t&&(this.prop("hidden",!0),acf.doAction("hide_field",this,e)),t},enable:function(t,e){t=acf.enable(this.$el,t);return t&&(this.prop("disabled",!1),acf.doAction("enable_field",this,e)),t},disable:function(t,e){t=acf.disable(this.$el,t);return t&&(this.prop("disabled",!0),acf.doAction("disable_field",this,e)),t},showEnable:function(t,e){return this.enable.apply(this,arguments),this.show.apply(this,arguments)},hideDisable:function(t,e){return this.disable.apply(this,arguments),this.hide.apply(this,arguments)},showNotice:function(t){"object"!=typeof t&&(t={text:t}),this.notice&&this.notice.remove(),t.target=this.$inputWrap(),this.notice=acf.newNotice(t)},removeNotice:function(t){this.notice&&(this.notice.away(t||0),this.notice=!1)},showError:function(t){this.$el.addClass("acf-error"),t!==i&&this.showNotice({text:t,type:"error",dismiss:!1}),acf.doAction("invalid_field",this),this.$el.one("focus change","input, select, textarea",e.proxy(this.removeError,this))},removeError:function(){this.$el.removeClass("acf-error"),this.removeNotice(250),acf.doAction("valid_field",this)},trigger:function(t,e,i){return"invalidField"==t&&(i=!0),acf.Model.prototype.trigger.apply(this,[t,e,i])}}),acf.newField=function(t){var e=t.data("type"),e=n(e),t=new(acf.models[e]||acf.Field)(t);return acf.doAction("new_field",t),t};var n=function(t){return acf.strPascalCase(t||"")+"Field"};acf.registerFieldType=function(t){var e=t.prototype.type,i=n(e);acf.models[i]=t,a.push(e)},acf.getFieldType=function(t){t=n(t);return acf.models[t]||!1},acf.getFieldTypes=function(i){i=acf.parseArgs(i,{category:""});var n=[];return a.map(function(t){var e=acf.getFieldType(t),t=e.prototype;i.category&&t.category!==i.category||n.push(e)}),n}}(jQuery),function(n){acf.findFields=function(t){var e=".acf-field",i=!1;return(t=!(t=acf.parseArgs(t,{key:"",name:"",type:"",is:"",parent:!1,sibling:!1,limit:!1,visible:!1,suppressFilters:!1})).suppressFilters?acf.applyFilters("find_fields_args",t):t).key&&(e+='[data-key="'+t.key+'"]'),t.type&&(e+='[data-type="'+t.type+'"]'),t.name&&(e+='[data-name="'+t.name+'"]'),t.is&&(e+=t.is),t.visible&&(e+=":visible"),i=t.parent?t.parent.find(e):t.sibling?t.sibling.siblings(e):n(e),t.suppressFilters||(i=i.not(".acf-clone .acf-field"),i=acf.applyFilters("find_fields",i)),i=t.limit?i.slice(0,t.limit):i},acf.findField=function(t,e){return acf.findFields({key:t,limit:1,parent:e,suppressFilters:!0})},acf.getField=function(t){return(t=!(t instanceof jQuery)?acf.findField(t):t).data("acf")||acf.newField(t)},acf.getFields=function(t){t instanceof jQuery||(t=acf.findFields(t));var e=[];return t.each(function(){var t=acf.getField(n(this));e.push(t)}),e},acf.findClosestField=function(t){return t.closest(".acf-field")},acf.getClosestField=function(t){t=acf.findClosestField(t);return this.getField(t)};var e=function(t){var a=t+"_field",s=t+"Field";acf.addAction(a,function(e){var i=acf.arrayArgs(arguments),n=i.slice(1);["type","name","key"].map(function(t){t="/"+t+"="+e.get(t);i=[a+t,e].concat(n),acf.doAction.apply(null,i)}),-1'),e=c('
    '),o=c(''),r=c(""),t.append(n.html()),o.append(r),e.append(o),a.append(t),a.append(e),n.remove(),s.remove(),a.attr("colspan",2),n=t,a=e,s=r),i.addClass("acf-accordion"),n.addClass("acf-accordion-title"),a.addClass("acf-accordion-content"),l++,this.get("multi_expand")&&i.attr("multi-expand",1);var r=acf.getPreference("this.accordions")||[];void 0!==r[l-1]&&this.set("open",r[l-1]),this.get("open")&&(i.addClass("-open"),a.css("display","block")),n.prepend(d.iconHtml({open:this.get("open")}));n=i.parent();s.addClass(n.hasClass("-left")?"-left":""),s.addClass(n.hasClass("-clear")?"-clear":""),s.append(i.nextUntil(".acf-field-accordion",".acf-field")),s.removeAttr("data-open data-multi_expand data-endpoint")}}});acf.registerFieldType(t);var d=new acf.Model({actions:{unload:"onUnload"},events:{"click .acf-accordion-title":"onClick","invalidField .acf-accordion":"onInvalidField"},isOpen:function(t){return t.hasClass("-open")},toggle:function(t){this.isOpen(t)?this.close(t):this.open(t)},iconHtml:function(t){return acf.isGutenberg()?t.open?'':'':t.open?'':''},open:function(t){var e=acf.isGutenberg()?0:300;t.find(".acf-accordion-content:first").slideDown(e).css("display","block"),t.find(".acf-accordion-icon:first").replaceWith(this.iconHtml({open:!0})),t.addClass("-open"),acf.doAction("show",t),t.attr("multi-expand")||t.siblings(".acf-accordion.-open").each(function(){d.close(c(this))})},close:function(t){var e=acf.isGutenberg()?0:300;t.find(".acf-accordion-content:first").slideUp(e),t.find(".acf-accordion-icon:first").replaceWith(this.iconHtml({open:!1})),t.removeClass("-open"),acf.doAction("hide",t)},onClick:function(t,e){t.preventDefault(),this.toggle(e.parent())},onInvalidField:function(t,e){this.busy||(this.busy=!0,this.setTimeout(function(){this.busy=!1},1e3),this.open(e))},onUnload:function(t){var e=[];c(".acf-accordion").each(function(){var t=c(this).hasClass("-open")?1:0;e.push(t)}),e.length&&acf.setPreference("this.accordions",e)}})}(jQuery),function(){var t=acf.Field.extend({type:"button_group",events:{'click input[type="radio"]':"onClick"},$control:function(){return this.$(".acf-button-group")},$input:function(){return this.$("input:checked")},setValue:function(t){this.$('input[value="'+t+'"]').prop("checked",!0).trigger("change")},onClick:function(t,e){var i=e.parent("label"),n=i.hasClass("selected");this.$(".selected").removeClass("selected"),i.addClass("selected"),this.get("allow_null")&&n&&(i.removeClass("selected"),e.prop("checked",!1).trigger("change"))}});acf.registerFieldType(t)}(jQuery),function(e){var t=acf.Field.extend({type:"checkbox",events:{"change input":"onChange","click .acf-add-checkbox":"onClickAdd","click .acf-checkbox-toggle":"onClickToggle","click .acf-checkbox-custom":"onClickCustom"},$control:function(){return this.$(".acf-checkbox-list")},$toggle:function(){return this.$(".acf-checkbox-toggle")},$input:function(){return this.$('input[type="hidden"]')},$inputs:function(){return this.$('input[type="checkbox"]').not(".acf-checkbox-toggle")},getValue:function(){var t=[];return this.$(":checked").each(function(){t.push(e(this).val())}),!!t.length&&t},onChange:function(t,e){var i=e.prop("checked"),n=e.parent("label"),e=this.$toggle();i?n.addClass("selected"):n.removeClass("selected"),e.length&&(0==this.$inputs().not(":checked").length?e.prop("checked",!0):e.prop("checked",!1))},onClickAdd:function(t,e){var i='
  • ';e.parent("li").before(i)},onClickToggle:function(t,e){var i=e.prop("checked"),n=this.$('input[type="checkbox"]'),e=this.$("label");n.prop("checked",i),i?e.addClass("selected"):e.removeClass("selected")},onClickCustom:function(t,e){var i=e.prop("checked"),n=e.next('input[type="text"]');i?n.prop("disabled",!1):(n.prop("disabled",!0),""==n.val()&&e.parent("li").remove())}});acf.registerFieldType(t)}(jQuery),function(){var t=acf.Field.extend({type:"color_picker",wait:"load",events:{duplicateField:"onDuplicate"},$control:function(){return this.$(".acf-color-picker")},$input:function(){return this.$('input[type="hidden"]')},$inputText:function(){return this.$('input[type="text"]')},setValue:function(t){acf.val(this.$input(),t),this.$inputText().iris("color",t)},initialize:function(){var e=this.$input(),i=this.$inputText(),t=function(t){setTimeout(function(){acf.val(e,i.val())},1)},t={defaultColor:!1,palettes:!0,hide:!0,change:t,clear:t},t=acf.applyFilters("color_picker_args",t,this);i.wpColorPicker(t)},onDuplicate:function(t,e,i){$colorPicker=i.find(".wp-picker-container"),$inputText=i.find('input[type="text"]'),$colorPicker.replaceWith($inputText)}});acf.registerFieldType(t)}(jQuery),function(n){var t=acf.Field.extend({type:"date_picker",events:{'blur input[type="text"]':"onBlur",duplicateField:"onDuplicate"},$control:function(){return this.$(".acf-date-picker")},$input:function(){return this.$('input[type="hidden"]')},$inputText:function(){return this.$('input[type="text"]')},initialize:function(){if(this.has("save_format"))return this.initializeCompatibility();var t=this.$input(),e=this.$inputText(),t={dateFormat:this.get("date_format"),altField:t,altFormat:"yymmdd",changeYear:!0,yearRange:"-100:+100",changeMonth:!0,showButtonPanel:!0,firstDay:this.get("first_day")},t=acf.applyFilters("date_picker_args",t,this);acf.newDatePicker(e,t),acf.doAction("date_picker_init",e,t,this)},initializeCompatibility:function(){var t=this.$input(),e=this.$inputText();e.val(t.val());var i={dateFormat:this.get("date_format"),altField:t,altFormat:this.get("save_format"),changeYear:!0,yearRange:"-100:+100",changeMonth:!0,showButtonPanel:!0,firstDay:this.get("first_day")},t=(i=acf.applyFilters("date_picker_args",i,this)).dateFormat;i.dateFormat=this.get("save_format"),acf.newDatePicker(e,i),e.datepicker("option","dateFormat",t),acf.doAction("date_picker_init",e,i,this)},onBlur:function(){this.$inputText().val()||acf.val(this.$input(),"")},onDuplicate:function(t,e,i){i.find('input[type="text"]').removeClass("hasDatepicker").removeAttr("id")}});acf.registerFieldType(t);new acf.Model({priority:5,wait:"ready",initialize:function(){var t=acf.get("locale"),e=acf.get("rtl"),i=acf.get("datePickerL10n");return!!i&&(void 0!==n.datepicker&&(i.isRTL=e,n.datepicker.regional[t]=i,void n.datepicker.setDefaults(i)))}});acf.newDatePicker=function(t,e){if(void 0===n.datepicker)return!1;t.datepicker(e=e||{}),n("body > #ui-datepicker-div").exists()&&n("body > #ui-datepicker-div").wrap('
    ')}}(jQuery),function(n){var t=acf.models.DatePickerField.extend({type:"date_time_picker",$control:function(){return this.$(".acf-date-time-picker")},initialize:function(){var t=this.$input(),e=this.$inputText(),t={dateFormat:this.get("date_format"),timeFormat:this.get("time_format"),altField:t,altFieldTimeOnly:!1,altFormat:"yy-mm-dd",altTimeFormat:"HH:mm:ss",changeYear:!0,yearRange:"-100:+100",changeMonth:!0,showButtonPanel:!0,firstDay:this.get("first_day"),controlType:"select",oneLine:!0},t=acf.applyFilters("date_time_picker_args",t,this);acf.newDateTimePicker(e,t),acf.doAction("date_time_picker_init",e,t,this)}});acf.registerFieldType(t);new acf.Model({priority:5,wait:"ready",initialize:function(){var t=acf.get("locale"),e=acf.get("rtl"),i=acf.get("dateTimePickerL10n");return!!i&&(void 0!==n.timepicker&&(i.isRTL=e,n.timepicker.regional[t]=i,void n.timepicker.setDefaults(i)))}});acf.newDateTimePicker=function(t,e){if(void 0===n.timepicker)return!1;t.datetimepicker(e=e||{}),n("body > #ui-datepicker-div").exists()&&n("body > #ui-datepicker-div").wrap('
    ')}}(jQuery),function(e){var t=acf.Field.extend({type:"google_map",map:!1,wait:"load",events:{'click a[data-name="clear"]':"onClickClear",'click a[data-name="locate"]':"onClickLocate",'click a[data-name="search"]':"onClickSearch","keydown .search":"onKeydownSearch","keyup .search":"onKeyupSearch","focus .search":"onFocusSearch","blur .search":"onBlurSearch",showField:"onShow"},$control:function(){return this.$(".acf-google-map")},$search:function(){return this.$(".search")},$canvas:function(){return this.$(".canvas")},setState:function(t){this.$control().removeClass("-value -loading -searching"),(t="default"===t?this.val()?"value":"":t)&&this.$control().addClass("-"+t)},getValue:function(){var t=this.$input().val();return!!t&&JSON.parse(t)},setValue:function(t,e){var i="";t&&(i=JSON.stringify(t)),acf.val(this.$input(),i),e||(this.renderVal(t),acf.doAction("google_map_change",t,this.map,this))},renderVal:function(t){t?(this.setState("value"),this.$search().val(t.address),this.setPosition(t.lat,t.lng)):(this.setState(""),this.$search().val(""),this.map.marker.setVisible(!1))},newLatLng:function(t,e){return new google.maps.LatLng(parseFloat(t),parseFloat(e))},setPosition:function(t,e){this.map.marker.setPosition({lat:parseFloat(t),lng:parseFloat(e)}),this.map.marker.setVisible(!0),this.center()},center:function(){var t,e=this.map.marker.getPosition();e=e?(t=e.lat(),e.lng()):(t=this.get("lat"),this.get("lng")),this.map.setCenter({lat:parseFloat(t),lng:parseFloat(e)})},initialize:function(){!function(t){if(a)return t();if(acf.isset(window,"google","maps","Geocoder"))return a=new google.maps.Geocoder,t();acf.addAction("google_map_api_loaded",t),i||(t=acf.get("google_map_api"))&&(i=!0,e.ajax({url:t,dataType:"script",cache:!0,success:function(){a=new google.maps.Geocoder,acf.doAction("google_map_api_loaded")}}))}(this.initializeMap.bind(this))},initializeMap:function(){var t=this.getValue(),e=acf.parseArgs(t,{zoom:this.get("zoom"),lat:this.get("lat"),lng:this.get("lng")}),i={scrollwheel:!1,zoom:parseInt(e.zoom),center:{lat:parseFloat(e.lat),lng:parseFloat(e.lng)},mapTypeId:google.maps.MapTypeId.ROADMAP,marker:{draggable:!0,raiseOnDrag:!0},autocomplete:{}},i=acf.applyFilters("google_map_args",i,this),n=new google.maps.Map(this.$canvas()[0],i),a=acf.parseArgs(i.marker,{draggable:!0,raiseOnDrag:!0,map:n}),a=acf.applyFilters("google_map_marker_args",a,this),e=new google.maps.Marker(a),a=!1;acf.isset(google,"maps","places","Autocomplete")&&(i=i.autocomplete||{},i=acf.applyFilters("google_map_autocomplete_args",i,this),(a=new google.maps.places.Autocomplete(this.$search()[0],i)).bindTo("bounds",n)),this.addMapEvents(this,n,e,a),n.acf=this,n.marker=e,n.autocomplete=a,this.map=n,t&&this.setPosition(t.lat,t.lng),acf.doAction("google_map_init",n,e,this)},addMapEvents:function(i,e,t,n){google.maps.event.addListener(e,"click",function(t){var e=t.latLng.lat(),t=t.latLng.lng();i.searchPosition(e,t)}),google.maps.event.addListener(t,"dragend",function(){var t=this.getPosition().lat(),e=this.getPosition().lng();i.searchPosition(t,e)}),n&&google.maps.event.addListener(n,"place_changed",function(){var t=this.getPlace();i.searchPlace(t)}),google.maps.event.addListener(e,"zoom_changed",function(){var t=i.val();t&&(t.zoom=e.getZoom(),i.setValue(t,!0))})},searchPosition:function(i,n){this.setState("loading"),a.geocode({location:{lat:i,lng:n}},function(t,e){this.setState(""),"OK"!==e?this.showNotice({text:acf.__("Location not found: %s").replace("%s",e),type:"warning"}):((t=this.parseResult(t[0])).lat=i,t.lng=n,this.val(t))}.bind(this))},searchPlace:function(t){var e;t&&(t.geometry?(t.formatted_address=this.$search().val(),e=this.parseResult(t),this.val(e)):t.name&&this.searchAddress(t.name))},searchAddress:function(i){if(i){var t=i.split(",");if(2==t.length){var e=parseFloat(t[0]),t=parseFloat(t[1]);if(e&&t)return this.searchPosition(e,t)}this.setState("loading"),a.geocode({address:i},function(t,e){this.setState(""),"OK"!==e?this.showNotice({text:acf.__("Location not found: %s").replace("%s",e),type:"warning"}):((t=this.parseResult(t[0])).address=i,this.val(t))}.bind(this))}},searchLocation:function(){if(!navigator.geolocation)return alert(acf.__("Sorry, this browser does not support geolocation"));this.setState("loading"),navigator.geolocation.getCurrentPosition(function(t){this.setState("");var e=t.coords.latitude,t=t.coords.longitude;this.searchPosition(e,t)}.bind(this),function(t){this.setState("")}.bind(this))},parseResult:function(t){var e={address:t.formatted_address,lat:t.geometry.location.lat(),lng:t.geometry.location.lng()};e.zoom=this.map.getZoom(),t.place_id&&(e.place_id=t.place_id),t.name&&(e.name=t.name);var i,n={street_number:["street_number"],street_name:["street_address","route"],city:["locality"],state:["administrative_area_level_1","administrative_area_level_2","administrative_area_level_3","administrative_area_level_4","administrative_area_level_5"],post_code:["postal_code"],country:["country"]};for(i in n)for(var a=n[i],s=0;s
    '):this.$el=n('
      '),i.before(this.$el),this.set("index",a,!0),a++},initializeTabs:function(){var t=this.getVisible().shift(),e=(acf.getPreference("this.tabs")||[])[this.get("index")];(t=this.tabs[e]&&this.tabs[e].isVisible()?this.tabs[e]:t)?this.selectTab(t):this.closeTabs(),this.set("initialized",!0)},getVisible:function(){return this.tabs.filter(function(t){return t.isVisible()})},getActive:function(){return this.active},setActive:function(t){return this.active=t},hasActive:function(){return!1!==this.active},isActive:function(t){var e=this.getActive();return e&&e.cid===t.cid},closeActive:function(){this.hasActive()&&this.closeTab(this.getActive())},openTab:function(t){this.closeActive(),t.open(),this.setActive(t)},closeTab:function(t){t.close(),this.setActive(!1)},closeTabs:function(){this.tabs.map(this.closeTab,this)},selectTab:function(e){this.tabs.map(function(t){e.cid!==t.cid&&this.closeTab(t)},this),this.openTab(e)},addTab:function(t,e){t=n("
    • "+t.outerHTML()+"
    • ");this.$("ul").append(t);e=new i({$el:t,field:e,group:this});return this.tabs.push(e),e},reset:function(){return this.closeActive(),this.refresh()},refresh:function(){if(this.hasActive())return!1;var t=this.getVisible().shift();return t&&this.openTab(t),t},onRefresh:function(){var t,e,i;"left"===this.get("placement")&&(t=this.$el.parent(),i=this.$el.children("ul"),e=t.is("td")?"height":"min-height",i=i.position().top+i.outerHeight(!0)-1,t.css(e,i))}}),i=acf.Model.extend({group:!1,field:!1,events:{"click a":"onClick"},index:function(){return this.$el.index()},isVisible:function(){return acf.isVisible(this.$el)},isActive:function(){return this.$el.hasClass("active")},open:function(){this.$el.addClass("active"),this.field.showFields()},close:function(){this.$el.removeClass("active"),this.field.hideFields()},onClick:function(t,e){t.preventDefault(),this.toggle()},toggle:function(){this.isActive()||this.group.openTab(this)}});new acf.Model({priority:50,actions:{prepare:"render",append:"render",unload:"onUnload",invalid_field:"onInvalidField"},findTabs:function(){return n(".acf-tab-wrap")},getTabs:function(){return acf.getInstances(this.findTabs())},render:function(t){this.getTabs().map(function(t){t.get("initialized")||t.initializeTabs()})},onInvalidField:function(t){this.busy||t.hiddenByTab&&(t.hiddenByTab.toggle(),this.busy=!0,this.setTimeout(function(){this.busy=!1},100))},onUnload:function(){var e=[];this.getTabs().map(function(t){t=t.hasActive()?t.getActive().index():0;e.push(t)}),e.length&&acf.setPreference("this.tabs",e)}})}(jQuery),function(){var t=acf.models.SelectField.extend({type:"post_object"});acf.registerFieldType(t)}(jQuery),function(){var t=acf.models.SelectField.extend({type:"page_link"});acf.registerFieldType(t)}(jQuery),function(){var t=acf.models.SelectField.extend({type:"user"});acf.registerFieldType(t)}(jQuery),function(p){var t=acf.Field.extend({type:"taxonomy",data:{ftype:"select"},select2:!1,wait:"load",events:{'click a[data-name="add"]':"onClickAdd",'click input[type="radio"]':"onClickRadio",removeField:"onRemove"},$control:function(){return this.$(".acf-taxonomy-field")},$input:function(){return this.getRelatedPrototype().$input.apply(this,arguments)},getRelatedType:function(){var t=this.get("ftype");return t="multi_select"==t?"select":t},getRelatedPrototype:function(){return acf.getFieldType(this.getRelatedType()).prototype},getValue:function(){return this.getRelatedPrototype().getValue.apply(this,arguments)},setValue:function(){return this.getRelatedPrototype().setValue.apply(this,arguments)},initialize:function(){this.getRelatedPrototype().initialize.apply(this,arguments)},onRemove:function(){var t=this.getRelatedPrototype();t.onRemove&&t.onRemove.apply(this,arguments)},onClickAdd:function(t,e){var i=this,n=!1,a=!1,s=!1,o=!1,r=!1,c=!1,l=function(t){n.loading(!1),n.content(t),a=n.$("form"),s=n.$('input[name="term_name"]'),o=n.$('select[name="term_parent"]'),r=n.$(".acf-submit-button"),s.trigger("focus"),n.on("submit","form",d)},d=function(t,e){if(t.preventDefault(),t.stopImmediatePropagation(),""===s.val())return s.trigger("focus"),!1;acf.startButtonLoading(r);t={action:"acf/fields/taxonomy/add_term",field_key:i.get("key"),term_name:s.val(),term_parent:o.length?o.val():0};p.ajax({url:acf.get("ajaxurl"),data:acf.prepareForAjax(t),type:"post",dataType:"json",success:u})},u=function(t){acf.stopButtonLoading(r),c&&c.remove(),c=acf.isAjaxSuccess(t)?(s.val(""),f(t.data),acf.newNotice({type:"success",text:acf.getAjaxMessage(t),target:a,timeout:2e3,dismiss:!1})):acf.newNotice({type:"error",text:acf.getAjaxError(t),target:a,timeout:2e3,dismiss:!1}),s.trigger("focus")},f=function(e){var t=p('");e.term_parent?o.children('option[value="'+e.term_parent+'"]').after(t):o.append(t),acf.getFields({type:"taxonomy"}).map(function(t){t.get("taxonomy")==i.get("taxonomy")&&t.appendTerm(e)}),i.selectTerm(e.term_id)};!function(){n=acf.newPopup({title:e.attr("title"),loading:!0,width:"300px"});var t={action:"acf/fields/taxonomy/add_term",field_key:i.get("key")};p.ajax({url:acf.get("ajaxurl"),data:acf.prepareForAjax(t),type:"post",dataType:"html",success:l})}()},appendTerm:function(t){"select"==this.getRelatedType()?this.appendTermSelect(t):this.appendTermCheckbox(t)},appendTermSelect:function(t){this.select2.addOption({id:t.term_id,text:t.term_label})},appendTermCheckbox:function(t){var e=this.$("[name]:first").attr("name"),i=this.$("ul:first");"checkbox"==this.getRelatedType()&&(e+="[]");e=p(['
    • ',"","
    • "].join(""));t.term_parent&&((i=(t=i.find('li[data-id="'+t.term_parent+'"]')).children("ul")).exists()||(i=p('
        '),t.append(i))),i.append(e)},selectTerm:function(t){"select"==this.getRelatedType()?this.select2.selectOption(t):this.$('input[value="'+t+'"]').prop("checked",!0).trigger("change")},onClickRadio:function(t,e){var i=e.parent("label"),n=i.hasClass("selected");this.$(".selected").removeClass("selected"),i.addClass("selected"),this.get("allow_null")&&n&&(i.removeClass("selected"),e.prop("checked",!1).trigger("change"))}});acf.registerFieldType(t)}(jQuery),function(i){var t=acf.models.DatePickerField.extend({type:"time_picker",$control:function(){return this.$(".acf-time-picker")},initialize:function(){var t=this.$input(),e=this.$inputText(),t={timeFormat:this.get("time_format"),altField:t,altFieldTimeOnly:!1,altTimeFormat:"HH:mm:ss",showButtonPanel:!0,controlType:"select",oneLine:!0,closeText:acf.get("dateTimePickerL10n").selectText,timeOnly:!0,onClose:function(t,e,i){e=e.dpDiv.find(".ui-datepicker-close");!t&&e.is(":hover")&&i._updateDateTime()}},t=acf.applyFilters("time_picker_args",t,this);acf.newTimePicker(e,t),acf.doAction("time_picker_init",e,t,this)}});acf.registerFieldType(t),acf.newTimePicker=function(t,e){if(void 0===i.timepicker)return!1;t.timepicker(e=e||{}),i("body > #ui-datepicker-div").exists()&&i("body > #ui-datepicker-div").wrap('
        ')}}(jQuery),function(){var t=acf.Field.extend({type:"true_false",events:{"change .acf-switch-input":"onChange","focus .acf-switch-input":"onFocus","blur .acf-switch-input":"onBlur","keypress .acf-switch-input":"onKeypress"},$input:function(){return this.$('input[type="checkbox"]')},$switch:function(){return this.$(".acf-switch")},getValue:function(){return this.$input().prop("checked")?1:0},initialize:function(){this.render()},render:function(){var t,e,i=this.$switch();i.length&&(t=i.children(".acf-switch-on"),e=i.children(".acf-switch-off"),(i=Math.max(t.width(),e.width()))&&(t.css("min-width",i),e.css("min-width",i)))},switchOn:function(){this.$input().prop("checked",!0),this.$switch().addClass("-on")},switchOff:function(){this.$input().prop("checked",!1),this.$switch().removeClass("-on")},onChange:function(t,e){e.prop("checked")?this.switchOn():this.switchOff()},onFocus:function(t,e){this.$switch().addClass("-focus")},onBlur:function(t,e){this.$switch().removeClass("-focus")},onKeypress:function(t,e){return 37===t.keyCode?this.switchOff():39===t.keyCode?this.switchOn():void 0}});acf.registerFieldType(t)}(jQuery),function(){var t=acf.Field.extend({type:"url",events:{'keyup input[type="url"]':"onkeyup"},$control:function(){return this.$(".acf-input-wrap")},$input:function(){return this.$('input[type="url"]')},initialize:function(){this.render()},isValid:function(){var t=this.val();return!!t&&(-1!==t.indexOf("://")||0===t.indexOf("//"))},render:function(){this.isValid()?this.$control().addClass("-valid"):this.$control().removeClass("-valid")},onkeyup:function(t,e){this.render()}});acf.registerFieldType(t)}(jQuery),function(){var t=acf.Field.extend({type:"wysiwyg",wait:"load",events:{"mousedown .acf-editor-wrap.delay":"onMousedown",unmountField:"disableEditor",remountField:"enableEditor",removeField:"disableEditor"},$control:function(){return this.$(".acf-editor-wrap")},$input:function(){return this.$("textarea")},getMode:function(){return this.$control().hasClass("tmce-active")?"visual":"text"},initialize:function(){this.$control().hasClass("delay")||this.initializeEditor()},initializeEditor:function(){var t=this.$control(),e=this.$input(),i={tinymce:!0,quicktags:!0,toolbar:this.get("toolbar"),mode:this.getMode(),field:this},n=e.attr("id"),a=acf.uniqueId("acf-editor-"),s=e.data(),e=e.val();acf.rename({target:t,search:n,replace:a,destructive:!0}),this.set("id",a,!0),this.$input().data(s).val(e),acf.tinymce.initialize(a,i)},onMousedown:function(t){t.preventDefault();t=this.$control();t.removeClass("delay"),t.find(".acf-editor-toolbar").remove(),this.initializeEditor()},enableEditor:function(){"visual"==this.getMode()&&acf.tinymce.enable(this.get("id"))},disableEditor:function(){acf.tinymce.destroy(this.get("id"))}});acf.registerFieldType(t)}(jQuery),function(e){var s=[];acf.Condition=acf.Model.extend({type:"",operator:"==",label:"",choiceType:"input",fieldTypes:[],data:{conditions:!1,field:!1,rule:{}},events:{change:"change",keyup:"change",enableField:"change",disableField:"change"},setup:function(t){e.extend(this.data,t)},getEventTarget:function(t,e){return t||this.get("field").$el},change:function(t,e){this.get("conditions").change(t)},match:function(t,e){return!1},calculate:function(){return this.match(this.get("rule"),this.get("field"))},choices:function(t){return''}}),acf.newCondition=function(t,e){var i=e.get("field"),n=i.getField(t.field);if(!i||!n)return!1;e={rule:t,target:i,conditions:e,field:n},n=n.get("type"),t=t.operator;return new(acf.getConditionTypes({fieldType:n,operator:t})[0]||acf.Condition)(e)};function n(t){return acf.strPascalCase(t||"")+"Condition"}acf.registerConditionType=function(t){var e=t.prototype.type,i=n(e);acf.models[i]=t,s.push(e)},acf.getConditionType=function(t){t=n(t);return acf.models[t]||!1},acf.registerConditionForFieldType=function(t,e){t=acf.getConditionType(t);t&&t.prototype.fieldTypes.push(e)},acf.getConditionTypes=function(n){n=acf.parseArgs(n,{fieldType:"",operator:""});var a=[];return s.map(function(t){var e=acf.getConditionType(t),i=e.prototype.fieldTypes,t=e.prototype.operator;n.fieldType&&-1===i.indexOf(n.fieldType)||n.operator&&t!==n.operator||a.push(e)}),a}}(jQuery),function(){function a(t,e){var i=acf.getFields({key:e,sibling:t.$el,suppressFilters:!0});return!!(i=!i.length?acf.getFields({key:e,parent:t.$el.parent(),suppressFilters:!0}):i).length&&i[0]}var t="conditional_logic";new acf.Model({id:"conditionsManager",priority:20,actions:{new_field:"onNewField"},onNewField:function(t){t.has("conditions")&&t.getConditions().render()}});acf.Field.prototype.getField=function(t){var e=a(this,t);if(e)return e;for(var i=this.parents(),n=0;n'}});acf.registerConditionType(i);var t=i.extend({type:"hasNoValue",operator:"==empty",label:s("Has no value"),match:function(t,e){return!i.prototype.match.apply(this,arguments)}});acf.registerConditionType(t);var o=acf.Condition.extend({type:"equalTo",operator:"==",label:s("Value is equal to"),fieldTypes:["text","textarea","number","range","email","url","password"],match:function(t,e){return acf.isNumeric(t.value)?(i=t.value,n=e.val(),parseFloat(i)===parseFloat(n)):a(t.value,e.val());var i,n},choices:function(t){return''}});acf.registerConditionType(o);var e=o.extend({type:"notEqualTo",operator:"!=",label:s("Value is not equal to"),match:function(t,e){return!o.prototype.match.apply(this,arguments)}});acf.registerConditionType(e);t=acf.Condition.extend({type:"patternMatch",operator:"==pattern",label:s("Value matches pattern"),fieldTypes:["text","textarea","email","url","password","wysiwyg"],match:function(t,e){return function(t,e){e=new RegExp(n(e),"gi");return n(t).match(e)}(e.val(),t.value)},choices:function(t){return''}});acf.registerConditionType(t);t=acf.Condition.extend({type:"contains",operator:"==contains",label:s("Value contains"),fieldTypes:["text","textarea","number","email","url","password","wysiwyg","oembed","select"],match:function(t,e){return e=e.val(),t=t.value,-1'}});acf.registerConditionType(t);t=o.extend({type:"trueFalseEqualTo",choiceType:"select",fieldTypes:["true_false"],choices:function(t){return[{id:1,text:s("Checked")}]}});acf.registerConditionType(t);t=e.extend({type:"trueFalseNotEqualTo",choiceType:"select",fieldTypes:["true_false"],choices:function(t){return[{id:1,text:s("Checked")}]}});acf.registerConditionType(t);var r=acf.Condition.extend({type:"selectEqualTo",operator:"==",label:s("Value is equal to"),fieldTypes:["select","checkbox","radio","button_group"],match:function(t,e){var i=e.val();return i instanceof Array?(e=t.value,-1",label:s("Value is greater than"),fieldTypes:["number","range"],match:function(t,e){e=e.val();return e instanceof Array&&(e=e.length),e=e,t=t.value,parseFloat(e)>parseFloat(t)},choices:function(t){return''}});acf.registerConditionType(t);e=t.extend({type:"lessThan",operator:"<",label:s("Value is less than"),match:function(t,e){e=e.val();return e instanceof Array&&(e=e.length),e=e,t=t.value,parseFloat(e)'}});acf.registerConditionType(e);t=t.extend({type:"selectionGreaterThan",label:s("Selection is greater than"),fieldTypes:["checkbox","select","post_object","page_link","relationship","taxonomy","user"]});acf.registerConditionType(t);e=e.extend({type:"selectionLessThan",label:s("Selection is less than"),fieldTypes:["checkbox","select","post_object","page_link","relationship","taxonomy","user"]});acf.registerConditionType(e)}(jQuery),function(t){acf.unload=new acf.Model({wait:"load",active:!0,changed:!1,actions:{validation_failure:"startListening",validation_success:"stopListening"},events:{"change form .acf-field":"startListening","submit form":"stopListening"},enable:function(){this.active=!0},disable:function(){this.active=!1},reset:function(){this.stopListening()},startListening:function(){!this.changed&&this.active&&(this.changed=!0,t(window).on("beforeunload",this.onUnload))},stopListening:function(){this.changed=!1,t(window).off("beforeunload",this.onUnload)},onUnload:function(){return acf.__("The changes you made will be lost if you navigate away from this page")}})}(jQuery),function(e){new acf.Model({wait:"prepare",priority:1,initialize:function(){(acf.get("postboxes")||[]).map(acf.newPostbox)}});acf.getPostbox=function(t){return"string"==typeof arguments[0]&&(t=e("#"+arguments[0])),acf.getInstance(t)},acf.getPostboxes=function(){return acf.getInstances(e(".acf-postbox"))},acf.newPostbox=function(t){return new acf.models.Postbox(t)},acf.models.Postbox=acf.Model.extend({data:{id:"",key:"",style:"default",label:"top",edit:""},setup:function(t){t.editLink&&(t.edit=t.editLink),e.extend(this.data,t),this.$el=this.$postbox()},$postbox:function(){return e("#"+this.get("id"))},$hide:function(){return e("#"+this.get("id")+"-hide")},$hideLabel:function(){return this.$hide().parent()},$hndle:function(){return this.$("> .hndle")},$handleActions:function(){return this.$("> .postbox-header .handle-actions")},$inside:function(){return this.$("> .inside")},isVisible:function(){return this.$el.hasClass("acf-hidden")},initialize:function(){this.$el.addClass("acf-postbox"),this.$el.removeClass("hide-if-js"),"block"===acf.get("editor")||"default"!==(t=this.get("style"))&&this.$el.addClass(t),this.$inside().addClass("acf-fields").addClass("-"+this.get("label"));var t,e=this.get("edit");e&&(t='',(e=this.$handleActions()).length?e.prepend(t):this.$hndle().append(t)),this.show()},show:function(){this.$hideLabel().show(),this.$hide().prop("checked",!0),this.$el.show().removeClass("acf-hidden"),acf.doAction("show_postbox",this)},enable:function(){acf.enable(this.$el,"postbox")},showEnable:function(){this.enable(),this.show()},hide:function(){this.$hideLabel().hide(),this.$el.hide().addClass("acf-hidden"),acf.doAction("hide_postbox",this)},disable:function(){acf.disable(this.$el,"postbox")},hideDisable:function(){this.disable(),this.hide()},html:function(t){this.$inside().html(t),acf.doAction("append",this.$el)}})}(jQuery),function(a){acf.newMediaPopup=function(t){var e=null,e=new("edit"==(t=acf.parseArgs(t,{mode:"select",title:"",button:"",type:"",field:!1,allowedTypes:"",library:"all",multiple:!1,attachment:0,autoOpen:!0,open:function(){},select:function(){},close:function(){}})).mode?acf.models.EditMediaPopup:acf.models.SelectMediaPopup)(t);return t.autoOpen&&setTimeout(function(){e.open()},1),acf.doAction("new_media_popup",e),e};function e(){var t=acf.get("post_id");return acf.isNumeric(t)?t:0}acf.getMimeTypes=function(){return this.get("mimeTypes")},acf.getMimeType=function(t){var e,i=acf.getMimeTypes();if(void 0!==i[t])return i[t];for(e in i)if(-1!==e.indexOf(t))return i[e];return!1};var n=acf.Model.extend({id:"MediaPopup",data:{},defaults:{},frame:!1,setup:function(t){a.extend(this.data,t)},initialize:function(){var t=this.getFrameOptions();this.addFrameStates(t);var e=wp.media(t);(e.acf=this).addFrameEvents(e,t),this.frame=e},open:function(){this.frame.open()},close:function(){this.frame.close()},remove:function(){this.frame.detach(),this.frame.remove()},getFrameOptions:function(){var t={title:this.get("title"),multiple:this.get("multiple"),library:{},states:[]};return this.get("type")&&(t.library.type=this.get("type")),"uploadedTo"===this.get("library")&&(t.library.uploadedTo=e()),this.get("attachment")&&(t.library.post__in=[this.get("attachment")]),this.get("button")&&(t.button={text:this.get("button")}),t},addFrameStates:function(t){var e=wp.media.query(t.library);this.get("field")&&acf.isset(e,"mirroring","args")&&(e.mirroring.args._acfuploader=this.get("field")),t.states.push(new wp.media.controller.Library({library:e,multiple:this.get("multiple"),title:this.get("title"),priority:20,filterable:"all",editable:!0,allowLocalEdits:!0})),acf.isset(wp,"media","controller","EditImage")&&t.states.push(new wp.media.controller.EditImage)},addFrameEvents:function(i,t){i.on("open",function(){this.$el.closest(".media-modal").addClass("acf-media-modal -"+this.acf.get("mode"))},i),i.on("content:render:edit-image",function(){var t=this.state().get("image"),t=new wp.media.view.EditImage({model:t,controller:this}).render();this.content.set(t),t.loadEditor()},i),i.on("select",function(){var t=i.state().get("selection");t&&t.each(function(t,e){i.acf.get("select").apply(i.acf,[t,e])})}),i.on("close",function(){setTimeout(function(){i.acf.get("close").apply(i.acf),i.acf.remove()},1)})}});acf.models.SelectMediaPopup=n.extend({id:"SelectMediaPopup",setup:function(t){t.button||(t.button=acf._x("Select","verb")),n.prototype.setup.apply(this,arguments)},addFrameEvents:function(e,t){acf.isset(_wpPluploadSettings,"defaults","multipart_params")&&(_wpPluploadSettings.defaults.multipart_params._acfuploader=this.get("field"),e.on("open",function(){delete _wpPluploadSettings.defaults.multipart_params._acfuploader})),e.on("content:activate:browse",function(){var t=!1;try{t=e.content.get().toolbar}catch(t){return void console.log(t)}e.acf.customizeFilters.apply(e.acf,[t])}),n.prototype.addFrameEvents.apply(this,arguments)},customizeFilters:function(t){var i,e=t.get("filters");"image"==this.get("type")&&(e.filters.all.text=acf.__("All images"),delete e.filters.audio,delete e.filters.video,delete e.filters.image,a.each(e.filters,function(t,e){e.props.type=e.props.type||"image"})),this.get("allowedTypes")&&this.get("allowedTypes").split(" ").join("").split(".").join("").split(",").map(function(t){t=acf.getMimeType(t);t&&(e.filters[t]={text:t,props:{status:null,type:t,uploadedTo:null,orderby:"date",order:"DESC"},priority:20})}),"uploadedTo"===this.get("library")&&(i=this.frame.options.library.uploadedTo,delete e.filters.unattached,delete e.filters.uploaded,a.each(e.filters,function(t,e){e.text+=" ("+acf.__("Uploaded to this post")+")",e.props.uploadedTo=i}));var n=this.get("field");a.each(e.filters,function(t,e){e.props._acfuploader=n}),t.get("search").model.attributes._acfuploader=n,e.renderFilters&&e.renderFilters()}}),acf.models.EditMediaPopup=n.extend({id:"SelectMediaPopup",setup:function(t){t.button||(t.button=acf._x("Update","verb")),n.prototype.setup.apply(this,arguments)},addFrameEvents:function(i,t){i.on("open",function(){this.$el.closest(".media-modal").addClass("acf-expanded"),"browse"!=this.content.mode()&&this.content.mode("browse");var t=this.state().get("selection"),e=wp.media.attachment(i.acf.get("attachment"));t.add(e)},i),n.prototype.addFrameEvents.apply(this,arguments)}});new acf.Model({id:"customizePrototypes",wait:"ready",initialize:function(){var t;acf.isset(window,"wp","media","view")&&((t=e())&&acf.isset(wp,"media","view","settings","post")&&(wp.media.view.settings.post.id=t),this.customizeAttachmentsButton(),this.customizeAttachmentsRouter(),this.customizeAttachmentFilters(),this.customizeAttachmentCompat(),this.customizeAttachmentLibrary())},customizeAttachmentsButton:function(){var t;acf.isset(wp,"media","view","Button")&&(t=wp.media.view.Button,wp.media.view.Button=t.extend({initialize:function(){var t=_.defaults(this.options,this.defaults);this.model=new Backbone.Model(t),this.listenTo(this.model,"change",this.render)}}))},customizeAttachmentsRouter:function(){var t;acf.isset(wp,"media","view","Router")&&(t=wp.media.view.Router,wp.media.view.Router=t.extend({addExpand:function(){var t=a(['',''+acf.__("Expand Details")+"",''+acf.__("Collapse Details")+"",""].join(""));t.on("click",function(t){t.preventDefault();t=a(this).closest(".media-modal");t.hasClass("acf-expanded")?t.removeClass("acf-expanded"):t.addClass("acf-expanded")}),this.$el.append(t)},initialize:function(){return t.prototype.initialize.apply(this,arguments),this.addExpand(),this}}))},customizeAttachmentFilters:function(){acf.isset(wp,"media","view","AttachmentFilters","All")&&(wp.media.view.AttachmentFilters.All.prototype.renderFilters=function(){this.$el.html(_.chain(this.filters).map(function(t,e){return{el:a("").val(e).html(t.text)[0],priority:t.priority||50}},this).sortBy("priority").pluck("el").value())})},customizeAttachmentCompat:function(){var t,e;acf.isset(wp,"media","view","AttachmentCompat")&&(t=wp.media.view.AttachmentCompat,e=!1,wp.media.view.AttachmentCompat=t.extend({render:function(){return this.rendered?this:(t.prototype.render.apply(this,arguments),this.$("#acf-form-data").length&&(clearTimeout(e),e=setTimeout(a.proxy(function(){this.rendered=!0,acf.doAction("append",this.$el)},this),50)),this)},save:function(t){var e;t&&t.preventDefault(),e=acf.serializeForAjax(this.$el),this.controller.trigger("attachment:compat:waiting",["waiting"]),this.model.saveCompat(e).always(_.bind(this.postSave,this))}}))},customizeAttachmentLibrary:function(){var o;acf.isset(wp,"media","view","Attachment","Library")&&(o=wp.media.view.Attachment.Library,wp.media.view.Attachment.Library=o.extend({render:function(){var t=acf.isget(this,"controller","acf"),e=acf.isget(this,"model","attributes");return t&&e&&(e.acf_errors&&this.$el.addClass("acf-disabled"),(t=t.get("selected"))&&-1',''+acf.__("Restricted")+"",''+n+"",''+a+"","
        "].join("")),e.reset(),void e.single(i)}return o.prototype.toggleSelection.apply(this,arguments)}}))}})}(jQuery),function(u){acf.screen=new acf.Model({active:!0,xhr:!1,timeout:!1,wait:"load",events:{"change #page_template":"onChange","change #parent_id":"onChange","change #post-formats-select":"onChange","change .categorychecklist":"onChange","change .tagsdiv":"onChange",'change .acf-taxonomy-field[data-save="1"]':"onChange","change #product-type":"onChange"},isPost:function(){return"post"===acf.get("screen")},isUser:function(){return"user"===acf.get("screen")},isTaxonomy:function(){return"taxonomy"===acf.get("screen")},isAttachment:function(){return"attachment"===acf.get("screen")},isNavMenu:function(){return"nav_menu"===acf.get("screen")},isWidget:function(){return"widget"===acf.get("screen")},isComment:function(){return"comment"===acf.get("screen")},getPageTemplate:function(){var t=u("#page_template");return t.length?t.val():null},getPageParent:function(t,e){return(e=u("#parent_id")).length?e.val():null},getPageType:function(t,e){return this.getPageParent()?"child":"parent"},getPostType:function(){return u("#post_type").val()},getPostFormat:function(t,e){if((e=u("#post-formats-select input:checked")).length){e=e.val();return"0"==e?"standard":e}return null},getPostCoreTerms:function(){var t,e={},i=acf.serialize(u(".categorydiv, .tagsdiv"));for(t in i.tax_input&&(e=i.tax_input),i.post_category&&(e.category=i.post_category),e)acf.isArray(e[t])||(e[t]=e[t].split(/,[\s]?/));return e},getPostTerms:function(){var t,i=this.getPostCoreTerms();for(t in acf.getFields({type:"taxonomy"}).map(function(t){var e;t.get("save")&&(e=t.val(),t=t.get("taxonomy"),e&&(i[t]=i[t]||[],e=acf.isArray(e)?e:[e],i[t]=i[t].concat(e)))}),null!==(productType=this.getProductType())&&(i.product_type=[productType]),i)i[t]=acf.uniqueArray(i[t]);return i},getProductType:function(){var t=u("#product-type");return t.length?t.val():null},check:function(){var e;"post"===acf.get("screen")&&(this.xhr&&this.xhr.abort(),e=acf.parseArgs(this.data,{action:"acf/ajax/check_screen",screen:acf.get("screen"),exists:[]}),this.isPost()&&(e.post_id=acf.get("post_id")),null!==(postType=this.getPostType())&&(e.post_type=postType),null!==(pageTemplate=this.getPageTemplate())&&(e.page_template=pageTemplate),null!==(pageParent=this.getPageParent())&&(e.page_parent=pageParent),null!==(pageType=this.getPageType())&&(e.page_type=pageType),null!==(postFormat=this.getPostFormat())&&(e.post_format=postFormat),null!==(postTerms=this.getPostTerms())&&(e.post_terms=postTerms),acf.getPostboxes().map(function(t){e.exists.push(t.get("key"))}),e=acf.applyFilters("check_screen_args",e),this.xhr=u.ajax({url:acf.get("ajaxurl"),data:acf.prepareForAjax(e),type:"post",dataType:"json",context:this,success:function(t){"post"==acf.get("screen")?this.renderPostScreen(t):"user"==acf.get("screen")&&this.renderUserScreen(t),acf.doAction("check_screen_complete",t,e)}}))},onChange:function(t,e){this.setTimeout(this.check,1)},renderPostScreen:function(c){function l(t,e){var i,n=u._data(t[0]).events;for(i in n)for(var a=0;a','

        ',""+acf.escHtml(e.title)+"","

        ",'
        ','","
        ",""]:['",'

        ',""+acf.escHtml(e.title)+"","

        "]).join("");var n,a,s=u(['
        ',a,'
        ',e.html,"
        ","
        "].join(""));u("#adv-settings").length&&(n=u("#adv-settings .metabox-prefs"),a=u(['"].join("")),l(n.find("input").first(),a.find("input")),n.append(a)),u(".postbox").length&&(l(u(".postbox .handlediv").first(),s.children(".handlediv")),l(u(".postbox .hndle").first(),s.children(".hndle"))),"side"===e.position?u("#"+e.position+"-sortables").append(s):u("#"+e.position+"-sortables").prepend(s);var o=[];if(c.results.map(function(t){e.position===t.position&&u("#"+e.position+"-sortables #"+t.id).length&&o.push(t.id)}),d(e.id,o),c.sorted)for(var r in c.sorted){o=c.sorted[r].split(",");if(d(e.id,o))break}i=acf.newPostbox(e),acf.doAction("append",s),acf.doAction("append_postbox",i)}return i.showEnable(),c.visible.push(e.id),e}),acf.getPostboxes().map(function(t){-1===c.visible.indexOf(t.get("id"))&&(t.hideDisable(),c.hidden.push(t.get("id")))}),u("#acf-style").html(c.style),acf.doAction("refresh_post_screen",c)},renderUserScreen:function(t){}});new acf.Model({postEdits:{},wait:"prepare",initialize:function(){acf.isGutenberg()&&(wp.data.subscribe(acf.debounce(this.onChange).bind(this)),acf.screen.getPageTemplate=this.getPageTemplate,acf.screen.getPageParent=this.getPageParent,acf.screen.getPostType=this.getPostType,acf.screen.getPostFormat=this.getPostFormat,acf.screen.getPostCoreTerms=this.getPostCoreTerms,acf.unload.disable(),5.3<=parseFloat(acf.get("wp_version"))&&this.addAction("refresh_post_screen",this.onRefreshPostScreen),wp.domReady(acf.refresh))},onChange:function(){var e=["template","parent","format"];(wp.data.select("core").getTaxonomies()||[]).map(function(t){e.push(t.rest_base)});var i=wp.data.select("core/editor").getPostEdits(),n={};e.map(function(t){void 0!==i[t]&&(n[t]=i[t])}),JSON.stringify(n)!==JSON.stringify(this.postEdits)&&(this.postEdits=n,acf.screen.check())},getPageTemplate:function(){return wp.data.select("core/editor").getEditedPostAttribute("template")},getPageParent:function(t,e){return wp.data.select("core/editor").getEditedPostAttribute("parent")},getPostType:function(){return wp.data.select("core/editor").getEditedPostAttribute("type")},getPostFormat:function(t,e){return wp.data.select("core/editor").getEditedPostAttribute("format")},getPostCoreTerms:function(){var i={};return(wp.data.select("core").getTaxonomies()||[]).map(function(t){var e=wp.data.select("core/editor").getEditedPostAttribute(t.rest_base);e&&(i[t.slug]=e)}),i},onRefreshPostScreen:function(e){var i=wp.data.select("core/edit-post"),t=wp.data.dispatch("core/edit-post"),n={};i.getActiveMetaBoxLocations().map(function(t){n[t]=i.getMetaBoxesPerLocation(t)});var a,s=[];for(a in n)n[a].map(function(t){s.push(t.id)});for(a in e.results.filter(function(t){return-1===s.indexOf(t.id)}).map(function(t,e){var i=t.position;n[i]=n[i]||[],n[i].push({id:t.id,title:t.title})}),n)n[a]=n[a].filter(function(t){return-1===e.hidden.indexOf(t.id)});t.setAvailableMetaBoxesPerLocation(n)}})}(jQuery),function(l){function n(){return acf.isset(window,"jQuery","fn","select2","amd")?4:!!acf.isset(window,"Select2")&&3}acf.newSelect2=function(t,e){return e=acf.parseArgs(e,{allowNull:!1,placeholder:"",multiple:!1,field:!1,ajax:!1,ajaxAction:"",ajaxData:function(t){return t},ajaxResults:function(t){return t}}),e=new(4==n()?a:s)(t,e),acf.doAction("new_select2",e),e};var i=acf.Model.extend({setup:function(t,e){l.extend(this.data,e),this.$el=t},initialize:function(){},selectOption:function(t){t=this.getOption(t);t.prop("selected")||t.prop("selected",!0).trigger("change")},unselectOption:function(t){t=this.getOption(t);t.prop("selected")&&t.prop("selected",!1).trigger("change")},getOption:function(t){return this.$('option[value="'+t+'"]')},addOption:function(t){t=acf.parseArgs(t,{id:"",text:"",selected:!1});var e=this.getOption(t.id);return e.length||((e=l("")).html(t.text),e.attr("value",t.id),e.prop("selected",t.selected),this.$el.append(e)),e},getValue:function(){var e=[],t=this.$el.find("option:selected");return t.exists()&&(t=t.sort(function(t,e){return+t.getAttribute("data-i")-+e.getAttribute("data-i")})).each(function(){var t=l(this);e.push({$el:t,id:t.attr("value"),text:t.text()})}),e},mergeOptions:function(){},getChoices:function(){var i=function(t){var e=[];return t.children().each(function(){var t=l(this);t.is("optgroup")?e.push({text:t.attr("label"),children:i(t)}):e.push({id:t.attr("value"),text:t.text()})}),e};return i(this.$el)},getAjaxData:function(t){var e={action:this.get("ajaxAction"),s:t.term||"",paged:t.page||1},i=this.get("field");i&&(e.field_key=i.get("key"));var n=this.get("ajaxData");return n&&(e=n.apply(this,[e,t])),e=acf.applyFilters("select2_ajax_data",e,this.data,this.$el,i||!1,this),acf.prepareForAjax(e)},getAjaxResults:function(t,e){t=acf.parseArgs(t,{results:!1,more:!1});var i=this.get("ajaxResults");return i&&(t=i.apply(this,[t,e])),t=acf.applyFilters("select2_ajax_results",t,e,this)},processAjaxResults:function(t,e){return(t=this.getAjaxResults(t,e)).more&&(t.pagination={more:!0}),setTimeout(l.proxy(this.mergeOptions,this),1),t},destroy:function(){this.$el.data("select2")&&this.$el.select2("destroy"),this.$el.siblings(".select2-container").remove()}}),a=i.extend({initialize:function(){var e=this.$el;(n={width:"100%",allowClear:this.get("allowNull"),placeholder:this.get("placeholder"),multiple:this.get("multiple"),data:[],escapeMarkup:function(t){return acf.escHtml(t)}}).multiple&&this.getValue().map(function(t){t.$el.detach().appendTo(e)});var t=e.attr("data-ajax");void 0!==t&&(e.removeData("ajax"),e.removeAttr("data-ajax")),this.get("ajax")&&(n.ajax={url:acf.get("ajaxurl"),delay:250,dataType:"json",type:"post",cache:!1,data:l.proxy(this.getAjaxData,this),processResults:l.proxy(this.processAjaxResults,this)});var i=this.get("field"),n=acf.applyFilters("select2_args",n,e,this.data,i||!1,this);e.select2(n);var a,s=e.next(".select2-container");n.multiple&&((a=s.find("ul")).sortable({stop:function(t){a.find(".select2-selection__choice").each(function(){l(l(this).data("data").element).detach().appendTo(e)}),e.trigger("change")}}),e.on("select2:select",this.proxy(function(t){this.getOption(t.params.data.id).detach().appendTo(this.$el)}))),s.addClass("-acf"),void 0!==t&&e.attr("data-ajax",t),acf.doAction("select2_init",e,n,this.data,i||!1,this)},mergeOptions:function(){var i=!1,n=!1;l('.select2-results__option[role="group"]').each(function(){var t=l(this).children("ul"),e=l(this).children("strong");if(n&&n.text()===e.text())return i.append(t.children()),void l(this).remove();i=t,n=e})}}),s=i.extend({initialize:function(){var i=this.$el,n=this.getValue(),a=this.get("multiple"),t={width:"100%",allowClear:this.get("allowNull"),placeholder:this.get("placeholder"),separator:"||",multiple:this.get("multiple"),data:this.getChoices(),escapeMarkup:function(t){return acf.escHtml(t)},dropdownCss:{"z-index":"999999999"},initSelection:function(t,e){e(a?n:n.shift())}},e=i.siblings("input");e.length||(e=l(''),i.before(e)),inputValue=n.map(function(t){return t.id}).join("||"),e.val(inputValue),t.multiple&&n.map(function(t){t.$el.detach().appendTo(i)}),t.allowClear&&(t.data=t.data.filter(function(t){return""!==t.id})),i.removeData("ajax"),i.removeAttr("data-ajax"),this.get("ajax")&&(t.ajax={url:acf.get("ajaxurl"),quietMillis:250,dataType:"json",type:"post",cache:!1,data:l.proxy(this.getAjaxData,this),results:l.proxy(this.processAjaxResults,this)});var s=this.get("field"),t=acf.applyFilters("select2_args",t,i,this.data,s||!1,this);e.select2(t);var o,r=e.select2("container"),c=l.proxy(this.getOption,this);t.multiple&&(o=r.find("ul")).sortable({stop:function(){o.find(".select2-search-choice").each(function(){var t=l(this).data("select2Data");c(t.id).detach().appendTo(i)}),i.trigger("change")}}),e.on("select2-selecting",function(t){var e=t.choice,t=c(e.id);(t=!t.length?l('"):t).detach().appendTo(i)}),r.addClass("-acf"),acf.doAction("select2_init",i,t,this.data,s||!1,this),e.on("change",function(){var t=e.val();t.indexOf("||")&&(t=t.split("||")),i.val(t).trigger("change")}),i.hide()},mergeOptions:function(){var i=!1;l("#select2-drop .select2-result-with-children").each(function(){var t=l(this).children("ul"),e=l(this).children(".select2-result-label");if(i&&i.text()===e.text())return i.append(t.children()),void l(this).remove();i=e})},getAjaxData:function(t,e){return i.prototype.getAjaxData.apply(this,[{term:t,page:e}])}});new acf.Model({priority:5,wait:"prepare",actions:{duplicate:"onDuplicate"},initialize:function(){var t=acf.get("locale"),e=(acf.get("rtl"),acf.get("select2L10n")),i=n();return!!e&&(0!==t.indexOf("en")&&void(4==i?this.addTranslations4():3==i&&this.addTranslations3()))},addTranslations4:function(){var e=acf.get("select2L10n"),t=(t=acf.get("locale")).replace("_","-"),i={errorLoading:function(){return e.load_fail},inputTooLong:function(t){t=t.input.length-t.maximum;return 1'),t.addClass("acf-sortable-tr-helper"),t.children().each(function(){c(this).width(c(this).width())}),e.height(t.height()+"px"),t.removeClass("acf-sortable-tr-helper"))}}),new acf.Model({actions:{after_duplicate:"onAfterDuplicate"},onAfterDuplicate:function(t,e){var i=[];t.find("select").each(function(t){i.push(c(this).val())}),e.find("select").each(function(t){c(this).val(i[t])})}}),new acf.Model({id:"tableHelper",priority:20,actions:{refresh:"renderTables"},renderTables:function(t){var e=this;c(".acf-table:visible").each(function(){e.renderTable(c(this))})},renderTable:function(t){var e=t.find("> thead > tr:visible > th[data-key]"),a=t.find("> tbody > tr:visible > td[data-key]");if(!e.length||!a.length)return!1;e.each(function(t){var e=c(this),i=e.data("key"),n=a.filter('[data-key="'+i+'"]'),i=n.filter(".acf-hidden");n.removeClass("acf-empty"),n.length===i.length?acf.hide(e):(acf.show(e),i.addClass("acf-empty"))}),e.css("width","auto");var e=e.not(".acf-hidden"),i=100;e.length;e.filter("[data-width]").each(function(){var t=c(this).data("width");c(this).css("width",t+"%"),i-=t});var n=e.not("[data-width]");n.length&&(t=i/n.length,n.css("width",t+"%"),i=0),0'),e=c('
        '),o=c('
          '),r=c(""),t.append(n.html()),o.append(r),e.append(o),a.append(t),a.append(e),n.remove(),s.remove(),a.attr("colspan",2),n=t,a=e,s=r),i.addClass("acf-accordion"),n.addClass("acf-accordion-title"),a.addClass("acf-accordion-content"),l++,this.get("multi_expand")&&i.attr("multi-expand",1);var r=acf.getPreference("this.accordions")||[];void 0!==r[l-1]&&this.set("open",r[l-1]),this.get("open")&&(i.addClass("-open"),a.css("display","block")),n.prepend(d.iconHtml({open:this.get("open")}));n=i.parent();s.addClass(n.hasClass("-left")?"-left":""),s.addClass(n.hasClass("-clear")?"-clear":""),s.append(i.nextUntil(".acf-field-accordion",".acf-field")),s.removeAttr("data-open data-multi_expand data-endpoint")}}});acf.registerFieldType(t);var d=new acf.Model({actions:{unload:"onUnload"},events:{"click .acf-accordion-title":"onClick","invalidField .acf-accordion":"onInvalidField"},isOpen:function(t){return t.hasClass("-open")},toggle:function(t){this.isOpen(t)?this.close(t):this.open(t)},iconHtml:function(t){return acf.isGutenberg()?t.open?'':'':t.open?'':''},open:function(t){var e=acf.isGutenberg()?0:300;t.find(".acf-accordion-content:first").slideDown(e).css("display","block"),t.find(".acf-accordion-icon:first").replaceWith(this.iconHtml({open:!0})),t.addClass("-open"),acf.doAction("show",t),t.attr("multi-expand")||t.siblings(".acf-accordion.-open").each(function(){d.close(c(this))})},close:function(t){var e=acf.isGutenberg()?0:300;t.find(".acf-accordion-content:first").slideUp(e),t.find(".acf-accordion-icon:first").replaceWith(this.iconHtml({open:!1})),t.removeClass("-open"),acf.doAction("hide",t)},onClick:function(t,e){t.preventDefault(),this.toggle(e.parent())},onInvalidField:function(t,e){this.busy||(this.busy=!0,this.setTimeout(function(){this.busy=!1},1e3),this.open(e))},onUnload:function(t){var e=[];c(".acf-accordion").each(function(){var t=c(this).hasClass("-open")?1:0;e.push(t)}),e.length&&acf.setPreference("this.accordions",e)}})}(jQuery),function(){var t=acf.Field.extend({type:"button_group",events:{'click input[type="radio"]':"onClick"},$control:function(){return this.$(".acf-button-group")},$input:function(){return this.$("input:checked")},setValue:function(t){this.$('input[value="'+t+'"]').prop("checked",!0).trigger("change")},onClick:function(t,e){var i=e.parent("label"),n=i.hasClass("selected");this.$(".selected").removeClass("selected"),i.addClass("selected"),this.get("allow_null")&&n&&(i.removeClass("selected"),e.prop("checked",!1).trigger("change"))}});acf.registerFieldType(t)}(jQuery),function(e){var t=acf.Field.extend({type:"checkbox",events:{"change input":"onChange","click .acf-add-checkbox":"onClickAdd","click .acf-checkbox-toggle":"onClickToggle","click .acf-checkbox-custom":"onClickCustom"},$control:function(){return this.$(".acf-checkbox-list")},$toggle:function(){return this.$(".acf-checkbox-toggle")},$input:function(){return this.$('input[type="hidden"]')},$inputs:function(){return this.$('input[type="checkbox"]').not(".acf-checkbox-toggle")},getValue:function(){var t=[];return this.$(":checked").each(function(){t.push(e(this).val())}),!!t.length&&t},onChange:function(t,e){var i=e.prop("checked"),n=e.parent("label"),e=this.$toggle();i?n.addClass("selected"):n.removeClass("selected"),e.length&&(0==this.$inputs().not(":checked").length?e.prop("checked",!0):e.prop("checked",!1))},onClickAdd:function(t,e){var i='
        • ';e.parent("li").before(i)},onClickToggle:function(t,e){var i=e.prop("checked"),n=this.$('input[type="checkbox"]'),e=this.$("label");n.prop("checked",i),i?e.addClass("selected"):e.removeClass("selected")},onClickCustom:function(t,e){var i=e.prop("checked"),n=e.next('input[type="text"]');i?n.prop("disabled",!1):(n.prop("disabled",!0),""==n.val()&&e.parent("li").remove())}});acf.registerFieldType(t)}(jQuery),function(){var t=acf.Field.extend({type:"color_picker",wait:"load",events:{duplicateField:"onDuplicate"},$control:function(){return this.$(".acf-color-picker")},$input:function(){return this.$('input[type="hidden"]')},$inputText:function(){return this.$('input[type="text"]')},setValue:function(t){acf.val(this.$input(),t),this.$inputText().iris("color",t)},initialize:function(){var e=this.$input(),i=this.$inputText(),t=function(t){setTimeout(function(){acf.val(e,i.val())},1)},t={defaultColor:!1,palettes:!0,hide:!0,change:t,clear:t},t=acf.applyFilters("color_picker_args",t,this);i.wpColorPicker(t)},onDuplicate:function(t,e,i){$colorPicker=i.find(".wp-picker-container"),$inputText=i.find('input[type="text"]'),$colorPicker.replaceWith($inputText)}});acf.registerFieldType(t)}(jQuery),function(n){var t=acf.Field.extend({type:"date_picker",events:{'blur input[type="text"]':"onBlur",duplicateField:"onDuplicate"},$control:function(){return this.$(".acf-date-picker")},$input:function(){return this.$('input[type="hidden"]')},$inputText:function(){return this.$('input[type="text"]')},initialize:function(){if(this.has("save_format"))return this.initializeCompatibility();var t=this.$input(),e=this.$inputText(),t={dateFormat:this.get("date_format"),altField:t,altFormat:"yymmdd",changeYear:!0,yearRange:"-100:+100",changeMonth:!0,showButtonPanel:!0,firstDay:this.get("first_day")},t=acf.applyFilters("date_picker_args",t,this);acf.newDatePicker(e,t),acf.doAction("date_picker_init",e,t,this)},initializeCompatibility:function(){var t=this.$input(),e=this.$inputText();e.val(t.val());var i={dateFormat:this.get("date_format"),altField:t,altFormat:this.get("save_format"),changeYear:!0,yearRange:"-100:+100",changeMonth:!0,showButtonPanel:!0,firstDay:this.get("first_day")},t=(i=acf.applyFilters("date_picker_args",i,this)).dateFormat;i.dateFormat=this.get("save_format"),acf.newDatePicker(e,i),e.datepicker("option","dateFormat",t),acf.doAction("date_picker_init",e,i,this)},onBlur:function(){this.$inputText().val()||acf.val(this.$input(),"")},onDuplicate:function(t,e,i){i.find('input[type="text"]').removeClass("hasDatepicker").removeAttr("id")}});acf.registerFieldType(t);new acf.Model({priority:5,wait:"ready",initialize:function(){var t=acf.get("locale"),e=acf.get("rtl"),i=acf.get("datePickerL10n");return!!i&&(void 0!==n.datepicker&&(i.isRTL=e,n.datepicker.regional[t]=i,void n.datepicker.setDefaults(i)))}});acf.newDatePicker=function(t,e){if(void 0===n.datepicker)return!1;t.datepicker(e=e||{}),n("body > #ui-datepicker-div").exists()&&n("body > #ui-datepicker-div").wrap('
          ')}}(jQuery),function(n){var t=acf.models.DatePickerField.extend({type:"date_time_picker",$control:function(){return this.$(".acf-date-time-picker")},initialize:function(){var t=this.$input(),e=this.$inputText(),t={dateFormat:this.get("date_format"),timeFormat:this.get("time_format"),altField:t,altFieldTimeOnly:!1,altFormat:"yy-mm-dd",altTimeFormat:"HH:mm:ss",changeYear:!0,yearRange:"-100:+100",changeMonth:!0,showButtonPanel:!0,firstDay:this.get("first_day"),controlType:"select",oneLine:!0},t=acf.applyFilters("date_time_picker_args",t,this);acf.newDateTimePicker(e,t),acf.doAction("date_time_picker_init",e,t,this)}});acf.registerFieldType(t);new acf.Model({priority:5,wait:"ready",initialize:function(){var t=acf.get("locale"),e=acf.get("rtl"),i=acf.get("dateTimePickerL10n");return!!i&&(void 0!==n.timepicker&&(i.isRTL=e,n.timepicker.regional[t]=i,void n.timepicker.setDefaults(i)))}});acf.newDateTimePicker=function(t,e){if(void 0===n.timepicker)return!1;t.datetimepicker(e=e||{}),n("body > #ui-datepicker-div").exists()&&n("body > #ui-datepicker-div").wrap('
          ')}}(jQuery),function(e){var t=acf.Field.extend({type:"google_map",map:!1,wait:"load",events:{'click a[data-name="clear"]':"onClickClear",'click a[data-name="locate"]':"onClickLocate",'click a[data-name="search"]':"onClickSearch","keydown .search":"onKeydownSearch","keyup .search":"onKeyupSearch","focus .search":"onFocusSearch","blur .search":"onBlurSearch",showField:"onShow"},$control:function(){return this.$(".acf-google-map")},$search:function(){return this.$(".search")},$canvas:function(){return this.$(".canvas")},setState:function(t){this.$control().removeClass("-value -loading -searching"),(t="default"===t?this.val()?"value":"":t)&&this.$control().addClass("-"+t)},getValue:function(){var t=this.$input().val();return!!t&&JSON.parse(t)},setValue:function(t,e){var i="";t&&(i=JSON.stringify(t)),acf.val(this.$input(),i),e||(this.renderVal(t),acf.doAction("google_map_change",t,this.map,this))},renderVal:function(t){t?(this.setState("value"),this.$search().val(t.address),this.setPosition(t.lat,t.lng)):(this.setState(""),this.$search().val(""),this.map.marker.setVisible(!1))},newLatLng:function(t,e){return new google.maps.LatLng(parseFloat(t),parseFloat(e))},setPosition:function(t,e){this.map.marker.setPosition({lat:parseFloat(t),lng:parseFloat(e)}),this.map.marker.setVisible(!0),this.center()},center:function(){var t,e=this.map.marker.getPosition();e=e?(t=e.lat(),e.lng()):(t=this.get("lat"),this.get("lng")),this.map.setCenter({lat:parseFloat(t),lng:parseFloat(e)})},initialize:function(){!function(t){if(a)return t();if(acf.isset(window,"google","maps","Geocoder"))return a=new google.maps.Geocoder,t();acf.addAction("google_map_api_loaded",t),i||(t=acf.get("google_map_api"))&&(i=!0,e.ajax({url:t,dataType:"script",cache:!0,success:function(){a=new google.maps.Geocoder,acf.doAction("google_map_api_loaded")}}))}(this.initializeMap.bind(this))},initializeMap:function(){var t=this.getValue(),e=acf.parseArgs(t,{zoom:this.get("zoom"),lat:this.get("lat"),lng:this.get("lng")}),i={scrollwheel:!1,zoom:parseInt(e.zoom),center:{lat:parseFloat(e.lat),lng:parseFloat(e.lng)},mapTypeId:google.maps.MapTypeId.ROADMAP,marker:{draggable:!0,raiseOnDrag:!0},autocomplete:{}},i=acf.applyFilters("google_map_args",i,this),n=new google.maps.Map(this.$canvas()[0],i),a=acf.parseArgs(i.marker,{draggable:!0,raiseOnDrag:!0,map:n}),a=acf.applyFilters("google_map_marker_args",a,this),e=new google.maps.Marker(a),a=!1;acf.isset(google,"maps","places","Autocomplete")&&(i=i.autocomplete||{},i=acf.applyFilters("google_map_autocomplete_args",i,this),(a=new google.maps.places.Autocomplete(this.$search()[0],i)).bindTo("bounds",n)),this.addMapEvents(this,n,e,a),n.acf=this,n.marker=e,n.autocomplete=a,this.map=n,t&&this.setPosition(t.lat,t.lng),acf.doAction("google_map_init",n,e,this)},addMapEvents:function(i,e,t,n){google.maps.event.addListener(e,"click",function(t){var e=t.latLng.lat(),t=t.latLng.lng();i.searchPosition(e,t)}),google.maps.event.addListener(t,"dragend",function(){var t=this.getPosition().lat(),e=this.getPosition().lng();i.searchPosition(t,e)}),n&&google.maps.event.addListener(n,"place_changed",function(){var t=this.getPlace();i.searchPlace(t)}),google.maps.event.addListener(e,"zoom_changed",function(){var t=i.val();t&&(t.zoom=e.getZoom(),i.setValue(t,!0))})},searchPosition:function(i,n){this.setState("loading"),a.geocode({location:{lat:i,lng:n}},function(t,e){this.setState(""),"OK"!==e?this.showNotice({text:acf.__("Location not found: %s").replace("%s",e),type:"warning"}):((t=this.parseResult(t[0])).lat=i,t.lng=n,this.val(t))}.bind(this))},searchPlace:function(t){var e;t&&(t.geometry?(t.formatted_address=this.$search().val(),e=this.parseResult(t),this.val(e)):t.name&&this.searchAddress(t.name))},searchAddress:function(i){if(i){var t=i.split(",");if(2==t.length){var e=parseFloat(t[0]),t=parseFloat(t[1]);if(e&&t)return this.searchPosition(e,t)}this.setState("loading"),a.geocode({address:i},function(t,e){this.setState(""),"OK"!==e?this.showNotice({text:acf.__("Location not found: %s").replace("%s",e),type:"warning"}):((t=this.parseResult(t[0])).address=i,this.val(t))}.bind(this))}},searchLocation:function(){if(!navigator.geolocation)return alert(acf.__("Sorry, this browser does not support geolocation"));this.setState("loading"),navigator.geolocation.getCurrentPosition(function(t){this.setState("");var e=t.coords.latitude,t=t.coords.longitude;this.searchPosition(e,t)}.bind(this),function(t){this.setState("")}.bind(this))},parseResult:function(t){var e={address:t.formatted_address,lat:t.geometry.location.lat(),lng:t.geometry.location.lng()};e.zoom=this.map.getZoom(),t.place_id&&(e.place_id=t.place_id),t.name&&(e.name=t.name);var i,n={street_number:["street_number"],street_name:["street_address","route"],city:["locality"],state:["administrative_area_level_1","administrative_area_level_2","administrative_area_level_3","administrative_area_level_4","administrative_area_level_5"],post_code:["postal_code"],country:["country"]};for(i in n)for(var a=n[i],s=0;s
          '):this.$el=n('
            '),i.before(this.$el),this.set("index",a,!0),a++},initializeTabs:function(){var t=this.getVisible().shift(),e=(acf.getPreference("this.tabs")||[])[this.get("index")];(t=this.tabs[e]&&this.tabs[e].isVisible()?this.tabs[e]:t)?this.selectTab(t):this.closeTabs(),this.set("initialized",!0)},getVisible:function(){return this.tabs.filter(function(t){return t.isVisible()})},getActive:function(){return this.active},setActive:function(t){return this.active=t},hasActive:function(){return!1!==this.active},isActive:function(t){var e=this.getActive();return e&&e.cid===t.cid},closeActive:function(){this.hasActive()&&this.closeTab(this.getActive())},openTab:function(t){this.closeActive(),t.open(),this.setActive(t)},closeTab:function(t){t.close(),this.setActive(!1)},closeTabs:function(){this.tabs.map(this.closeTab,this)},selectTab:function(e){this.tabs.map(function(t){e.cid!==t.cid&&this.closeTab(t)},this),this.openTab(e)},addTab:function(t,e){t=n("
          • "+t.outerHTML()+"
          • ");this.$("ul").append(t);e=new i({$el:t,field:e,group:this});return this.tabs.push(e),e},reset:function(){return this.closeActive(),this.refresh()},refresh:function(){if(this.hasActive())return!1;var t=this.getVisible().shift();return t&&this.openTab(t),t},onRefresh:function(){var t,e,i;"left"===this.get("placement")&&(t=this.$el.parent(),i=this.$el.children("ul"),e=t.is("td")?"height":"min-height",i=i.position().top+i.outerHeight(!0)-1,t.css(e,i))}}),i=acf.Model.extend({group:!1,field:!1,events:{"click a":"onClick"},index:function(){return this.$el.index()},isVisible:function(){return acf.isVisible(this.$el)},isActive:function(){return this.$el.hasClass("active")},open:function(){this.$el.addClass("active"),this.field.showFields()},close:function(){this.$el.removeClass("active"),this.field.hideFields()},onClick:function(t,e){t.preventDefault(),this.toggle()},toggle:function(){this.isActive()||this.group.openTab(this)}});new acf.Model({priority:50,actions:{prepare:"render",append:"render",unload:"onUnload",invalid_field:"onInvalidField"},findTabs:function(){return n(".acf-tab-wrap")},getTabs:function(){return acf.getInstances(this.findTabs())},render:function(t){this.getTabs().map(function(t){t.get("initialized")||t.initializeTabs()})},onInvalidField:function(t){this.busy||t.hiddenByTab&&(t.hiddenByTab.toggle(),this.busy=!0,this.setTimeout(function(){this.busy=!1},100))},onUnload:function(){var e=[];this.getTabs().map(function(t){t=t.hasActive()?t.getActive().index():0;e.push(t)}),e.length&&acf.setPreference("this.tabs",e)}})}(jQuery),function(){var t=acf.models.SelectField.extend({type:"post_object"});acf.registerFieldType(t)}(jQuery),function(){var t=acf.models.SelectField.extend({type:"page_link"});acf.registerFieldType(t)}(jQuery),function(){var t=acf.models.SelectField.extend({type:"user"});acf.registerFieldType(t)}(jQuery),function(p){var t=acf.Field.extend({type:"taxonomy",data:{ftype:"select"},select2:!1,wait:"load",events:{'click a[data-name="add"]':"onClickAdd",'click input[type="radio"]':"onClickRadio",removeField:"onRemove"},$control:function(){return this.$(".acf-taxonomy-field")},$input:function(){return this.getRelatedPrototype().$input.apply(this,arguments)},getRelatedType:function(){var t=this.get("ftype");return t="multi_select"==t?"select":t},getRelatedPrototype:function(){return acf.getFieldType(this.getRelatedType()).prototype},getValue:function(){return this.getRelatedPrototype().getValue.apply(this,arguments)},setValue:function(){return this.getRelatedPrototype().setValue.apply(this,arguments)},initialize:function(){this.getRelatedPrototype().initialize.apply(this,arguments)},onRemove:function(){var t=this.getRelatedPrototype();t.onRemove&&t.onRemove.apply(this,arguments)},onClickAdd:function(t,e){var i=this,n=!1,a=!1,s=!1,o=!1,r=!1,c=!1,l=function(t){n.loading(!1),n.content(t),a=n.$("form"),s=n.$('input[name="term_name"]'),o=n.$('select[name="term_parent"]'),r=n.$(".acf-submit-button"),s.trigger("focus"),n.on("submit","form",d)},d=function(t,e){if(t.preventDefault(),t.stopImmediatePropagation(),""===s.val())return s.trigger("focus"),!1;acf.startButtonLoading(r);t={action:"acf/fields/taxonomy/add_term",field_key:i.get("key"),term_name:s.val(),term_parent:o.length?o.val():0};p.ajax({url:acf.get("ajaxurl"),data:acf.prepareForAjax(t),type:"post",dataType:"json",success:u})},u=function(t){acf.stopButtonLoading(r),c&&c.remove(),c=acf.isAjaxSuccess(t)?(s.val(""),f(t.data),acf.newNotice({type:"success",text:acf.getAjaxMessage(t),target:a,timeout:2e3,dismiss:!1})):acf.newNotice({type:"error",text:acf.getAjaxError(t),target:a,timeout:2e3,dismiss:!1}),s.trigger("focus")},f=function(e){var t=p('");e.term_parent?o.children('option[value="'+e.term_parent+'"]').after(t):o.append(t),acf.getFields({type:"taxonomy"}).map(function(t){t.get("taxonomy")==i.get("taxonomy")&&t.appendTerm(e)}),i.selectTerm(e.term_id)};!function(){n=acf.newPopup({title:e.attr("title"),loading:!0,width:"300px"});var t={action:"acf/fields/taxonomy/add_term",field_key:i.get("key")};p.ajax({url:acf.get("ajaxurl"),data:acf.prepareForAjax(t),type:"post",dataType:"html",success:l})}()},appendTerm:function(t){"select"==this.getRelatedType()?this.appendTermSelect(t):this.appendTermCheckbox(t)},appendTermSelect:function(t){this.select2.addOption({id:t.term_id,text:t.term_label})},appendTermCheckbox:function(t){var e=this.$("[name]:first").attr("name"),i=this.$("ul:first");"checkbox"==this.getRelatedType()&&(e+="[]");e=p(['
          • ',"","
          • "].join(""));t.term_parent&&((i=(t=i.find('li[data-id="'+t.term_parent+'"]')).children("ul")).exists()||(i=p('
              '),t.append(i))),i.append(e)},selectTerm:function(t){"select"==this.getRelatedType()?this.select2.selectOption(t):this.$('input[value="'+t+'"]').prop("checked",!0).trigger("change")},onClickRadio:function(t,e){var i=e.parent("label"),n=i.hasClass("selected");this.$(".selected").removeClass("selected"),i.addClass("selected"),this.get("allow_null")&&n&&(i.removeClass("selected"),e.prop("checked",!1).trigger("change"))}});acf.registerFieldType(t)}(jQuery),function(i){var t=acf.models.DatePickerField.extend({type:"time_picker",$control:function(){return this.$(".acf-time-picker")},initialize:function(){var t=this.$input(),e=this.$inputText(),t={timeFormat:this.get("time_format"),altField:t,altFieldTimeOnly:!1,altTimeFormat:"HH:mm:ss",showButtonPanel:!0,controlType:"select",oneLine:!0,closeText:acf.get("dateTimePickerL10n").selectText,timeOnly:!0,onClose:function(t,e,i){e=e.dpDiv.find(".ui-datepicker-close");!t&&e.is(":hover")&&i._updateDateTime()}},t=acf.applyFilters("time_picker_args",t,this);acf.newTimePicker(e,t),acf.doAction("time_picker_init",e,t,this)}});acf.registerFieldType(t),acf.newTimePicker=function(t,e){if(void 0===i.timepicker)return!1;t.timepicker(e=e||{}),i("body > #ui-datepicker-div").exists()&&i("body > #ui-datepicker-div").wrap('
              ')}}(jQuery),function(){var t=acf.Field.extend({type:"true_false",events:{"change .acf-switch-input":"onChange","focus .acf-switch-input":"onFocus","blur .acf-switch-input":"onBlur","keypress .acf-switch-input":"onKeypress"},$input:function(){return this.$('input[type="checkbox"]')},$switch:function(){return this.$(".acf-switch")},getValue:function(){return this.$input().prop("checked")?1:0},initialize:function(){this.render()},render:function(){var t,e,i=this.$switch();i.length&&(t=i.children(".acf-switch-on"),e=i.children(".acf-switch-off"),(i=Math.max(t.width(),e.width()))&&(t.css("min-width",i),e.css("min-width",i)))},switchOn:function(){this.$input().prop("checked",!0),this.$switch().addClass("-on")},switchOff:function(){this.$input().prop("checked",!1),this.$switch().removeClass("-on")},onChange:function(t,e){e.prop("checked")?this.switchOn():this.switchOff()},onFocus:function(t,e){this.$switch().addClass("-focus")},onBlur:function(t,e){this.$switch().removeClass("-focus")},onKeypress:function(t,e){return 37===t.keyCode?this.switchOff():39===t.keyCode?this.switchOn():void 0}});acf.registerFieldType(t)}(jQuery),function(){var t=acf.Field.extend({type:"url",events:{'keyup input[type="url"]':"onkeyup"},$control:function(){return this.$(".acf-input-wrap")},$input:function(){return this.$('input[type="url"]')},initialize:function(){this.render()},isValid:function(){var t=this.val();return!!t&&(-1!==t.indexOf("://")||0===t.indexOf("//"))},render:function(){this.isValid()?this.$control().addClass("-valid"):this.$control().removeClass("-valid")},onkeyup:function(t,e){this.render()}});acf.registerFieldType(t)}(jQuery),function(){var t=acf.Field.extend({type:"wysiwyg",wait:"load",events:{"mousedown .acf-editor-wrap.delay":"onMousedown",unmountField:"disableEditor",remountField:"enableEditor",removeField:"disableEditor"},$control:function(){return this.$(".acf-editor-wrap")},$input:function(){return this.$("textarea")},getMode:function(){return this.$control().hasClass("tmce-active")?"visual":"text"},initialize:function(){this.$control().hasClass("delay")||this.initializeEditor()},initializeEditor:function(){var t=this.$control(),e=this.$input(),i={tinymce:!0,quicktags:!0,toolbar:this.get("toolbar"),mode:this.getMode(),field:this},n=e.attr("id"),a=acf.uniqueId("acf-editor-"),s=e.data(),e=e.val();acf.rename({target:t,search:n,replace:a,destructive:!0}),this.set("id",a,!0),this.$input().data(s).val(e),acf.tinymce.initialize(a,i)},onMousedown:function(t){t.preventDefault();t=this.$control();t.removeClass("delay"),t.find(".acf-editor-toolbar").remove(),this.initializeEditor()},enableEditor:function(){"visual"==this.getMode()&&acf.tinymce.enable(this.get("id"))},disableEditor:function(){acf.tinymce.destroy(this.get("id"))}});acf.registerFieldType(t)}(jQuery),function(e){var s=[];acf.Condition=acf.Model.extend({type:"",operator:"==",label:"",choiceType:"input",fieldTypes:[],data:{conditions:!1,field:!1,rule:{}},events:{change:"change",keyup:"change",enableField:"change",disableField:"change"},setup:function(t){e.extend(this.data,t)},getEventTarget:function(t,e){return t||this.get("field").$el},change:function(t,e){this.get("conditions").change(t)},match:function(t,e){return!1},calculate:function(){return this.match(this.get("rule"),this.get("field"))},choices:function(t){return''}}),acf.newCondition=function(t,e){var i=e.get("field"),n=i.getField(t.field);if(!i||!n)return!1;e={rule:t,target:i,conditions:e,field:n},n=n.get("type"),t=t.operator;return new(acf.getConditionTypes({fieldType:n,operator:t})[0]||acf.Condition)(e)};function n(t){return acf.strPascalCase(t||"")+"Condition"}acf.registerConditionType=function(t){var e=t.prototype.type,i=n(e);acf.models[i]=t,s.push(e)},acf.getConditionType=function(t){t=n(t);return acf.models[t]||!1},acf.registerConditionForFieldType=function(t,e){t=acf.getConditionType(t);t&&t.prototype.fieldTypes.push(e)},acf.getConditionTypes=function(n){n=acf.parseArgs(n,{fieldType:"",operator:""});var a=[];return s.map(function(t){var e=acf.getConditionType(t),i=e.prototype.fieldTypes,t=e.prototype.operator;n.fieldType&&-1===i.indexOf(n.fieldType)||n.operator&&t!==n.operator||a.push(e)}),a}}(jQuery),function(){function a(t,e){var i=acf.getFields({key:e,sibling:t.$el,suppressFilters:!0});return!!(i=!i.length?acf.getFields({key:e,parent:t.$el.parent(),suppressFilters:!0}):i).length&&i[0]}var t="conditional_logic";new acf.Model({id:"conditionsManager",priority:20,actions:{new_field:"onNewField"},onNewField:function(t){t.has("conditions")&&t.getConditions().render()}});acf.Field.prototype.getField=function(t){var e=a(this,t);if(e)return e;for(var i=this.parents(),n=0;n'}});acf.registerConditionType(i);var t=i.extend({type:"hasNoValue",operator:"==empty",label:s("Has no value"),match:function(t,e){return!i.prototype.match.apply(this,arguments)}});acf.registerConditionType(t);var o=acf.Condition.extend({type:"equalTo",operator:"==",label:s("Value is equal to"),fieldTypes:["text","textarea","number","range","email","url","password"],match:function(t,e){return acf.isNumeric(t.value)?(i=t.value,n=e.val(),parseFloat(i)===parseFloat(n)):a(t.value,e.val());var i,n},choices:function(t){return''}});acf.registerConditionType(o);var e=o.extend({type:"notEqualTo",operator:"!=",label:s("Value is not equal to"),match:function(t,e){return!o.prototype.match.apply(this,arguments)}});acf.registerConditionType(e);t=acf.Condition.extend({type:"patternMatch",operator:"==pattern",label:s("Value matches pattern"),fieldTypes:["text","textarea","email","url","password","wysiwyg"],match:function(t,e){return function(t,e){e=new RegExp(n(e),"gi");return n(t).match(e)}(e.val(),t.value)},choices:function(t){return''}});acf.registerConditionType(t);t=acf.Condition.extend({type:"contains",operator:"==contains",label:s("Value contains"),fieldTypes:["text","textarea","number","email","url","password","wysiwyg","oembed","select"],match:function(t,e){return e=e.val(),t=t.value,-1'}});acf.registerConditionType(t);t=o.extend({type:"trueFalseEqualTo",choiceType:"select",fieldTypes:["true_false"],choices:function(t){return[{id:1,text:s("Checked")}]}});acf.registerConditionType(t);t=e.extend({type:"trueFalseNotEqualTo",choiceType:"select",fieldTypes:["true_false"],choices:function(t){return[{id:1,text:s("Checked")}]}});acf.registerConditionType(t);var r=acf.Condition.extend({type:"selectEqualTo",operator:"==",label:s("Value is equal to"),fieldTypes:["select","checkbox","radio","button_group"],match:function(t,e){var i=e.val();return i instanceof Array?(e=t.value,-1",label:s("Value is greater than"),fieldTypes:["number","range"],match:function(t,e){e=e.val();return e instanceof Array&&(e=e.length),e=e,t=t.value,parseFloat(e)>parseFloat(t)},choices:function(t){return''}});acf.registerConditionType(t);e=t.extend({type:"lessThan",operator:"<",label:s("Value is less than"),match:function(t,e){e=e.val();return e instanceof Array&&(e=e.length),e=e,t=t.value,parseFloat(e)'}});acf.registerConditionType(e);t=t.extend({type:"selectionGreaterThan",label:s("Selection is greater than"),fieldTypes:["checkbox","select","post_object","page_link","relationship","taxonomy","user"]});acf.registerConditionType(t);e=e.extend({type:"selectionLessThan",label:s("Selection is less than"),fieldTypes:["checkbox","select","post_object","page_link","relationship","taxonomy","user"]});acf.registerConditionType(e)}(jQuery),function(t){acf.unload=new acf.Model({wait:"load",active:!0,changed:!1,actions:{validation_failure:"startListening",validation_success:"stopListening"},events:{"change form .acf-field":"startListening","submit form":"stopListening"},enable:function(){this.active=!0},disable:function(){this.active=!1},reset:function(){this.stopListening()},startListening:function(){!this.changed&&this.active&&(this.changed=!0,t(window).on("beforeunload",this.onUnload))},stopListening:function(){this.changed=!1,t(window).off("beforeunload",this.onUnload)},onUnload:function(){return acf.__("The changes you made will be lost if you navigate away from this page")}})}(jQuery),function(e){new acf.Model({wait:"prepare",priority:1,initialize:function(){(acf.get("postboxes")||[]).map(acf.newPostbox)}});acf.getPostbox=function(t){return"string"==typeof arguments[0]&&(t=e("#"+arguments[0])),acf.getInstance(t)},acf.getPostboxes=function(){return acf.getInstances(e(".acf-postbox"))},acf.newPostbox=function(t){return new acf.models.Postbox(t)},acf.models.Postbox=acf.Model.extend({data:{id:"",key:"",style:"default",label:"top",edit:""},setup:function(t){t.editLink&&(t.edit=t.editLink),e.extend(this.data,t),this.$el=this.$postbox()},$postbox:function(){return e("#"+this.get("id"))},$hide:function(){return e("#"+this.get("id")+"-hide")},$hideLabel:function(){return this.$hide().parent()},$hndle:function(){return this.$("> .hndle")},$handleActions:function(){return this.$("> .postbox-header .handle-actions")},$inside:function(){return this.$("> .inside")},isVisible:function(){return this.$el.hasClass("acf-hidden")},initialize:function(){this.$el.addClass("acf-postbox"),this.$el.removeClass("hide-if-js"),"block"===acf.get("editor")||"default"!==(t=this.get("style"))&&this.$el.addClass(t),this.$inside().addClass("acf-fields").addClass("-"+this.get("label"));var t,e=this.get("edit");e&&(t='',(e=this.$handleActions()).length?e.prepend(t):this.$hndle().append(t)),this.show()},show:function(){this.$hideLabel().show(),this.$hide().prop("checked",!0),this.$el.show().removeClass("acf-hidden"),acf.doAction("show_postbox",this)},enable:function(){acf.enable(this.$el,"postbox")},showEnable:function(){this.enable(),this.show()},hide:function(){this.$hideLabel().hide(),this.$el.hide().addClass("acf-hidden"),acf.doAction("hide_postbox",this)},disable:function(){acf.disable(this.$el,"postbox")},hideDisable:function(){this.disable(),this.hide()},html:function(t){this.$inside().html(t),acf.doAction("append",this.$el)}})}(jQuery),function(a){acf.newMediaPopup=function(t){var e=null,e=new("edit"==(t=acf.parseArgs(t,{mode:"select",title:"",button:"",type:"",field:!1,allowedTypes:"",library:"all",multiple:!1,attachment:0,autoOpen:!0,open:function(){},select:function(){},close:function(){}})).mode?acf.models.EditMediaPopup:acf.models.SelectMediaPopup)(t);return t.autoOpen&&setTimeout(function(){e.open()},1),acf.doAction("new_media_popup",e),e};function e(){var t=acf.get("post_id");return acf.isNumeric(t)?t:0}acf.getMimeTypes=function(){return this.get("mimeTypes")},acf.getMimeType=function(t){var e,i=acf.getMimeTypes();if(void 0!==i[t])return i[t];for(e in i)if(-1!==e.indexOf(t))return i[e];return!1};var n=acf.Model.extend({id:"MediaPopup",data:{},defaults:{},frame:!1,setup:function(t){a.extend(this.data,t)},initialize:function(){var t=this.getFrameOptions();this.addFrameStates(t);var e=wp.media(t);(e.acf=this).addFrameEvents(e,t),this.frame=e},open:function(){this.frame.open()},close:function(){this.frame.close()},remove:function(){this.frame.detach(),this.frame.remove()},getFrameOptions:function(){var t={title:this.get("title"),multiple:this.get("multiple"),library:{},states:[]};return this.get("type")&&(t.library.type=this.get("type")),"uploadedTo"===this.get("library")&&(t.library.uploadedTo=e()),this.get("attachment")&&(t.library.post__in=[this.get("attachment")]),this.get("button")&&(t.button={text:this.get("button")}),t},addFrameStates:function(t){var e=wp.media.query(t.library);this.get("field")&&acf.isset(e,"mirroring","args")&&(e.mirroring.args._acfuploader=this.get("field")),t.states.push(new wp.media.controller.Library({library:e,multiple:this.get("multiple"),title:this.get("title"),priority:20,filterable:"all",editable:!0,allowLocalEdits:!0})),acf.isset(wp,"media","controller","EditImage")&&t.states.push(new wp.media.controller.EditImage)},addFrameEvents:function(i,t){i.on("open",function(){this.$el.closest(".media-modal").addClass("acf-media-modal -"+this.acf.get("mode"))},i),i.on("content:render:edit-image",function(){var t=this.state().get("image"),t=new wp.media.view.EditImage({model:t,controller:this}).render();this.content.set(t),t.loadEditor()},i),i.on("select",function(){var t=i.state().get("selection");t&&t.each(function(t,e){i.acf.get("select").apply(i.acf,[t,e])})}),i.on("close",function(){setTimeout(function(){i.acf.get("close").apply(i.acf),i.acf.remove()},1)})}});acf.models.SelectMediaPopup=n.extend({id:"SelectMediaPopup",setup:function(t){t.button||(t.button=acf._x("Select","verb")),n.prototype.setup.apply(this,arguments)},addFrameEvents:function(e,t){acf.isset(_wpPluploadSettings,"defaults","multipart_params")&&(_wpPluploadSettings.defaults.multipart_params._acfuploader=this.get("field"),e.on("open",function(){delete _wpPluploadSettings.defaults.multipart_params._acfuploader})),e.on("content:activate:browse",function(){var t=!1;try{t=e.content.get().toolbar}catch(t){return void console.log(t)}e.acf.customizeFilters.apply(e.acf,[t])}),n.prototype.addFrameEvents.apply(this,arguments)},customizeFilters:function(t){var i,e=t.get("filters");"image"==this.get("type")&&(e.filters.all.text=acf.__("All images"),delete e.filters.audio,delete e.filters.video,delete e.filters.image,a.each(e.filters,function(t,e){e.props.type=e.props.type||"image"})),this.get("allowedTypes")&&this.get("allowedTypes").split(" ").join("").split(".").join("").split(",").map(function(t){t=acf.getMimeType(t);t&&(e.filters[t]={text:t,props:{status:null,type:t,uploadedTo:null,orderby:"date",order:"DESC"},priority:20})}),"uploadedTo"===this.get("library")&&(i=this.frame.options.library.uploadedTo,delete e.filters.unattached,delete e.filters.uploaded,a.each(e.filters,function(t,e){e.text+=" ("+acf.__("Uploaded to this post")+")",e.props.uploadedTo=i}));var n=this.get("field");a.each(e.filters,function(t,e){e.props._acfuploader=n}),t.get("search").model.attributes._acfuploader=n,e.renderFilters&&e.renderFilters()}}),acf.models.EditMediaPopup=n.extend({id:"SelectMediaPopup",setup:function(t){t.button||(t.button=acf._x("Update","verb")),n.prototype.setup.apply(this,arguments)},addFrameEvents:function(i,t){i.on("open",function(){this.$el.closest(".media-modal").addClass("acf-expanded"),"browse"!=this.content.mode()&&this.content.mode("browse");var t=this.state().get("selection"),e=wp.media.attachment(i.acf.get("attachment"));t.add(e)},i),n.prototype.addFrameEvents.apply(this,arguments)}});new acf.Model({id:"customizePrototypes",wait:"ready",initialize:function(){var t;acf.isset(window,"wp","media","view")&&((t=e())&&acf.isset(wp,"media","view","settings","post")&&(wp.media.view.settings.post.id=t),this.customizeAttachmentsButton(),this.customizeAttachmentsRouter(),this.customizeAttachmentFilters(),this.customizeAttachmentCompat(),this.customizeAttachmentLibrary())},customizeAttachmentsButton:function(){var t;acf.isset(wp,"media","view","Button")&&(t=wp.media.view.Button,wp.media.view.Button=t.extend({initialize:function(){var t=_.defaults(this.options,this.defaults);this.model=new Backbone.Model(t),this.listenTo(this.model,"change",this.render)}}))},customizeAttachmentsRouter:function(){var t;acf.isset(wp,"media","view","Router")&&(t=wp.media.view.Router,wp.media.view.Router=t.extend({addExpand:function(){var t=a(['',''+acf.__("Expand Details")+"",''+acf.__("Collapse Details")+"",""].join(""));t.on("click",function(t){t.preventDefault();t=a(this).closest(".media-modal");t.hasClass("acf-expanded")?t.removeClass("acf-expanded"):t.addClass("acf-expanded")}),this.$el.append(t)},initialize:function(){return t.prototype.initialize.apply(this,arguments),this.addExpand(),this}}))},customizeAttachmentFilters:function(){acf.isset(wp,"media","view","AttachmentFilters","All")&&(wp.media.view.AttachmentFilters.All.prototype.renderFilters=function(){this.$el.html(_.chain(this.filters).map(function(t,e){return{el:a("").val(e).html(t.text)[0],priority:t.priority||50}},this).sortBy("priority").pluck("el").value())})},customizeAttachmentCompat:function(){var t,e;acf.isset(wp,"media","view","AttachmentCompat")&&(t=wp.media.view.AttachmentCompat,e=!1,wp.media.view.AttachmentCompat=t.extend({render:function(){return this.rendered?this:(t.prototype.render.apply(this,arguments),this.$("#acf-form-data").length&&(clearTimeout(e),e=setTimeout(a.proxy(function(){this.rendered=!0,acf.doAction("append",this.$el)},this),50)),this)},save:function(t){var e;t&&t.preventDefault(),e=acf.serializeForAjax(this.$el),this.controller.trigger("attachment:compat:waiting",["waiting"]),this.model.saveCompat(e).always(_.bind(this.postSave,this))}}))},customizeAttachmentLibrary:function(){var o;acf.isset(wp,"media","view","Attachment","Library")&&(o=wp.media.view.Attachment.Library,wp.media.view.Attachment.Library=o.extend({render:function(){var t=acf.isget(this,"controller","acf"),e=acf.isget(this,"model","attributes");return t&&e&&(e.acf_errors&&this.$el.addClass("acf-disabled"),(t=t.get("selected"))&&-1',''+acf.__("Restricted")+"",''+n+"",''+a+"","
              "].join("")),e.reset(),void e.single(i)}return o.prototype.toggleSelection.apply(this,arguments)}}))}})}(jQuery),function(u){acf.screen=new acf.Model({active:!0,xhr:!1,timeout:!1,wait:"load",events:{"change #page_template":"onChange","change #parent_id":"onChange","change #post-formats-select":"onChange","change .categorychecklist":"onChange","change .tagsdiv":"onChange",'change .acf-taxonomy-field[data-save="1"]':"onChange","change #product-type":"onChange"},isPost:function(){return"post"===acf.get("screen")},isUser:function(){return"user"===acf.get("screen")},isTaxonomy:function(){return"taxonomy"===acf.get("screen")},isAttachment:function(){return"attachment"===acf.get("screen")},isNavMenu:function(){return"nav_menu"===acf.get("screen")},isWidget:function(){return"widget"===acf.get("screen")},isComment:function(){return"comment"===acf.get("screen")},getPageTemplate:function(){var t=u("#page_template");return t.length?t.val():null},getPageParent:function(t,e){return(e=u("#parent_id")).length?e.val():null},getPageType:function(t,e){return this.getPageParent()?"child":"parent"},getPostType:function(){return u("#post_type").val()},getPostFormat:function(t,e){if((e=u("#post-formats-select input:checked")).length){e=e.val();return"0"==e?"standard":e}return null},getPostCoreTerms:function(){var t,e={},i=acf.serialize(u(".categorydiv, .tagsdiv"));for(t in i.tax_input&&(e=i.tax_input),i.post_category&&(e.category=i.post_category),e)acf.isArray(e[t])||(e[t]=e[t].split(/,[\s]?/));return e},getPostTerms:function(){var t,i=this.getPostCoreTerms();for(t in acf.getFields({type:"taxonomy"}).map(function(t){var e;t.get("save")&&(e=t.val(),t=t.get("taxonomy"),e&&(i[t]=i[t]||[],e=acf.isArray(e)?e:[e],i[t]=i[t].concat(e)))}),null!==(productType=this.getProductType())&&(i.product_type=[productType]),i)i[t]=acf.uniqueArray(i[t]);return i},getProductType:function(){var t=u("#product-type");return t.length?t.val():null},check:function(){var e;"post"===acf.get("screen")&&(this.xhr&&this.xhr.abort(),e=acf.parseArgs(this.data,{action:"acf/ajax/check_screen",screen:acf.get("screen"),exists:[]}),this.isPost()&&(e.post_id=acf.get("post_id")),null!==(postType=this.getPostType())&&(e.post_type=postType),null!==(pageTemplate=this.getPageTemplate())&&(e.page_template=pageTemplate),null!==(pageParent=this.getPageParent())&&(e.page_parent=pageParent),null!==(pageType=this.getPageType())&&(e.page_type=pageType),null!==(postFormat=this.getPostFormat())&&(e.post_format=postFormat),null!==(postTerms=this.getPostTerms())&&(e.post_terms=postTerms),acf.getPostboxes().map(function(t){e.exists.push(t.get("key"))}),e=acf.applyFilters("check_screen_args",e),this.xhr=u.ajax({url:acf.get("ajaxurl"),data:acf.prepareForAjax(e),type:"post",dataType:"json",context:this,success:function(t){"post"==acf.get("screen")?this.renderPostScreen(t):"user"==acf.get("screen")&&this.renderUserScreen(t),acf.doAction("check_screen_complete",t,e)}}))},onChange:function(t,e){this.setTimeout(this.check,1)},renderPostScreen:function(c){function l(t,e){var i,n=u._data(t[0]).events;for(i in n)for(var a=0;a','

              ',""+acf.escHtml(e.title)+"","

              ",'
              ','","
              ",""]:['",'

              ',""+acf.escHtml(e.title)+"","

              "]).join("");var n,a,s=u(['
              ',a,'
              ',e.html,"
              ","
              "].join(""));u("#adv-settings").length&&(n=u("#adv-settings .metabox-prefs"),a=u(['"].join("")),l(n.find("input").first(),a.find("input")),n.append(a)),u(".postbox").length&&(l(u(".postbox .handlediv").first(),s.children(".handlediv")),l(u(".postbox .hndle").first(),s.children(".hndle"))),"side"===e.position?u("#"+e.position+"-sortables").append(s):u("#"+e.position+"-sortables").prepend(s);var o=[];if(c.results.map(function(t){e.position===t.position&&u("#"+e.position+"-sortables #"+t.id).length&&o.push(t.id)}),d(e.id,o),c.sorted)for(var r in c.sorted){o=c.sorted[r].split(",");if(d(e.id,o))break}i=acf.newPostbox(e),acf.doAction("append",s),acf.doAction("append_postbox",i)}return i.showEnable(),c.visible.push(e.id),e}),acf.getPostboxes().map(function(t){-1===c.visible.indexOf(t.get("id"))&&(t.hideDisable(),c.hidden.push(t.get("id")))}),u("#acf-style").html(c.style),acf.doAction("refresh_post_screen",c)},renderUserScreen:function(t){}});new acf.Model({postEdits:{},wait:"prepare",initialize:function(){acf.isGutenberg()&&(wp.data.subscribe(acf.debounce(this.onChange).bind(this)),acf.screen.getPageTemplate=this.getPageTemplate,acf.screen.getPageParent=this.getPageParent,acf.screen.getPostType=this.getPostType,acf.screen.getPostFormat=this.getPostFormat,acf.screen.getPostCoreTerms=this.getPostCoreTerms,acf.unload.disable(),5.3<=parseFloat(acf.get("wp_version"))&&this.addAction("refresh_post_screen",this.onRefreshPostScreen),wp.domReady(acf.refresh))},onChange:function(){var e=["template","parent","format"];(wp.data.select("core").getTaxonomies()||[]).map(function(t){e.push(t.rest_base)});var i=wp.data.select("core/editor").getPostEdits(),n={};e.map(function(t){void 0!==i[t]&&(n[t]=i[t])}),JSON.stringify(n)!==JSON.stringify(this.postEdits)&&(this.postEdits=n,acf.screen.check())},getPageTemplate:function(){return wp.data.select("core/editor").getEditedPostAttribute("template")},getPageParent:function(t,e){return wp.data.select("core/editor").getEditedPostAttribute("parent")},getPostType:function(){return wp.data.select("core/editor").getEditedPostAttribute("type")},getPostFormat:function(t,e){return wp.data.select("core/editor").getEditedPostAttribute("format")},getPostCoreTerms:function(){var i={};return(wp.data.select("core").getTaxonomies()||[]).map(function(t){var e=wp.data.select("core/editor").getEditedPostAttribute(t.rest_base);e&&(i[t.slug]=e)}),i},onRefreshPostScreen:function(e){var i=wp.data.select("core/edit-post"),t=wp.data.dispatch("core/edit-post"),n={};i.getActiveMetaBoxLocations().map(function(t){n[t]=i.getMetaBoxesPerLocation(t)});var a,s=[];for(a in n)n[a].map(function(t){s.push(t.id)});for(a in e.results.filter(function(t){return-1===s.indexOf(t.id)}).map(function(t,e){var i=t.position;n[i]=n[i]||[],n[i].push({id:t.id,title:t.title})}),n)n[a]=n[a].filter(function(t){return-1===e.hidden.indexOf(t.id)});t.setAvailableMetaBoxesPerLocation(n)}})}(jQuery),function(l){function n(){return acf.isset(window,"jQuery","fn","select2","amd")?4:!!acf.isset(window,"Select2")&&3}acf.newSelect2=function(t,e){return e=acf.parseArgs(e,{allowNull:!1,placeholder:"",multiple:!1,field:!1,ajax:!1,ajaxAction:"",ajaxData:function(t){return t},ajaxResults:function(t){return t}}),e=new(4==n()?a:s)(t,e),acf.doAction("new_select2",e),e};var i=acf.Model.extend({setup:function(t,e){l.extend(this.data,e),this.$el=t},initialize:function(){},selectOption:function(t){t=this.getOption(t);t.prop("selected")||t.prop("selected",!0).trigger("change")},unselectOption:function(t){t=this.getOption(t);t.prop("selected")&&t.prop("selected",!1).trigger("change")},getOption:function(t){return this.$('option[value="'+t+'"]')},addOption:function(t){t=acf.parseArgs(t,{id:"",text:"",selected:!1});var e=this.getOption(t.id);return e.length||((e=l("")).html(t.text),e.attr("value",t.id),e.prop("selected",t.selected),this.$el.append(e)),e},getValue:function(){var e=[],t=this.$el.find("option:selected");return t.exists()&&(t=t.sort(function(t,e){return+t.getAttribute("data-i")-+e.getAttribute("data-i")})).each(function(){var t=l(this);e.push({$el:t,id:t.attr("value"),text:t.text()})}),e},mergeOptions:function(){},getChoices:function(){var i=function(t){var e=[];return t.children().each(function(){var t=l(this);t.is("optgroup")?e.push({text:t.attr("label"),children:i(t)}):e.push({id:t.attr("value"),text:t.text()})}),e};return i(this.$el)},getAjaxData:function(t){var e={action:this.get("ajaxAction"),s:t.term||"",paged:t.page||1},i=this.get("field");i&&(e.field_key=i.get("key"));var n=this.get("ajaxData");return n&&(e=n.apply(this,[e,t])),e=acf.applyFilters("select2_ajax_data",e,this.data,this.$el,i||!1,this),acf.prepareForAjax(e)},getAjaxResults:function(t,e){t=acf.parseArgs(t,{results:!1,more:!1});var i=this.get("ajaxResults");return i&&(t=i.apply(this,[t,e])),t=acf.applyFilters("select2_ajax_results",t,e,this)},processAjaxResults:function(t,e){return(t=this.getAjaxResults(t,e)).more&&(t.pagination={more:!0}),setTimeout(l.proxy(this.mergeOptions,this),1),t},destroy:function(){this.$el.data("select2")&&this.$el.select2("destroy"),this.$el.siblings(".select2-container").remove()}}),a=i.extend({initialize:function(){var e=this.$el,t={width:"100%",allowClear:this.get("allowNull"),placeholder:this.get("placeholder"),multiple:this.get("multiple"),data:[],escapeMarkup:function(t){return"string"!=typeof t?t:acf.escHtml(t)}};acf.isset(window,"jQuery","fn","selectWoo")||(t.templateSelection=function(t){var e=l('');return e.html(acf.escHtml(t.text)),e.data("element",t.element),e}),t.multiple&&this.getValue().map(function(t){t.$el.detach().appendTo(e)});var i=e.attr("data-ajax");void 0!==i&&(e.removeData("ajax"),e.removeAttr("data-ajax")),this.get("ajax")&&(t.ajax={url:acf.get("ajaxurl"),delay:250,dataType:"json",type:"post",cache:!1,data:l.proxy(this.getAjaxData,this),processResults:l.proxy(this.processAjaxResults,this)});var n=this.get("field"),t=acf.applyFilters("select2_args",t,e,this.data,n||!1,this);e.select2(t);var a,s=e.next(".select2-container");t.multiple&&((a=s.find("ul")).sortable({stop:function(t){a.find(".select2-selection__choice").each(function(){(l(this).data("data")?l(l(this).data("data").element):l(l(this).children("span.acf-selection").data("element"))).detach().appendTo(e)}),e.trigger("change")}}),e.on("select2:select",this.proxy(function(t){this.getOption(t.params.data.id).detach().appendTo(this.$el)}))),s.addClass("-acf"),void 0!==i&&e.attr("data-ajax",i),acf.doAction("select2_init",e,t,this.data,n||!1,this)},mergeOptions:function(){var i=!1,n=!1;l('.select2-results__option[role="group"]').each(function(){var t=l(this).children("ul"),e=l(this).children("strong");if(n&&n.text()===e.text())return i.append(t.children()),void l(this).remove();i=t,n=e})}}),s=i.extend({initialize:function(){var i=this.$el,n=this.getValue(),a=this.get("multiple"),t={width:"100%",allowClear:this.get("allowNull"),placeholder:this.get("placeholder"),separator:"||",multiple:this.get("multiple"),data:this.getChoices(),escapeMarkup:function(t){return acf.escHtml(t)},dropdownCss:{"z-index":"999999999"},initSelection:function(t,e){e(a?n:n.shift())}},e=i.siblings("input");e.length||(e=l(''),i.before(e)),inputValue=n.map(function(t){return t.id}).join("||"),e.val(inputValue),t.multiple&&n.map(function(t){t.$el.detach().appendTo(i)}),t.allowClear&&(t.data=t.data.filter(function(t){return""!==t.id})),i.removeData("ajax"),i.removeAttr("data-ajax"),this.get("ajax")&&(t.ajax={url:acf.get("ajaxurl"),quietMillis:250,dataType:"json",type:"post",cache:!1,data:l.proxy(this.getAjaxData,this),results:l.proxy(this.processAjaxResults,this)});var s=this.get("field"),t=acf.applyFilters("select2_args",t,i,this.data,s||!1,this);e.select2(t);var o,r=e.select2("container"),c=l.proxy(this.getOption,this);t.multiple&&(o=r.find("ul")).sortable({stop:function(){o.find(".select2-search-choice").each(function(){var t=l(this).data("select2Data");c(t.id).detach().appendTo(i)}),i.trigger("change")}}),e.on("select2-selecting",function(t){var e=t.choice,t=c(e.id);(t=!t.length?l('"):t).detach().appendTo(i)}),r.addClass("-acf"),acf.doAction("select2_init",i,t,this.data,s||!1,this),e.on("change",function(){var t=e.val();t.indexOf("||")&&(t=t.split("||")),i.val(t).trigger("change")}),i.hide()},mergeOptions:function(){var i=!1;l("#select2-drop .select2-result-with-children").each(function(){var t=l(this).children("ul"),e=l(this).children(".select2-result-label");if(i&&i.text()===e.text())return i.append(t.children()),void l(this).remove();i=e})},getAjaxData:function(t,e){return i.prototype.getAjaxData.apply(this,[{term:t,page:e}])}});new acf.Model({priority:5,wait:"prepare",actions:{duplicate:"onDuplicate"},initialize:function(){var t=acf.get("locale"),e=(acf.get("rtl"),acf.get("select2L10n")),i=n();return!!e&&(0!==t.indexOf("en")&&void(4==i?this.addTranslations4():3==i&&this.addTranslations3()))},addTranslations4:function(){var e=acf.get("select2L10n"),t=(t=acf.get("locale")).replace("_","-"),i={errorLoading:function(){return e.load_fail},inputTooLong:function(t){t=t.input.length-t.maximum;return 1'),t.addClass("acf-sortable-tr-helper"),t.children().each(function(){c(this).width(c(this).width())}),e.height(t.height()+"px"),t.removeClass("acf-sortable-tr-helper"))}}),new acf.Model({actions:{after_duplicate:"onAfterDuplicate"},onAfterDuplicate:function(t,e){var i=[];t.find("select").each(function(t){i.push(c(this).val())}),e.find("select").each(function(t){c(this).val(i[t])})}}),new acf.Model({id:"tableHelper",priority:20,actions:{refresh:"renderTables"},renderTables:function(t){var e=this;c(".acf-table:visible").each(function(){e.renderTable(c(this))})},renderTable:function(t){var e=t.find("> thead > tr:visible > th[data-key]"),a=t.find("> tbody > tr:visible > td[data-key]");if(!e.length||!a.length)return!1;e.each(function(t){var e=c(this),i=e.data("key"),n=a.filter('[data-key="'+i+'"]'),i=n.filter(".acf-hidden");n.removeClass("acf-empty"),n.length===i.length?acf.hide(e):(acf.show(e),i.addClass("acf-empty"))}),e.css("width","auto");var e=e.not(".acf-hidden"),i=100;e.length;e.filter("[data-width]").each(function(){var t=c(this).data("width");c(this).css("width",t+"%"),i-=t});var n=e.not("[data-width]");n.length&&(t=i/n.length,n.css("width",t+"%"),i=0),0 arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } + +function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } + +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } + +function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); } + +function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } + +function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } + +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +(function ($, undefined) { + acf.jsxNameReplacements = { + "accent-height": "accentHeight", + "accentheight": "accentHeight", + "accept-charset": "acceptCharset", + "acceptcharset": "acceptCharset", + "accesskey": "accessKey", + "alignment-baseline": "alignmentBaseline", + "alignmentbaseline": "alignmentBaseline", + "allowedblocks": "allowedBlocks", + "allowfullscreen": "allowFullScreen", + "allowreorder": "allowReorder", + "arabic-form": "arabicForm", + "arabicform": "arabicForm", + "attributename": "attributeName", + "attributetype": "attributeType", + "autocapitalize": "autoCapitalize", + "autocomplete": "autoComplete", + "autocorrect": "autoCorrect", + "autofocus": "autoFocus", + "autoplay": "autoPlay", + "autoreverse": "autoReverse", + "autosave": "autoSave", + "basefrequency": "baseFrequency", + "baseline-shift": "baselineShift", + "baselineshift": "baselineShift", + "baseprofile": "baseProfile", + "calcmode": "calcMode", + "cap-height": "capHeight", + "capheight": "capHeight", + "cellpadding": "cellPadding", + "cellspacing": "cellSpacing", + "charset": "charSet", + "class": "className", + "classid": "classID", + "classname": "className", + "clip-path": "clipPath", + "clip-rule": "clipRule", + "clippath": "clipPath", + "clippathunits": "clipPathUnits", + "cliprule": "clipRule", + "color-interpolation": "colorInterpolation", + "color-interpolation-filters": "colorInterpolationFilters", + "color-profile": "colorProfile", + "color-rendering": "colorRendering", + "colorinterpolation": "colorInterpolation", + "colorinterpolationfilters": "colorInterpolationFilters", + "colorprofile": "colorProfile", + "colorrendering": "colorRendering", + "colspan": "colSpan", + "contenteditable": "contentEditable", + "contentscripttype": "contentScriptType", + "contentstyletype": "contentStyleType", + "contextmenu": "contextMenu", + "controlslist": "controlsList", + "crossorigin": "crossOrigin", + "dangerouslysetinnerhtml": "dangerouslySetInnerHTML", + "datetime": "dateTime", + "defaultchecked": "defaultChecked", + "defaultvalue": "defaultValue", + "diffuseconstant": "diffuseConstant", + "disablepictureinpicture": "disablePictureInPicture", + "disableremoteplayback": "disableRemotePlayback", + "dominant-baseline": "dominantBaseline", + "dominantbaseline": "dominantBaseline", + "edgemode": "edgeMode", + "enable-background": "enableBackground", + "enablebackground": "enableBackground", + "enctype": "encType", + "enterkeyhint": "enterKeyHint", + "externalresourcesrequired": "externalResourcesRequired", + "fill-opacity": "fillOpacity", + "fill-rule": "fillRule", + "fillopacity": "fillOpacity", + "fillrule": "fillRule", + "filterres": "filterRes", + "filterunits": "filterUnits", + "flood-color": "floodColor", + "flood-opacity": "floodOpacity", + "floodcolor": "floodColor", + "floodopacity": "floodOpacity", + "font-family": "fontFamily", + "font-size": "fontSize", + "font-size-adjust": "fontSizeAdjust", + "font-stretch": "fontStretch", + "font-style": "fontStyle", + "font-variant": "fontVariant", + "font-weight": "fontWeight", + "fontfamily": "fontFamily", + "fontsize": "fontSize", + "fontsizeadjust": "fontSizeAdjust", + "fontstretch": "fontStretch", + "fontstyle": "fontStyle", + "fontvariant": "fontVariant", + "fontweight": "fontWeight", + "for": "htmlFor", + "formaction": "formAction", + "formenctype": "formEncType", + "formmethod": "formMethod", + "formnovalidate": "formNoValidate", + "formtarget": "formTarget", + "frameborder": "frameBorder", + "glyph-name": "glyphName", + "glyph-orientation-horizontal": "glyphOrientationHorizontal", + "glyph-orientation-vertical": "glyphOrientationVertical", + "glyphname": "glyphName", + "glyphorientationhorizontal": "glyphOrientationHorizontal", + "glyphorientationvertical": "glyphOrientationVertical", + "glyphref": "glyphRef", + "gradienttransform": "gradientTransform", + "gradientunits": "gradientUnits", + "horiz-adv-x": "horizAdvX", + "horiz-origin-x": "horizOriginX", + "horizadvx": "horizAdvX", + "horizoriginx": "horizOriginX", + "hreflang": "hrefLang", + "htmlfor": "htmlFor", + "http-equiv": "httpEquiv", + "httpequiv": "httpEquiv", + "image-rendering": "imageRendering", + "imagerendering": "imageRendering", + "innerhtml": "innerHTML", + "inputmode": "inputMode", + "itemid": "itemID", + "itemprop": "itemProp", + "itemref": "itemRef", + "itemscope": "itemScope", + "itemtype": "itemType", + "kernelmatrix": "kernelMatrix", + "kernelunitlength": "kernelUnitLength", + "keyparams": "keyParams", + "keypoints": "keyPoints", + "keysplines": "keySplines", + "keytimes": "keyTimes", + "keytype": "keyType", + "lengthadjust": "lengthAdjust", + "letter-spacing": "letterSpacing", + "letterspacing": "letterSpacing", + "lighting-color": "lightingColor", + "lightingcolor": "lightingColor", + "limitingconeangle": "limitingConeAngle", + "marginheight": "marginHeight", + "marginwidth": "marginWidth", + "marker-end": "markerEnd", + "marker-mid": "markerMid", + "marker-start": "markerStart", + "markerend": "markerEnd", + "markerheight": "markerHeight", + "markermid": "markerMid", + "markerstart": "markerStart", + "markerunits": "markerUnits", + "markerwidth": "markerWidth", + "maskcontentunits": "maskContentUnits", + "maskunits": "maskUnits", + "maxlength": "maxLength", + "mediagroup": "mediaGroup", + "minlength": "minLength", + "nomodule": "noModule", + "novalidate": "noValidate", + "numoctaves": "numOctaves", + "overline-position": "overlinePosition", + "overline-thickness": "overlineThickness", + "overlineposition": "overlinePosition", + "overlinethickness": "overlineThickness", + "paint-order": "paintOrder", + "paintorder": "paintOrder", + "panose-1": "panose1", + "pathlength": "pathLength", + "patterncontentunits": "patternContentUnits", + "patterntransform": "patternTransform", + "patternunits": "patternUnits", + "playsinline": "playsInline", + "pointer-events": "pointerEvents", + "pointerevents": "pointerEvents", + "pointsatx": "pointsAtX", + "pointsaty": "pointsAtY", + "pointsatz": "pointsAtZ", + "preservealpha": "preserveAlpha", + "preserveaspectratio": "preserveAspectRatio", + "primitiveunits": "primitiveUnits", + "radiogroup": "radioGroup", + "readonly": "readOnly", + "referrerpolicy": "referrerPolicy", + "refx": "refX", + "refy": "refY", + "rendering-intent": "renderingIntent", + "renderingintent": "renderingIntent", + "repeatcount": "repeatCount", + "repeatdur": "repeatDur", + "requiredextensions": "requiredExtensions", + "requiredfeatures": "requiredFeatures", + "rowspan": "rowSpan", + "shape-rendering": "shapeRendering", + "shaperendering": "shapeRendering", + "specularconstant": "specularConstant", + "specularexponent": "specularExponent", + "spellcheck": "spellCheck", + "spreadmethod": "spreadMethod", + "srcdoc": "srcDoc", + "srclang": "srcLang", + "srcset": "srcSet", + "startoffset": "startOffset", + "stddeviation": "stdDeviation", + "stitchtiles": "stitchTiles", + "stop-color": "stopColor", + "stop-opacity": "stopOpacity", + "stopcolor": "stopColor", + "stopopacity": "stopOpacity", + "strikethrough-position": "strikethroughPosition", + "strikethrough-thickness": "strikethroughThickness", + "strikethroughposition": "strikethroughPosition", + "strikethroughthickness": "strikethroughThickness", + "stroke-dasharray": "strokeDasharray", + "stroke-dashoffset": "strokeDashoffset", + "stroke-linecap": "strokeLinecap", + "stroke-linejoin": "strokeLinejoin", + "stroke-miterlimit": "strokeMiterlimit", + "stroke-opacity": "strokeOpacity", + "stroke-width": "strokeWidth", + "strokedasharray": "strokeDasharray", + "strokedashoffset": "strokeDashoffset", + "strokelinecap": "strokeLinecap", + "strokelinejoin": "strokeLinejoin", + "strokemiterlimit": "strokeMiterlimit", + "strokeopacity": "strokeOpacity", + "strokewidth": "strokeWidth", + "suppresscontenteditablewarning": "suppressContentEditableWarning", + "suppresshydrationwarning": "suppressHydrationWarning", + "surfacescale": "surfaceScale", + "systemlanguage": "systemLanguage", + "tabindex": "tabIndex", + "tablevalues": "tableValues", + "targetx": "targetX", + "targety": "targetY", + "templatelock": "templateLock", + "text-anchor": "textAnchor", + "text-decoration": "textDecoration", + "text-rendering": "textRendering", + "textanchor": "textAnchor", + "textdecoration": "textDecoration", + "textlength": "textLength", + "textrendering": "textRendering", + "underline-position": "underlinePosition", + "underline-thickness": "underlineThickness", + "underlineposition": "underlinePosition", + "underlinethickness": "underlineThickness", + "unicode-bidi": "unicodeBidi", + "unicode-range": "unicodeRange", + "unicodebidi": "unicodeBidi", + "unicoderange": "unicodeRange", + "units-per-em": "unitsPerEm", + "unitsperem": "unitsPerEm", + "usemap": "useMap", + "v-alphabetic": "vAlphabetic", + "v-hanging": "vHanging", + "v-ideographic": "vIdeographic", + "v-mathematical": "vMathematical", + "valphabetic": "vAlphabetic", + "vector-effect": "vectorEffect", + "vectoreffect": "vectorEffect", + "vert-adv-y": "vertAdvY", + "vert-origin-x": "vertOriginX", + "vert-origin-y": "vertOriginY", + "vertadvy": "vertAdvY", + "vertoriginx": "vertOriginX", + "vertoriginy": "vertOriginY", + "vhanging": "vHanging", + "videographic": "vIdeographic", + "viewbox": "viewBox", + "viewtarget": "viewTarget", + "vmathematical": "vMathematical", + "word-spacing": "wordSpacing", + "wordspacing": "wordSpacing", + "writing-mode": "writingMode", + "writingmode": "writingMode", + "x-height": "xHeight", + "xchannelselector": "xChannelSelector", + "xheight": "xHeight", + "xlink:actuate": "xlinkActuate", + "xlink:arcrole": "xlinkArcrole", + "xlink:href": "xlinkHref", + "xlink:role": "xlinkRole", + "xlink:show": "xlinkShow", + "xlink:title": "xlinkTitle", + "xlink:type": "xlinkType", + "xlinkactuate": "xlinkActuate", + "xlinkarcrole": "xlinkArcrole", + "xlinkhref": "xlinkHref", + "xlinkrole": "xlinkRole", + "xlinkshow": "xlinkShow", + "xlinktitle": "xlinkTitle", + "xlinktype": "xlinkType", + "xml:base": "xmlBase", + "xml:lang": "xmlLang", + "xml:space": "xmlSpace", + "xmlbase": "xmlBase", + "xmllang": "xmlLang", + "xmlns:xlink": "xmlnsXlink", + "xmlnsxlink": "xmlnsXlink", + "xmlspace": "xmlSpace", + "ychannelselector": "yChannelSelector", + "zoomandpan": "zoomAndPan" + }; +})(jQuery); + +(function ($, undefined) { + // Dependencies. + var _wp$blockEditor = wp.blockEditor, + BlockControls = _wp$blockEditor.BlockControls, + InspectorControls = _wp$blockEditor.InspectorControls, + InnerBlocks = _wp$blockEditor.InnerBlocks; + var _wp$components = wp.components, + Toolbar = _wp$components.Toolbar, + IconButton = _wp$components.IconButton, + Placeholder = _wp$components.Placeholder, + Spinner = _wp$components.Spinner; + var Fragment = wp.element.Fragment; + var _React = React, + Component = _React.Component; + var withSelect = wp.data.withSelect; + var createHigherOrderComponent = wp.compose.createHigherOrderComponent; + /** + * Storage for registered block types. + * + * @since 5.8.0 + * @var object + */ + + var blockTypes = {}; + /** + * Returns a block type for the given name. + * + * @date 20/2/19 + * @since 5.8.0 + * + * @param string name The block name. + * @return (object|false) + */ + + function getBlockType(name) { + return blockTypes[name] || false; + } + /** + * Returns true if a block exists for the given name. + * + * @date 20/2/19 + * @since 5.8.0 + * + * @param string name The block name. + * @return bool + */ + + + function isBlockType(name) { + return !!blockTypes[name]; + } + /** + * Returns true if the provided block is new. + * + * @date 31/07/2020 + * @since 5.9.0 + * + * @param object props The block props. + * @return bool + */ + + + function isNewBlock(props) { + return !props.attributes.id; + } + /** + * Returns true if the provided block is a duplicate: + * True when there are is another block with the same "id", but a different "clientId". + * + * @date 31/07/2020 + * @since 5.9.0 + * + * @param object props The block props. + * @return bool + */ + + + function isDuplicateBlock(props) { + return getBlocks().filter(function (block) { + return block.attributes.id === props.attributes.id; + }).filter(function (block) { + return block.clientId !== props.clientId; + }).length; + } + /** + * Registers a block type. + * + * @date 19/2/19 + * @since 5.8.0 + * + * @param object blockType The block type settings localized from PHP. + * @return object The result from wp.blocks.registerBlockType(). + */ + + + function registerBlockType(blockType) { + // Bail ealry if is excluded post_type. + var allowedTypes = blockType.post_types || []; + + if (allowedTypes.length) { + // Always allow block to appear on "Edit reusable Block" screen. + allowedTypes.push('wp_block'); // Check post type. + + var postType = acf.get('postType'); + + if (allowedTypes.indexOf(postType) === -1) { + return false; + } + } // Handle svg HTML. + + + if (typeof blockType.icon === 'string' && blockType.icon.substr(0, 4) === 'value pairs used to filter results. + * @return array. + */ + + + function getBlocks(args) { + // Get all blocks (avoid deprecated warning). + var blocks = select('core/block-editor').getBlocks(); // Append innerBlocks. + + var i = 0; + + while (i < blocks.length) { + blocks = blocks.concat(blocks[i].innerBlocks); + i++; + } // Loop over args and filter. + + + for (var k in args) { + blocks = blocks.filter(function (block) { + return block.attributes[k] === args[k]; + }); + } // Return results. + + + return blocks; + } // Data storage for AJAX requests. + + + var ajaxQueue = {}; + /** + * Fetches a JSON result from the AJAX API. + * + * @date 28/2/19 + * @since 5.7.13 + * + * @param object block The block props. + * @query object The query args used in AJAX callback. + * @return object The AJAX promise. + */ + + function fetchBlock(args) { + var _args$attributes = args.attributes, + attributes = _args$attributes === void 0 ? {} : _args$attributes, + _args$query = args.query, + query = _args$query === void 0 ? {} : _args$query, + _args$delay = args.delay, + delay = _args$delay === void 0 ? 0 : _args$delay; // Use storage or default data. + + var id = attributes.id; + var data = ajaxQueue[id] || { + query: {}, + timeout: false, + promise: $.Deferred() + }; // Append query args to storage. + + data.query = _objectSpread(_objectSpread({}, data.query), query); // Set fresh timeout. + + clearTimeout(data.timeout); + data.timeout = setTimeout(function () { + $.ajax({ + url: acf.get('ajaxurl'), + dataType: 'json', + type: 'post', + cache: false, + data: acf.prepareForAjax({ + action: 'acf/ajax/fetch-block', + block: JSON.stringify(attributes), + query: data.query + }) + }).always(function () { + // Clean up queue after AJAX request is complete. + ajaxQueue[id] = null; + }).done(function () { + data.promise.resolve.apply(this, arguments); + }).fail(function () { + data.promise.reject.apply(this, arguments); + }); + }, delay); // Update storage. + + ajaxQueue[id] = data; // Return promise. + + return data.promise; + } + /** + * Returns true if both object are the same. + * + * @date 19/05/2020 + * @since 5.9.0 + * + * @param object obj1 + * @param object obj2 + * @return bool + */ + + + function compareObjects(obj1, obj2) { + return JSON.stringify(obj1) === JSON.stringify(obj2); + } + /** + * Converts HTML into a React element. + * + * @date 19/05/2020 + * @since 5.9.0 + * + * @param string html The HTML to convert. + * @return object Result of React.createElement(). + */ + + + acf.parseJSX = function (html) { + return parseNode($(html)[0]); + }; + /** + * Converts a DOM node into a React element. + * + * @date 19/05/2020 + * @since 5.9.0 + * + * @param DOM node The DOM node. + * @return object Result of React.createElement(). + */ + + + function parseNode(node) { + // Get node name. + var nodeName = parseNodeName(node.nodeName.toLowerCase()); + + if (!nodeName) { + return null; + } // Get node attributes in React friendly format. + + + var nodeAttrs = {}; + acf.arrayArgs(node.attributes).map(parseNodeAttr).forEach(function (attr) { + nodeAttrs[attr.name] = attr.value; + }); // Define args for React.createElement(). + + var args = [nodeName, nodeAttrs]; + acf.arrayArgs(node.childNodes).forEach(function (child) { + if (child instanceof Text) { + var text = child.textContent; + + if (text) { + args.push(text); + } + } else { + args.push(parseNode(child)); + } + }); // Return element. + + return React.createElement.apply(this, args); + } + + ; + /** + * Converts a node or attribute name into it's JSX compliant name + * + * @date 05/07/2021 + * @since 5.9.8 + * + * @param string name The node or attribute name. + * @returns string + */ + + function getJSXName(name) { + var replacement = acf.isget(acf, 'jsxNameReplacements', name); + if (replacement) return replacement; + return name; + } + /** + * Converts the given name into a React friendly name or component. + * + * @date 19/05/2020 + * @since 5.9.0 + * + * @param string name The node name in lowercase. + * @return mixed + */ + + + function parseNodeName(name) { + switch (name) { + case 'innerblocks': + return InnerBlocks; + + case 'script': + return Script; + + case '#comment': + return null; + + default: + // Replace names for JSX counterparts. + name = getJSXName(name); + } + + return name; + } + /** + * Converts the given attribute into a React friendly name and value object. + * + * @date 19/05/2020 + * @since 5.9.0 + * + * @param obj nodeAttr The node attribute. + * @return obj + */ + + + function parseNodeAttr(nodeAttr) { + var name = nodeAttr.name; + var value = nodeAttr.value; + + switch (name) { + // Class. + case 'class': + name = 'className'; + break; + // Style. + + case 'style': + var css = {}; + value.split(';').forEach(function (s) { + var pos = s.indexOf(':'); + + if (pos > 0) { + var ruleName = s.substr(0, pos).trim(); + var ruleValue = s.substr(pos + 1).trim(); // Rename core properties, but not CSS variables. + + if (ruleName.charAt(0) !== '-') { + ruleName = acf.strCamelCase(ruleName); + } + + css[ruleName] = ruleValue; + } + }); + value = css; + break; + // Default. + + default: + // No formatting needed for "data-x" attributes. + if (name.indexOf('data-') === 0) { + break; + } // Replace names for JSX counterparts. + + + name = getJSXName(name); // Convert JSON values. + + var c1 = value.charAt(0); + + if (c1 === '[' || c1 === '{') { + value = JSON.parse(value); + } // Convert bool values. + + + if (value === 'true' || value === 'false') { + value = value === 'true'; + } + + break; + } + + return { + name: name, + value: value + }; + } + /** + * Higher Order Component used to set default block attribute values. + * + * By modifying block attributes directly, instead of defining defaults in registerBlockType(), + * WordPress will include them always within the saved block serialized JSON. + * + * @date 31/07/2020 + * @since 5.9.0 + * + * @param Component BlockListBlock The BlockListBlock Component. + * @return Component + */ + + + var withDefaultAttributes = createHigherOrderComponent(function (BlockListBlock) { + return /*#__PURE__*/function (_Component) { + _inherits(WrappedBlockEdit, _Component); + + var _super = _createSuper(WrappedBlockEdit); + + function WrappedBlockEdit(props) { + var _this; + + _classCallCheck(this, WrappedBlockEdit); + + _this = _super.call(this, props); // Extract vars. + + var _this$props = _this.props, + name = _this$props.name, + attributes = _this$props.attributes; // Only run on ACF Blocks. + + var blockType = getBlockType(name); + + if (!blockType) { + return _possibleConstructorReturn(_this); + } // Set unique ID and default attributes for newly added blocks. + + + if (isNewBlock(props)) { + attributes.id = acf.uniqid('block_'); + + for (var attribute in blockType.attributes) { + if (attributes[attribute] === undefined && blockType[attribute] !== undefined) { + attributes[attribute] = blockType[attribute]; + } + } + + return _possibleConstructorReturn(_this); + } // Generate new ID for duplicated blocks. + + + if (isDuplicateBlock(props)) { + attributes.id = acf.uniqid('block_'); + return _possibleConstructorReturn(_this); + } + + return _this; + } + + _createClass(WrappedBlockEdit, [{ + key: "render", + value: function render() { + return /*#__PURE__*/React.createElement(BlockListBlock, this.props); + } + }]); + + return WrappedBlockEdit; + }(Component); + }, 'withDefaultAttributes'); + wp.hooks.addFilter('editor.BlockListBlock', 'acf/with-default-attributes', withDefaultAttributes); + /** + * The BlockSave functional component. + * + * @date 08/07/2020 + * @since 5.9.0 + */ + + function BlockSave() { + return /*#__PURE__*/React.createElement(InnerBlocks.Content, null); + } + /** + * The BlockEdit component. + * + * @date 19/2/19 + * @since 5.7.12 + */ + + + var BlockEdit = /*#__PURE__*/function (_Component2) { + _inherits(BlockEdit, _Component2); + + var _super2 = _createSuper(BlockEdit); + + function BlockEdit(props) { + var _this2; + + _classCallCheck(this, BlockEdit); + + _this2 = _super2.call(this, props); + + _this2.setup(); + + return _this2; + } + + _createClass(BlockEdit, [{ + key: "setup", + value: function setup() { + var _this$props2 = this.props, + name = _this$props2.name, + attributes = _this$props2.attributes; + var blockType = getBlockType(name); // Restrict current mode. + + function restrictMode(modes) { + if (modes.indexOf(attributes.mode) === -1) { + attributes.mode = modes[0]; + } + } + + switch (blockType.mode) { + case 'edit': + restrictMode(['edit', 'preview']); + break; + + case 'preview': + restrictMode(['preview', 'edit']); + break; + + default: + restrictMode(['auto']); + break; + } + } + }, { + key: "render", + value: function render() { + var _this$props3 = this.props, + name = _this$props3.name, + attributes = _this$props3.attributes, + setAttributes = _this$props3.setAttributes; + var mode = attributes.mode; + var blockType = getBlockType(name); // Show toggle only for edit/preview modes. + + var showToggle = blockType.supports.mode; + + if (mode === 'auto') { + showToggle = false; + } // Configure toggle variables. + + + var toggleText = mode === 'preview' ? acf.__('Switch to Edit') : acf.__('Switch to Preview'); + var toggleIcon = mode === 'preview' ? 'edit' : 'welcome-view-site'; + + function toggleMode() { + setAttributes({ + mode: mode === 'preview' ? 'edit' : 'preview' + }); + } // Return template. + + + return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(BlockControls, null, showToggle && /*#__PURE__*/React.createElement(Toolbar, null, /*#__PURE__*/React.createElement(IconButton, { + className: "components-icon-button components-toolbar__control", + label: toggleText, + icon: toggleIcon, + onClick: toggleMode + }))), /*#__PURE__*/React.createElement(InspectorControls, null, mode === 'preview' && /*#__PURE__*/React.createElement("div", { + className: "acf-block-component acf-block-panel" + }, /*#__PURE__*/React.createElement(BlockForm, this.props))), /*#__PURE__*/React.createElement(BlockBody, this.props)); + } + }]); + + return BlockEdit; + }(Component); + /** + * The BlockBody component. + * + * @date 19/2/19 + * @since 5.7.12 + */ + + + var _BlockBody = /*#__PURE__*/function (_Component3) { + _inherits(_BlockBody, _Component3); + + var _super3 = _createSuper(_BlockBody); + + function _BlockBody() { + _classCallCheck(this, _BlockBody); + + return _super3.apply(this, arguments); + } + + _createClass(_BlockBody, [{ + key: "render", + value: function render() { + var _this$props4 = this.props, + attributes = _this$props4.attributes, + isSelected = _this$props4.isSelected; + var mode = attributes.mode; + return /*#__PURE__*/React.createElement("div", { + className: "acf-block-component acf-block-body" + }, mode === 'auto' && isSelected ? /*#__PURE__*/React.createElement(BlockForm, this.props) : mode === 'auto' && !isSelected ? /*#__PURE__*/React.createElement(BlockPreview, this.props) : mode === 'preview' ? /*#__PURE__*/React.createElement(BlockPreview, this.props) : /*#__PURE__*/React.createElement(BlockForm, this.props)); + } + }]); + + return _BlockBody; + }(Component); // Append blockIndex to component props. + + + var BlockBody = withSelect(function (select, ownProps) { + var clientId = ownProps.clientId; // Use optional rootClientId to allow discoverability of child blocks. + + var rootClientId = select('core/block-editor').getBlockRootClientId(clientId); + var index = select('core/block-editor').getBlockIndex(clientId, rootClientId); + return { + index: index + }; + })(_BlockBody); + /** + * A react component to append HTMl. + * + * @date 19/2/19 + * @since 5.7.12 + * + * @param string children The html to insert. + * @return void + */ + + var Div = /*#__PURE__*/function (_Component4) { + _inherits(Div, _Component4); + + var _super4 = _createSuper(Div); + + function Div() { + _classCallCheck(this, Div); + + return _super4.apply(this, arguments); + } + + _createClass(Div, [{ + key: "render", + value: function render() { + return /*#__PURE__*/React.createElement("div", { + dangerouslySetInnerHTML: { + __html: this.props.children + } + }); + } + }]); + + return Div; + }(Component); + /** + * A react Component for inline scripts. + * + * This Component uses a combination of React references and jQuery to append the + * inline ")); + } + }, { + key: "componentDidUpdate", + value: function componentDidUpdate() { + this.setHTML(this.props.children); + } + }, { + key: "componentDidMount", + value: function componentDidMount() { + this.setHTML(this.props.children); + } + }]); + + return Script; + }(Component); // Data storage for DynamicHTML components. + + + var store = {}; + /** + * DynamicHTML Class. + * + * A react componenet to load and insert dynamic HTML. + * + * @date 19/2/19 + * @since 5.7.12 + * + * @param void + * @return void + */ + + var DynamicHTML = /*#__PURE__*/function (_Component6) { + _inherits(DynamicHTML, _Component6); + + var _super6 = _createSuper(DynamicHTML); + + function DynamicHTML(props) { + var _this4; + + _classCallCheck(this, DynamicHTML); + + _this4 = _super6.call(this, props); // Bind callbacks. + + _this4.setRef = _this4.setRef.bind(_assertThisInitialized(_this4)); // Define default props and call setup(). + + _this4.id = ''; + _this4.el = false; + _this4.subscribed = true; + _this4.renderMethod = 'jQuery'; + + _this4.setup(props); // Load state. + + + _this4.loadState(); + + return _this4; + } + + _createClass(DynamicHTML, [{ + key: "setup", + value: function setup(props) {// Do nothing. + } + }, { + key: "fetch", + value: function fetch() {// Do nothing. + } + }, { + key: "maybePreload", + value: function maybePreload(blockId) { + if (this.state.html === undefined) { + var preloadedBlocks = acf.get('preloadedBlocks'); + + if (preloadedBlocks && preloadedBlocks[blockId]) { + // Set HTML to the preloaded version. + this.setHtml(preloadedBlocks[blockId]); // Delete the preloaded HTML so we don't try to load it again. + + delete preloadedBlocks[blockId]; + acf.set('preloadedBlocks', preloadedBlocks); + return true; + } + } + + return false; + } + }, { + key: "loadState", + value: function loadState() { + this.state = store[this.id] || {}; + } + }, { + key: "setState", + value: function setState(state) { + store[this.id] = _objectSpread(_objectSpread({}, this.state), state); // Update component state if subscribed. + // - Allows AJAX callback to update store without modifying state of an unmounted component. + + if (this.subscribed) { + _get(_getPrototypeOf(DynamicHTML.prototype), "setState", this).call(this, state); + } + } + }, { + key: "setHtml", + value: function setHtml(html) { + html = html ? html.trim() : ''; // Bail early if html has not changed. + + if (html === this.state.html) { + return; + } // Update state. + + + var state = { + html: html + }; + + if (this.renderMethod === 'jsx') { + state.jsx = acf.parseJSX(html); + state.$el = $(this.el); + } else { + state.$el = $(html); + } + + this.setState(state); + } + }, { + key: "setRef", + value: function setRef(el) { + this.el = el; + } + }, { + key: "render", + value: function render() { + // Render JSX. + if (this.state.jsx) { + return /*#__PURE__*/React.createElement("div", { + ref: this.setRef + }, this.state.jsx); + } // Return HTML. + + + return /*#__PURE__*/React.createElement("div", { + ref: this.setRef + }, /*#__PURE__*/React.createElement(Placeholder, null, /*#__PURE__*/React.createElement(Spinner, null))); + } + }, { + key: "shouldComponentUpdate", + value: function shouldComponentUpdate(nextProps, nextState) { + if (nextProps.index !== this.props.index) { + this.componentWillMove(); + } + + return nextState.html !== this.state.html; + } + }, { + key: "display", + value: function display(context) { + // This method is called after setting new HTML and the Component render. + // The jQuery render method simply needs to move $el into place. + if (this.renderMethod === 'jQuery') { + var $el = this.state.$el; + var $prevParent = $el.parent(); + var $thisParent = $(this.el); // Move $el into place. + + $thisParent.html($el); // Special case for reusable blocks. + // Multiple instances of the same reusable block share the same block id. + // This causes all instances to share the same state (cool), which unfortunately + // pulls $el back and forth between the last rendered reusable block. + // This simple fix leaves a "clone" behind :) + + if ($prevParent.length && $prevParent[0] !== $thisParent[0]) { + $prevParent.html($el.clone()); + } + } // Call context specific method. + + + switch (context) { + case 'append': + this.componentDidAppend(); + break; + + case 'remount': + this.componentDidRemount(); + break; + } + } + }, { + key: "componentDidMount", + value: function componentDidMount() { + // Fetch on first load. + if (this.state.html === undefined) { + //console.log('componentDidMount', this.id); + this.fetch(); // Or remount existing HTML. + } else { + this.display('remount'); + } + } + }, { + key: "componentDidUpdate", + value: function componentDidUpdate(prevProps, prevState) { + // HTML has changed. + this.display('append'); + } + }, { + key: "componentDidAppend", + value: function componentDidAppend() { + acf.doAction('append', this.state.$el); + } + }, { + key: "componentWillUnmount", + value: function componentWillUnmount() { + acf.doAction('unmount', this.state.$el); // Unsubscribe this component from state. + + this.subscribed = false; + } + }, { + key: "componentDidRemount", + value: function componentDidRemount() { + var _this5 = this; + + this.subscribed = true; // Use setTimeout to avoid incorrect timing of events. + // React will unmount and mount components in DOM order. + // This means a new component can be mounted before an old one is unmounted. + // ACF shares $el across new/old components which is un-React-like. + // This timout ensures that unmounting occurs before remounting. + + setTimeout(function () { + acf.doAction('remount', _this5.state.$el); + }); + } + }, { + key: "componentWillMove", + value: function componentWillMove() { + var _this6 = this; + + acf.doAction('unmount', this.state.$el); + setTimeout(function () { + acf.doAction('remount', _this6.state.$el); + }); + } + }]); + + return DynamicHTML; + }(Component); + /** + * BlockForm Class. + * + * A react componenet to handle the block form. + * + * @date 19/2/19 + * @since 5.7.12 + * + * @param string id the block id. + * @return void + */ + + + var BlockForm = /*#__PURE__*/function (_DynamicHTML) { + _inherits(BlockForm, _DynamicHTML); + + var _super7 = _createSuper(BlockForm); + + function BlockForm() { + _classCallCheck(this, BlockForm); + + return _super7.apply(this, arguments); + } + + _createClass(BlockForm, [{ + key: "setup", + value: function setup(props) { + this.id = "BlockForm-".concat(props.attributes.id); + } + }, { + key: "fetch", + value: function fetch() { + var _this7 = this; + + // Extract props. + var attributes = this.props.attributes; // Try preloaded data first. + + var preloaded = this.maybePreload(attributes.id); + + if (preloaded) { + return; + } // Request AJAX and update HTML on complete. + + + fetchBlock({ + attributes: attributes, + query: { + form: true + } + }).done(function (json) { + _this7.setHtml(json.data.form); + }); + } + }, { + key: "componentDidAppend", + value: function componentDidAppend() { + _get(_getPrototypeOf(BlockForm.prototype), "componentDidAppend", this).call(this); // Extract props. + + + var _this$props5 = this.props, + attributes = _this$props5.attributes, + setAttributes = _this$props5.setAttributes; + var $el = this.state.$el; // Callback for updating block data. + + function serializeData() { + var silent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + var data = acf.serialize($el, "acf-".concat(attributes.id)); + + if (silent) { + attributes.data = data; + } else { + setAttributes({ + data: data + }); + } + } // Add events. + + + var timeout = false; + $el.on('change keyup', function () { + clearTimeout(timeout); + timeout = setTimeout(serializeData, 300); + }); // Ensure newly added block is saved with data. + // Do it silently to avoid triggering a preview render. + + if (!attributes.data) { + serializeData(true); + } + } + }]); + + return BlockForm; + }(DynamicHTML); + /** + * BlockPreview Class. + * + * A react componenet to handle the block preview. + * + * @date 19/2/19 + * @since 5.7.12 + * + * @param string id the block id. + * @return void + */ + + + var BlockPreview = /*#__PURE__*/function (_DynamicHTML2) { + _inherits(BlockPreview, _DynamicHTML2); + + var _super8 = _createSuper(BlockPreview); + + function BlockPreview() { + _classCallCheck(this, BlockPreview); + + return _super8.apply(this, arguments); + } + + _createClass(BlockPreview, [{ + key: "setup", + value: function setup(props) { + this.id = "BlockPreview-".concat(props.attributes.id); + var blockType = getBlockType(props.name); + + if (blockType.supports.jsx) { + this.renderMethod = 'jsx'; + } //console.log('setup', this.id); + + } + }, { + key: "fetch", + value: function fetch() { + var _this8 = this; + + var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var _args$attributes2 = args.attributes, + attributes = _args$attributes2 === void 0 ? this.props.attributes : _args$attributes2, + _args$delay2 = args.delay, + delay = _args$delay2 === void 0 ? 0 : _args$delay2; // Remember attributes used to fetch HTML. + + this.setState({ + prevAttributes: attributes + }); // Try preloaded data first. + + var preloaded = this.maybePreload(attributes.id); + + if (preloaded) { + return; + } // Request AJAX and update HTML on complete. + + + fetchBlock({ + attributes: attributes, + query: { + preview: true + }, + delay: delay + }).done(function (json) { + _this8.setHtml(json.data.preview); + }); + } + }, { + key: "componentDidAppend", + value: function componentDidAppend() { + _get(_getPrototypeOf(BlockPreview.prototype), "componentDidAppend", this).call(this); // Extract props. + + + var attributes = this.props.attributes; + var $el = this.state.$el; // Generate action friendly type. + + var type = attributes.name.replace('acf/', ''); // Do action. + + acf.doAction('render_block_preview', $el, attributes); + acf.doAction("render_block_preview/type=".concat(type), $el, attributes); + } + }, { + key: "shouldComponentUpdate", + value: function shouldComponentUpdate(nextProps, nextState) { + var nextAttributes = nextProps.attributes; + var thisAttributes = this.props.attributes; // Update preview if block data has changed. + + if (!compareObjects(nextAttributes, thisAttributes)) { + var delay = 0; // Delay fetch when editing className or anchor to simulate conscistent logic to custom fields. + + if (nextAttributes.className !== thisAttributes.className) { + delay = 300; + } + + if (nextAttributes.anchor !== thisAttributes.anchor) { + delay = 300; + } + + this.fetch({ + attributes: nextAttributes, + delay: delay + }); + } + + return _get(_getPrototypeOf(BlockPreview.prototype), "shouldComponentUpdate", this).call(this, nextProps, nextState); + } + }, { + key: "componentDidRemount", + value: function componentDidRemount() { + _get(_getPrototypeOf(BlockPreview.prototype), "componentDidRemount", this).call(this); // Update preview if data has changed since last render (changing from "edit" to "preview"). + + + if (!compareObjects(this.state.prevAttributes, this.props.attributes)) { + //console.log('componentDidRemount', this.id); + this.fetch(); + } + } + }]); + + return BlockPreview; + }(DynamicHTML); + /** + * Initializes ACF Blocks logic and registration. + * + * @since 5.9.0 + */ + + + function initialize() { + // Add support for WordPress versions before 5.2. + if (!wp.blockEditor) { + wp.blockEditor = wp.editor; + } // Register block types. + + + var blockTypes = acf.get('blockTypes'); + + if (blockTypes) { + blockTypes.map(registerBlockType); + } + } // Run the initialize callback during the "prepare" action. + // This ensures that all localized data is available and that blocks are registered before the WP editor has been instantiated. + + + acf.addAction('prepare', initialize); + /** + * Returns a valid vertical alignment. + * + * @date 07/08/2020 + * @since 5.9.0 + * + * @param string align A vertical alignment. + * @return string + */ + + function validateVerticalAlignment(align) { + var ALIGNMENTS = ['top', 'center', 'bottom']; + var DEFAULT = 'top'; + return ALIGNMENTS.includes(align) ? align : DEFAULT; + } + /** + * Returns a valid horizontal alignment. + * + * @date 07/08/2020 + * @since 5.9.0 + * + * @param string align A horizontal alignment. + * @return string + */ + + + function validateHorizontalAlignment(align) { + var ALIGNMENTS = ['left', 'center', 'right']; + var DEFAULT = acf.get('rtl') ? 'right' : 'left'; + return ALIGNMENTS.includes(align) ? align : DEFAULT; + } + /** + * Returns a valid matrix alignment. + * + * Written for "upgrade-path" compatibility from vertical alignment to matrix alignment. + * + * @date 07/08/2020 + * @since 5.9.0 + * + * @param string align A matrix alignment. + * @return string + */ + + + function validateMatrixAlignment(align) { + var DEFAULT = 'center center'; + + if (align) { + var _align$split = align.split(' '), + _align$split2 = _slicedToArray(_align$split, 2), + y = _align$split2[0], + x = _align$split2[1]; + + return validateVerticalAlignment(y) + ' ' + validateHorizontalAlignment(x); + } + + return DEFAULT; + } // Dependencies. + + + var _wp$blockEditor2 = wp.blockEditor, + AlignmentToolbar = _wp$blockEditor2.AlignmentToolbar, + BlockVerticalAlignmentToolbar = _wp$blockEditor2.BlockVerticalAlignmentToolbar; + var BlockAlignmentMatrixToolbar = wp.blockEditor.__experimentalBlockAlignmentMatrixToolbar || wp.blockEditor.BlockAlignmentMatrixToolbar; // Gutenberg v10.x begins transition from Toolbar components to Control components. + + var BlockAlignmentMatrixControl = wp.blockEditor.__experimentalBlockAlignmentMatrixControl || wp.blockEditor.BlockAlignmentMatrixControl; + /** + * Appends extra attributes for block types that support align_content. + * + * @date 08/07/2020 + * @since 5.9.0 + * + * @param object attributes The block type attributes. + * @return object + */ + + function withAlignContentAttributes(attributes) { + attributes.align_content = { + type: 'string' + }; + return attributes; + } + /** + * A higher order component adding align_content editing functionality. + * + * @date 08/07/2020 + * @since 5.9.0 + * + * @param component OriginalBlockEdit The original BlockEdit component. + * @param object blockType The block type settings. + * @return component + */ + + + function withAlignContentComponent(OriginalBlockEdit, blockType) { + // Determine alignment vars + var type = blockType.supports.align_content; + var AlignmentComponent, validateAlignment; + + switch (type) { + case 'matrix': + AlignmentComponent = BlockAlignmentMatrixControl || BlockAlignmentMatrixToolbar; + validateAlignment = validateMatrixAlignment; + break; + + default: + AlignmentComponent = BlockVerticalAlignmentToolbar; + validateAlignment = validateVerticalAlignment; + break; + } // Ensure alignment component exists. + + + if (AlignmentComponent === undefined) { + console.warn("The \"".concat(type, "\" alignment component was not found.")); + return OriginalBlockEdit; + } // Ensure correct block attribute data is sent in intial preview AJAX request. + + + blockType.align_content = validateAlignment(blockType.align_content); // Return wrapped component. + + return /*#__PURE__*/function (_Component7) { + _inherits(WrappedBlockEdit, _Component7); + + var _super9 = _createSuper(WrappedBlockEdit); + + function WrappedBlockEdit() { + _classCallCheck(this, WrappedBlockEdit); + + return _super9.apply(this, arguments); + } + + _createClass(WrappedBlockEdit, [{ + key: "render", + value: function render() { + var _this$props6 = this.props, + attributes = _this$props6.attributes, + setAttributes = _this$props6.setAttributes; + var align_content = attributes.align_content; + + function onChangeAlignContent(align_content) { + setAttributes({ + align_content: validateAlignment(align_content) + }); + } + + return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(BlockControls, { + group: "block" + }, /*#__PURE__*/React.createElement(AlignmentComponent, { + label: acf.__('Change content alignment'), + value: validateAlignment(align_content), + onChange: onChangeAlignContent + })), /*#__PURE__*/React.createElement(OriginalBlockEdit, this.props)); + } + }]); + + return WrappedBlockEdit; + }(Component); + } + /** + * Appends extra attributes for block types that support align_text. + * + * @date 08/07/2020 + * @since 5.9.0 + * + * @param object attributes The block type attributes. + * @return object + */ + + + function withAlignTextAttributes(attributes) { + attributes.align_text = { + type: 'string' + }; + return attributes; + } + /** + * A higher order component adding align_text editing functionality. + * + * @date 08/07/2020 + * @since 5.9.0 + * + * @param component OriginalBlockEdit The original BlockEdit component. + * @param object blockType The block type settings. + * @return component + */ + + + function withAlignTextComponent(OriginalBlockEdit, blockType) { + var validateAlignment = validateHorizontalAlignment; // Ensure correct block attribute data is sent in intial preview AJAX request. + + blockType.align_text = validateAlignment(blockType.align_text); // Return wrapped component. + + return /*#__PURE__*/function (_Component8) { + _inherits(WrappedBlockEdit, _Component8); + + var _super10 = _createSuper(WrappedBlockEdit); + + function WrappedBlockEdit() { + _classCallCheck(this, WrappedBlockEdit); + + return _super10.apply(this, arguments); + } + + _createClass(WrappedBlockEdit, [{ + key: "render", + value: function render() { + var _this$props7 = this.props, + attributes = _this$props7.attributes, + setAttributes = _this$props7.setAttributes; + var align_text = attributes.align_text; + + function onChangeAlignText(align_text) { + setAttributes({ + align_text: validateAlignment(align_text) + }); + } + + return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(BlockControls, null, /*#__PURE__*/React.createElement(AlignmentToolbar, { + value: validateAlignment(align_text), + onChange: onChangeAlignText + })), /*#__PURE__*/React.createElement(OriginalBlockEdit, this.props)); + } + }]); + + return WrappedBlockEdit; + }(Component); + } +})(jQuery); \ No newline at end of file diff --git a/assets/build/js/pro/acf-pro-blocks-legacy.min.js b/assets/build/js/pro/acf-pro-blocks-legacy.min.js new file mode 100755 index 0000000..eeb569d --- /dev/null +++ b/assets/build/js/pro/acf-pro-blocks-legacy.min.js @@ -0,0 +1 @@ +"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _slicedToArray(e,t){return _arrayWithHoles(e)||_iterableToArrayLimit(e,t)||_unsupportedIterableToArray(e,t)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Map"===(r="Object"===r&&e.constructor?e.constructor.name:r)||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r".concat(e,"<\/script>"))}},{key:"componentDidUpdate",value:function(){this.setHTML(this.props.children)}},{key:"componentDidMount",value:function(){this.setHTML(this.props.children)}}]),t}(),A={},P=function(){_inherits(n,h);var r=_createSuper(n);function n(e){var t;return _classCallCheck(this,n),(t=r.call(this,e)).setRef=t.setRef.bind(_assertThisInitialized(t)),t.id="",t.el=!1,t.subscribed=!0,t.renderMethod="jQuery",t.setup(e),t.loadState(),t}return _createClass(n,[{key:"setup",value:function(e){}},{key:"fetch",value:function(){}},{key:"maybePreload",value:function(e){if(this.state.html===s){var t=acf.get("preloadedBlocks");if(t&&t[e])return this.setHtml(t[e]),delete t[e],acf.set("preloadedBlocks",t),!0}return!1}},{key:"loadState",value:function(){this.state=A[this.id]||{}}},{key:"setState",value:function(e){A[this.id]=_objectSpread(_objectSpread({},this.state),e),this.subscribed&&_get(_getPrototypeOf(n.prototype),"setState",this).call(this,e)}},{key:"setHtml",value:function(e){var t;(e=e?e.trim():"")!==this.state.html&&(t={html:e},"jsx"===this.renderMethod?(t.jsx=acf.parseJSX(e),t.$el=o(this.el)):t.$el=o(e),this.setState(t))}},{key:"setRef",value:function(e){this.el=e}},{key:"render",value:function(){return this.state.jsx?React.createElement("div",{ref:this.setRef},this.state.jsx):React.createElement("div",{ref:this.setRef},React.createElement(i,null,React.createElement(p,null)))}},{key:"shouldComponentUpdate",value:function(e,t){return e.index!==this.props.index&&this.componentWillMove(),t.html!==this.state.html}},{key:"display",value:function(e){var t,r,n;switch("jQuery"===this.renderMethod&&(r=(t=this.state.$el).parent(),(n=o(this.el)).html(t),r.length&&r[0]!==n[0]&&r.html(t.clone())),e){case"append":this.componentDidAppend();break;case"remount":this.componentDidRemount()}}},{key:"componentDidMount",value:function(){this.state.html===s?this.fetch():this.display("remount")}},{key:"componentDidUpdate",value:function(e,t){this.display("append")}},{key:"componentDidAppend",value:function(){acf.doAction("append",this.state.$el)}},{key:"componentWillUnmount",value:function(){acf.doAction("unmount",this.state.$el),this.subscribed=!1}},{key:"componentDidRemount",value:function(){var e=this;this.subscribed=!0,setTimeout(function(){acf.doAction("remount",e.state.$el)})}},{key:"componentWillMove",value:function(){var e=this;acf.doAction("unmount",this.state.$el),setTimeout(function(){acf.doAction("remount",e.state.$el)})}}]),n}(),E=function(){_inherits(a,P);var e=_createSuper(a);function a(){return _classCallCheck(this,a),e.apply(this,arguments)}return _createClass(a,[{key:"setup",value:function(e){this.id="BlockForm-".concat(e.attributes.id)}},{key:"fetch",value:function(){var t=this,e=this.props.attributes;this.maybePreload(e.id)||k({attributes:e,query:{form:!0}}).done(function(e){t.setHtml(e.data.form)})}},{key:"componentDidAppend",value:function(){_get(_getPrototypeOf(a.prototype),"componentDidAppend",this).call(this);var e=this.props,r=e.attributes,n=e.setAttributes,i=this.state.$el;function t(){var e=0 0) { var ruleName = s.substr(0, pos).trim(); var ruleValue = s.substr(pos + 1).trim(); // Rename core properties, but not CSS variables. - if (ruleName.charAt(0) !== '-') { + if (ruleName.charAt(0) !== "-") { ruleName = acf.strCamelCase(ruleName); } @@ -824,7 +839,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope default: // No formatting needed for "data-x" attributes. - if (name.indexOf('data-') === 0) { + if (name.indexOf("data-") === 0) { break; } // Replace names for JSX counterparts. @@ -833,13 +848,13 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope var c1 = value.charAt(0); - if (c1 === '[' || c1 === '{') { + if (c1 === "[" || c1 === "{") { value = JSON.parse(value); } // Convert bool values. - if (value === 'true' || value === 'false') { - value = value === 'true'; + if (value === "true" || value === "false") { + value = value === "true"; } break; @@ -852,8 +867,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope } /** * Higher Order Component used to set default block attribute values. - * - * By modifying block attributes directly, instead of defining defaults in registerBlockType(), + * + * By modifying block attributes directly, instead of defining defaults in registerBlockType(), * WordPress will include them always within the saved block serialized JSON. * * @date 31/07/2020 @@ -889,7 +904,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope if (isNewBlock(props)) { - attributes.id = acf.uniqid('block_'); + attributes.id = acf.uniqid("block_"); for (var attribute in blockType.attributes) { if (attributes[attribute] === undefined && blockType[attribute] !== undefined) { @@ -902,7 +917,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope if (isDuplicateBlock(props)) { - attributes.id = acf.uniqid('block_'); + attributes.id = acf.uniqid("block_"); return _possibleConstructorReturn(_this); } @@ -918,8 +933,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope return WrappedBlockEdit; }(Component); - }, 'withDefaultAttributes'); - wp.hooks.addFilter('editor.BlockListBlock', 'acf/with-default-attributes', withDefaultAttributes); + }, "withDefaultAttributes"); + wp.hooks.addFilter("editor.BlockListBlock", "acf/with-default-attributes", withDefaultAttributes); /** * The BlockSave functional component. * @@ -964,22 +979,22 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope var blockType = getBlockType(name); // Restrict current mode. function restrictMode(modes) { - if (modes.indexOf(attributes.mode) === -1) { + if (!modes.includes(attributes.mode)) { attributes.mode = modes[0]; } } switch (blockType.mode) { - case 'edit': - restrictMode(['edit', 'preview']); + case "edit": + restrictMode(["edit", "preview"]); break; - case 'preview': - restrictMode(['preview', 'edit']); + case "preview": + restrictMode(["preview", "edit"]); break; default: - restrictMode(['auto']); + restrictMode(["auto"]); break; } } @@ -995,27 +1010,27 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope var showToggle = blockType.supports.mode; - if (mode === 'auto') { + if (mode === "auto") { showToggle = false; } // Configure toggle variables. - var toggleText = mode === 'preview' ? acf.__('Switch to Edit') : acf.__('Switch to Preview'); - var toggleIcon = mode === 'preview' ? 'edit' : 'welcome-view-site'; + var toggleText = mode === "preview" ? acf.__("Switch to Edit") : acf.__("Switch to Preview"); + var toggleIcon = mode === "preview" ? "edit" : "welcome-view-site"; function toggleMode() { setAttributes({ - mode: mode === 'preview' ? 'edit' : 'preview' + mode: mode === "preview" ? "edit" : "preview" }); } // Return template. - return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(BlockControls, null, showToggle && /*#__PURE__*/React.createElement(Toolbar, null, /*#__PURE__*/React.createElement(IconButton, { + return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(BlockControls, null, showToggle && /*#__PURE__*/React.createElement(ToolbarGroup, null, /*#__PURE__*/React.createElement(ToolbarButton, { className: "components-icon-button components-toolbar__control", label: toggleText, icon: toggleIcon, onClick: toggleMode - }))), /*#__PURE__*/React.createElement(InspectorControls, null, mode === 'preview' && /*#__PURE__*/React.createElement("div", { + }))), /*#__PURE__*/React.createElement(InspectorControls, null, mode === "preview" && /*#__PURE__*/React.createElement("div", { className: "acf-block-component acf-block-panel" }, /*#__PURE__*/React.createElement(BlockForm, this.props))), /*#__PURE__*/React.createElement(BlockBody, this.props)); } @@ -1024,46 +1039,29 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope return BlockEdit; }(Component); /** - * The BlockBody component. + * The BlockBody functional component. * * @date 19/2/19 * @since 5.7.12 */ - var _BlockBody = /*#__PURE__*/function (_Component3) { - _inherits(_BlockBody, _Component3); - - var _super3 = _createSuper(_BlockBody); - - function _BlockBody() { - _classCallCheck(this, _BlockBody); - - return _super3.apply(this, arguments); - } - - _createClass(_BlockBody, [{ - key: "render", - value: function render() { - var _this$props4 = this.props, - attributes = _this$props4.attributes, - isSelected = _this$props4.isSelected; - var mode = attributes.mode; - return /*#__PURE__*/React.createElement("div", { - className: "acf-block-component acf-block-body" - }, mode === 'auto' && isSelected ? /*#__PURE__*/React.createElement(BlockForm, this.props) : mode === 'auto' && !isSelected ? /*#__PURE__*/React.createElement(BlockPreview, this.props) : mode === 'preview' ? /*#__PURE__*/React.createElement(BlockPreview, this.props) : /*#__PURE__*/React.createElement(BlockForm, this.props)); - } - }]); - - return _BlockBody; - }(Component); // Append blockIndex to component props. + function _BlockBody(props) { + var wpProps = useBlockProps(); + var attributes = props.attributes, + isSelected = props.isSelected; + var mode = attributes.mode; + return /*#__PURE__*/React.createElement("div", wpProps, /*#__PURE__*/React.createElement("div", { + className: "acf-block-component acf-block-body" + }, mode === "auto" && isSelected ? /*#__PURE__*/React.createElement(BlockForm, props) : mode === "auto" && !isSelected ? /*#__PURE__*/React.createElement(BlockPreview, props) : mode === "preview" ? /*#__PURE__*/React.createElement(BlockPreview, props) : /*#__PURE__*/React.createElement(BlockForm, props))); + } // Append blockIndex to component props. var BlockBody = withSelect(function (select, ownProps) { var clientId = ownProps.clientId; // Use optional rootClientId to allow discoverability of child blocks. - var rootClientId = select('core/block-editor').getBlockRootClientId(clientId); - var index = select('core/block-editor').getBlockIndex(clientId, rootClientId); + var rootClientId = select("core/block-editor").getBlockRootClientId(clientId); + var index = select("core/block-editor").getBlockIndex(clientId, rootClientId); return { index: index }; @@ -1078,15 +1076,15 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope * @return void */ - var Div = /*#__PURE__*/function (_Component4) { - _inherits(Div, _Component4); + var Div = /*#__PURE__*/function (_Component3) { + _inherits(Div, _Component3); - var _super4 = _createSuper(Div); + var _super3 = _createSuper(Div); function Div() { _classCallCheck(this, Div); - return _super4.apply(this, arguments); + return _super3.apply(this, arguments); } _createClass(Div, [{ @@ -1104,7 +1102,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope }(Component); /** * A react Component for inline scripts. - * + * * This Component uses a combination of React references and jQuery to append the * inline - post_type !== 'acf-field-group' ) { - return $post_id; - } - - // only save once! WordPress save's a revision as well. - if( wp_is_post_revision($post_id) ) { - return $post_id; - } - - // verify nonce - if( !acf_verify_nonce('field_group') ) { - return $post_id; - } - - // Bail early if request came from an unauthorised user. - if( !current_user_can(acf_get_setting('capability')) ) { - return $post_id; - } - - - // disable filters to ensure ACF loads raw data from DB - acf_disable_filters(); - - - // save fields - if( !empty($_POST['acf_fields']) ) { - - // loop - foreach( $_POST['acf_fields'] as $field ) { - - // vars - $specific = false; - $save = acf_extract_var( $field, 'save' ); - - - // only saved field if has changed - if( $save == 'meta' ) { - $specific = array( - 'menu_order', - 'post_parent', - ); - } - - // set parent - if( !$field['parent'] ) { - $field['parent'] = $post_id; - } - - // save field - acf_update_field( $field, $specific ); - + + + /* + * save_post + * + * This function will save all the field group data + * + * @type function + * @date 23/06/12 + * @since 1.0.0 + * + * @param $post_id (int) + * @return $post_id (int) + */ + + function save_post( $post_id, $post ) { + + // do not save if this is an auto save routine + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { + return $post_id; } - } - - - // delete fields - if( $_POST['_acf_delete_fields'] ) { - - // clean - $ids = explode('|', $_POST['_acf_delete_fields']); - $ids = array_map( 'intval', $ids ); - - - // loop - foreach( $ids as $id ) { - - // bai early if no id - if( !$id ) continue; - - - // delete - acf_delete_field( $id ); - + + // bail early if not acf-field-group + if ( $post->post_type !== 'acf-field-group' ) { + return $post_id; } - - } - - - // add args - $_POST['acf_field_group']['ID'] = $post_id; - $_POST['acf_field_group']['title'] = $_POST['post_title']; - - - // save field group - acf_update_field_group( $_POST['acf_field_group'] ); - - - // return - return $post_id; - } - - - /* - * mb_fields - * - * This function will render the HTML for the medtabox 'acf-field-group-fields' - * - * @type function - * @date 28/09/13 - * @since 5.0.0 - * - * @param N/A - * @return N/A - */ - - function mb_fields() { - - // global - global $field_group; - - - // get fields - $view = array( - 'fields' => acf_get_fields( $field_group ), - 'parent' => 0 - ); - - - // load view - acf_get_view('field-group-fields', $view); - - } - - - /* - * mb_options - * - * This function will render the HTML for the medtabox 'acf-field-group-options' - * - * @type function - * @date 28/09/13 - * @since 5.0.0 - * - * @param N/A - * @return N/A - */ - - function mb_options() { - - // global - global $field_group; - - - // field key (leave in for compatibility) - if( !acf_is_field_group_key( $field_group['key']) ) { - - $field_group['key'] = uniqid('group_'); - + + // only save once! WordPress save's a revision as well. + if ( wp_is_post_revision( $post_id ) ) { + return $post_id; + } + + // verify nonce + if ( ! acf_verify_nonce( 'field_group' ) ) { + return $post_id; + } + + // Bail early if request came from an unauthorised user. + if ( ! current_user_can( acf_get_setting( 'capability' ) ) ) { + return $post_id; + } + + // disable filters to ensure ACF loads raw data from DB + acf_disable_filters(); + + // save fields + if ( ! empty( $_POST['acf_fields'] ) ) { + + // loop + foreach ( $_POST['acf_fields'] as $field ) { + + // vars + $specific = false; + $save = acf_extract_var( $field, 'save' ); + + // only saved field if has changed + if ( $save == 'meta' ) { + $specific = array( + 'menu_order', + 'post_parent', + ); + } + + // set parent + if ( ! $field['parent'] ) { + $field['parent'] = $post_id; + } + + // save field + acf_update_field( $field, $specific ); + + } + } + + // delete fields + if ( $_POST['_acf_delete_fields'] ) { + + // clean + $ids = explode( '|', $_POST['_acf_delete_fields'] ); + $ids = array_map( 'intval', $ids ); + + // loop + foreach ( $ids as $id ) { + + // bai early if no id + if ( ! $id ) { + continue; + } + + // delete + acf_delete_field( $id ); + + } + } + + // add args + $_POST['acf_field_group']['ID'] = $post_id; + $_POST['acf_field_group']['title'] = $_POST['post_title']; + + // save field group + acf_update_field_group( $_POST['acf_field_group'] ); + + // return + return $post_id; } - - - // view - acf_get_view('field-group-options'); - - } - - - /* - * mb_locations - * - * This function will render the HTML for the medtabox 'acf-field-group-locations' - * - * @type function - * @date 28/09/13 - * @since 5.0.0 - * - * @param N/A - * @return N/A - */ - - function mb_locations() { - - // global - global $field_group; - - - // UI needs at lease 1 location rule - if( empty($field_group['location']) ) { - - $field_group['location'] = array( - - // group 0 - array( - - // rule 0 - array( - 'param' => 'post_type', - 'operator' => '==', - 'value' => 'post', - ) - ) - + + + /* + * mb_fields + * + * This function will render the HTML for the medtabox 'acf-field-group-fields' + * + * @type function + * @date 28/09/13 + * @since 5.0.0 + * + * @param N/A + * @return N/A + */ + + function mb_fields() { + + // global + global $field_group; + + // get fields + $view = array( + 'fields' => acf_get_fields( $field_group ), + 'parent' => 0, ); + + // load view + acf_get_view( 'field-group-fields', $view ); + } - - - // view - acf_get_view('field-group-locations'); - - } - - - /* - * ajax_render_location_rule - * - * This function can be accessed via an AJAX action and will return the result from the render_location_value function - * - * @type function (ajax) - * @date 30/09/13 - * @since 5.0.0 - * - * @param n/a - * @return n/a - */ - - function ajax_render_location_rule() { - - // validate - if( !acf_verify_ajax() ) die(); - - // validate rule - $rule = acf_validate_location_rule($_POST['rule']); - - // view - acf_get_view( 'html-location-rule', array( - 'rule' => $rule - )); - - // die - die(); - } - - - /* - * ajax_render_field_settings - * - * This function will return HTML containing the field's settings based on it's new type - * - * @type function (ajax) - * @date 30/09/13 - * @since 5.0.0 - * - * @param n/a - * @return n/a - */ - - function ajax_render_field_settings() { - - // validate - if( !acf_verify_ajax() ) die(); - - // vars - $field = acf_maybe_get_POST('field'); - - // check - if( !$field ) die(); - - // set prefix - $field['prefix'] = acf_maybe_get_POST('prefix'); - - // validate - $field = acf_get_valid_field( $field ); - - // render - do_action("acf/render_field_settings/type={$field['type']}", $field); - - // return - die(); - - } - - /* - * ajax_move_field - * - * description - * - * @type function - * @date 20/01/2014 - * @since 5.0.0 - * - * @param $post_id (int) - * @return $post_id (int) - */ - - function ajax_move_field() { - - // disable filters to ensure ACF loads raw data from DB - acf_disable_filters(); - - - $args = acf_parse_args($_POST, array( - 'nonce' => '', - 'post_id' => 0, - 'field_id' => 0, - 'field_group_id' => 0 - )); - - - // verify nonce - if( !wp_verify_nonce($args['nonce'], 'acf_nonce') ) die(); - - - // confirm? - if( $args['field_id'] && $args['field_group_id'] ) { - - // vars - $field = acf_get_field($args['field_id']); - $field_group = acf_get_field_group($args['field_group_id']); - - - // update parent - $field['parent'] = $field_group['ID']; - - - // remove conditional logic - $field['conditional_logic'] = 0; - - - // update field - acf_update_field($field); - - - // Output HTML. - $link = '' . esc_html( $field_group['title'] ) . ''; - - echo '' . - '

              ' . __( 'Move Complete.', 'acf' ) . '

              ' . - '

              ' . sprintf( - acf_punctify( __( 'The %s field can now be found in the %s field group', 'acf' ) ), - esc_html( $field['label'] ), - $link - ). '

              ' . - '' . __( 'Close Window', 'acf' ) . ''; + + + /* + * mb_options + * + * This function will render the HTML for the medtabox 'acf-field-group-options' + * + * @type function + * @date 28/09/13 + * @since 5.0.0 + * + * @param N/A + * @return N/A + */ + + function mb_options() { + + // global + global $field_group; + + // field key (leave in for compatibility) + if ( ! acf_is_field_group_key( $field_group['key'] ) ) { + + $field_group['key'] = uniqid( 'group_' ); + + } + + // view + acf_get_view( 'field-group-options' ); + + } + + + /* + * mb_locations + * + * This function will render the HTML for the medtabox 'acf-field-group-locations' + * + * @type function + * @date 28/09/13 + * @since 5.0.0 + * + * @param N/A + * @return N/A + */ + + function mb_locations() { + + // global + global $field_group; + + // UI needs at lease 1 location rule + if ( empty( $field_group['location'] ) ) { + + $field_group['location'] = array( + + // group 0 + array( + + // rule 0 + array( + 'param' => 'post_type', + 'operator' => '==', + 'value' => 'post', + ), + ), + + ); + } + + // view + acf_get_view( 'field-group-locations' ); + + } + + + /* + * ajax_render_location_rule + * + * This function can be accessed via an AJAX action and will return the result from the render_location_value function + * + * @type function (ajax) + * @date 30/09/13 + * @since 5.0.0 + * + * @param n/a + * @return n/a + */ + + function ajax_render_location_rule() { + + // validate + if ( ! acf_verify_ajax() ) { + die(); + } + + // verify user capability + if ( ! acf_current_user_can_admin() ) { + die(); + } + + // validate rule + $rule = acf_validate_location_rule( $_POST['rule'] ); + + // view + acf_get_view( + 'html-location-rule', + array( + 'rule' => $rule, + ) + ); + + // die die(); } - - - // get all field groups - $field_groups = acf_get_field_groups(); - $choices = array(); - - - // check - if( !empty($field_groups) ) { - - // loop - foreach( $field_groups as $field_group ) { - - // bail early if no ID - if( !$field_group['ID'] ) continue; - - - // bail ealry if is current - if( $field_group['ID'] == $args['post_id'] ) continue; - - - // append - $choices[ $field_group['ID'] ] = $field_group['title']; - - } - - } - - - // render options - $field = acf_get_valid_field(array( - 'type' => 'select', - 'name' => 'acf_field_group', - 'choices' => $choices - )); - - - echo '

              ' . __('Please select the destination for this field', 'acf') . '

              '; - - echo '
              '; - - // render - acf_render_field_wrap( $field ); - - echo ''; - - echo ''; - - - // die - die(); - - } - -} -// initialize -new acf_admin_field_group(); + + /* + * ajax_render_field_settings + * + * This function will return HTML containing the field's settings based on it's new type + * + * @type function (ajax) + * @date 30/09/13 + * @since 5.0.0 + * + * @param n/a + * @return n/a + */ + + function ajax_render_field_settings() { + + // validate + if ( ! acf_verify_ajax() ) { + die(); + } + + // verify user capability + if ( ! acf_current_user_can_admin() ) { + die(); + } + + // vars + $field = acf_maybe_get_POST( 'field' ); + + // check + if ( ! $field ) { + die(); + } + + // set prefix + $field['prefix'] = acf_maybe_get_POST( 'prefix' ); + + // validate + $field = acf_get_valid_field( $field ); + + // render + do_action( "acf/render_field_settings/type={$field['type']}", $field ); + + // return + die(); + + } + + /* + * ajax_move_field + * + * description + * + * @type function + * @date 20/01/2014 + * @since 5.0.0 + * + * @param $post_id (int) + * @return $post_id (int) + */ + + function ajax_move_field() { + + // disable filters to ensure ACF loads raw data from DB + acf_disable_filters(); + + $args = acf_parse_args( + $_POST, + array( + 'nonce' => '', + 'post_id' => 0, + 'field_id' => 0, + 'field_group_id' => 0, + ) + ); + + // verify nonce + if ( ! wp_verify_nonce( $args['nonce'], 'acf_nonce' ) ) { + die(); + } + + // verify user capability + if ( ! acf_current_user_can_admin() ) { + die(); + } + + // confirm? + if ( $args['field_id'] && $args['field_group_id'] ) { + + // vars + $field = acf_get_field( $args['field_id'] ); + $field_group = acf_get_field_group( $args['field_group_id'] ); + + // update parent + $field['parent'] = $field_group['ID']; + + // remove conditional logic + $field['conditional_logic'] = 0; + + // update field + acf_update_field( $field ); + + // Output HTML. + $link = '' . esc_html( $field_group['title'] ) . ''; + + echo '' . + '

              ' . __( 'Move Complete.', 'acf' ) . '

              ' . + '

              ' . sprintf( + acf_punctify( __( 'The %1$s field can now be found in the %2$s field group', 'acf' ) ), + esc_html( $field['label'] ), + $link + ) . '

              ' . + '' . __( 'Close Window', 'acf' ) . ''; + die(); + } + + // get all field groups + $field_groups = acf_get_field_groups(); + $choices = array(); + + // check + if ( ! empty( $field_groups ) ) { + + // loop + foreach ( $field_groups as $field_group ) { + + // bail early if no ID + if ( ! $field_group['ID'] ) { + continue; + } + + // bail ealry if is current + if ( $field_group['ID'] == $args['post_id'] ) { + continue; + } + + // append + $choices[ $field_group['ID'] ] = $field_group['title']; + + } + } + + // render options + $field = acf_get_valid_field( + array( + 'type' => 'select', + 'name' => 'acf_field_group', + 'choices' => $choices, + ) + ); + + echo '

              ' . __( 'Please select the destination for this field', 'acf' ) . '

              '; + + echo '
              '; + + // render + acf_render_field_wrap( $field ); + + echo ''; + + echo ''; + + // die + die(); + + } + + } + + // initialize + new acf_admin_field_group(); endif; -?> \ No newline at end of file +?> diff --git a/includes/admin/admin-field-groups.php b/includes/admin/admin-field-groups.php index 89a51d0..a8b5575 100644 --- a/includes/admin/admin-field-groups.php +++ b/includes/admin/admin-field-groups.php @@ -1,713 +1,719 @@ -get_admin_url( ( $this->view ? '&post_status=' . $this->view : '' ) . $params ); - } - - /** - * Redirects users from ACF 4.0 admin page. - * - * @date 17/9/18 - * @since 5.7.6 - * - * @param void - * @return void - */ - public function handle_redirection() { - if( isset($_GET['post_type']) && $_GET['post_type'] === 'acf' ) { - wp_redirect( $this->get_admin_url() ); - exit; - } - } - - /** - * Constructor for the Field Groups admin page. - * - * @date 21/07/2014 - * @since 5.0.0 - * - * @param void - * @return void - */ - public function current_screen() { - - // Bail early if not Field Groups admin page. - if( !acf_is_screen('edit-acf-field-group') ) { - return; - } - - // Get the current view. - $this->view = isset( $_GET['post_status'] ) ? sanitize_text_field( $_GET['post_status'] ) : ''; - - // Setup and check for custom actions.. - $this->setup_sync(); - $this->check_sync(); - $this->check_duplicate(); - - // Modify publish post status text and order. - global $wp_post_statuses; - $wp_post_statuses['publish']->label_count = _n_noop( 'Active (%s)', 'Active (%s)', 'acf' ); - $wp_post_statuses['trash'] = acf_extract_var( $wp_post_statuses, 'trash' ); - - // Add hooks. - add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts') ); - add_action( 'admin_body_class', array( $this, 'admin_body_class' ) ); - add_filter( 'views_edit-acf-field-group', array( $this, 'admin_table_views' ), 10, 1 ); - add_filter( 'manage_acf-field-group_posts_columns', array( $this, 'admin_table_columns' ), 10, 1 ); - add_action( 'manage_acf-field-group_posts_custom_column', array( $this, 'admin_table_columns_html' ), 10, 2 ); - add_filter( 'display_post_states', array( $this, 'display_post_states' ), 10, 2 ); - add_filter( 'bulk_actions-edit-acf-field-group', array( $this, 'admin_table_bulk_actions' ), 10, 1 ); - add_action( 'admin_footer', array( $this, 'admin_footer' ), 1 ); - if( $this->view !== 'trash' ) { - add_filter( 'page_row_actions', array( $this, 'page_row_actions' ), 10, 2 ); + /** + * Array of field groups availbale for sync. + * + * @since 5.9.0 + * @var array + */ + public $sync = array(); + + /** + * The current view (post_status). + * + * @since 5.9.0 + * @var string + */ + public $view = ''; + + /** + * Constructor. + * + * @date 5/03/2014 + * @since 5.0.0 + * + * @param void + * @return void + */ + public function __construct() { + + // Add hooks. + add_action( 'load-edit.php', array( $this, 'handle_redirection' ) ); + add_action( 'current_screen', array( $this, 'current_screen' ) ); + + // Handle post status change events. + add_action( 'trashed_post', array( $this, 'trashed_post' ) ); + add_action( 'untrashed_post', array( $this, 'untrashed_post' ) ); + add_action( 'deleted_post', array( $this, 'deleted_post' ) ); } - // Add hooks for "sync" view. - if( $this->view === 'sync' ) { - add_action( 'admin_footer', array( $this, 'admin_footer__sync' ), 1 ); + /** + * Returns the Field Groups admin URL. + * + * @date 27/3/20 + * @since 5.9.0 + * + * @param string $params Extra URL params. + * @return string + */ + public function get_admin_url( $params = '' ) { + return admin_url( "edit.php?post_type=acf-field-group{$params}" ); } - } - - /** - * Sets up the field groups ready for sync. - * - * @date 17/4/20 - * @since 5.9.0 - * - * @param void - * @return void - */ - public function setup_sync() { - - // Review local json field groups. - if( acf_get_local_json_files() ) { - - // Get all groups in a single cached query to check if sync is available. - $all_field_groups = acf_get_field_groups(); - foreach( $all_field_groups as $field_group ) { - - // Extract vars. - $local = acf_maybe_get( $field_group, 'local' ); - $modified = acf_maybe_get( $field_group, 'modified' ); - $private = acf_maybe_get( $field_group, 'private' ); - - // Ignore if is private. - if( $private ) { - continue; - - // Ignore not local "json". - } elseif( $local !== 'json' ) { - continue; - - // Append to sync if not yet in database. - } elseif( !$field_group['ID'] ) { - $this->sync[ $field_group['key'] ] = $field_group; - - // Append to sync if "json" modified time is newer than database. - } elseif( $modified && $modified > get_post_modified_time('U', true, $field_group['ID']) ) { - $this->sync[ $field_group['key'] ] = $field_group; + + /** + * Returns the Field Groups admin URL taking into account the current view. + * + * @date 27/3/20 + * @since 5.9.0 + * + * @param string $params Extra URL params. + * @return string + */ + public function get_current_admin_url( $params = '' ) { + return $this->get_admin_url( ( $this->view ? '&post_status=' . $this->view : '' ) . $params ); + } + + /** + * Redirects users from ACF 4.0 admin page. + * + * @date 17/9/18 + * @since 5.7.6 + * + * @param void + * @return void + */ + public function handle_redirection() { + if ( isset( $_GET['post_type'] ) && $_GET['post_type'] === 'acf' ) { + wp_redirect( $this->get_admin_url() ); + exit; + } + } + + /** + * Constructor for the Field Groups admin page. + * + * @date 21/07/2014 + * @since 5.0.0 + * + * @param void + * @return void + */ + public function current_screen() { + + // Bail early if not Field Groups admin page. + if ( ! acf_is_screen( 'edit-acf-field-group' ) ) { + return; + } + + // Get the current view. + $this->view = isset( $_GET['post_status'] ) ? sanitize_text_field( $_GET['post_status'] ) : ''; + + // Setup and check for custom actions.. + $this->setup_sync(); + $this->check_sync(); + $this->check_duplicate(); + + // Modify publish post status text and order. + global $wp_post_statuses; + $wp_post_statuses['publish']->label_count = _n_noop( 'Active (%s)', 'Active (%s)', 'acf' ); + $wp_post_statuses['trash'] = acf_extract_var( $wp_post_statuses, 'trash' ); + + // Add hooks. + add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); + add_action( 'admin_body_class', array( $this, 'admin_body_class' ) ); + add_filter( 'views_edit-acf-field-group', array( $this, 'admin_table_views' ), 10, 1 ); + add_filter( 'manage_acf-field-group_posts_columns', array( $this, 'admin_table_columns' ), 10, 1 ); + add_action( 'manage_acf-field-group_posts_custom_column', array( $this, 'admin_table_columns_html' ), 10, 2 ); + add_filter( 'display_post_states', array( $this, 'display_post_states' ), 10, 2 ); + add_filter( 'bulk_actions-edit-acf-field-group', array( $this, 'admin_table_bulk_actions' ), 10, 1 ); + add_action( 'admin_footer', array( $this, 'admin_footer' ), 1 ); + if ( $this->view !== 'trash' ) { + add_filter( 'page_row_actions', array( $this, 'page_row_actions' ), 10, 2 ); + } + + // Add hooks for "sync" view. + if ( $this->view === 'sync' ) { + add_action( 'admin_footer', array( $this, 'admin_footer__sync' ), 1 ); + } + } + + /** + * Sets up the field groups ready for sync. + * + * @date 17/4/20 + * @since 5.9.0 + * + * @param void + * @return void + */ + public function setup_sync() { + + // Review local json field groups. + if ( acf_get_local_json_files() ) { + + // Get all groups in a single cached query to check if sync is available. + $all_field_groups = acf_get_field_groups(); + foreach ( $all_field_groups as $field_group ) { + + // Extract vars. + $local = acf_maybe_get( $field_group, 'local' ); + $modified = acf_maybe_get( $field_group, 'modified' ); + $private = acf_maybe_get( $field_group, 'private' ); + + // Ignore if is private. + if ( $private ) { + continue; + + // Ignore not local "json". + } elseif ( $local !== 'json' ) { + continue; + + // Append to sync if not yet in database. + } elseif ( ! $field_group['ID'] ) { + $this->sync[ $field_group['key'] ] = $field_group; + + // Append to sync if "json" modified time is newer than database. + } elseif ( $modified && $modified > get_post_modified_time( 'U', true, $field_group['ID'] ) ) { + $this->sync[ $field_group['key'] ] = $field_group; + } } } } - } - - /** - * Enqueues admin scripts. - * - * @date 18/4/20 - * @since 5.9.0 - * - * @param void - * @return void - */ - public function admin_enqueue_scripts() { - acf_enqueue_script( 'acf' ); - - // Localize text. - acf_localize_text(array( - 'Review local JSON changes' => __( 'Review local JSON changes', 'acf' ), - 'Loading diff' => __( 'Loading diff', 'acf' ), - 'Sync changes' => __( 'Sync changes', 'acf' ), - )); - } - - /** - * Modifies the admin body class. - * - * @date 18/4/20 - * @since 5.9.0 - * - * @param string $classes Space-separated list of CSS classes. - * @return string - */ - public function admin_body_class( $classes ) { - $classes .= ' acf-admin-field-groups'; - if( $this->view ) { - $classes .= " view-{$this->view}"; + + /** + * Enqueues admin scripts. + * + * @date 18/4/20 + * @since 5.9.0 + * + * @param void + * @return void + */ + public function admin_enqueue_scripts() { + acf_enqueue_script( 'acf' ); + + // Localize text. + acf_localize_text( + array( + 'Review local JSON changes' => __( 'Review local JSON changes', 'acf' ), + 'Loading diff' => __( 'Loading diff', 'acf' ), + 'Sync changes' => __( 'Sync changes', 'acf' ), + ) + ); } - return $classes; - } - - /** - * returns the disabled post state HTML. - * - * @date 17/4/20 - * @since 5.9.0 - * - * @param void - * @return string - */ - public function get_disabled_post_state() { - return ' ' . _x( 'Disabled', 'post status', 'acf' ); - } - - /** - * Adds the "disabled" post state for the admin table title. - * - * @date 1/4/20 - * @since 5.9.0 - * - * @param array $post_states An array of post display states. - * @param WP_Post $post The current post object. - * @return array - */ - public function display_post_states( $post_states, $post ) { - if( $post->post_status === 'acf-disabled' ) { - $post_states['acf-disabled'] = $this->get_disabled_post_state(); + + /** + * Modifies the admin body class. + * + * @date 18/4/20 + * @since 5.9.0 + * + * @param string $classes Space-separated list of CSS classes. + * @return string + */ + public function admin_body_class( $classes ) { + $classes .= ' acf-admin-field-groups'; + if ( $this->view ) { + $classes .= " view-{$this->view}"; + } + return $classes; } - return $post_states; - } - - /** - * Customizes the admin table columns. - * - * @date 1/4/20 - * @since 5.9.0 - * - * @param array $columns The columns array. - * @return array - */ - public function admin_table_columns( $_columns ) { - $columns = array( - 'cb' => $_columns['cb'], - 'title' => $_columns['title'], - 'acf-description' => __('Description', 'acf'), - 'acf-key' => __('Key', 'acf'), - 'acf-location' => __('Location', 'acf'), - 'acf-count' => __('Fields', 'acf'), - ); - if( acf_get_local_json_files() ) { - $columns['acf-json'] = __('Local JSON', 'acf'); + + /** + * returns the disabled post state HTML. + * + * @date 17/4/20 + * @since 5.9.0 + * + * @param void + * @return string + */ + public function get_disabled_post_state() { + return ' ' . _x( 'Disabled', 'post status', 'acf' ); } - return $columns; - } - - /** - * Renders the admin table column HTML - * - * @date 1/4/20 - * @since 5.9.0 - * - * @param string $column_name The name of the column to display. - * @param int $post_id The current post ID. - * @return void - */ - public function admin_table_columns_html( $column_name, $post_id ) { - $field_group = acf_get_field_group( $post_id ); - if( $field_group ) { - $this->render_admin_table_column( $column_name, $field_group ); + + /** + * Adds the "disabled" post state for the admin table title. + * + * @date 1/4/20 + * @since 5.9.0 + * + * @param array $post_states An array of post display states. + * @param WP_Post $post The current post object. + * @return array + */ + public function display_post_states( $post_states, $post ) { + if ( $post->post_status === 'acf-disabled' ) { + $post_states['acf-disabled'] = $this->get_disabled_post_state(); + } + return $post_states; } - } - - /** - * Renders a specific admin table column. - * - * @date 17/4/20 - * @since 5.9.0 - * - * @param string $column_name The name of the column to display. - * @param array $field_group The field group. - * @return void - */ - public function render_admin_table_column( $column_name, $field_group ) { - switch ( $column_name ) { - - // Key. - case 'acf-key': - echo esc_html( $field_group['key'] ); - break; - - // Description. - case 'acf-description': - if( $field_group['description'] ) { - echo '' . acf_esc_html( $field_group['description'] ) . ''; - } - break; - - // Location. - case 'acf-location': - $this->render_admin_table_column_locations( $field_group ); - break; - - // Count. - case 'acf-count': - echo esc_html( acf_get_field_count( $field_group ) ); - break; - - // Local JSON. - case 'acf-json': - $this->render_admin_table_column_local_status( $field_group ); - break; + + /** + * Customizes the admin table columns. + * + * @date 1/4/20 + * @since 5.9.0 + * + * @param array $columns The columns array. + * @return array + */ + public function admin_table_columns( $_columns ) { + $columns = array( + 'cb' => $_columns['cb'], + 'title' => $_columns['title'], + 'acf-description' => __( 'Description', 'acf' ), + 'acf-key' => __( 'Key', 'acf' ), + 'acf-location' => __( 'Location', 'acf' ), + 'acf-count' => __( 'Fields', 'acf' ), + ); + if ( acf_get_local_json_files() ) { + $columns['acf-json'] = __( 'Local JSON', 'acf' ); + } + return $columns; } - } - - /** - * Displays a visual representation of the field group's locations. - * - * @date 1/4/20 - * @since 5.9.0 - * - * @param array $field_group The field group. - * @return void - */ - public function render_admin_table_column_locations( $field_group ) { - $objects = array(); - - // Loop over location rules and determine connected object types. - if( $field_group['location'] ) { - foreach( $field_group['location'] as $i => $rules ) { - - // Determine object types for each rule. - foreach( $rules as $j => $rule ) { - - // Get location type and subtype for the current rule. - $location = acf_get_location_rule( $rule['param'] ); - $location_object_type = ''; - $location_object_subtype = ''; - if( $location ) { - $location_object_type = $location->get_object_type( $rule ); - $location_object_subtype = $location->get_object_subtype( $rule ); + + /** + * Renders the admin table column HTML + * + * @date 1/4/20 + * @since 5.9.0 + * + * @param string $column_name The name of the column to display. + * @param int $post_id The current post ID. + * @return void + */ + public function admin_table_columns_html( $column_name, $post_id ) { + $field_group = acf_get_field_group( $post_id ); + if ( $field_group ) { + $this->render_admin_table_column( $column_name, $field_group ); + } + } + + /** + * Renders a specific admin table column. + * + * @date 17/4/20 + * @since 5.9.0 + * + * @param string $column_name The name of the column to display. + * @param array $field_group The field group. + * @return void + */ + public function render_admin_table_column( $column_name, $field_group ) { + switch ( $column_name ) { + + // Key. + case 'acf-key': + echo esc_html( $field_group['key'] ); + break; + + // Description. + case 'acf-description': + if ( $field_group['description'] ) { + echo '' . acf_esc_html( $field_group['description'] ) . ''; } - $rules[ $j ]['object_type'] = $location_object_type; - $rules[ $j ]['object_subtype'] = $location_object_subtype; - } - - // Now that each $rule conains object type data... - $object_types = array_column( $rules, 'object_type' ); - $object_types = array_filter( $object_types ); - $object_types = array_values( $object_types ); - if( $object_types ) { - $object_type = $object_types[0]; - } else { - continue; - } - - $object_subtypes = array_column( $rules, 'object_subtype' ); - $object_subtypes = array_filter( $object_subtypes ); - $object_subtypes = array_values( $object_subtypes ); - $object_subtypes = array_map('acf_array', $object_subtypes); - if( count($object_subtypes) > 1 ) { - $object_subtypes = call_user_func_array('array_intersect', $object_subtypes); + break; + + // Location. + case 'acf-location': + $this->render_admin_table_column_locations( $field_group ); + break; + + // Count. + case 'acf-count': + echo esc_html( acf_get_field_count( $field_group ) ); + break; + + // Local JSON. + case 'acf-json': + $this->render_admin_table_column_local_status( $field_group ); + break; + } + } + + /** + * Displays a visual representation of the field group's locations. + * + * @date 1/4/20 + * @since 5.9.0 + * + * @param array $field_group The field group. + * @return void + */ + public function render_admin_table_column_locations( $field_group ) { + $objects = array(); + + // Loop over location rules and determine connected object types. + if ( $field_group['location'] ) { + foreach ( $field_group['location'] as $i => $rules ) { + + // Determine object types for each rule. + foreach ( $rules as $j => $rule ) { + + // Get location type and subtype for the current rule. + $location = acf_get_location_rule( $rule['param'] ); + $location_object_type = ''; + $location_object_subtype = ''; + if ( $location ) { + $location_object_type = $location->get_object_type( $rule ); + $location_object_subtype = $location->get_object_subtype( $rule ); + } + $rules[ $j ]['object_type'] = $location_object_type; + $rules[ $j ]['object_subtype'] = $location_object_subtype; + } + + // Now that each $rule conains object type data... + $object_types = array_column( $rules, 'object_type' ); + $object_types = array_filter( $object_types ); + $object_types = array_values( $object_types ); + if ( $object_types ) { + $object_type = $object_types[0]; + } else { + continue; + } + + $object_subtypes = array_column( $rules, 'object_subtype' ); + $object_subtypes = array_filter( $object_subtypes ); $object_subtypes = array_values( $object_subtypes ); - } elseif( $object_subtypes ) { - $object_subtypes = $object_subtypes[0]; - } else { - $object_subtypes = array( '' ); - } - - // Append to objects. - foreach( $object_subtypes as $object_subtype ) { - $object = acf_get_object_type( $object_type, $object_subtype ); - if( $object ) { - $objects[ $object->name ] = $object; + $object_subtypes = array_map( 'acf_array', $object_subtypes ); + if ( count( $object_subtypes ) > 1 ) { + $object_subtypes = call_user_func_array( 'array_intersect', $object_subtypes ); + $object_subtypes = array_values( $object_subtypes ); + } elseif ( $object_subtypes ) { + $object_subtypes = $object_subtypes[0]; + } else { + $object_subtypes = array( '' ); + } + + // Append to objects. + foreach ( $object_subtypes as $object_subtype ) { + $object = acf_get_object_type( $object_type, $object_subtype ); + if ( $object ) { + $objects[ $object->name ] = $object; + } } } } - } - - // Reset keys. - $objects = array_values( $objects ); - - // Display. - $html = ''; - if( $objects ) { - $limit = 3; - $total = count( $objects ); - - // Icon. - $html .= ' '; - - // Labels. - $labels = array_column( $objects, 'label' ); - $labels = array_slice( $labels, 0, 3 ); - $html .= implode(', ', $labels ); - - // More. - if( $total > $limit ) { - $html .= ', ...'; - } - } else { - $html = ' ' . __( 'Various', 'acf' ); - } - - // Filter. - echo acf_esc_html( $html ); - } - - /** - * Returns a human readable file location. - * - * @date 17/4/20 - * @since 5.9.0 - * - * @param string $file The full file path. - * @return string - */ - public function get_human_readable_file_location( $file ) { - - // Generate friendly file path. - $theme_path = get_stylesheet_directory(); - if( strpos($file, $theme_path) !== false ) { - $rel_file = str_replace( $theme_path, '', $file ); - $located = sprintf( __('Located in theme: %s', 'acf'), $rel_file ); - - } elseif( strpos($file, WP_PLUGIN_DIR) !== false ) { - $rel_file = str_replace( WP_PLUGIN_DIR, '', $file ); - $located = sprintf( __('Located in plugin: %s', 'acf'), $rel_file ); - - } else { - $rel_file = str_replace( ABSPATH, '', $file ); - $located = sprintf( __('Located in: %s', 'acf'), $rel_file ); - } - return $located; - } - - /** - * Displays the local JSON status of a field group. - * - * @date 14/4/20 - * @since 5.9.0 - * - * @param type $var Description. Default. - * @return type Description. - */ - public function render_admin_table_column_local_status( $field_group ) { - $json = acf_get_local_json_files(); - if( isset( $json[ $field_group['key'] ] ) ) { - $file = $json[ $field_group['key'] ]; - if( isset($this->sync[ $field_group['key'] ]) ) { - $url = $this->get_admin_url( '&acfsync=' . $field_group['key'] . '&_wpnonce=' . wp_create_nonce('bulk-posts') ); - echo '' . __( 'Sync available', 'acf' ) . ''; - if( $field_group['ID'] ) { - echo ''; - } else { - echo ''; + + // Reset keys. + $objects = array_values( $objects ); + + // Display. + $html = ''; + if ( $objects ) { + $limit = 3; + $total = count( $objects ); + + // Icon. + $html .= ' '; + + // Labels. + $labels = array_column( $objects, 'label' ); + $labels = array_slice( $labels, 0, 3 ); + $html .= implode( ', ', $labels ); + + // More. + if ( $total > $limit ) { + $html .= ', ...'; } } else { - echo __( 'Saved', 'acf' ); + $html = ' ' . __( 'Various', 'acf' ); } - } else { - echo '' . __( 'Awaiting save', 'acf' ) . ''; - } - } - - /** - * Customizes the page row actions visible on hover. - * - * @date 14/4/20 - * @since 5.9.0 - * - * @param array $actions The array of actions HTML. - * @param WP_Post $post The post. - * @return array - */ - public function page_row_actions( $actions, $post ) { - // Remove "Quick Edit" action. - unset( $actions['inline'], $actions['inline hide-if-no-js'] ); - - // Append "Duplicate" action. - $duplicate_action_url = $this->get_admin_url( '&acfduplicate=' . $post->ID . '&_wpnonce=' . wp_create_nonce('bulk-posts') ); - $actions[ 'acfduplicate' ] = '' . __( 'Duplicate', 'acf' ) . ''; - - // Return actions in custom order. - $order = array( 'edit', 'acfduplicate', 'trash' ); - return array_merge( array_flip($order), $actions ); - } - - /** - * Modifies the admin table bulk actions dropdown. - * - * @date 15/4/20 - * @since 5.9.0 - * - * @param array $actions The actions array. - * @return array - */ - public function admin_table_bulk_actions( $actions ) { - - // Add "duplicate" action. - if( $this->view !== 'sync' ) { - $actions[ 'acfduplicate' ] = __( 'Duplicate', 'acf' ); + // Filter. + echo acf_esc_html( $html ); } - - // Add "Sync" action. - if( $this->sync ) { - if( $this->view === 'sync' ) { - $actions = array(); + + /** + * Returns a human readable file location. + * + * @date 17/4/20 + * @since 5.9.0 + * + * @param string $file The full file path. + * @return string + */ + public function get_human_readable_file_location( $file ) { + + // Generate friendly file path. + $theme_path = get_stylesheet_directory(); + if ( strpos( $file, $theme_path ) !== false ) { + $rel_file = str_replace( $theme_path, '', $file ); + $located = sprintf( __( 'Located in theme: %s', 'acf' ), $rel_file ); + + } elseif ( strpos( $file, WP_PLUGIN_DIR ) !== false ) { + $rel_file = str_replace( WP_PLUGIN_DIR, '', $file ); + $located = sprintf( __( 'Located in plugin: %s', 'acf' ), $rel_file ); + + } else { + $rel_file = str_replace( ABSPATH, '', $file ); + $located = sprintf( __( 'Located in: %s', 'acf' ), $rel_file ); } - $actions[ 'acfsync' ] = __( 'Sync changes', 'acf' ); + return $located; } - return $actions; - } - - /** - * Checks for the custom "duplicate" action. - * - * @date 15/4/20 - * @since 5.9.0 - * - * @param void - * @return void - */ - public function check_duplicate() { - - // Display notice on success redirect. - if( isset($_GET['acfduplicatecomplete']) ) { - $ids = array_map( 'intval', explode(',', $_GET['acfduplicatecomplete']) ); - - // Generate text. - $text = sprintf( - _n( 'Field group duplicated.', '%s field groups duplicated.', count($ids), 'acf' ), - count($ids) - ); - - // Append links to text. - $links = array(); - foreach( $ids as $id ) { - $links[] = '' . get_the_title( $id ) . ''; - } - $text .= ' ' . implode( ', ', $links ); - - // Add notice. - acf_add_admin_notice( $text, 'success' ); - return; - } - - // Find items to duplicate. - $ids = array(); - if( isset($_GET['acfduplicate']) ) { - $ids[] = intval( $_GET['acfduplicate'] ); - } elseif( isset($_GET['post'], $_GET['action2']) && $_GET['action2'] === 'acfduplicate' ) { - $ids = array_map( 'intval', $_GET['post'] ); - } - - if( $ids ) { - check_admin_referer('bulk-posts'); - - // Duplicate field groups and generate array of new IDs. - $new_ids = array(); - foreach( $ids as $id ) { - $field_group = acf_duplicate_field_group( $id ); - $new_ids[] = $field_group['ID']; - } - - // Redirect. - wp_redirect( $this->get_admin_url( '&acfduplicatecomplete=' . implode(',', $new_ids) ) ); - exit; - } - } - - /** - * Checks for the custom "acfsync" action. - * - * @date 15/4/20 - * @since 5.9.0 - * - * @param void - * @return void - */ - public function check_sync() { - - // Display notice on success redirect. - if( isset($_GET['acfsynccomplete']) ) { - $ids = array_map( 'intval', explode(',', $_GET['acfsynccomplete']) ); - - // Generate text. - $text = sprintf( - _n( 'Field group synchronised.', '%s field groups synchronised.', count($ids), 'acf' ), - count($ids) - ); - - // Append links to text. - $links = array(); - foreach( $ids as $id ) { - $links[] = '' . get_the_title( $id ) . ''; - } - $text .= ' ' . implode( ', ', $links ); - - // Add notice. - acf_add_admin_notice( $text, 'success' ); - return; - } - - // Find items to sync. - $keys = array(); - if( isset($_GET['acfsync']) ) { - $keys[] = sanitize_text_field( $_GET['acfsync'] ); - } elseif( isset($_GET['post'], $_GET['action2']) && $_GET['action2'] === 'acfsync' ) { - $keys = array_map( 'sanitize_text_field', $_GET['post'] ); - } - - if( $keys && $this->sync ) { - check_admin_referer('bulk-posts'); - - // Disabled "Local JSON" controller to prevent the .json file from being modified during import. - acf_update_setting( 'json', false ); - - // Sync field groups and generate array of new IDs. - $files = acf_get_local_json_files(); - $new_ids = array(); - foreach( $this->sync as $key => $field_group ) { - if( $field_group['key'] && in_array($field_group['key'], $keys) ) { - // Import. - } elseif( $field_group['ID'] && in_array($field_group['ID'], $keys) ) { - // Import. + + /** + * Displays the local JSON status of a field group. + * + * @date 14/4/20 + * @since 5.9.0 + * + * @param type $var Description. Default. + * @return type Description. + */ + public function render_admin_table_column_local_status( $field_group ) { + $json = acf_get_local_json_files(); + if ( isset( $json[ $field_group['key'] ] ) ) { + $file = $json[ $field_group['key'] ]; + if ( isset( $this->sync[ $field_group['key'] ] ) ) { + $url = $this->get_admin_url( '&acfsync=' . $field_group['key'] . '&_wpnonce=' . wp_create_nonce( 'bulk-posts' ) ); + echo '' . __( 'Sync available', 'acf' ) . ''; + if ( $field_group['ID'] ) { + echo ''; + } else { + echo ''; + } } else { - // Ignore. - continue; + echo __( 'Saved', 'acf' ); } - $local_field_group = json_decode( file_get_contents( $files[ $key ] ), true ); - $local_field_group['ID'] = $field_group['ID']; - $result = acf_import_field_group( $local_field_group ); - $new_ids[] = $result['ID']; + } else { + echo '' . __( 'Awaiting save', 'acf' ) . ''; } - - // Redirect. - wp_redirect( $this->get_current_admin_url( '&acfsynccomplete=' . implode(',', $new_ids) ) ); - exit; } - } - - /** - * Customizes the admin table subnav. - * - * @date 17/4/20 - * @since 5.9.0 - * - * @param array $views The available views. - * @return array - */ - public function admin_table_views( $views ) { - global $wp_list_table, $wp_query; - - // Count items. - $count = count( $this->sync ); - - // Append "sync" link to subnav. - if( $count ) { - $views['sync'] = sprintf( - '%s (%s)', - ( $this->view === 'sync' ? 'class="current"' : '' ), - esc_url( $this->get_admin_url( '&post_status=sync' ) ), - esc_html( __('Sync available', 'acf') ), - $count - ); + + /** + * Customizes the page row actions visible on hover. + * + * @date 14/4/20 + * @since 5.9.0 + * + * @param array $actions The array of actions HTML. + * @param WP_Post $post The post. + * @return array + */ + public function page_row_actions( $actions, $post ) { + + // Remove "Quick Edit" action. + unset( $actions['inline'], $actions['inline hide-if-no-js'] ); + + // Append "Duplicate" action. + $duplicate_action_url = $this->get_admin_url( '&acfduplicate=' . $post->ID . '&_wpnonce=' . wp_create_nonce( 'bulk-posts' ) ); + $actions['acfduplicate'] = '' . __( 'Duplicate', 'acf' ) . ''; + + // Return actions in custom order. + $order = array( 'edit', 'acfduplicate', 'trash' ); + return array_merge( array_flip( $order ), $actions ); } - - // Modify table pagination args to match JSON data. - if( $this->view === 'sync' ) { - $wp_list_table->set_pagination_args( array( - 'total_items' => $count, - 'total_pages' => 1, - 'per_page' => $count - )); - $wp_query->post_count = 1; // At least one post is needed to render bulk drop-down. + + /** + * Modifies the admin table bulk actions dropdown. + * + * @date 15/4/20 + * @since 5.9.0 + * + * @param array $actions The actions array. + * @return array + */ + public function admin_table_bulk_actions( $actions ) { + + // Add "duplicate" action. + if ( $this->view !== 'sync' ) { + $actions['acfduplicate'] = __( 'Duplicate', 'acf' ); + } + + // Add "Sync" action. + if ( $this->sync ) { + if ( $this->view === 'sync' ) { + $actions = array(); + } + $actions['acfsync'] = __( 'Sync changes', 'acf' ); + } + return $actions; } - return $views; - } - - /** - * Prints scripts into the admin footer. - * - * @date 20/4/20 - * @since 5.9.0 - * - * @param void - * @return void - */ - function admin_footer() { - ?> + + /** + * Checks for the custom "duplicate" action. + * + * @date 15/4/20 + * @since 5.9.0 + * + * @param void + * @return void + */ + public function check_duplicate() { + + // Display notice on success redirect. + if ( isset( $_GET['acfduplicatecomplete'] ) ) { + $ids = array_map( 'intval', explode( ',', $_GET['acfduplicatecomplete'] ) ); + + // Generate text. + $text = sprintf( + _n( 'Field group duplicated.', '%s field groups duplicated.', count( $ids ), 'acf' ), + count( $ids ) + ); + + // Append links to text. + $links = array(); + foreach ( $ids as $id ) { + $links[] = '' . get_the_title( $id ) . ''; + } + $text .= ' ' . implode( ', ', $links ); + + // Add notice. + acf_add_admin_notice( $text, 'success' ); + return; + } + + // Find items to duplicate. + $ids = array(); + if ( isset( $_GET['acfduplicate'] ) ) { + $ids[] = intval( $_GET['acfduplicate'] ); + } elseif ( isset( $_GET['post'], $_GET['action2'] ) && $_GET['action2'] === 'acfduplicate' ) { + $ids = array_map( 'intval', $_GET['post'] ); + } + + if ( $ids ) { + check_admin_referer( 'bulk-posts' ); + + // Duplicate field groups and generate array of new IDs. + $new_ids = array(); + foreach ( $ids as $id ) { + $field_group = acf_duplicate_field_group( $id ); + $new_ids[] = $field_group['ID']; + } + + // Redirect. + wp_redirect( $this->get_admin_url( '&acfduplicatecomplete=' . implode( ',', $new_ids ) ) ); + exit; + } + } + + /** + * Checks for the custom "acfsync" action. + * + * @date 15/4/20 + * @since 5.9.0 + * + * @param void + * @return void + */ + public function check_sync() { + + // Display notice on success redirect. + if ( isset( $_GET['acfsynccomplete'] ) ) { + $ids = array_map( 'intval', explode( ',', $_GET['acfsynccomplete'] ) ); + + // Generate text. + $text = sprintf( + _n( 'Field group synchronised.', '%s field groups synchronised.', count( $ids ), 'acf' ), + count( $ids ) + ); + + // Append links to text. + $links = array(); + foreach ( $ids as $id ) { + $links[] = '' . get_the_title( $id ) . ''; + } + $text .= ' ' . implode( ', ', $links ); + + // Add notice. + acf_add_admin_notice( $text, 'success' ); + return; + } + + // Find items to sync. + $keys = array(); + if ( isset( $_GET['acfsync'] ) ) { + $keys[] = sanitize_text_field( $_GET['acfsync'] ); + } elseif ( isset( $_GET['post'], $_GET['action2'] ) && $_GET['action2'] === 'acfsync' ) { + $keys = array_map( 'sanitize_text_field', $_GET['post'] ); + } + + if ( $keys && $this->sync ) { + check_admin_referer( 'bulk-posts' ); + + // Disabled "Local JSON" controller to prevent the .json file from being modified during import. + acf_update_setting( 'json', false ); + + // Sync field groups and generate array of new IDs. + $files = acf_get_local_json_files(); + $new_ids = array(); + foreach ( $this->sync as $key => $field_group ) { + if ( $field_group['key'] && in_array( $field_group['key'], $keys ) ) { + // Import. + } elseif ( $field_group['ID'] && in_array( $field_group['ID'], $keys ) ) { + // Import. + } else { + // Ignore. + continue; + } + $local_field_group = json_decode( file_get_contents( $files[ $key ] ), true ); + $local_field_group['ID'] = $field_group['ID']; + $result = acf_import_field_group( $local_field_group ); + $new_ids[] = $result['ID']; + } + + // Redirect. + wp_redirect( $this->get_current_admin_url( '&acfsynccomplete=' . implode( ',', $new_ids ) ) ); + exit; + } + } + + /** + * Customizes the admin table subnav. + * + * @date 17/4/20 + * @since 5.9.0 + * + * @param array $views The available views. + * @return array + */ + public function admin_table_views( $views ) { + global $wp_list_table, $wp_query; + + // Count items. + $count = count( $this->sync ); + + // Append "sync" link to subnav. + if ( $count ) { + $views['sync'] = sprintf( + '%s (%s)', + ( $this->view === 'sync' ? 'class="current"' : '' ), + esc_url( $this->get_admin_url( '&post_status=sync' ) ), + esc_html( __( 'Sync available', 'acf' ) ), + $count + ); + } + + // Modify table pagination args to match JSON data. + if ( $this->view === 'sync' ) { + $wp_list_table->set_pagination_args( + array( + 'total_items' => $count, + 'total_pages' => 1, + 'per_page' => $count, + ) + ); + $wp_query->post_count = 1; // At least one post is needed to render bulk drop-down. + } + return $views; + } + + /** + * Prints scripts into the admin footer. + * + * @date 20/4/20 + * @since 5.9.0 + * + * @param void + * @return void + */ + function admin_footer() { + ?> - get_columns(); - $hidden = get_hidden_columns( $wp_list_table->screen ); - ?> + get_columns(); + $hidden = get_hidden_columns( $wp_list_table->screen ); + ?>
                - sync as $k => $field_group ) { - echo ''; - foreach( $columns as $column_name => $column_label ) { - $el = 'td'; - if( $column_name === 'cb' ) { - $el = 'th'; - $classes = 'check-column'; - $column_label = ''; - } elseif( $column_name === 'title' ) { - $classes = "$column_name column-$column_name column-primary"; - } else { - $classes = "$column_name column-$column_name"; - } - if( in_array( $column_name, $hidden, true ) ) { - $classes .= ' hidden'; - } - echo "<$el class=\"$classes\" data-colname=\"$column_label\">"; - switch ( $column_name ) { - - // Checkbox. - case 'cb': - echo ''; - echo ''; - break; - - // Title. - case 'title': - $post_state = ''; - if( !$field_group['active'] ) { - $post_state = ' — ' . $this->get_disabled_post_state() . ''; + sync as $k => $field_group ) { + echo ''; + foreach ( $columns as $column_name => $column_label ) { + $el = 'td'; + if ( $column_name === 'cb' ) { + $el = 'th'; + $classes = 'check-column'; + $column_label = ''; + } elseif ( $column_name === 'title' ) { + $classes = "$column_name column-$column_name column-primary"; + } else { + $classes = "$column_name column-$column_name"; } - echo '' . esc_html( $field_group['title']) . '' . $post_state . ''; - echo '
                ' . $this->get_human_readable_file_location( $field_group['local_file'] ) . '
                '; - echo ''; - break; - - // All other columns. - default: - $this->render_admin_table_column( $column_name, $field_group ); - break; + if ( in_array( $column_name, $hidden, true ) ) { + $classes .= ' hidden'; + } + echo "<$el class=\"$classes\" data-colname=\"$column_label\">"; + switch ( $column_name ) { + + // Checkbox. + case 'cb': + echo ''; + echo ''; + break; + + // Title. + case 'title': + $post_state = ''; + if ( ! $field_group['active'] ) { + $post_state = ' — ' . $this->get_disabled_post_state() . ''; + } + echo '' . esc_html( $field_group['title'] ) . '' . $post_state . ''; + echo '
                ' . $this->get_human_readable_file_location( $field_group['local_file'] ) . '
                '; + echo ''; + break; + + // All other columns. + default: + $this->render_admin_table_column( $column_name, $field_group ); + break; + } + echo ""; + } + echo ''; } - echo ""; - } - echo ''; - } - ?> + ?>
                @@ -824,56 +830,56 @@ class ACF_Admin_Field_Groups { $('#the-list').html( $('#acf-the-list').children() ); })(jQuery); - '', - - /** @type string The type of notice (warning, error, success, info). */ - 'type' => 'info', - - /** @type bool If the notice can be dismissed. */ - 'dismissible' => true, - ); - - /** - * render - * - * Renders the notice HTML. - * - * @date 27/12/18 - * @since 5.8.0 - * - * @param void - * @return void - */ - function render() { - $notice_text = $this->get('text'); - $notice_type = $this->get('type'); - $is_dismissible = $this->get('dismissible'); - - printf('
                %s
                ', - esc_attr( $notice_type ), - $is_dismissible ? 'is-dismissible' : '', - acf_esc_html( wpautop( acf_punctify( $notice_text ) ) ) + class ACF_Admin_Notice extends ACF_Data { + + /** @var array Storage for data. */ + var $data = array( + + /** @type string Text displayed in notice. */ + 'text' => '', + + /** @type string The type of notice (warning, error, success, info). */ + 'type' => 'info', + + /** @type bool If the notice can be dismissed. */ + 'dismissible' => true, ); + + /** + * render + * + * Renders the notice HTML. + * + * @date 27/12/18 + * @since 5.8.0 + * + * @param void + * @return void + */ + function render() { + $notice_text = $this->get( 'text' ); + $notice_type = $this->get( 'type' ); + $is_dismissible = $this->get( 'dismissible' ); + + printf( + '
                %s
                ', + esc_attr( $notice_type ), + $is_dismissible ? 'is-dismissible' : '', + acf_esc_html( wpautop( acf_punctify( $notice_text ) ) ) + ); + } } -} endif; // class_exists check /** -* acf_new_admin_notice -* -* Instantiates and returns a new model. -* -* @date 23/12/18 -* @since 5.8.0 -* -* @param array $data Optional data to set. -* @return ACF_Admin_Notice -*/ + * acf_new_admin_notice + * + * Instantiates and returns a new model. + * + * @date 23/12/18 + * @since 5.8.0 + * + * @param array $data Optional data to set. + * @return ACF_Admin_Notice + */ function acf_new_admin_notice( $data = false ) { - + // Create notice. $instance = new ACF_Admin_Notice( $data ); - + // Register notice. acf_get_store( 'notices' )->set( $instance->cid, $instance ); - + // Return notice. return $instance; } @@ -93,40 +96,45 @@ function acf_new_admin_notice( $data = false ) { * * Renders all admin notices HTML. * - * @date 10/1/19 - * @since 5.7.10 + * @date 10/1/19 + * @since 5.7.10 * - * @param void - * @return void + * @param void + * @return void */ function acf_render_admin_notices() { - + // Get notices. $notices = acf_get_store( 'notices' )->get_data(); - + // Loop over notices and render. - if( $notices ) { - foreach( $notices as $notice ) { + if ( $notices ) { + foreach ( $notices as $notice ) { $notice->render(); } } } // Render notices during admin action. -add_action('admin_notices', 'acf_render_admin_notices', 99); +add_action( 'admin_notices', 'acf_render_admin_notices', 99 ); /** * acf_add_admin_notice * * Creates and returns a new notice. * - * @date 17/10/13 - * @since 5.0.0 + * @date 17/10/13 + * @since 5.0.0 * - * @param string $text The admin notice text. - * @param string $class The type of notice (warning, error, success, info). - * @return ACF_Admin_Notice + * @param string $text The admin notice text. + * @param string $class The type of notice (warning, error, success, info). + * @return ACF_Admin_Notice */ function acf_add_admin_notice( $text = '', $type = 'info' ) { - return acf_new_admin_notice( array( 'text' => $text, 'type' => $type ) ); -} \ No newline at end of file + return acf_new_admin_notice( + array( + 'text' => $text, + 'type' => $type, + ) + ); +} diff --git a/includes/admin/admin-tools.php b/includes/admin/admin-tools.php index 5462b89..2fe04ba 100644 --- a/includes/admin/admin-tools.php +++ b/includes/admin/admin-tools.php @@ -1,291 +1,285 @@ -tools[ $instance->name ] = $instance; - - } - - - /** - * get_tool - * - * This function will return a tool tool class - * - * @date 10/10/17 - * @since 5.6.3 - * - * @param string $name - * @return n/a - */ - - function get_tool( $name ) { - - return isset( $this->tools[$name] ) ? $this->tools[$name] : null; - - } - - - /** - * get_tools - * - * This function will return an array of all tools - * - * @date 10/10/17 - * @since 5.6.3 - * - * @param n/a - * @return array - */ - - function get_tools() { - - return $this->tools; - - } - - - /* - * admin_menu - * - * This function will add the ACF menu item to the WP admin - * - * @type action (admin_menu) - * @date 28/09/13 - * @since 5.0.0 - * - * @param n/a - * @return n/a - */ - - function admin_menu() { - - // bail early if no show_admin - if( !acf_get_setting('show_admin') ) return; - - - // add page - $page = add_submenu_page('edit.php?post_type=acf-field-group', __('Tools','acf'), __('Tools','acf'), acf_get_setting('capability'), 'acf-tools', array($this, 'html')); - - - // actions - add_action('load-' . $page, array($this, 'load')); - - } - - - /** - * load - * - * description - * - * @date 10/10/17 - * @since 5.6.3 - * - * @param n/a - * @return n/a - */ - - function load() { - - // disable filters (default to raw data) - acf_disable_filters(); - - - // include tools - $this->include_tools(); - - - // check submit - $this->check_submit(); - - - // load acf scripts - acf_enqueue_scripts(); - - } - - - /** - * include_tools - * - * description - * - * @date 10/10/17 - * @since 5.6.3 - * - * @param n/a - * @return n/a - */ - - function include_tools() { - - // include - acf_include('includes/admin/tools/class-acf-admin-tool.php'); - acf_include('includes/admin/tools/class-acf-admin-tool-export.php'); - acf_include('includes/admin/tools/class-acf-admin-tool-import.php'); - - - // action - do_action('acf/include_admin_tools'); - - } - - - /** - * check_submit - * - * description - * - * @date 10/10/17 - * @since 5.6.3 - * - * @param n/a - * @return n/a - */ - - function check_submit() { - - // loop - foreach( $this->get_tools() as $tool ) { - - // load - $tool->load(); - - - // submit - if( acf_verify_nonce($tool->name) ) { - $tool->submit(); + class acf_admin_tools { + + + /** @var array Contains an array of admin tool instances */ + var $tools = array(); + + + /** @var string The active tool */ + var $active = ''; + + + /** + * __construct + * + * This function will setup the class functionality + * + * @date 10/10/17 + * @since 5.6.3 + * + * @param n/a + * @return n/a + */ + + function __construct() { + + // actions + add_action( 'admin_menu', array( $this, 'admin_menu' ) ); + + } + + + /** + * register_tool + * + * This function will store a tool tool class + * + * @date 10/10/17 + * @since 5.6.3 + * + * @param string $class + * @return n/a + */ + + function register_tool( $class ) { + + $instance = new $class(); + $this->tools[ $instance->name ] = $instance; + + } + + + /** + * get_tool + * + * This function will return a tool tool class + * + * @date 10/10/17 + * @since 5.6.3 + * + * @param string $name + * @return n/a + */ + + function get_tool( $name ) { + + return isset( $this->tools[ $name ] ) ? $this->tools[ $name ] : null; + + } + + + /** + * get_tools + * + * This function will return an array of all tools + * + * @date 10/10/17 + * @since 5.6.3 + * + * @param n/a + * @return array + */ + + function get_tools() { + + return $this->tools; + + } + + + /* + * admin_menu + * + * This function will add the ACF menu item to the WP admin + * + * @type action (admin_menu) + * @date 28/09/13 + * @since 5.0.0 + * + * @param n/a + * @return n/a + */ + + function admin_menu() { + + // bail early if no show_admin + if ( ! acf_get_setting( 'show_admin' ) ) { + return; } - + + // add page + $page = add_submenu_page( 'edit.php?post_type=acf-field-group', __( 'Tools', 'acf' ), __( 'Tools', 'acf' ), acf_get_setting( 'capability' ), 'acf-tools', array( $this, 'html' ) ); + + // actions + add_action( 'load-' . $page, array( $this, 'load' ) ); + } - - } - - - /** - * html - * - * description - * - * @date 10/10/17 - * @since 5.6.3 - * - * @param n/a - * @return n/a - */ - - function html() { - - // vars - $screen = get_current_screen(); - $active = acf_maybe_get_GET('tool'); - - - // view - $view = array( - 'screen_id' => $screen->id, - 'active' => $active - ); - - - // register metaboxes - foreach( $this->get_tools() as $tool ) { - - // check active - if( $active && $active !== $tool->name ) continue; - - // add metabox - add_meta_box( 'acf-admin-tool-' . $tool->name, acf_esc_html( $tool->title ), array($this, 'metabox_html'), $screen->id, 'normal', 'default', array('tool' => $tool->name) ); - + + + /** + * load + * + * description + * + * @date 10/10/17 + * @since 5.6.3 + * + * @param n/a + * @return n/a + */ + + function load() { + + // disable filters (default to raw data) + acf_disable_filters(); + + // include tools + $this->include_tools(); + + // check submit + $this->check_submit(); + + // load acf scripts + acf_enqueue_scripts(); + } - - - // view - acf_get_view( 'html-admin-tools', $view ); - - } - - - /** - * meta_box_html - * - * description - * - * @date 10/10/17 - * @since 5.6.3 - * - * @param n/a - * @return n/a - */ - - function metabox_html( $post, $metabox ) { - - // vars - $tool = $this->get_tool($metabox['args']['tool']); - - - ?> + + + /** + * include_tools + * + * description + * + * @date 10/10/17 + * @since 5.6.3 + * + * @param n/a + * @return n/a + */ + + function include_tools() { + + // include + acf_include( 'includes/admin/tools/class-acf-admin-tool.php' ); + acf_include( 'includes/admin/tools/class-acf-admin-tool-export.php' ); + acf_include( 'includes/admin/tools/class-acf-admin-tool-import.php' ); + + // action + do_action( 'acf/include_admin_tools' ); + + } + + + /** + * check_submit + * + * description + * + * @date 10/10/17 + * @since 5.6.3 + * + * @param n/a + * @return n/a + */ + + function check_submit() { + + // loop + foreach ( $this->get_tools() as $tool ) { + + // load + $tool->load(); + + // submit + if ( acf_verify_nonce( $tool->name ) ) { + $tool->submit(); + } + } + + } + + + /** + * html + * + * description + * + * @date 10/10/17 + * @since 5.6.3 + * + * @param n/a + * @return n/a + */ + + function html() { + + // vars + $screen = get_current_screen(); + $active = acf_maybe_get_GET( 'tool' ); + + // view + $view = array( + 'screen_id' => $screen->id, + 'active' => $active, + ); + + // register metaboxes + foreach ( $this->get_tools() as $tool ) { + + // check active + if ( $active && $active !== $tool->name ) { + continue; + } + + // add metabox + add_meta_box( 'acf-admin-tool-' . $tool->name, acf_esc_html( $tool->title ), array( $this, 'metabox_html' ), $screen->id, 'normal', 'default', array( 'tool' => $tool->name ) ); + + } + + // view + acf_get_view( 'html-admin-tools', $view ); + + } + + + /** + * meta_box_html + * + * description + * + * @date 10/10/17 + * @since 5.6.3 + * + * @param n/a + * @return n/a + */ + + function metabox_html( $post, $metabox ) { + + // vars + $tool = $this->get_tool( $metabox['args']['tool'] ); + + ?>
                html(); ?> name ); ?>
                - admin_tools = new acf_admin_tools(); + } + + } + + // initialize + acf()->admin_tools = new acf_admin_tools(); endif; // class_exists check @@ -295,18 +289,18 @@ endif; // class_exists check * * alias of acf()->admin_tools->register_tool() * -* @type function -* @date 31/5/17 -* @since 5.6.0 +* @type function +* @date 31/5/17 +* @since 5.6.0 * -* @param n/a -* @return n/a +* @param n/a +* @return n/a */ function acf_register_admin_tool( $class ) { - + return acf()->admin_tools->register_tool( $class ); - + } @@ -315,18 +309,18 @@ function acf_register_admin_tool( $class ) { * * This function will return the admin URL to the tools page * -* @type function -* @date 31/5/17 -* @since 5.6.0 +* @type function +* @date 31/5/17 +* @since 5.6.0 * -* @param n/a -* @return n/a +* @param n/a +* @return n/a */ function acf_get_admin_tools_url() { - - return admin_url('edit.php?post_type=acf-field-group&page=acf-tools'); - + + return admin_url( 'edit.php?post_type=acf-field-group&page=acf-tools' ); + } @@ -335,19 +329,19 @@ function acf_get_admin_tools_url() { * * This function will return the admin URL to the tools page * -* @type function -* @date 31/5/17 -* @since 5.6.0 +* @type function +* @date 31/5/17 +* @since 5.6.0 * -* @param n/a -* @return n/a +* @param n/a +* @return n/a */ function acf_get_admin_tool_url( $tool = '' ) { - - return acf_get_admin_tools_url() . '&tool='.$tool; - + + return acf_get_admin_tools_url() . '&tool=' . $tool; + } -?> \ No newline at end of file +?> diff --git a/includes/admin/admin-upgrade.php b/includes/admin/admin-upgrade.php index e3275cb..fde6349 100644 --- a/includes/admin/admin-upgrade.php +++ b/includes/admin/admin-upgrade.php @@ -1,244 +1,246 @@ - 0 ) ); - if( $sites ) { - - // Unhook action to avoid memory issue (as seen in wp-includes/ms-site.php). - remove_action( 'switch_blog', 'wp_switch_roles_and_user', 1 ); - foreach( $sites as $site ) { - - // Switch site. - switch_to_blog( $site->blog_id ); - - // Check for upgrade. - $site_upgrade = acf_has_upgrade(); - - // Restore site. - // Ideally, we would switch back to the original site at after looping, however, - // the restore_current_blog() is needed to modify global vars. - restore_current_blog(); - - // Check if upgrade was found. - if( $site_upgrade ) { - $upgrade = true; - break; - } - } - add_action( 'switch_blog', 'wp_switch_roles_and_user', 1, 2 ); - } - - // Bail early if no upgrade is needed. - if( !$upgrade ) { - return; - } - - // Add notice. - add_action('network_admin_notices', array($this, 'network_admin_notices')); - - // Add page. - $page = add_submenu_page( - 'index.php', - __('Upgrade Database','acf'), - __('Upgrade Database','acf'), - acf_get_setting('capability'), - 'acf-upgrade-network', - array( $this,'network_admin_html' ) - ); - add_action( "load-$page", array( $this, 'network_admin_load' ) ); - } - - /** - * admin_load - * - * Runs during the loading of the admin page. - * - * @date 24/8/18 - * @since 5.7.4 - * - * @param type $var Description. Default. - * @return type Description. - */ - function admin_load() { - - // remove prompt - remove_action('admin_notices', array($this, 'admin_notices')); - - // Enqueue core script. - acf_enqueue_script( 'acf' ); - } - - /** - * network_admin_load - * - * Runs during the loading of the network admin page. - * - * @date 24/8/18 - * @since 5.7.4 - * - * @param type $var Description. Default. - * @return type Description. - */ - function network_admin_load() { - - // remove prompt - remove_action('network_admin_notices', array($this, 'network_admin_notices')); - - // Enqueue core script. - acf_enqueue_script( 'acf' ); - } - - /** - * admin_notices - * - * Displays the DB Upgrade prompt. - * - * @date 23/8/18 - * @since 5.7.3 - * - * @param void - * @return void - */ - function admin_notices() { - - // vars - $view = array( - 'button_text' => __("Upgrade Database", 'acf'), - 'button_url' => admin_url('index.php?page=acf-upgrade'), - 'confirm' => true - ); - - // view - acf_get_view('html-notice-upgrade', $view); - } - - /** - * network_admin_notices - * - * Displays the DB Upgrade prompt on a multi site. - * - * @date 23/8/18 - * @since 5.7.3 - * - * @param void - * @return void - */ - function network_admin_notices() { - - // vars - $view = array( - 'button_text' => __("Review sites & upgrade", 'acf'), - 'button_url' => network_admin_url('index.php?page=acf-upgrade-network'), - 'confirm' => false - ); - - // view - acf_get_view('html-notice-upgrade', $view); - } - - /** - * admin_html - * - * Displays the HTML for the admin page. - * - * @date 24/8/18 - * @since 5.7.4 - * - * @param void - * @return void - */ - function admin_html() { - acf_get_view('html-admin-page-upgrade'); - } - - /** - * network_admin_html - * - * Displays the HTML for the network upgrade admin page. - * - * @date 24/8/18 - * @since 5.7.4 - * - * @param void - * @return void - */ - function network_admin_html() { - acf_get_view('html-admin-page-upgrade-network'); - } +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly } -// instantiate -acf_new_instance('ACF_Admin_Upgrade'); +if ( ! class_exists( 'ACF_Admin_Upgrade' ) ) : + + class ACF_Admin_Upgrade { + + /** + * __construct + * + * Sets up the class functionality. + * + * @date 31/7/18 + * @since 5.7.2 + * + * @param void + * @return void + */ + function __construct() { + + // actions + add_action( 'admin_menu', array( $this, 'admin_menu' ), 20 ); + if ( is_multisite() ) { + add_action( 'network_admin_menu', array( $this, 'network_admin_menu' ), 20 ); + } + } + + /** + * admin_menu + * + * Setus up logic if DB Upgrade is needed on a single site. + * + * @date 24/8/18 + * @since 5.7.4 + * + * @param void + * @return void + */ + function admin_menu() { + + // check if upgrade is avaialble + if ( acf_has_upgrade() ) { + + // add notice + add_action( 'admin_notices', array( $this, 'admin_notices' ) ); + + // add page + $page = add_submenu_page( 'index.php', __( 'Upgrade Database', 'acf' ), __( 'Upgrade Database', 'acf' ), acf_get_setting( 'capability' ), 'acf-upgrade', array( $this, 'admin_html' ) ); + + // actions + add_action( 'load-' . $page, array( $this, 'admin_load' ) ); + } + } + + /** + * network_admin_menu + * + * Sets up admin logic if DB Upgrade is required on a multi site. + * + * @date 24/8/18 + * @since 5.7.4 + * + * @param void + * @return void + */ + function network_admin_menu() { + + // Vars. + $upgrade = false; + + // Loop over sites and check for upgrades. + $sites = get_sites( array( 'number' => 0 ) ); + if ( $sites ) { + + // Unhook action to avoid memory issue (as seen in wp-includes/ms-site.php). + remove_action( 'switch_blog', 'wp_switch_roles_and_user', 1 ); + foreach ( $sites as $site ) { + + // Switch site. + switch_to_blog( $site->blog_id ); + + // Check for upgrade. + $site_upgrade = acf_has_upgrade(); + + // Restore site. + // Ideally, we would switch back to the original site at after looping, however, + // the restore_current_blog() is needed to modify global vars. + restore_current_blog(); + + // Check if upgrade was found. + if ( $site_upgrade ) { + $upgrade = true; + break; + } + } + add_action( 'switch_blog', 'wp_switch_roles_and_user', 1, 2 ); + } + + // Bail early if no upgrade is needed. + if ( ! $upgrade ) { + return; + } + + // Add notice. + add_action( 'network_admin_notices', array( $this, 'network_admin_notices' ) ); + + // Add page. + $page = add_submenu_page( + 'index.php', + __( 'Upgrade Database', 'acf' ), + __( 'Upgrade Database', 'acf' ), + acf_get_setting( 'capability' ), + 'acf-upgrade-network', + array( $this, 'network_admin_html' ) + ); + add_action( "load-$page", array( $this, 'network_admin_load' ) ); + } + + /** + * admin_load + * + * Runs during the loading of the admin page. + * + * @date 24/8/18 + * @since 5.7.4 + * + * @param type $var Description. Default. + * @return type Description. + */ + function admin_load() { + + // remove prompt + remove_action( 'admin_notices', array( $this, 'admin_notices' ) ); + + // Enqueue core script. + acf_enqueue_script( 'acf' ); + } + + /** + * network_admin_load + * + * Runs during the loading of the network admin page. + * + * @date 24/8/18 + * @since 5.7.4 + * + * @param type $var Description. Default. + * @return type Description. + */ + function network_admin_load() { + + // remove prompt + remove_action( 'network_admin_notices', array( $this, 'network_admin_notices' ) ); + + // Enqueue core script. + acf_enqueue_script( 'acf' ); + } + + /** + * admin_notices + * + * Displays the DB Upgrade prompt. + * + * @date 23/8/18 + * @since 5.7.3 + * + * @param void + * @return void + */ + function admin_notices() { + + // vars + $view = array( + 'button_text' => __( 'Upgrade Database', 'acf' ), + 'button_url' => admin_url( 'index.php?page=acf-upgrade' ), + 'confirm' => true, + ); + + // view + acf_get_view( 'html-notice-upgrade', $view ); + } + + /** + * network_admin_notices + * + * Displays the DB Upgrade prompt on a multi site. + * + * @date 23/8/18 + * @since 5.7.3 + * + * @param void + * @return void + */ + function network_admin_notices() { + + // vars + $view = array( + 'button_text' => __( 'Review sites & upgrade', 'acf' ), + 'button_url' => network_admin_url( 'index.php?page=acf-upgrade-network' ), + 'confirm' => false, + ); + + // view + acf_get_view( 'html-notice-upgrade', $view ); + } + + /** + * admin_html + * + * Displays the HTML for the admin page. + * + * @date 24/8/18 + * @since 5.7.4 + * + * @param void + * @return void + */ + function admin_html() { + acf_get_view( 'html-admin-page-upgrade' ); + } + + /** + * network_admin_html + * + * Displays the HTML for the network upgrade admin page. + * + * @date 24/8/18 + * @since 5.7.4 + * + * @param void + * @return void + */ + function network_admin_html() { + acf_get_view( 'html-admin-page-upgrade-network' ); + } + } + + // instantiate + acf_new_instance( 'ACF_Admin_Upgrade' ); endif; // class_exists check -?> \ No newline at end of file + diff --git a/includes/admin/admin.php b/includes/admin/admin.php index d27d175..8af062b 100644 --- a/includes/admin/admin.php +++ b/includes/admin/admin.php @@ -1,207 +1,209 @@ -= 5.3 ) { - $classes .= ' acf-admin-5-3'; - } else { - $classes .= ' acf-admin-3-8'; - } - - // Add browser for specific CSS. - $classes .= ' acf-browser-' . acf_get_browser(); - - // Return classes. - return $classes; - } - - /** - * Adds custom functionality to "ACF" admin pages. - * - * @date 7/4/20 - * @since 5.9.0 - * - * @param void - * @return void - */ - function current_screen( $screen ) { - - // Determine if the current page being viewed is "ACF" related. - if( isset( $screen->post_type ) && $screen->post_type === 'acf-field-group' ) { - add_action( 'in_admin_header', array( $this, 'in_admin_header' ) ); - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); - $this->setup_help_tab(); - } - } - - /** - * Sets up the admin help tab. - * - * @date 20/4/20 - * @since 5.9.0 - * - * @param void - * @return void - */ - public function setup_help_tab() { - $screen = get_current_screen(); - - // Overview tab. - $screen->add_help_tab( - array( - 'id' => 'overview', - 'title' => __( 'Overview', 'acf' ), - 'content' => - '

                ' . __( 'Overview', 'acf' ) . '

                ' . - '

                ' . __( 'The Advanced Custom Fields plugin provides a visual form builder to customize WordPress edit screens with extra fields, and an intuitive API to display custom field values in any theme template file.', 'acf' ) . '

                ' . - '

                ' . sprintf( - __( 'Before creating your first Field Group, we recommend first reading our Getting started guide to familiarize yourself with the plugin\'s philosophy and best practises.', 'acf' ), - 'https://www.advancedcustomfields.com/resources/getting-started-with-acf/' - ) . '

                ' . - '

                ' . __( 'Please use the Help & Support tab to get in touch should you find yourself requiring assistance.', 'acf' ) . '

                ' . - '' - ) - ); - - // Help tab. - $screen->add_help_tab( - array( - 'id' => 'help', - 'title' => __( 'Help & Support', 'acf' ), - 'content' => - '

                ' . __( 'Help & Support', 'acf' ) . '

                ' . - '

                ' . __( 'We are fanatical about support, and want you to get the best out of your website with ACF. If you run into any difficulties, there are several places you can find help:', 'acf' ) . '

                ' . - '' - ) - ); - - // Sidebar. - $screen->set_help_sidebar( - '

                ' . __( 'Information', 'acf' ) . '

                ' . - '

                ' . sprintf( __( 'Version %s', 'acf' ), ACF_VERSION ) . '

                ' . - '

                ' . __( 'View details', 'acf' ) . '

                ' . - '

                ' . __( 'Visit website', 'acf' ) . '

                ' . - '' - ); - } - - /** - * Renders the admin navigation element. - * - * @date 27/3/20 - * @since 5.9.0 - * - * @param void - * @return void - */ - function in_admin_header() { - acf_get_view( 'html-admin-navigation' ); - } - - /** - * Modifies the admin footer text. - * - * @date 7/4/20 - * @since 5.9.0 - * - * @param string $text The admin footer text. - * @return string - */ - function admin_footer_text( $text ) { - // Use RegExp to append "ACF" after the element allowing translations to read correctly. - return preg_replace( '/()/', '$1 ' . __('and', 'acf') . ' ACF', $text, 1 ); - } +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly } -// Instantiate. -acf_new_instance('ACF_Admin'); +if ( ! class_exists( 'ACF_Admin' ) ) : + + class ACF_Admin { + + /** + * Constructor. + * + * @date 23/06/12 + * @since 5.0.0 + * + * @param void + * @return void + */ + function __construct() { + + // Add actions. + add_action( 'admin_menu', array( $this, 'admin_menu' ) ); + add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); + add_action( 'admin_body_class', array( $this, 'admin_body_class' ) ); + add_action( 'current_screen', array( $this, 'current_screen' ) ); + } + + /** + * Adds the ACF menu item. + * + * @date 28/09/13 + * @since 5.0.0 + * + * @param void + * @return void + */ + function admin_menu() { + + // Bail early if ACF is hidden. + if ( ! acf_get_setting( 'show_admin' ) ) { + return; + } + + // Vars. + $slug = 'edit.php?post_type=acf-field-group'; + $cap = acf_get_setting( 'capability' ); + + // Add menu items. + add_menu_page( __( 'Custom Fields', 'acf' ), __( 'Custom Fields', 'acf' ), $cap, $slug, false, 'dashicons-welcome-widgets-menus', 80 ); + add_submenu_page( $slug, __( 'Field Groups', 'acf' ), __( 'Field Groups', 'acf' ), $cap, $slug ); + add_submenu_page( $slug, __( 'Add New', 'acf' ), __( 'Add New', 'acf' ), $cap, 'post-new.php?post_type=acf-field-group' ); + } + + /** + * Enqueues global admin styling. + * + * @date 28/09/13 + * @since 5.0.0 + * + * @param void + * @return void + */ + function admin_enqueue_scripts() { + wp_enqueue_style( 'acf-global' ); + } + + /** + * Appends custom admin body classes. + * + * @date 5/11/19 + * @since 5.8.7 + * + * @param string $classes Space-separated list of CSS classes. + * @return string + */ + function admin_body_class( $classes ) { + global $wp_version; + + // Determine body class version. + $wp_minor_version = floatval( $wp_version ); + if ( $wp_minor_version >= 5.3 ) { + $classes .= ' acf-admin-5-3'; + } else { + $classes .= ' acf-admin-3-8'; + } + + // Add browser for specific CSS. + $classes .= ' acf-browser-' . acf_get_browser(); + + // Return classes. + return $classes; + } + + /** + * Adds custom functionality to "ACF" admin pages. + * + * @date 7/4/20 + * @since 5.9.0 + * + * @param void + * @return void + */ + function current_screen( $screen ) { + + // Determine if the current page being viewed is "ACF" related. + if ( isset( $screen->post_type ) && $screen->post_type === 'acf-field-group' ) { + add_action( 'in_admin_header', array( $this, 'in_admin_header' ) ); + add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); + $this->setup_help_tab(); + } + } + + /** + * Sets up the admin help tab. + * + * @date 20/4/20 + * @since 5.9.0 + * + * @param void + * @return void + */ + public function setup_help_tab() { + $screen = get_current_screen(); + + // Overview tab. + $screen->add_help_tab( + array( + 'id' => 'overview', + 'title' => __( 'Overview', 'acf' ), + 'content' => + '

                ' . __( 'Overview', 'acf' ) . '

                ' . + '

                ' . __( 'The Advanced Custom Fields plugin provides a visual form builder to customize WordPress edit screens with extra fields, and an intuitive API to display custom field values in any theme template file.', 'acf' ) . '

                ' . + '

                ' . sprintf( + __( 'Before creating your first Field Group, we recommend first reading our Getting started guide to familiarize yourself with the plugin\'s philosophy and best practises.', 'acf' ), + 'https://www.advancedcustomfields.com/resources/getting-started-with-acf/' + ) . '

                ' . + '

                ' . __( 'Please use the Help & Support tab to get in touch should you find yourself requiring assistance.', 'acf' ) . '

                ' . + '', + ) + ); + + // Help tab. + $screen->add_help_tab( + array( + 'id' => 'help', + 'title' => __( 'Help & Support', 'acf' ), + 'content' => + '

                ' . __( 'Help & Support', 'acf' ) . '

                ' . + '

                ' . __( 'We are fanatical about support, and want you to get the best out of your website with ACF. If you run into any difficulties, there are several places you can find help:', 'acf' ) . '

                ' . + '', + ) + ); + + // Sidebar. + $screen->set_help_sidebar( + '

                ' . __( 'Information', 'acf' ) . '

                ' . + '

                ' . sprintf( __( 'Version %s', 'acf' ), ACF_VERSION ) . '

                ' . + '

                ' . __( 'View details', 'acf' ) . '

                ' . + '

                ' . __( 'Visit website', 'acf' ) . '

                ' . + '' + ); + } + + /** + * Renders the admin navigation element. + * + * @date 27/3/20 + * @since 5.9.0 + * + * @param void + * @return void + */ + function in_admin_header() { + acf_get_view( 'html-admin-navigation' ); + } + + /** + * Modifies the admin footer text. + * + * @date 7/4/20 + * @since 5.9.0 + * + * @param string $text The admin footer text. + * @return string + */ + function admin_footer_text( $text ) { + // Use RegExp to append "ACF" after the element allowing translations to read correctly. + return preg_replace( '/()/', '$1 ' . __( 'and', 'acf' ) . ' ACF', $text, 1 ); + } + } + + // Instantiate. + acf_new_instance( 'ACF_Admin' ); endif; // class_exists check diff --git a/includes/admin/tools/class-acf-admin-tool-export.php b/includes/admin/tools/class-acf-admin-tool-export.php index f506dc6..42df051 100644 --- a/includes/admin/tools/class-acf-admin-tool-export.php +++ b/includes/admin/tools/class-acf-admin-tool-export.php @@ -1,366 +1,359 @@ -name = 'export'; + $this->title = __( 'Export Field Groups', 'acf' ); + + // active + if ( $this->is_active() ) { + $this->title .= ' - ' . __( 'Generate PHP', 'acf' ); + } -class ACF_Admin_Tool_Export extends ACF_Admin_Tool { - - /** @var string View context */ - var $view = ''; - - - /** @var array Export data */ - var $json = ''; - - - /** - * initialize - * - * This function will initialize the admin tool - * - * @date 10/10/17 - * @since 5.6.3 - * - * @param n/a - * @return n/a - */ - - function initialize() { - - // vars - $this->name = 'export'; - $this->title = __("Export Field Groups", 'acf'); - - - // active - if( $this->is_active() ) { - $this->title .= ' - ' . __('Generate PHP', 'acf'); - } - - } - - - /** - * submit - * - * This function will run when the tool's form has been submit - * - * @date 10/10/17 - * @since 5.6.3 - * - * @param n/a - * @return n/a - */ - - function submit() { - - // vars - $action = acf_maybe_get_POST('action'); - - - // download - if( $action === 'download' ) { - - $this->submit_download(); - - // generate - } elseif( $action === 'generate' ) { - - $this->submit_generate(); - - } - - } - - - /** - * submit_download - * - * description - * - * @date 17/10/17 - * @since 5.6.3 - * - * @param n/a - * @return n/a - */ - - function submit_download() { - - // vars - $json = $this->get_selected(); - - - // validate - if( $json === false ) { - return acf_add_admin_notice( __("No field groups selected", 'acf'), 'warning' ); - } - - - // headers - $file_name = 'acf-export-' . date('Y-m-d') . '.json'; - header( "Content-Description: File Transfer" ); - header( "Content-Disposition: attachment; filename={$file_name}" ); - header( "Content-Type: application/json; charset=utf-8" ); - - - // return - echo acf_json_encode( $json ); - die; - - } - - - /** - * submit_generate - * - * description - * - * @date 17/10/17 - * @since 5.6.3 - * - * @param n/a - * @return n/a - */ - - function submit_generate() { - - // vars - $keys = $this->get_selected_keys(); - - - // validate - if( !$keys ) { - return acf_add_admin_notice( __("No field groups selected", 'acf'), 'warning' ); - } - - - // url - $url = add_query_arg( 'keys', implode('+', $keys), $this->get_url() ); - - - // redirect - wp_redirect( $url ); - exit; - - } - - - /** - * load - * - * description - * - * @date 21/10/17 - * @since 5.6.3 - * - * @param n/a - * @return n/a - */ - - function load() { - - // active - if( $this->is_active() ) { - - // get selected keys - $selected = $this->get_selected_keys(); - - - // add notice - if( $selected ) { - $count = count($selected); - $text = sprintf( _n( 'Exported 1 field group.', 'Exported %s field groups.', $count, 'acf' ), $count ); - acf_add_admin_notice( $text, 'success' ); - } } - } - - - /** - * html - * - * This function will output the metabox HTML - * - * @date 10/10/17 - * @since 5.6.3 - * - * @param n/a - * @return n/a - */ - - function html() { - - // single (generate PHP) - if( $this->is_active() ) { - - $this->html_single(); - - // archive - } else { - - $this->html_archive(); - + + /** + * submit + * + * This function will run when the tool's form has been submit + * + * @date 10/10/17 + * @since 5.6.3 + * + * @param n/a + * @return n/a + */ + + function submit() { + + // vars + $action = acf_maybe_get_POST( 'action' ); + + // download + if ( $action === 'download' ) { + + $this->submit_download(); + + // generate + } elseif ( $action === 'generate' ) { + + $this->submit_generate(); + + } + } - - } - - - /** - * html_field_selection - * - * description - * - * @date 24/10/17 - * @since 5.6.3 - * - * @param n/a - * @return n/a - */ - - function html_field_selection() { - - // vars - $choices = array(); - $selected = $this->get_selected_keys(); - $field_groups = acf_get_field_groups(); - - - // loop - if( $field_groups ) { - foreach( $field_groups as $field_group ) { - $choices[ $field_group['key'] ] = esc_html( $field_group['title'] ); - } + + + /** + * submit_download + * + * description + * + * @date 17/10/17 + * @since 5.6.3 + * + * @param n/a + * @return n/a + */ + + function submit_download() { + + // vars + $json = $this->get_selected(); + + // validate + if ( $json === false ) { + return acf_add_admin_notice( __( 'No field groups selected', 'acf' ), 'warning' ); + } + + // headers + $file_name = 'acf-export-' . date( 'Y-m-d' ) . '.json'; + header( 'Content-Description: File Transfer' ); + header( "Content-Disposition: attachment; filename={$file_name}" ); + header( 'Content-Type: application/json; charset=utf-8' ); + + // return + echo acf_json_encode( $json ); + die; + } - - - // render - acf_render_field_wrap(array( - 'label' => __('Select Field Groups', 'acf'), - 'type' => 'checkbox', - 'name' => 'keys', - 'prefix' => false, - 'value' => $selected, - 'toggle' => true, - 'choices' => $choices, - )); - - } - - - /** - * html_panel_selection - * - * description - * - * @date 21/10/17 - * @since 5.6.3 - * - * @param n/a - * @return n/a - */ - - function html_panel_selection() { - - ?> + + + /** + * submit_generate + * + * description + * + * @date 17/10/17 + * @since 5.6.3 + * + * @param n/a + * @return n/a + */ + + function submit_generate() { + + // vars + $keys = $this->get_selected_keys(); + + // validate + if ( ! $keys ) { + return acf_add_admin_notice( __( 'No field groups selected', 'acf' ), 'warning' ); + } + + // url + $url = add_query_arg( 'keys', implode( '+', $keys ), $this->get_url() ); + + // redirect + wp_redirect( $url ); + exit; + + } + + + /** + * load + * + * description + * + * @date 21/10/17 + * @since 5.6.3 + * + * @param n/a + * @return n/a + */ + + function load() { + + // active + if ( $this->is_active() ) { + + // get selected keys + $selected = $this->get_selected_keys(); + + // add notice + if ( $selected ) { + $count = count( $selected ); + $text = sprintf( _n( 'Exported 1 field group.', 'Exported %s field groups.', $count, 'acf' ), $count ); + acf_add_admin_notice( $text, 'success' ); + } + } + + } + + + /** + * html + * + * This function will output the metabox HTML + * + * @date 10/10/17 + * @since 5.6.3 + * + * @param n/a + * @return n/a + */ + + function html() { + + // single (generate PHP) + if ( $this->is_active() ) { + + $this->html_single(); + + // archive + } else { + + $this->html_archive(); + + } + + } + + + /** + * html_field_selection + * + * description + * + * @date 24/10/17 + * @since 5.6.3 + * + * @param n/a + * @return n/a + */ + + function html_field_selection() { + + // vars + $choices = array(); + $selected = $this->get_selected_keys(); + $field_groups = acf_get_field_groups(); + + // loop + if ( $field_groups ) { + foreach ( $field_groups as $field_group ) { + $choices[ $field_group['key'] ] = esc_html( $field_group['title'] ); + } + } + + // render + acf_render_field_wrap( + array( + 'label' => __( 'Select Field Groups', 'acf' ), + 'type' => 'checkbox', + 'name' => 'keys', + 'prefix' => false, + 'value' => $selected, + 'toggle' => true, + 'choices' => $choices, + ) + ); + + } + + + /** + * html_panel_selection + * + * description + * + * @date 21/10/17 + * @since 5.6.3 + * + * @param n/a + * @return n/a + */ + + function html_panel_selection() { + + ?>
                -

                +

                html_field_selection(); ?>
                - +
                -

                +

                - __('Empty settings', 'acf'), - 'type' => 'select', - 'name' => 'minimal', - 'prefix' => false, - 'value' => '', - 'choices' => array( - 'all' => __('Include all settings', 'acf'), - 'minimal' => __('Ignore empty settings', 'acf'), + 'label' => __('Empty settings', 'acf'), + 'type' => 'select', + 'name' => 'minimal', + 'prefix' => false, + 'value' => '', + 'choices' => array( + 'all' => __('Include all settings', 'acf'), + 'minimal' => __('Ignore empty settings', 'acf'), ) )); -*/ - + */ + ?>
                - -

                + +

                html_field_selection(); ?>

                - - + +

                - +
                html_generate(); ?> @@ -368,80 +361,76 @@ class ACF_Admin_Tool_Export extends ACF_Admin_Tool {
                html_panel_selection(); ?>

                - +

                - get_selected(); - $str_replace = array( - " " => "\t", - "'!!__(!!\'" => "__('", - "!!\', !!\'" => "', '", - "!!\')!!'" => "')", - "array (" => "array(" - ); - $preg_replace = array( - '/([\t\r\n]+?)array/' => 'array', - '/[0-9]+ => array/' => 'array' - ); + -

                - + + + /** + * html_generate + * + * description + * + * @date 17/10/17 + * @since 5.6.3 + * + * @param n/a + * @return n/a + */ + + function html_generate() { + + // prevent default translation and fake __() within string + acf_update_setting( 'l10n_var_export', true ); + + // vars + $json = $this->get_selected(); + $str_replace = array( + ' ' => "\t", + "'!!__(!!\'" => "__('", + "!!\', !!\'" => "', '", + "!!\')!!'" => "')", + 'array (' => 'array(', + ); + $preg_replace = array( + '/([\t\r\n]+?)array/' => 'array', + '/[0-9]+ => array/' => 'array', + ); + + ?> +

                +

                @@ -480,7 +469,7 @@ class ACF_Admin_Tool_Export extends ACF_Admin_Tool { // tooltip acf.newTooltip({ - text: "", + text: "", timeout: 250, target: $(this), }); @@ -495,102 +484,97 @@ class ACF_Admin_Tool_Export extends ACF_Admin_Tool { })(jQuery); - get_selected_keys(); - $json = array(); - - - // bail early if no keys - if( !$selected ) return false; - - - // construct JSON - foreach( $selected as $key ) { - - // load field group - $field_group = acf_get_field_group( $key ); - - - // validate field group - if( empty($field_group) ) continue; - - - // load fields - $field_group['fields'] = acf_get_fields( $field_group ); - - - // prepare for export - $field_group = acf_prepare_field_group_for_export( $field_group ); - - - // add to json array - $json[] = $field_group; - - } - - - // return - return $json; - - } -} + get_selected_keys(); + $json = array(); + + // bail early if no keys + if ( ! $selected ) { + return false; + } + + // construct JSON + foreach ( $selected as $key ) { + + // load field group + $field_group = acf_get_field_group( $key ); + + // validate field group + if ( empty( $field_group ) ) { + continue; + } + + // load fields + $field_group['fields'] = acf_get_fields( $field_group ); + + // prepare for export + $field_group = acf_prepare_field_group_for_export( $field_group ); + + // add to json array + $json[] = $field_group; + + } + + // return + return $json; + + } + } + + // initialize + acf_register_admin_tool( 'ACF_Admin_Tool_Export' ); endif; // class_exists check -?> \ No newline at end of file +?> diff --git a/includes/admin/tools/class-acf-admin-tool-import.php b/includes/admin/tools/class-acf-admin-tool-import.php index 1faaccd..cb85391 100644 --- a/includes/admin/tools/class-acf-admin-tool-import.php +++ b/includes/admin/tools/class-acf-admin-tool-import.php @@ -1,157 +1,161 @@ -name = 'import'; - $this->title = __("Import Field Groups", 'acf'); - $this->icon = 'dashicons-upload'; - - } - - - /** - * html - * - * This function will output the metabox HTML - * - * @date 10/10/17 - * @since 5.6.3 - * - * @param n/a - * @return n/a - */ - - function html() { - - ?> -

                + class ACF_Admin_Tool_Import extends ACF_Admin_Tool { + + + /** + * initialize + * + * This function will initialize the admin tool + * + * @date 10/10/17 + * @since 5.6.3 + * + * @param n/a + * @return n/a + */ + + function initialize() { + + // vars + $this->name = 'import'; + $this->title = __( 'Import Field Groups', 'acf' ); + $this->icon = 'dashicons-upload'; + + } + + + /** + * html + * + * This function will output the metabox HTML + * + * @date 10/10/17 + * @since 5.6.3 + * + * @param n/a + * @return n/a + */ + + function html() { + + ?> +

                - __('Select File', 'acf'), - 'type' => 'file', - 'name' => 'acf_import_file', - 'value' => false, - 'uploader' => 'basic', - )); - + __( 'Select File', 'acf' ), + 'type' => 'file', + 'name' => 'acf_import_file', + 'value' => false, + 'uploader' => 'basic', + ) + ); + ?>

                - +

                - ID; - } - - // Import field group. - $field_group = acf_import_field_group( $field_group ); - - // append message - $ids[] = $field_group['ID']; - } - - // Count number of imported field groups. - $total = count($ids); - - // Generate text. - $text = sprintf( _n( 'Imported 1 field group', 'Imported %s field groups', $total, 'acf' ), $total ); - - // Add links to text. - $links = array(); - foreach( $ids as $id ) { - $links[] = '' . get_the_title( $id ) . ''; - } - $text .= ' ' . implode( ', ', $links ); - - // Add notice - acf_add_admin_notice( $text, 'success' ); - } -} + ID; + } + + // Import field group. + $field_group = acf_import_field_group( $field_group ); + + // append message + $ids[] = $field_group['ID']; + } + + // Count number of imported field groups. + $total = count( $ids ); + + // Generate text. + $text = sprintf( _n( 'Imported 1 field group', 'Imported %s field groups', $total, 'acf' ), $total ); + + // Add links to text. + $links = array(); + foreach ( $ids as $id ) { + $links[] = '' . get_the_title( $id ) . ''; + } + $text .= ' ' . implode( ', ', $links ); + + // Add notice + acf_add_admin_notice( $text, 'success' ); + } + } + + // initialize + acf_register_admin_tool( 'ACF_Admin_Tool_Import' ); endif; // class_exists check -?> \ No newline at end of file +?> diff --git a/includes/admin/tools/class-acf-admin-tool.php b/includes/admin/tools/class-acf-admin-tool.php index 9f4c683..757298c 100644 --- a/includes/admin/tools/class-acf-admin-tool.php +++ b/includes/admin/tools/class-acf-admin-tool.php @@ -1,195 +1,194 @@ -name; - } - - - /** - * get_title - * - * This function will return the Tool's title - * - * @date 19/10/17 - * @since 5.6.3 - * - * @param n/a - * @return n/a - */ - - function get_title() { - return $this->title; - } - - - /** - * get_url - * - * This function will return the Tool's title - * - * @date 19/10/17 - * @since 5.6.3 - * - * @param n/a - * @return n/a - */ - - function get_url() { - return acf_get_admin_tool_url( $this->name ); - } - - - /** - * is_active - * - * This function will return true if the tool is active - * - * @date 19/10/17 - * @since 5.6.3 - * - * @param n/a - * @return bool - */ - - function is_active() { - return acf_maybe_get_GET('tool') === $this->name; - } - - - /* - * __construct - * - * This function will setup the class functionality - * - * @type function - * @date 27/6/17 - * @since 5.6.0 - * - * @param n/a - * @return n/a - */ - - function __construct() { - - // initialize - $this->initialize(); - - } - - - /** - * initialize - * - * This function will initialize the admin tool - * - * @date 10/10/17 - * @since 5.6.3 - * - * @param n/a - * @return n/a - */ - - function initialize() { - - /* do nothing */ - - } - - - - /** - * load - * - * This function is called during the admin page load - * - * @date 10/10/17 - * @since 5.6.3 - * - * @param n/a - * @return n/a - */ - - function load() { - - /* do nothing */ - - } - - - /** - * html - * - * This function will output the metabox HTML - * - * @date 10/10/17 - * @since 5.6.3 - * - * @param n/a - * @return n/a - */ - - function html() { - - - - } - - - /** - * submit - * - * This function will run when the tool's form has been submit - * - * @date 10/10/17 - * @since 5.6.3 - * - * @param n/a - * @return n/a - */ - - function submit() { - - - } - - +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly } +if ( ! class_exists( 'ACF_Admin_Tool' ) ) : + + class ACF_Admin_Tool { + + + /** @var string Tool name */ + var $name = ''; + + + /** @var string Tool title */ + var $title = ''; + + + /** @var string Dashicon slug */ + // var $icon = ''; + + + /** @var boolean Redirect form to single */ + // var $redirect = false; + + + /** + * get_name + * + * This function will return the Tool's name + * + * @date 19/10/17 + * @since 5.6.3 + * + * @param n/a + * @return n/a + */ + + function get_name() { + return $this->name; + } + + + /** + * get_title + * + * This function will return the Tool's title + * + * @date 19/10/17 + * @since 5.6.3 + * + * @param n/a + * @return n/a + */ + + function get_title() { + return $this->title; + } + + + /** + * get_url + * + * This function will return the Tool's title + * + * @date 19/10/17 + * @since 5.6.3 + * + * @param n/a + * @return n/a + */ + + function get_url() { + return acf_get_admin_tool_url( $this->name ); + } + + + /** + * is_active + * + * This function will return true if the tool is active + * + * @date 19/10/17 + * @since 5.6.3 + * + * @param n/a + * @return bool + */ + + function is_active() { + return acf_maybe_get_GET( 'tool' ) === $this->name; + } + + + /* + * __construct + * + * This function will setup the class functionality + * + * @type function + * @date 27/6/17 + * @since 5.6.0 + * + * @param n/a + * @return n/a + */ + + function __construct() { + + // initialize + $this->initialize(); + + } + + + /** + * initialize + * + * This function will initialize the admin tool + * + * @date 10/10/17 + * @since 5.6.3 + * + * @param n/a + * @return n/a + */ + + function initialize() { + + /* do nothing */ + + } + + + + /** + * load + * + * This function is called during the admin page load + * + * @date 10/10/17 + * @since 5.6.3 + * + * @param n/a + * @return n/a + */ + + function load() { + + /* do nothing */ + + } + + + /** + * html + * + * This function will output the metabox HTML + * + * @date 10/10/17 + * @since 5.6.3 + * + * @param n/a + * @return n/a + */ + + function html() { + + } + + + /** + * submit + * + * This function will run when the tool's form has been submit + * + * @date 10/10/17 + * @since 5.6.3 + * + * @param n/a + * @return n/a + */ + + function submit() { + + } + + + } + endif; // class_exists check -?> \ No newline at end of file + diff --git a/includes/admin/views/field-group-field-conditional-logic.php b/includes/admin/views/field-group-field-conditional-logic.php index a49f761..06d3565 100644 --- a/includes/admin/views/field-group-field-conditional-logic.php +++ b/includes/admin/views/field-group-field-conditional-logic.php @@ -1,55 +1,64 @@ - - + - 'true_false', - 'name' => 'conditional_logic', - 'prefix' => $field['prefix'], - 'value' => $disabled ? 0 : 1, - 'ui' => 1, - 'class' => 'conditions-toggle', - )); - + 'true_false', + 'name' => 'conditional_logic', + 'prefix' => $field['prefix'], + 'value' => $disabled ? 0 : 1, + 'ui' => 1, + 'class' => 'conditions-toggle', + ) + ); + ?> -
                style="display:none;"> +
                + style="display:none;"> - $group ): - + $group ) : + // validate - if( empty($group) ) continue; - - + if ( empty( $group ) ) { + continue; + } + + // vars // $group_id must be completely different to $rule_id to avoid JS issues $group_id = "group_{$group_id}"; - $h4 = ($group_id == "group_0") ? __("Show this field if",'acf') : __("or",'acf'); - + $h4 = ( $group_id == 'group_0' ) ? __( 'Show this field if', 'acf' ) : __( 'or', 'acf' ); + ?>
                @@ -57,85 +66,95 @@ if( empty($field['conditional_logic']) ) { - $rule ): - + $rule ) : + // valid rule - $rule = wp_parse_args( $rule, array( - 'field' => '', - 'operator' => '', - 'value' => '', - )); - - - // vars + $rule = wp_parse_args( + $rule, + array( + 'field' => '', + 'operator' => '', + 'value' => '', + ) + ); + + + // vars // $group_id must be completely different to $rule_id to avoid JS issues $rule_id = "rule_{$rule_id}"; - $prefix = "{$field['prefix']}[conditional_logic][{$group_id}][{$rule_id}]"; - + $prefix = "{$field['prefix']}[conditional_logic][{$group_id}][{$rule_id}]"; + // data attributes $attributes = array( - 'data-id' => $rule_id, - 'data-field' => $rule['field'], - 'data-operator' => $rule['operator'], - 'data-value' => $rule['value'] + 'data-id' => $rule_id, + 'data-field' => $rule['field'], + 'data-operator' => $rule['operator'], + 'data-value' => $rule['value'], ); - + ?> - > + > - \ No newline at end of file + diff --git a/includes/admin/views/field-group-field.php b/includes/admin/views/field-group-field.php index 453edb2..131b9b2 100644 --- a/includes/admin/views/field-group-field.php +++ b/includes/admin/views/field-group-field.php @@ -1,55 +1,62 @@ - 'acf-field-object acf-field-object-' . acf_slugify( $field['type'] ), - 'data-id' => $field['ID'], - 'data-key' => $field['key'], - 'data-type' => $field['type'], + 'class' => 'acf-field-object acf-field-object-' . acf_slugify( $field['type'] ), + 'data-id' => $field['ID'], + 'data-key' => $field['key'], + 'data-type' => $field['type'], ); // Misc template vars. -$field_label = acf_get_field_label( $field, 'admin' ); +$field_label = acf_get_field_label( $field, 'admin' ); $field_type_label = acf_get_field_type_label( $field['type'] ); ?>
                >
                - $field['ID'], - 'key' => $field['key'], - 'parent' => $field['parent'], - 'menu_order' => $i, - 'save' => '' + 'ID' => $field['ID'], + 'key' => $field['key'], + 'parent' => $field['parent'], + 'menu_order' => $i, + 'save' => '', ); - foreach( $meta_inputs as $k => $v ): - acf_hidden_input(array( 'name' => $input_prefix . '[' . $k . ']', 'value' => $v, 'id' => $input_id . '-' . $k )); - endforeach; ?> + foreach ( $meta_inputs as $k => $v ) : + acf_hidden_input( + array( + 'name' => $input_prefix . '[' . $k . ']', + 'value' => $v, + 'id' => $input_id . '-' . $k, + ) + ); + endforeach; + ?>
                - 'select', - 'prefix' => $prefix, - 'name' => 'field', - 'class' => 'condition-rule-field', - 'disabled' => $disabled, - 'value' => $rule['field'], - 'choices' => array( - $rule['field'] => $rule['field'] + 'select', + 'prefix' => $prefix, + 'name' => 'field', + 'class' => 'condition-rule-field', + 'disabled' => $disabled, + 'value' => $rule['field'], + 'choices' => array( + $rule['field'] => $rule['field'], + ), ) - )); - + ); + ?> - 'select', - 'prefix' => $prefix, - 'name' => 'operator', - 'class' => 'condition-rule-operator', - 'disabled' => $disabled, - 'value' => $rule['operator'], - 'choices' => array( - $rule['operator'] => $rule['operator'] + 'select', + 'prefix' => $prefix, + 'name' => 'operator', + 'class' => 'condition-rule-operator', + 'disabled' => $disabled, + 'value' => $rule['operator'], + 'choices' => array( + $rule['operator'] => $rule['operator'], + ), ) - )); - + ); + ?> - 'select', - 'prefix' => $prefix, - 'name' => 'value', - 'class' => 'condition-rule-value', - 'disabled' => $disabled, - 'value' => $rule['value'], - 'choices' => array( - $rule['value'] => $rule['value'] + acf_render_field( + array( + 'type' => 'select', + 'prefix' => $prefix, + 'name' => 'value', + 'class' => 'condition-rule-value', + 'disabled' => $disabled, + 'value' => $rule['value'], + 'choices' => array( + $rule['value'] => $rule['value'], + ), ) - )); - + ); + ?> - + @@ -148,11 +167,11 @@ if( empty($field['conditional_logic']) ) { -

                +

                - +
                - __('Field Label','acf'), - 'instructions' => __('This is the name which will appear on the EDIT page','acf'), - 'name' => 'label', - 'type' => 'text', - 'class' => 'field-label' - ), true); - - + acf_render_field_setting( + $field, + array( + 'label' => __( 'Field Label', 'acf' ), + 'instructions' => __( 'This is the name which will appear on the EDIT page', 'acf' ), + 'name' => 'label', + 'type' => 'text', + 'class' => 'field-label', + ), + true + ); + + // name - acf_render_field_setting($field, array( - 'label' => __('Field Name','acf'), - 'instructions' => __('Single word, no spaces. Underscores and dashes allowed','acf'), - 'name' => 'name', - 'type' => 'text', - 'class' => 'field-name' - ), true); - - + acf_render_field_setting( + $field, + array( + 'label' => __( 'Field Name', 'acf' ), + 'instructions' => __( 'Single word, no spaces. Underscores and dashes allowed', 'acf' ), + 'name' => 'name', + 'type' => 'text', + 'class' => 'field-name', + ), + true + ); + + // type - acf_render_field_setting($field, array( - 'label' => __('Field Type','acf'), - 'instructions' => '', - 'type' => 'select', - 'name' => 'type', - 'choices' => acf_get_grouped_field_types(), - 'class' => 'field-type' - ), true); - - + acf_render_field_setting( + $field, + array( + 'label' => __( 'Field Type', 'acf' ), + 'instructions' => '', + 'type' => 'select', + 'name' => 'type', + 'choices' => acf_get_grouped_field_types(), + 'class' => 'field-type', + ), + true + ); + + // instructions - acf_render_field_setting($field, array( - 'label' => __('Instructions','acf'), - 'instructions' => __('Instructions for authors. Shown when submitting data','acf'), - 'type' => 'textarea', - 'name' => 'instructions', - 'rows' => 5 - ), true); - - + acf_render_field_setting( + $field, + array( + 'label' => __( 'Instructions', 'acf' ), + 'instructions' => __( 'Instructions for authors. Shown when submitting data', 'acf' ), + 'type' => 'textarea', + 'name' => 'instructions', + 'rows' => 5, + ), + true + ); + + // required - acf_render_field_setting($field, array( - 'label' => __('Required?','acf'), - 'instructions' => '', - 'type' => 'true_false', - 'name' => 'required', - 'ui' => 1, - 'class' => 'field-required' - ), true); - - + acf_render_field_setting( + $field, + array( + 'label' => __( 'Required?', 'acf' ), + 'instructions' => '', + 'type' => 'true_false', + 'name' => 'required', + 'ui' => 1, + 'class' => 'field-required', + ), + true + ); + + // 3rd party settings - do_action('acf/render_field_settings', $field); - - + do_action( 'acf/render_field_settings', $field ); + + // type specific settings - do_action("acf/render_field_settings/type={$field['type']}", $field); - - + do_action( "acf/render_field_settings/type={$field['type']}", $field ); + + // conditional logic - acf_get_view('field-group-field-conditional-logic', array( 'field' => $field )); - - + acf_get_view( 'field-group-field-conditional-logic', array( 'field' => $field ) ); + + // wrapper - acf_render_field_wrap(array( - 'label' => __('Wrapper Attributes','acf'), - 'instructions' => '', - 'type' => 'number', - 'name' => 'width', - 'prefix' => $field['prefix'] . '[wrapper]', - 'value' => $field['wrapper']['width'], - 'prepend' => __('width', 'acf'), - 'append' => '%', - 'wrapper' => array( - 'data-name' => 'wrapper', - 'class' => 'acf-field-setting-wrapper' - ) - ), 'tr'); - - acf_render_field_wrap(array( - 'label' => '', - 'instructions' => '', - 'type' => 'text', - 'name' => 'class', - 'prefix' => $field['prefix'] . '[wrapper]', - 'value' => $field['wrapper']['class'], - 'prepend' => __('class', 'acf'), - 'wrapper' => array( - 'data-append' => 'wrapper' - ) - ), 'tr'); - - acf_render_field_wrap(array( - 'label' => '', - 'instructions' => '', - 'type' => 'text', - 'name' => 'id', - 'prefix' => $field['prefix'] . '[wrapper]', - 'value' => $field['wrapper']['id'], - 'prepend' => __('id', 'acf'), - 'wrapper' => array( - 'data-append' => 'wrapper' - ) - ), 'tr'); - + acf_render_field_wrap( + array( + 'label' => __( 'Wrapper Attributes', 'acf' ), + 'instructions' => '', + 'type' => 'number', + 'name' => 'width', + 'prefix' => $field['prefix'] . '[wrapper]', + 'value' => $field['wrapper']['width'], + 'prepend' => __( 'width', 'acf' ), + 'append' => '%', + 'wrapper' => array( + 'data-name' => 'wrapper', + 'class' => 'acf-field-setting-wrapper', + ), + ), + 'tr' + ); + + acf_render_field_wrap( + array( + 'label' => '', + 'instructions' => '', + 'type' => 'text', + 'name' => 'class', + 'prefix' => $field['prefix'] . '[wrapper]', + 'value' => $field['wrapper']['class'], + 'prepend' => __( 'class', 'acf' ), + 'wrapper' => array( + 'data-append' => 'wrapper', + ), + ), + 'tr' + ); + + acf_render_field_wrap( + array( + 'label' => '', + 'instructions' => '', + 'type' => 'text', + 'name' => 'id', + 'prefix' => $field['prefix'] . '[wrapper]', + 'value' => $field['wrapper']['id'], + 'prepend' => __( 'id', 'acf' ), + 'wrapper' => array( + 'data-append' => 'wrapper', + ), + ), + 'tr' + ); + ?> @@ -185,4 +221,4 @@ $field_type_label = acf_get_field_type_label( $field['type'] );
                -
                \ No newline at end of file +
                diff --git a/includes/admin/views/field-group-fields.php b/includes/admin/views/field-group-fields.php index e4a9e50..72b2246 100644 --- a/includes/admin/views/field-group-fields.php +++ b/includes/admin/views/field-group-fields.php @@ -1,52 +1,76 @@
                  -
                • -
                • -
                • -
                • -
                • +
                • +
                • +
                • +
                • +
                -
                +
                - + Add Field button to create your first field.",'acf'); ?> + + Add Field button to create your first field.', 'acf' ); ?>
                - $field ): - - acf_get_view('field-group-field', array( 'field' => $field, 'i' => $i )); - + $field ) : + + acf_get_view( + 'field-group-field', + array( + 'field' => $field, + 'i' => $i, + ) + ); + endforeach; - - endif; ?> + + endif; + ?>
                • - +
                - 'acfcloneindex', - 'key' => 'acfcloneindex', - 'label' => __('New Field','acf'), - 'name' => 'new_field', - 'type' => 'text' - )); - + $clone = acf_get_valid_field( + array( + 'ID' => 'acfcloneindex', + 'key' => 'acfcloneindex', + 'label' => __( 'New Field', 'acf' ), + 'name' => 'new_field', + 'type' => 'text', + ) + ); + ?> - + -
                \ No newline at end of file +
                diff --git a/includes/admin/views/field-group-locations.php b/includes/admin/views/field-group-locations.php index 12c76a8..9b0a9bb 100644 --- a/includes/admin/views/field-group-locations.php +++ b/includes/admin/views/field-group-locations.php @@ -6,29 +6,36 @@ global $field_group; ?>
                - -

                + +

                - $group ): - + $group ) : + // bail ealry if no group - if( empty($group) ) return; - - + if ( empty( $group ) ) { + return; + } + + // view - acf_get_view('html-location-group', array( - 'group' => $group, - 'group_id' => "group_{$i}" - )); + acf_get_view( + 'html-location-group', + array( + 'group' => $group, + 'group_id' => "group_{$i}", + ) + ); + + endforeach; + ?> - endforeach; ?> +

                -

                - - +
                @@ -42,4 +49,4 @@ if( typeof acf !== 'undefined' ) { }); } - \ No newline at end of file + diff --git a/includes/admin/views/field-group-options.php b/includes/admin/views/field-group-options.php index e72cd08..64cba73 100644 --- a/includes/admin/views/field-group-options.php +++ b/includes/admin/views/field-group-options.php @@ -2,143 +2,159 @@ // global global $field_group; - - + + // active -acf_render_field_wrap(array( - 'label' => __('Active','acf'), - 'instructions' => '', - 'type' => 'true_false', - 'name' => 'active', - 'prefix' => 'acf_field_group', - 'value' => $field_group['active'], - 'ui' => 1, - //'ui_on_text' => __('Active', 'acf'), - //'ui_off_text' => __('Inactive', 'acf'), -)); +acf_render_field_wrap( + array( + 'label' => __( 'Active', 'acf' ), + 'instructions' => '', + 'type' => 'true_false', + 'name' => 'active', + 'prefix' => 'acf_field_group', + 'value' => $field_group['active'], + 'ui' => 1, + // 'ui_on_text' => __('Active', 'acf'), + // 'ui_off_text' => __('Inactive', 'acf'), + ) +); // style -acf_render_field_wrap(array( - 'label' => __('Style','acf'), - 'instructions' => '', - 'type' => 'select', - 'name' => 'style', - 'prefix' => 'acf_field_group', - 'value' => $field_group['style'], - 'choices' => array( - 'default' => __("Standard (WP metabox)",'acf'), - 'seamless' => __("Seamless (no metabox)",'acf'), +acf_render_field_wrap( + array( + 'label' => __( 'Style', 'acf' ), + 'instructions' => '', + 'type' => 'select', + 'name' => 'style', + 'prefix' => 'acf_field_group', + 'value' => $field_group['style'], + 'choices' => array( + 'default' => __( 'Standard (WP metabox)', 'acf' ), + 'seamless' => __( 'Seamless (no metabox)', 'acf' ), + ), ) -)); +); // position -acf_render_field_wrap(array( - 'label' => __('Position','acf'), - 'instructions' => '', - 'type' => 'select', - 'name' => 'position', - 'prefix' => 'acf_field_group', - 'value' => $field_group['position'], - 'choices' => array( - 'acf_after_title' => __("High (after title)",'acf'), - 'normal' => __("Normal (after content)",'acf'), - 'side' => __("Side",'acf'), - ), - 'default_value' => 'normal' -)); +acf_render_field_wrap( + array( + 'label' => __( 'Position', 'acf' ), + 'instructions' => '', + 'type' => 'select', + 'name' => 'position', + 'prefix' => 'acf_field_group', + 'value' => $field_group['position'], + 'choices' => array( + 'acf_after_title' => __( 'High (after title)', 'acf' ), + 'normal' => __( 'Normal (after content)', 'acf' ), + 'side' => __( 'Side', 'acf' ), + ), + 'default_value' => 'normal', + ) +); // label_placement -acf_render_field_wrap(array( - 'label' => __('Label placement','acf'), - 'instructions' => '', - 'type' => 'select', - 'name' => 'label_placement', - 'prefix' => 'acf_field_group', - 'value' => $field_group['label_placement'], - 'choices' => array( - 'top' => __("Top aligned",'acf'), - 'left' => __("Left aligned",'acf'), +acf_render_field_wrap( + array( + 'label' => __( 'Label placement', 'acf' ), + 'instructions' => '', + 'type' => 'select', + 'name' => 'label_placement', + 'prefix' => 'acf_field_group', + 'value' => $field_group['label_placement'], + 'choices' => array( + 'top' => __( 'Top aligned', 'acf' ), + 'left' => __( 'Left aligned', 'acf' ), + ), ) -)); +); // instruction_placement -acf_render_field_wrap(array( - 'label' => __('Instruction placement','acf'), - 'instructions' => '', - 'type' => 'select', - 'name' => 'instruction_placement', - 'prefix' => 'acf_field_group', - 'value' => $field_group['instruction_placement'], - 'choices' => array( - 'label' => __("Below labels",'acf'), - 'field' => __("Below fields",'acf'), +acf_render_field_wrap( + array( + 'label' => __( 'Instruction placement', 'acf' ), + 'instructions' => '', + 'type' => 'select', + 'name' => 'instruction_placement', + 'prefix' => 'acf_field_group', + 'value' => $field_group['instruction_placement'], + 'choices' => array( + 'label' => __( 'Below labels', 'acf' ), + 'field' => __( 'Below fields', 'acf' ), + ), ) -)); +); // menu_order -acf_render_field_wrap(array( - 'label' => __('Order No.','acf'), - 'instructions' => __('Field groups with a lower order will appear first','acf'), - 'type' => 'number', - 'name' => 'menu_order', - 'prefix' => 'acf_field_group', - 'value' => $field_group['menu_order'], -)); +acf_render_field_wrap( + array( + 'label' => __( 'Order No.', 'acf' ), + 'instructions' => __( 'Field groups with a lower order will appear first', 'acf' ), + 'type' => 'number', + 'name' => 'menu_order', + 'prefix' => 'acf_field_group', + 'value' => $field_group['menu_order'], + ) +); // description -acf_render_field_wrap(array( - 'label' => __('Description','acf'), - 'instructions' => __('Shown in field group list','acf'), - 'type' => 'text', - 'name' => 'description', - 'prefix' => 'acf_field_group', - 'value' => $field_group['description'], -)); +acf_render_field_wrap( + array( + 'label' => __( 'Description', 'acf' ), + 'instructions' => __( 'Shown in field group list', 'acf' ), + 'type' => 'text', + 'name' => 'description', + 'prefix' => 'acf_field_group', + 'value' => $field_group['description'], + ) +); // hide on screen $choices = array( - 'permalink' => __("Permalink", 'acf'), - 'the_content' => __("Content Editor",'acf'), - 'excerpt' => __("Excerpt", 'acf'), - 'custom_fields' => __("Custom Fields", 'acf'), - 'discussion' => __("Discussion", 'acf'), - 'comments' => __("Comments", 'acf'), - 'revisions' => __("Revisions", 'acf'), - 'slug' => __("Slug", 'acf'), - 'author' => __("Author", 'acf'), - 'format' => __("Format", 'acf'), - 'page_attributes' => __("Page Attributes", 'acf'), - 'featured_image' => __("Featured Image", 'acf'), - 'categories' => __("Categories", 'acf'), - 'tags' => __("Tags", 'acf'), - 'send-trackbacks' => __("Send Trackbacks", 'acf'), + 'permalink' => __( 'Permalink', 'acf' ), + 'the_content' => __( 'Content Editor', 'acf' ), + 'excerpt' => __( 'Excerpt', 'acf' ), + 'custom_fields' => __( 'Custom Fields', 'acf' ), + 'discussion' => __( 'Discussion', 'acf' ), + 'comments' => __( 'Comments', 'acf' ), + 'revisions' => __( 'Revisions', 'acf' ), + 'slug' => __( 'Slug', 'acf' ), + 'author' => __( 'Author', 'acf' ), + 'format' => __( 'Format', 'acf' ), + 'page_attributes' => __( 'Page Attributes', 'acf' ), + 'featured_image' => __( 'Featured Image', 'acf' ), + 'categories' => __( 'Categories', 'acf' ), + 'tags' => __( 'Tags', 'acf' ), + 'send-trackbacks' => __( 'Send Trackbacks', 'acf' ), ); -if( acf_get_setting('remove_wp_meta_box') ) { - unset( $choices['custom_fields'] ); +if ( acf_get_setting( 'remove_wp_meta_box' ) ) { + unset( $choices['custom_fields'] ); } -acf_render_field_wrap(array( - 'label' => __('Hide on screen','acf'), - 'instructions' => __('Select items to hide them from the edit screen.','acf') . '

                ' . __("If multiple field groups appear on an edit screen, the first field group's options will be used (the one with the lowest order number)",'acf'), - 'type' => 'checkbox', - 'name' => 'hide_on_screen', - 'prefix' => 'acf_field_group', - 'value' => $field_group['hide_on_screen'], - 'toggle' => true, - 'choices' => $choices -)); +acf_render_field_wrap( + array( + 'label' => __( 'Hide on screen', 'acf' ), + 'instructions' => __( 'Select items to hide them from the edit screen.', 'acf' ) . '

                ' . __( "If multiple field groups appear on an edit screen, the first field group's options will be used (the one with the lowest order number)", 'acf' ), + 'type' => 'checkbox', + 'name' => 'hide_on_screen', + 'prefix' => 'acf_field_group', + 'value' => $field_group['hide_on_screen'], + 'toggle' => true, + 'choices' => $choices, + ) +); // 3rd party settings -do_action('acf/render_field_group_settings', $field_group); - +do_action( 'acf/render_field_group_settings', $field_group ); + ?>
                @@ -152,4 +168,4 @@ if( typeof acf !== 'undefined' ) { }); } - \ No newline at end of file + diff --git a/includes/admin/views/html-admin-navigation.php b/includes/admin/views/html-admin-navigation.php index ecf145f..d3e6e9e 100644 --- a/includes/admin/views/html-admin-navigation.php +++ b/includes/admin/views/html-admin-navigation.php @@ -1,12 +1,14 @@ - $sub_item ) { - +if ( isset( $submenu[ $parent_slug ] ) ) { + foreach ( $submenu[ $parent_slug ] as $i => $sub_item ) { + // Check user can access page. - if ( !current_user_can( $sub_item[1] ) ) { + if ( ! current_user_can( $sub_item[1] ) ) { continue; } - + // Ignore "Add New". - if( $i === 1 ) { + if ( $i === 1 ) { continue; } - + // Define tab. $tab = array( - 'text' => $sub_item[0], - 'url' => $sub_item[2] + 'text' => $sub_item[0], + 'url' => $sub_item[2], ); - + // Convert submenu slug "test" to "$parent_slug&page=test". - if( !strpos($sub_item[2], '.php') ) { + if ( ! strpos( $sub_item[2], '.php' ) ) { $tab['url'] = add_query_arg( array( 'page' => $sub_item[2] ), $parent_slug ); } - + // Detect active state. - if( $submenu_file === $sub_item[2] || $plugin_page === $sub_item[2] ) { + if ( $submenu_file === $sub_item[2] || $plugin_page === $sub_item[2] ) { $tab['is_active'] = true; } - + // Special case for "Add New" page. - if( $i === 0 && $submenu_file === 'post-new.php?post_type=acf-field-group' ) { + if ( $i === 0 && $submenu_file === 'post-new.php?post_type=acf-field-group' ) { $tab['is_active'] = true; } $tabs[] = $tab; @@ -55,35 +57,37 @@ if( isset($submenu[ $parent_slug ]) ) { /** * Filters the admin navigation tabs. * - * @date 27/3/20 - * @since 5.9.0 + * @date 27/3/20 + * @since 5.9.0 * - * @param array $tabs The array of navigation tabs. + * @param array $tabs The array of navigation tabs. */ $tabs = apply_filters( 'acf/admin/toolbar', $tabs ); // Bail early if set to false. -if( $tabs === false ) { +if ( $tabs === false ) { return; } ?>
                -

                - + %s', - !empty( $tab['is_active'] ) ? ' is-active' : '', + ! empty( $tab['is_active'] ) ? ' is-active' : '', esc_url( $tab['url'] ), acf_esc_html( $tab['text'] ) ); - } ?> + } + ?> - - - -

                -
                - + + + +

                +
                + -
                \ No newline at end of file +
                diff --git a/includes/admin/views/html-admin-page-upgrade-network.php b/includes/admin/views/html-admin-page-upgrade-network.php index 903733e..9ee2a5b 100644 --- a/includes/admin/views/html-admin-page-upgrade-network.php +++ b/includes/admin/views/html-admin-page-upgrade-network.php @@ -1,14 +1,14 @@
                -

                +

                -

                -

                +

                +

                @@ -33,9 +33,9 @@ - + @@ -44,53 +44,57 @@ - + $site ): - - // switch blog - switch_to_blog( $site['blog_id'] ); - - ?> - class="alternate"> + if ( $sites ) : + foreach ( $sites as $i => $site ) : + + // switch blog + switch_to_blog( $site['blog_id'] ); + + ?> + + class="alternate"> -
                - +
                - +
                - + -
                +
                - - - - + + + +
                -

                -

                Return to network dashboard', 'acf'), network_admin_url() ); ?>

                +

                +

                Return to network dashboard', 'acf' ), network_admin_url() ); ?>

                -
                \ No newline at end of file +
                diff --git a/includes/admin/views/html-admin-page-upgrade.php b/includes/admin/views/html-admin-page-upgrade.php index 3c0f9aa..a3ab091 100644 --- a/includes/admin/views/html-admin-page-upgrade.php +++ b/includes/admin/views/html-admin-page-upgrade.php @@ -1,14 +1,14 @@
                -

                +

                - + -

                -

                +

                +

                -

                See what\'s new', 'acf' ), admin_url('edit.php?post_type=acf-field-group') ); ?>

                +

                See what\'s new', 'acf' ), admin_url( 'edit.php?post_type=acf-field-group' ) ); ?>

                - + -

                +

                -
                \ No newline at end of file +
                diff --git a/includes/admin/views/html-admin-tools.php b/includes/admin/views/html-admin-tools.php index 145ac6c..6e87aaa 100644 --- a/includes/admin/views/html-admin-tools.php +++ b/includes/admin/views/html-admin-tools.php @@ -1,27 +1,30 @@ -
                -

                +

                +

                -
                \ No newline at end of file + diff --git a/includes/admin/views/html-location-group.php b/includes/admin/views/html-location-group.php index 14dc961..804f9fe 100644 --- a/includes/admin/views/html-location-group.php +++ b/includes/admin/views/html-location-group.php @@ -1,25 +1,30 @@
                -

                +

                - $rule ): - + $rule ) : + // validate rule - $rule = acf_validate_location_rule($rule); - + $rule = acf_validate_location_rule( $rule ); + // append id and group - $rule['id'] = "rule_{$i}"; + $rule['id'] = "rule_{$i}"; $rule['group'] = $group_id; - + // view - acf_get_view('html-location-rule', array( - 'rule' => $rule - )); - - endforeach; ?> + acf_get_view( + 'html-location-rule', + array( + 'rule' => $rule, + ) + ); + + endforeach; + ?>
                -
                \ No newline at end of file + diff --git a/includes/admin/views/html-location-rule.php b/includes/admin/views/html-location-rule.php index 1171133..2e99bc8 100644 --- a/includes/admin/views/html-location-rule.php +++ b/includes/admin/views/html-location-rule.php @@ -1,91 +1,97 @@ - - 'select', - 'name' => 'param', - 'prefix' => $prefix, - 'value' => $rule['param'], - 'choices' => $choices, - 'class' => 'refresh-location-rule' - )); - + if ( is_array( $choices ) ) { + + acf_render_field( + array( + 'type' => 'select', + 'name' => 'param', + 'prefix' => $prefix, + 'value' => $rule['param'], + 'choices' => $choices, + 'class' => 'refresh-location-rule', + ) + ); + } - + ?> - 'select', - 'name' => 'operator', - 'prefix' => $prefix, - 'value' => $rule['operator'], - 'choices' => $choices - )); - - // custom + if ( is_array( $choices ) ) { + + acf_render_field( + array( + 'type' => 'select', + 'name' => 'operator', + 'prefix' => $prefix, + 'value' => $rule['operator'], + 'choices' => $choices, + ) + ); + + // custom } else { - + echo $choices; - + } - + ?> 'select', - 'name' => 'value', - 'prefix' => $prefix, - 'value' => $rule['value'], - 'choices' => $choices - )); - - // custom + if ( is_array( $choices ) ) { + + acf_render_field( + array( + 'type' => 'select', + 'name' => 'value', + 'prefix' => $prefix, + 'value' => $rule['value'], + 'choices' => $choices, + ) + ); + + // custom } else { - + echo $choices; - + } - + ?> - + - \ No newline at end of file + diff --git a/includes/admin/views/html-notice-upgrade.php b/includes/admin/views/html-notice-upgrade.php index 11f40fd..6676f1b 100644 --- a/includes/admin/views/html-notice-upgrade.php +++ b/includes/admin/views/html-notice-upgrade.php @@ -1,15 +1,22 @@ - @@ -17,11 +24,11 @@ if( !acf_get_setting('pro') ) {
                - -

                -


                - -

                + +

                +


                + +

                @@ -30,7 +37,7 @@ if( !acf_get_setting('pro') ) { - + - \ No newline at end of file + diff --git a/includes/ajax/class-acf-ajax-check-screen.php b/includes/ajax/class-acf-ajax-check-screen.php index c56eb56..5438bd8 100644 --- a/includes/ajax/class-acf-ajax-check-screen.php +++ b/includes/ajax/class-acf-ajax-check-screen.php @@ -1,98 +1,103 @@ request, array( - 'screen' => '', - 'post_id' => 0, - 'ajax' => true, - 'exists' => array() - )); - - // vars - $response = array( - 'results' => array(), - 'style' => '' - ); - - // get field groups - $field_groups = acf_get_field_groups( $args ); - - // loop through field groups - if( $field_groups ) { - foreach( $field_groups as $i => $field_group ) { - - // vars - $item = array( - 'id' => 'acf-' . $field_group['key'], - 'key' => $field_group['key'], - 'title' => $field_group['title'], - 'position' => $field_group['position'], - 'style' => $field_group['style'], - 'label' => $field_group['label_placement'], - 'edit' => acf_get_field_group_edit_link( $field_group['ID'] ), - 'html' => '' - ); - - // append html if doesnt already exist on page - if( !in_array($field_group['key'], $args['exists']) ) { - - // load fields - $fields = acf_get_fields( $field_group ); - - // get field HTML - ob_start(); - - // render - acf_render_fields( $fields, $args['post_id'], 'div', $field_group['instruction_placement'] ); - - $item['html'] = ob_get_clean(); - } - - // append - $response['results'][] = $item; - } - - // Get style from first field group. - $response['style'] = acf_get_field_group_style( $field_groups[0] ); - } - - // Custom metabox order. - if( $this->get('screen') == 'post' ) { - $response['sorted'] = get_user_option('meta-box-order_' . $this->get('post_type')); - } - - // return - return $response; - } +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly } -acf_new_instance('ACF_Ajax_Check_Screen'); +if ( ! class_exists( 'ACF_Ajax_Check_Screen' ) ) : + + class ACF_Ajax_Check_Screen extends ACF_Ajax { + + /** @var string The AJAX action name. */ + var $action = 'acf/ajax/check_screen'; + + /** @var bool Prevents access for non-logged in users. */ + var $public = false; + + /** + * get_response + * + * Returns the response data to sent back. + * + * @date 31/7/18 + * @since 5.7.2 + * + * @param array $request The request args. + * @return mixed The response data or WP_Error. + */ + function get_response( $request ) { + + // vars + $args = wp_parse_args( + $this->request, + array( + 'screen' => '', + 'post_id' => 0, + 'ajax' => true, + 'exists' => array(), + ) + ); + + // vars + $response = array( + 'results' => array(), + 'style' => '', + ); + + // get field groups + $field_groups = acf_get_field_groups( $args ); + + // loop through field groups + if ( $field_groups ) { + foreach ( $field_groups as $i => $field_group ) { + + // vars + $item = array( + 'id' => 'acf-' . $field_group['key'], + 'key' => $field_group['key'], + 'title' => $field_group['title'], + 'position' => $field_group['position'], + 'style' => $field_group['style'], + 'label' => $field_group['label_placement'], + 'edit' => acf_get_field_group_edit_link( $field_group['ID'] ), + 'html' => '', + ); + + // append html if doesnt already exist on page + if ( ! in_array( $field_group['key'], $args['exists'] ) ) { + + // load fields + $fields = acf_get_fields( $field_group ); + + // get field HTML + ob_start(); + + // render + acf_render_fields( $fields, $args['post_id'], 'div', $field_group['instruction_placement'] ); + + $item['html'] = ob_get_clean(); + } + + // append + $response['results'][] = $item; + } + + // Get style from first field group. + $response['style'] = acf_get_field_group_style( $field_groups[0] ); + } + + // Custom metabox order. + if ( $this->get( 'screen' ) == 'post' ) { + $response['sorted'] = get_user_option( 'meta-box-order_' . $this->get( 'post_type' ) ); + } + + // return + return $response; + } + } + + acf_new_instance( 'ACF_Ajax_Check_Screen' ); endif; // class_exists check -?> \ No newline at end of file + diff --git a/includes/ajax/class-acf-ajax-local-json-diff.php b/includes/ajax/class-acf-ajax-local-json-diff.php index a3ca7bb..7a370db 100644 --- a/includes/ajax/class-acf-ajax-local-json-diff.php +++ b/includes/ajax/class-acf-ajax-local-json-diff.php @@ -1,69 +1,71 @@ 404 ) ); - } - - // Disable filters and load field group directly from database. - acf_disable_filters(); - $field_group = acf_get_field_group( $id ); - if( !$field_group ) { - return new WP_Error( 'acf_invalid_id', __( 'Invalid field group ID.', 'acf' ), array( 'status' => 404 ) ); - } - $field_group['fields'] = acf_get_fields( $field_group ); - $field_group['modified'] = get_post_modified_time( 'U', true, $field_group['ID'] ); - $field_group = acf_prepare_field_group_for_export( $field_group ); - - // Load local field group file. - $files = acf_get_local_json_files(); - $key = $field_group['key']; - if( !isset( $files[ $key ] ) ) { - return new WP_Error( 'acf_cannot_compare', __( 'Sorry, this field group is unavailable for diff comparison.', 'acf' ), array( 'status' => 404 ) ); - } - $local_field_group = json_decode( file_get_contents( $files[ $key ] ), true ); - - // Render diff HTML. - $date_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); - $date_template = __( 'Last updated: %s', 'acf' ); - $json['html'] = ' + class ACF_Ajax_Local_JSON_Diff extends ACF_Ajax { + + /** @var string The AJAX action name. */ + var $action = 'acf/ajax/local_json_diff'; + + /** @var bool Prevents access for non-logged in users. */ + var $public = false; + + /** + * get_response + * + * Returns the response data to sent back. + * + * @date 31/7/18 + * @since 5.7.2 + * + * @param array $request The request args. + * @return mixed The response data or WP_Error. + */ + function get_response( $request ) { + $json = array(); + + // Extract props. + $id = isset( $request['id'] ) ? intval( $request['id'] ) : 0; + + // Bail ealry if missing props. + if ( ! $id ) { + return new WP_Error( 'acf_invalid_param', __( 'Invalid field group parameter(s).', 'acf' ), array( 'status' => 404 ) ); + } + + // Disable filters and load field group directly from database. + acf_disable_filters(); + $field_group = acf_get_field_group( $id ); + if ( ! $field_group ) { + return new WP_Error( 'acf_invalid_id', __( 'Invalid field group ID.', 'acf' ), array( 'status' => 404 ) ); + } + $field_group['fields'] = acf_get_fields( $field_group ); + $field_group['modified'] = get_post_modified_time( 'U', true, $field_group['ID'] ); + $field_group = acf_prepare_field_group_for_export( $field_group ); + + // Load local field group file. + $files = acf_get_local_json_files(); + $key = $field_group['key']; + if ( ! isset( $files[ $key ] ) ) { + return new WP_Error( 'acf_cannot_compare', __( 'Sorry, this field group is unavailable for diff comparison.', 'acf' ), array( 'status' => 404 ) ); + } + $local_field_group = json_decode( file_get_contents( $files[ $key ] ), true ); + + // Render diff HTML. + $date_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); + $date_template = __( 'Last updated: %s', 'acf' ); + $json['html'] = '
                - ' . __( 'Original field group', 'acf' ) . ' + ' . __( 'Original field group', 'acf' ) . ' ' . sprintf( $date_template, wp_date( $date_format, $field_group['modified'] ) ) . '
                - ' . __( 'JSON field group (newer)', 'acf' ) . ' + ' . __( 'JSON field group (newer)', 'acf' ) . ' ' . sprintf( $date_template, wp_date( $date_format, $local_field_group['modified'] ) ) . '
                @@ -71,10 +73,10 @@ class ACF_Ajax_Local_JSON_Diff extends ACF_Ajax { ' . wp_text_diff( acf_json_encode( $field_group ), acf_json_encode( $local_field_group ) ) . '
                '; - return $json; + return $json; + } } -} -acf_new_instance('ACF_Ajax_Local_JSON_Diff'); + acf_new_instance( 'ACF_Ajax_Local_JSON_Diff' ); endif; // class_exists check diff --git a/includes/ajax/class-acf-ajax-query-users.php b/includes/ajax/class-acf-ajax-query-users.php index 7173b62..8f674c9 100644 --- a/includes/ajax/class-acf-ajax-query-users.php +++ b/includes/ajax/class-acf-ajax-query-users.php @@ -1,273 +1,275 @@ per_page; - $args['paged'] = $this->page; - if( $this->is_search ) { - $args['search'] = "*{$this->search}*"; - } - - /** - * Filters the query args. - * - * @date 21/5/19 - * @since 5.8.1 - * - * @param array $args The query args. - * @param array $request The query request. - * @param ACF_Ajax_Query $query The query object. - */ - return apply_filters( "acf/ajax/query_users/args", $args, $request, $this ); - } - - /** - * Prepares args for the get_results() method. - * - * @date 23/3/20 - * @since 5.8.9 - * - * @param array args The query args. - * @return array - */ - function prepare_args( $args ) { - - // Parse pagination args that may have been modified. - if( isset($args['users_per_page']) ) { - $this->per_page = intval($args['users_per_page']); - unset( $args['users_per_page'] ); - - } elseif( isset($args['number']) ) { - $this->per_page = intval($args['number']); - } - - if( isset($args['paged']) ) { - $this->page = intval($args['paged']); - unset( $args['paged'] ); - } - - // Set pagination args for fine control. - $args['number'] = $this->per_page; - $args['offset'] = $this->per_page * ($this->page - 1); - $args['count_total'] = true; - return $args; - } - - /** - * get_results - * - * Returns an array of results for the given args. - * - * @date 31/7/18 - * @since 5.7.2 - * - * @param array args The query args. - * @return array - */ - function get_results( $args ) { - $results = array(); - - // Prepare args for quey. - $args = $this->prepare_args( $args ); - - // Get result groups. - if( !empty( $args['role__in']) ) { - $roles = acf_get_user_role_labels( $args['role__in'] ); - } else { - $roles = acf_get_user_role_labels(); - } - - // Return a flat array of results when searching or when queriying one group only. - if( $this->is_search || count($roles) === 1 ) { - - // Query users and append to results. - $wp_user_query = new WP_User_Query( $args ); - $users = (array) $wp_user_query->get_results(); - $total_users = $wp_user_query->get_total(); - foreach( $users as $user ) { - $results[] = $this->get_result( $user ); - } - - // Determine if more results exist. - // As this query does not return grouped results, the calculation can be exact (">"). - $this->more = ( $total_users > count($users) + $args['offset'] ); - - // Otherwise, group results via role. - } else { - - // Unset args that will interfer with query results. - unset( $args['role__in'], $args['role__not_in'] ); - - // Loop over each role. - foreach( $roles as $role => $role_label ) { - - // Query users (for this role only). - $args['role'] = $role; - $wp_user_query = new WP_User_Query( $args ); - $users = (array) $wp_user_query->get_results(); - $total_users = $wp_user_query->get_total(); - - //acf_log( $args ); - //acf_log( '- ', count($users) ); - //acf_log( '- ', $total_users ); - - // If users were found for this query... - if( $users ) { - - // Append optgroup of results. - $role_results = array(); - foreach( $users as $user ) { - $role_results[] = $this->get_result( $user ); - } - $results[] = array( - 'text' => $role_label, - 'children' => $role_results - ); - - // End loop when enough results have been found. - if( count($users) === $args['number'] ) { - - // Determine if more results exist. - // As this query does return grouped results, the calculation is best left fuzzy to avoid querying the next group (">="). - $this->more = ( $total_users >= count($users) + $args['offset'] ); - break; - - // Otherwise, modify the args so that the next query can continue on correctly. - } else { - $args['offset'] = 0; - $args['number'] -= count($users); - } - - // If no users were found (for the current pagination args), but there were users found for previous pages... - // Modify the args so that the next query is offset slightly less (the number of total users) and can continue on correctly. - } elseif( $total_users ) { - $args['offset'] -= $total_users; - continue; - - // Ignore roles that will never return a result. - } else { - continue; - } - } - } - - /** - * Filters the query results. - * - * @date 21/5/19 - * @since 5.8.1 - * - * @param array $results The query results. - * @param array $args The query args. - * @param ACF_Ajax_Query $query The query object. - */ - return apply_filters( "acf/ajax/query_users/results", $results, $args, $this ); - } - - /** - * get_result - * - * Returns a single result for the given item object. - * - * @date 31/7/18 - * @since 5.7.2 - * - * @param mixed $item A single item from the queried results. - * @return string - */ - function get_result( $user ) { - $item = acf_get_user_result( $user ); - - /** - * Filters the result item. - * - * @date 21/5/19 - * @since 5.8.1 - * - * @param array $item The choice id and text. - * @param ACF_User $user The user object. - * @param ACF_Ajax_Query $query The query object. - */ - return apply_filters( "acf/ajax/query_users/result", $item, $user, $this ); - } - - /** - * Filters the WP_User_Query search columns. - * - * @date 9/3/20 - * @since 5.8.8 - * - * @param array $columns An array of column names to be searched. - * @param string $search The search term. - * @param WP_User_Query $WP_User_Query The WP_User_Query instance. - * @return array - */ - function filter_search_columns( $columns, $search, $WP_User_Query ) { - - /** - * Filters the column names to be searched. - * - * @date 21/5/19 - * @since 5.8.1 - * - * @param array $columns An array of column names to be searched. - * @param string $search The search term. - * @param WP_User_Query $WP_User_Query The WP_User_Query instance. - * @param ACF_Ajax_Query $query The query object. - */ - return apply_filters( "acf/ajax/query_users/search_columns", $columns, $search, $WP_User_Query, $this ); - } +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly } -acf_new_instance('ACF_Ajax_Query_Users'); +if ( ! class_exists( 'ACF_Ajax_Query_Users' ) ) : + + class ACF_Ajax_Query_Users extends ACF_Ajax_Query { + + /** @var string The AJAX action name. */ + var $action = 'acf/ajax/query_users'; + + /** + * init_request + * + * Called at the beginning of a request to setup properties. + * + * @date 23/5/19 + * @since 5.8.1 + * + * @param array $request The request args. + * @return void + */ + function init_request( $request ) { + parent::init_request( $request ); + + // Customize query. + add_filter( 'user_search_columns', array( $this, 'filter_search_columns' ), 10, 3 ); + + /** + * Fires when a request is made. + * + * @date 21/5/19 + * @since 5.8.1 + * + * @param array $request The query request. + * @param ACF_Ajax_Query $query The query object. + */ + do_action( 'acf/ajax/query_users/init', $request, $this ); + } + + /** + * get_args + * + * Returns an array of args for this query. + * + * @date 31/7/18 + * @since 5.7.2 + * + * @param array $request The request args. + * @return array + */ + function get_args( $request ) { + $args = parent::get_args( $request ); + $args['number'] = $this->per_page; + $args['paged'] = $this->page; + if ( $this->is_search ) { + $args['search'] = "*{$this->search}*"; + } + + /** + * Filters the query args. + * + * @date 21/5/19 + * @since 5.8.1 + * + * @param array $args The query args. + * @param array $request The query request. + * @param ACF_Ajax_Query $query The query object. + */ + return apply_filters( 'acf/ajax/query_users/args', $args, $request, $this ); + } + + /** + * Prepares args for the get_results() method. + * + * @date 23/3/20 + * @since 5.8.9 + * + * @param array args The query args. + * @return array + */ + function prepare_args( $args ) { + + // Parse pagination args that may have been modified. + if ( isset( $args['users_per_page'] ) ) { + $this->per_page = intval( $args['users_per_page'] ); + unset( $args['users_per_page'] ); + + } elseif ( isset( $args['number'] ) ) { + $this->per_page = intval( $args['number'] ); + } + + if ( isset( $args['paged'] ) ) { + $this->page = intval( $args['paged'] ); + unset( $args['paged'] ); + } + + // Set pagination args for fine control. + $args['number'] = $this->per_page; + $args['offset'] = $this->per_page * ( $this->page - 1 ); + $args['count_total'] = true; + return $args; + } + + /** + * get_results + * + * Returns an array of results for the given args. + * + * @date 31/7/18 + * @since 5.7.2 + * + * @param array args The query args. + * @return array + */ + function get_results( $args ) { + $results = array(); + + // Prepare args for quey. + $args = $this->prepare_args( $args ); + + // Get result groups. + if ( ! empty( $args['role__in'] ) ) { + $roles = acf_get_user_role_labels( $args['role__in'] ); + } else { + $roles = acf_get_user_role_labels(); + } + + // Return a flat array of results when searching or when queriying one group only. + if ( $this->is_search || count( $roles ) === 1 ) { + + // Query users and append to results. + $wp_user_query = new WP_User_Query( $args ); + $users = (array) $wp_user_query->get_results(); + $total_users = $wp_user_query->get_total(); + foreach ( $users as $user ) { + $results[] = $this->get_result( $user ); + } + + // Determine if more results exist. + // As this query does not return grouped results, the calculation can be exact (">"). + $this->more = ( $total_users > count( $users ) + $args['offset'] ); + + // Otherwise, group results via role. + } else { + + // Unset args that will interfer with query results. + unset( $args['role__in'], $args['role__not_in'] ); + + // Loop over each role. + foreach ( $roles as $role => $role_label ) { + + // Query users (for this role only). + $args['role'] = $role; + $wp_user_query = new WP_User_Query( $args ); + $users = (array) $wp_user_query->get_results(); + $total_users = $wp_user_query->get_total(); + + // acf_log( $args ); + // acf_log( '- ', count($users) ); + // acf_log( '- ', $total_users ); + + // If users were found for this query... + if ( $users ) { + + // Append optgroup of results. + $role_results = array(); + foreach ( $users as $user ) { + $role_results[] = $this->get_result( $user ); + } + $results[] = array( + 'text' => $role_label, + 'children' => $role_results, + ); + + // End loop when enough results have been found. + if ( count( $users ) === $args['number'] ) { + + // Determine if more results exist. + // As this query does return grouped results, the calculation is best left fuzzy to avoid querying the next group (">="). + $this->more = ( $total_users >= count( $users ) + $args['offset'] ); + break; + + // Otherwise, modify the args so that the next query can continue on correctly. + } else { + $args['offset'] = 0; + $args['number'] -= count( $users ); + } + + // If no users were found (for the current pagination args), but there were users found for previous pages... + // Modify the args so that the next query is offset slightly less (the number of total users) and can continue on correctly. + } elseif ( $total_users ) { + $args['offset'] -= $total_users; + continue; + + // Ignore roles that will never return a result. + } else { + continue; + } + } + } + + /** + * Filters the query results. + * + * @date 21/5/19 + * @since 5.8.1 + * + * @param array $results The query results. + * @param array $args The query args. + * @param ACF_Ajax_Query $query The query object. + */ + return apply_filters( 'acf/ajax/query_users/results', $results, $args, $this ); + } + + /** + * get_result + * + * Returns a single result for the given item object. + * + * @date 31/7/18 + * @since 5.7.2 + * + * @param mixed $item A single item from the queried results. + * @return string + */ + function get_result( $user ) { + $item = acf_get_user_result( $user ); + + /** + * Filters the result item. + * + * @date 21/5/19 + * @since 5.8.1 + * + * @param array $item The choice id and text. + * @param ACF_User $user The user object. + * @param ACF_Ajax_Query $query The query object. + */ + return apply_filters( 'acf/ajax/query_users/result', $item, $user, $this ); + } + + /** + * Filters the WP_User_Query search columns. + * + * @date 9/3/20 + * @since 5.8.8 + * + * @param array $columns An array of column names to be searched. + * @param string $search The search term. + * @param WP_User_Query $WP_User_Query The WP_User_Query instance. + * @return array + */ + function filter_search_columns( $columns, $search, $WP_User_Query ) { + + /** + * Filters the column names to be searched. + * + * @date 21/5/19 + * @since 5.8.1 + * + * @param array $columns An array of column names to be searched. + * @param string $search The search term. + * @param WP_User_Query $WP_User_Query The WP_User_Query instance. + * @param ACF_Ajax_Query $query The query object. + */ + return apply_filters( 'acf/ajax/query_users/search_columns', $columns, $search, $WP_User_Query, $this ); + } + } + + acf_new_instance( 'ACF_Ajax_Query_Users' ); endif; // class_exists check diff --git a/includes/ajax/class-acf-ajax-query.php b/includes/ajax/class-acf-ajax-query.php index 026b05a..dd1bfe6 100644 --- a/includes/ajax/class-acf-ajax-query.php +++ b/includes/ajax/class-acf-ajax-query.php @@ -1,150 +1,152 @@ init_request( $request ); - - // Get query args. - $args = $this->get_args( $request ); - - // Get query results. - $results = $this->get_results( $args ); - if( is_wp_error($results) ) { - return $results; - } - - // Return response. - return array( - 'results' => $results, - 'more' => $this->more - ); - } - - /** - * init_request - * - * Called at the beginning of a request to setup properties. - * - * @date 23/5/19 - * @since 5.8.1 - * - * @param array $request The request args. - * @return void - */ - function init_request( $request ) { - - // Get field for this query. - if( isset($request['field_key']) ) { - $this->field = acf_get_field( $request['field_key'] ); - } - - // Update query properties. - if( isset($request['page']) ) { - $this->page = intval($request['page']); - } - if( isset($request['per_page']) ) { - $this->per_page = intval($request['per_page']); - } - if( isset($request['search']) && acf_not_empty($request['search']) ) { - $this->search = sanitize_text_field($request['search']); - $this->is_search = true; - } - if( isset($request['post_id']) ) { - $this->post_id = $request['post_id']; - } - } - - /** - * get_args - * - * Returns an array of args for this query. - * - * @date 31/7/18 - * @since 5.7.2 - * - * @param array $request The request args. - * @return array - */ - function get_args( $request ) { - - // Allow for custom "query" arg. - if( isset($request['query']) ) { - return (array) $request['query']; - } - return array(); - } - - /** - * get_items - * - * Returns an array of results for the given args. - * - * @date 31/7/18 - * @since 5.7.2 - * - * @param array args The query args. - * @return array - */ - function get_results( $args ) { - return array(); - } - - /** - * get_item - * - * Returns a single result for the given item object. - * - * @date 31/7/18 - * @since 5.7.2 - * - * @param mixed $item A single item from the queried results. - * @return array An array containing "id" and "text". - */ - function get_result( $item ) { - return false; - } +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly } +if ( ! class_exists( 'ACF_Ajax_Query' ) ) : + + class ACF_Ajax_Query extends ACF_Ajax { + + /** @var bool Prevents access for non-logged in users. */ + var $public = true; + + /** @var int The page of results to return. */ + var $page = 1; + + /** @var int The number of results per page. */ + var $per_page = 20; + + /** @var bool Signifies whether or not this AJAX query has more pages to load. */ + var $more = false; + + /** @var string The searched term. */ + var $search = ''; + + /** @var bool Signifies whether the current query is a search. */ + var $is_search = false; + + /** @var (int|string) The post_id being edited. */ + var $post_id = 0; + + /** @var array The ACF field related to this query. */ + var $field = false; + + /** + * get_response + * + * Returns the response data to sent back. + * + * @date 31/7/18 + * @since 5.7.2 + * + * @param array $request The request args. + * @return (array|WP_Error) The response data or WP_Error. + */ + function get_response( $request ) { + + // Init request. + $this->init_request( $request ); + + // Get query args. + $args = $this->get_args( $request ); + + // Get query results. + $results = $this->get_results( $args ); + if ( is_wp_error( $results ) ) { + return $results; + } + + // Return response. + return array( + 'results' => $results, + 'more' => $this->more, + ); + } + + /** + * init_request + * + * Called at the beginning of a request to setup properties. + * + * @date 23/5/19 + * @since 5.8.1 + * + * @param array $request The request args. + * @return void + */ + function init_request( $request ) { + + // Get field for this query. + if ( isset( $request['field_key'] ) ) { + $this->field = acf_get_field( $request['field_key'] ); + } + + // Update query properties. + if ( isset( $request['page'] ) ) { + $this->page = intval( $request['page'] ); + } + if ( isset( $request['per_page'] ) ) { + $this->per_page = intval( $request['per_page'] ); + } + if ( isset( $request['search'] ) && acf_not_empty( $request['search'] ) ) { + $this->search = sanitize_text_field( $request['search'] ); + $this->is_search = true; + } + if ( isset( $request['post_id'] ) ) { + $this->post_id = $request['post_id']; + } + } + + /** + * get_args + * + * Returns an array of args for this query. + * + * @date 31/7/18 + * @since 5.7.2 + * + * @param array $request The request args. + * @return array + */ + function get_args( $request ) { + + // Allow for custom "query" arg. + if ( isset( $request['query'] ) ) { + return (array) $request['query']; + } + return array(); + } + + /** + * get_items + * + * Returns an array of results for the given args. + * + * @date 31/7/18 + * @since 5.7.2 + * + * @param array args The query args. + * @return array + */ + function get_results( $args ) { + return array(); + } + + /** + * get_item + * + * Returns a single result for the given item object. + * + * @date 31/7/18 + * @since 5.7.2 + * + * @param mixed $item A single item from the queried results. + * @return array An array containing "id" and "text". + */ + function get_result( $item ) { + return false; + } + } + endif; // class_exists check diff --git a/includes/ajax/class-acf-ajax-upgrade.php b/includes/ajax/class-acf-ajax-upgrade.php index 2f08e53..b01452b 100644 --- a/includes/ajax/class-acf-ajax-upgrade.php +++ b/includes/ajax/class-acf-ajax-upgrade.php @@ -1,54 +1,56 @@ has('value') ) { - return acf_update_user_setting( $this->get('name'), $this->get('value') ); - - // get - } else { - return acf_get_user_setting( $this->get('name') ); - } - } +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly } -acf_new_instance('ACF_Ajax_User_Setting'); +if ( ! class_exists( 'ACF_Ajax_User_Setting' ) ) : + + class ACF_Ajax_User_Setting extends ACF_Ajax { + + /** @var string The AJAX action name. */ + var $action = 'acf/ajax/user_setting'; + + /** @var bool Prevents access for non-logged in users. */ + var $public = true; + + /** + * get_response + * + * Returns the response data to sent back. + * + * @date 31/7/18 + * @since 5.7.2 + * + * @param array $request The request args. + * @return mixed The response data or WP_Error. + */ + function get_response( $request ) { + + // update + if ( $this->has( 'value' ) ) { + return acf_update_user_setting( $this->get( 'name' ), $this->get( 'value' ) ); + + // get + } else { + return acf_get_user_setting( $this->get( 'name' ) ); + } + } + } + + acf_new_instance( 'ACF_Ajax_User_Setting' ); endif; // class_exists check diff --git a/includes/ajax/class-acf-ajax.php b/includes/ajax/class-acf-ajax.php index ed09791..9894bb7 100644 --- a/includes/ajax/class-acf-ajax.php +++ b/includes/ajax/class-acf-ajax.php @@ -1,227 +1,232 @@ initialize(); - $this->add_actions(); - } - - /** - * has - * - * Returns true if the request has data for the given key. - * - * @date 31/7/18 - * @since 5.7.2 - * - * @param string $key The data key. - * @return boolean - */ - function has( $key = '' ) { - return isset($this->request[$key]); - } - - /** - * get - * - * Returns request data for the given key. - * - * @date 31/7/18 - * @since 5.7.2 - * - * @param string $key The data key. - * @return mixed - */ - function get( $key = '' ) { - return isset($this->request[$key]) ? $this->request[$key] : null; - } - - /** - * Sets request data for the given key. - * - * @date 31/7/18 - * @since 5.7.2 - * - * @param string $key The data key. - * @param mixed $value The data value. - * @return ACF_Ajax - */ - function set( $key = '', $value = null ) { - $this->request[$key] = $value; - return $this; - } - - /** - * initialize - * - * Allows easy access to modifying properties without changing constructor. - * - * @date 31/7/18 - * @since 5.7.2 - * - * @param void - * @return void - */ - function initialize() { - /* do nothing */ - } - - /** - * add_actions - * - * Adds the ajax actions for this response. - * - * @date 31/7/18 - * @since 5.7.2 - * - * @param void - * @return void - */ - function add_actions() { - - // add action for logged-in users - add_action( "wp_ajax_{$this->action}", array($this, 'request') ); - - // add action for non logged-in users - if( $this->public ) { - add_action( "wp_ajax_nopriv_{$this->action}", array($this, 'request') ); - } - } - - /** - * request - * - * Callback for ajax action. Sets up properties and calls the get_response() function. - * - * @date 1/8/18 - * @since 5.7.2 - * - * @param void - * @return void - */ - function request() { - - // Store data for has() and get() functions. - $this->request = wp_unslash($_REQUEST); - - // Verify request and handle error. - $error = $this->verify_request( $this->request ); - if( is_wp_error( $error ) ) { - $this->send( $error ); - } - - // Send response. - $this->send( $this->get_response( $this->request ) ); - } - - /** - * Verifies the request. - * - * @date 9/3/20 - * @since 5.8.8 - * - * @param array $request The request args. - * @return (bool|WP_Error) True on success, WP_Error on fail. - */ - function verify_request( $request ) { - - // Verify nonce. - if( !acf_verify_ajax() ) { - return new WP_Error( 'acf_invalid_nonce', __( 'Invalid nonce.', 'acf' ), array( 'status' => 404 ) ); - } - return true; - } - - /** - * get_response - * - * Returns the response data to sent back. - * - * @date 31/7/18 - * @since 5.7.2 - * - * @param array $request The request args. - * @return mixed The response data or WP_Error. - */ - function get_response( $request ) { - return true; - } - - /** - * send - * - * Sends back JSON based on the $response as either success or failure. - * - * @date 31/7/18 - * @since 5.7.2 - * - * @param mixed $response The response to send back. - * @return void - */ - function send( $response ) { - - // Return error. - if( is_wp_error($response) ) { - $this->send_error( $response ); - - // Return success. - } else { - wp_send_json( $response ); - } - } - - /** - * Sends a JSON response for the given WP_Error object. - * - * @date 8/3/20 - * @since 5.8.8 - * - * @param WP_Error error The error object. - * @return void - */ - function send_error( $error ) { - - // Get error status - $error_data = $error->get_error_data(); - if( is_array($error_data) && isset($error_data['status']) ) { - $status_code = $error_data['status']; - } else { - $status_code = 500; - } - - wp_send_json(array( - 'code' => $error->get_error_code(), - 'message' => $error->get_error_message(), - 'data' => $error->get_error_data() - ), $status_code); - } +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly } +if ( ! class_exists( 'ACF_Ajax' ) ) : + + class ACF_Ajax { + + /** @var string The AJAX action name. */ + var $action = ''; + + /** @var array The $_REQUEST data. */ + var $request; + + /** @var bool Prevents access for non-logged in users. */ + var $public = false; + + /** + * __construct + * + * Sets up the class functionality. + * + * @date 31/7/18 + * @since 5.7.2 + * + * @param void + * @return void + */ + function __construct() { + $this->initialize(); + $this->add_actions(); + } + + /** + * has + * + * Returns true if the request has data for the given key. + * + * @date 31/7/18 + * @since 5.7.2 + * + * @param string $key The data key. + * @return boolean + */ + function has( $key = '' ) { + return isset( $this->request[ $key ] ); + } + + /** + * get + * + * Returns request data for the given key. + * + * @date 31/7/18 + * @since 5.7.2 + * + * @param string $key The data key. + * @return mixed + */ + function get( $key = '' ) { + return isset( $this->request[ $key ] ) ? $this->request[ $key ] : null; + } + + /** + * Sets request data for the given key. + * + * @date 31/7/18 + * @since 5.7.2 + * + * @param string $key The data key. + * @param mixed $value The data value. + * @return ACF_Ajax + */ + function set( $key = '', $value = null ) { + $this->request[ $key ] = $value; + return $this; + } + + /** + * initialize + * + * Allows easy access to modifying properties without changing constructor. + * + * @date 31/7/18 + * @since 5.7.2 + * + * @param void + * @return void + */ + function initialize() { + /* do nothing */ + } + + /** + * add_actions + * + * Adds the ajax actions for this response. + * + * @date 31/7/18 + * @since 5.7.2 + * + * @param void + * @return void + */ + function add_actions() { + + // add action for logged-in users + add_action( "wp_ajax_{$this->action}", array( $this, 'request' ) ); + + // add action for non logged-in users + if ( $this->public ) { + add_action( "wp_ajax_nopriv_{$this->action}", array( $this, 'request' ) ); + } + } + + /** + * request + * + * Callback for ajax action. Sets up properties and calls the get_response() function. + * + * @date 1/8/18 + * @since 5.7.2 + * + * @param void + * @return void + */ + function request() { + + // Store data for has() and get() functions. + $this->request = wp_unslash( $_REQUEST ); + + // Verify request and handle error. + $error = $this->verify_request( $this->request ); + if ( is_wp_error( $error ) ) { + $this->send( $error ); + } + + // Send response. + $this->send( $this->get_response( $this->request ) ); + } + + /** + * Verifies the request. + * + * @date 9/3/20 + * @since 5.8.8 + * + * @param array $request The request args. + * @return (bool|WP_Error) True on success, WP_Error on fail. + */ + function verify_request( $request ) { + + // Verify nonce. + if ( ! acf_verify_ajax() ) { + return new WP_Error( 'acf_invalid_nonce', __( 'Invalid nonce.', 'acf' ), array( 'status' => 404 ) ); + } + return true; + } + + /** + * get_response + * + * Returns the response data to sent back. + * + * @date 31/7/18 + * @since 5.7.2 + * + * @param array $request The request args. + * @return mixed The response data or WP_Error. + */ + function get_response( $request ) { + return true; + } + + /** + * send + * + * Sends back JSON based on the $response as either success or failure. + * + * @date 31/7/18 + * @since 5.7.2 + * + * @param mixed $response The response to send back. + * @return void + */ + function send( $response ) { + + // Return error. + if ( is_wp_error( $response ) ) { + $this->send_error( $response ); + + // Return success. + } else { + wp_send_json( $response ); + } + } + + /** + * Sends a JSON response for the given WP_Error object. + * + * @date 8/3/20 + * @since 5.8.8 + * + * @param WP_Error error The error object. + * @return void + */ + function send_error( $error ) { + + // Get error status + $error_data = $error->get_error_data(); + if ( is_array( $error_data ) && isset( $error_data['status'] ) ) { + $status_code = $error_data['status']; + } else { + $status_code = 500; + } + + wp_send_json( + array( + 'code' => $error->get_error_code(), + 'message' => $error->get_error_message(), + 'data' => $error->get_error_data(), + ), + $status_code + ); + } + } + endif; // class_exists check -?> \ No newline at end of file + diff --git a/includes/api/api-helpers.php b/includes/api/api-helpers.php index 1ef5cd8..ae9884e 100644 --- a/includes/api/api-helpers.php +++ b/includes/api/api-helpers.php @@ -1,35 +1,35 @@ -has_setting() -* -* @date 2/2/18 -* @since 5.6.5 -* -* @param n/a -* @return n/a -*/ + * acf_has_setting + * + * alias of acf()->has_setting() + * + * @date 2/2/18 + * @since 5.6.5 + * + * @param n/a + * @return n/a + */ function acf_has_setting( $name = '' ) { return acf()->has_setting( $name ); @@ -37,16 +37,16 @@ function acf_has_setting( $name = '' ) { /** -* acf_raw_setting -* -* alias of acf()->get_setting() -* -* @date 2/2/18 -* @since 5.6.5 -* -* @param n/a -* @return n/a -*/ + * acf_raw_setting + * + * alias of acf()->get_setting() + * + * @date 2/2/18 + * @since 5.6.5 + * + * @param n/a + * @return n/a + */ function acf_raw_setting( $name = '' ) { return acf()->get_setting( $name ); @@ -58,39 +58,39 @@ function acf_raw_setting( $name = '' ) { * * alias of acf()->update_setting() * -* @type function -* @date 28/09/13 -* @since 5.0.0 +* @type function +* @date 28/09/13 +* @since 5.0.0 * -* @param $name (string) -* @param $value (mixed) -* @return n/a +* @param $name (string) +* @param $value (mixed) +* @return n/a */ function acf_update_setting( $name, $value ) { - + // validate name $name = acf_validate_setting( $name ); - + // update return acf()->update_setting( $name, $value ); } /** -* acf_validate_setting -* -* Returns the changed setting name if available. -* -* @date 2/2/18 -* @since 5.6.5 -* -* @param n/a -* @return n/a -*/ + * acf_validate_setting + * + * Returns the changed setting name if available. + * + * @date 2/2/18 + * @since 5.6.5 + * + * @param n/a + * @return n/a + */ function acf_validate_setting( $name = '' ) { - return apply_filters( "acf/validate_setting", $name ); + return apply_filters( 'acf/validate_setting', $name ); } @@ -99,27 +99,27 @@ function acf_validate_setting( $name = '' ) { * * alias of acf()->get_setting() * -* @type function -* @date 28/09/13 -* @since 5.0.0 +* @type function +* @date 28/09/13 +* @since 5.0.0 * -* @param n/a -* @return n/a +* @param n/a +* @return n/a */ function acf_get_setting( $name, $value = null ) { - + // validate name $name = acf_validate_setting( $name ); - + // check settings - if( acf_has_setting($name) ) { + if ( acf_has_setting( $name ) ) { $value = acf_raw_setting( $name ); } - + // filter $value = apply_filters( "acf/settings/{$name}", $value ); - + // return return $value; } @@ -130,44 +130,44 @@ function acf_get_setting( $name, $value = null ) { * * This function will add a value into the settings array found in the acf object * -* @type function -* @date 28/09/13 -* @since 5.0.0 +* @type function +* @date 28/09/13 +* @since 5.0.0 * -* @param $name (string) -* @param $value (mixed) -* @return n/a +* @param $name (string) +* @param $value (mixed) +* @return n/a */ function acf_append_setting( $name, $value ) { - + // vars $setting = acf_raw_setting( $name ); - + // bail ealry if not array - if( !is_array($setting) ) { + if ( ! is_array( $setting ) ) { $setting = array(); } - + // append $setting[] = $value; - + // update return acf_update_setting( $name, $setting ); } /** -* acf_get_data -* -* Returns data. -* -* @date 28/09/13 -* @since 5.0.0 -* -* @param string $name -* @return mixed -*/ + * acf_get_data + * + * Returns data. + * + * @date 28/09/13 + * @since 5.0.0 + * + * @param string $name + * @return mixed + */ function acf_get_data( $name ) { return acf()->get_data( $name ); @@ -175,17 +175,17 @@ function acf_get_data( $name ) { /** -* acf_set_data -* -* Sets data. -* -* @date 28/09/13 -* @since 5.0.0 -* -* @param string $name -* @param mixed $value -* @return n/a -*/ + * acf_set_data + * + * Sets data. + * + * @date 28/09/13 + * @since 5.0.0 + * + * @param string $name + * @param mixed $value + * @return n/a + */ function acf_set_data( $name, $value ) { return acf()->set_data( $name, $value ); @@ -194,15 +194,15 @@ function acf_set_data( $name, $value ) { /** * Appends data to an existing key. * - * @date 11/06/2020 - * @since 5.9.0 + * @date 11/06/2020 + * @since 5.9.0 * - * @param string $name The data name. - * @return array $data The data array. + * @param string $name The data name. + * @return array $data The data array. */ function acf_append_data( $name, $data ) { $prev_data = acf()->get_data( $name ); - if( is_array($prev_data) ) { + if ( is_array( $prev_data ) ) { $data = array_merge( $prev_data, $data ); } acf()->set_data( $name, $data ); @@ -213,18 +213,18 @@ function acf_append_data( $name, $data ) { * * alias of acf()->init() * -* @type function -* @date 28/09/13 -* @since 5.0.0 +* @type function +* @date 28/09/13 +* @since 5.0.0 * -* @param n/a -* @return n/a +* @param n/a +* @return n/a */ function acf_init() { - + acf()->init(); - + } @@ -233,23 +233,23 @@ function acf_init() { * * This function will return true if this action has already been done * -* @type function -* @date 16/12/2015 -* @since 5.3.2 +* @type function +* @date 16/12/2015 +* @since 5.3.2 * -* @param $name (string) -* @return (boolean) +* @param $name (string) +* @return (boolean) */ function acf_has_done( $name ) { - + // return true if already done - if( acf_raw_setting("has_done_{$name}") ) { + if ( acf_raw_setting( "has_done_{$name}" ) ) { return true; } - + // update setting and return - acf_update_setting("has_done_{$name}", true); + acf_update_setting( "has_done_{$name}", true ); return false; } @@ -261,19 +261,19 @@ function acf_has_done( $name ) { * * This function will return the path to a file within an external folder * -* @type function -* @date 22/2/17 -* @since 5.5.8 +* @type function +* @date 22/2/17 +* @since 5.5.8 * -* @param $file (string) -* @param $path (string) -* @return (string) +* @param $file (string) +* @param $path (string) +* @return (string) */ function acf_get_external_path( $file, $path = '' ) { - - return plugin_dir_path( $file ) . $path; - + + return plugin_dir_path( $file ) . $path; + } @@ -282,64 +282,62 @@ function acf_get_external_path( $file, $path = '' ) { * * This function will return the url to a file within an external folder * -* @type function -* @date 22/2/17 -* @since 5.5.8 +* @type function +* @date 22/2/17 +* @since 5.5.8 * -* @param $file (string) -* @param $path (string) -* @return (string) +* @param $file (string) +* @param $path (string) +* @return (string) */ function acf_get_external_dir( $file, $path = '' ) { - - return acf_plugin_dir_url( $file ) . $path; - + + return acf_plugin_dir_url( $file ) . $path; + } /** -* acf_plugin_dir_url -* -* This function will calculate the url to a plugin folder. -* Different to the WP plugin_dir_url(), this function can calculate for urls outside of the plugins folder (theme include). -* -* @date 13/12/17 -* @since 5.6.8 -* -* @param type $var Description. Default. -* @return type Description. -*/ + * acf_plugin_dir_url + * + * This function will calculate the url to a plugin folder. + * Different to the WP plugin_dir_url(), this function can calculate for urls outside of the plugins folder (theme include). + * + * @date 13/12/17 + * @since 5.6.8 + * + * @param type $var Description. Default. + * @return type Description. + */ function acf_plugin_dir_url( $file ) { - + // vars $path = plugin_dir_path( $file ); $path = wp_normalize_path( $path ); - - + // check plugins - $check_path = wp_normalize_path( realpath(WP_PLUGIN_DIR) ); - if( strpos($path, $check_path) === 0 ) { + $check_path = wp_normalize_path( realpath( WP_PLUGIN_DIR ) ); + if ( strpos( $path, $check_path ) === 0 ) { return str_replace( $check_path, plugins_url(), $path ); } - + // check wp-content - $check_path = wp_normalize_path( realpath(WP_CONTENT_DIR) ); - if( strpos($path, $check_path) === 0 ) { + $check_path = wp_normalize_path( realpath( WP_CONTENT_DIR ) ); + if ( strpos( $path, $check_path ) === 0 ) { return str_replace( $check_path, content_url(), $path ); } - + // check root - $check_path = wp_normalize_path( realpath(ABSPATH) ); - if( strpos($path, $check_path) === 0 ) { - return str_replace( $check_path, site_url('/'), $path ); + $check_path = wp_normalize_path( realpath( ABSPATH ) ); + if ( strpos( $path, $check_path ) === 0 ) { + return str_replace( $check_path, site_url( '/' ), $path ); } - - - // return - return plugin_dir_url( $file ); - + + // return + return plugin_dir_url( $file ); + } @@ -348,28 +346,26 @@ function acf_plugin_dir_url( $file ) { * * This function will merge together 2 arrays and also convert any numeric values to ints * -* @type function -* @date 18/10/13 -* @since 5.0.0 +* @type function +* @date 18/10/13 +* @since 5.0.0 * -* @param $args (array) -* @param $defaults (array) -* @return $args (array) +* @param $args (array) +* @param $defaults (array) +* @return $args (array) */ function acf_parse_args( $args, $defaults = array() ) { - + // parse args $args = wp_parse_args( $args, $defaults ); - - + // parse types $args = acf_parse_types( $args ); - - + // return return $args; - + } @@ -378,12 +374,12 @@ function acf_parse_args( $args, $defaults = array() ) { * * This function will convert any numeric values to int and trim strings * -* @type function -* @date 18/10/13 -* @since 5.0.0 +* @type function +* @date 18/10/13 +* @since 5.0.0 * -* @param $var (mixed) -* @return $var (mixed) +* @param $var (mixed) +* @return $var (mixed) */ function acf_parse_types( $array ) { @@ -396,28 +392,28 @@ function acf_parse_types( $array ) { * * description * -* @type function -* @date 11/11/2014 -* @since 5.0.9 +* @type function +* @date 11/11/2014 +* @since 5.0.9 * -* @param $post_id (int) -* @return $post_id (int) +* @param $post_id (int) +* @return $post_id (int) */ function acf_parse_type( $v ) { - + // Check if is string. - if( is_string($v) ) { - + if ( is_string( $v ) ) { + // Trim ("Word " = "Word"). $v = trim( $v ); - + // Convert int strings to int ("123" = 123). - if( is_numeric($v) && strval(intval($v)) === $v ) { + if ( is_numeric( $v ) && strval( intval( $v ) ) === $v ) { $v = intval( $v ); } } - + // return. return $v; } @@ -428,33 +424,32 @@ function acf_parse_type( $v ) { * * This function will load in a file from the 'admin/views' folder and allow variables to be passed through * -* @type function -* @date 28/09/13 -* @since 5.0.0 +* @type function +* @date 28/09/13 +* @since 5.0.0 * -* @param $view_name (string) -* @param $args (array) -* @return n/a +* @param $view_name (string) +* @param $args (array) +* @return n/a */ function acf_get_view( $path = '', $args = array() ) { - + // allow view file name shortcut - if( substr($path, -4) !== '.php' ) { - - $path = acf_get_path("includes/admin/views/{$path}.php"); - + if ( substr( $path, -4 ) !== '.php' ) { + + $path = acf_get_path( "includes/admin/views/{$path}.php" ); + } - - + // include - if( file_exists($path) ) { - + if ( file_exists( $path ) ) { + extract( $args ); - include( $path ); - + include $path; + } - + } @@ -463,46 +458,44 @@ function acf_get_view( $path = '', $args = array() ) { * * description * -* @type function -* @date 2/11/2014 -* @since 5.0.9 +* @type function +* @date 2/11/2014 +* @since 5.0.9 * -* @param $post_id (int) -* @return $post_id (int) +* @param $post_id (int) +* @return $post_id (int) */ function acf_merge_atts( $atts, $extra = array() ) { - + // bail ealry if no $extra - if( empty($extra) ) return $atts; - - - // trim - $extra = array_map('trim', $extra); - $extra = array_filter($extra); - - - // merge in new atts - foreach( $extra as $k => $v ) { - - // append - if( $k == 'class' || $k == 'style' ) { - - $atts[ $k ] .= ' ' . $v; - - // merge - } else { - - $atts[ $k ] = $v; - - } - + if ( empty( $extra ) ) { + return $atts; } - - + + // trim + $extra = array_map( 'trim', $extra ); + $extra = array_filter( $extra ); + + // merge in new atts + foreach ( $extra as $k => $v ) { + + // append + if ( $k == 'class' || $k == 'style' ) { + + $atts[ $k ] .= ' ' . $v; + + // merge + } else { + + $atts[ $k ] = $v; + + } + } + // return return $atts; - + } @@ -511,18 +504,18 @@ function acf_merge_atts( $atts, $extra = array() ) { * * This function will create a basic nonce input * -* @type function -* @date 24/5/17 -* @since 5.6.0 +* @type function +* @date 24/5/17 +* @since 5.6.0 * -* @param $post_id (int) -* @return $post_id (int) +* @param $post_id (int) +* @return $post_id (int) */ function acf_nonce_input( $nonce = '' ) { - + echo ''; - + } @@ -531,35 +524,32 @@ function acf_nonce_input( $nonce = '' ) { * * This function will remove the var from the array, and return the var * -* @type function -* @date 2/10/13 -* @since 5.0.0 +* @type function +* @date 2/10/13 +* @since 5.0.0 * -* @param $array (array) -* @param $key (string) -* @return (mixed) +* @param $array (array) +* @param $key (string) +* @return (mixed) */ function acf_extract_var( &$array, $key, $default = null ) { - + // check if exists // - uses array_key_exists to extract NULL values (isset will fail) - if( is_array($array) && array_key_exists($key, $array) ) { - + if ( is_array( $array ) && array_key_exists( $key, $array ) ) { + // store value $v = $array[ $key ]; - - + // unset unset( $array[ $key ] ); - - + // return return $v; - + } - - + // return return $default; } @@ -570,24 +560,24 @@ function acf_extract_var( &$array, $key, $default = null ) { * * This function will remove the vars from the array, and return the vars * -* @type function -* @date 8/10/13 -* @since 5.0.0 +* @type function +* @date 8/10/13 +* @since 5.0.0 * -* @param $post_id (int) -* @return $post_id (int) +* @param $post_id (int) +* @return $post_id (int) */ function acf_extract_vars( &$array, $keys ) { - + $r = array(); - - foreach( $keys as $key ) { - + + foreach ( $keys as $key ) { + $r[ $key ] = acf_extract_var( $array, $key ); - + } - + return $r; } @@ -597,129 +587,127 @@ function acf_extract_vars( &$array, $keys ) { * * This function will return a sub array of data * -* @type function -* @date 15/03/2016 -* @since 5.3.2 +* @type function +* @date 15/03/2016 +* @since 5.3.2 * -* @param $post_id (int) -* @return $post_id (int) +* @param $post_id (int) +* @return $post_id (int) */ function acf_get_sub_array( $array, $keys ) { - + $r = array(); - - foreach( $keys as $key ) { - + + foreach ( $keys as $key ) { + $r[ $key ] = $array[ $key ]; - + } - + return $r; - + } /** -* acf_get_post_types -* -* Returns an array of post type names. -* -* @date 7/10/13 -* @since 5.0.0 -* -* @param array $args Optional. An array of key => value arguments to match against the post type objects. Default empty array. -* @return array A list of post type names. -*/ + * acf_get_post_types + * + * Returns an array of post type names. + * + * @date 7/10/13 + * @since 5.0.0 + * + * @param array $args Optional. An array of key => value arguments to match against the post type objects. Default empty array. + * @return array A list of post type names. + */ function acf_get_post_types( $args = array() ) { - + // vars $post_types = array(); - + // extract special arg - $exclude = acf_extract_var( $args, 'exclude', array() ); + $exclude = acf_extract_var( $args, 'exclude', array() ); $exclude[] = 'acf-field'; $exclude[] = 'acf-field-group'; - + // get post type objects $objects = get_post_types( $args, 'objects' ); - + // loop - foreach( $objects as $i => $object ) { - + foreach ( $objects as $i => $object ) { + // bail early if is exclude - if( in_array($i, $exclude) ) continue; - + if ( in_array( $i, $exclude ) ) { + continue; + } + // bail early if is builtin (WP) private post type // - nav_menu_item, revision, customize_changeset, etc - if( $object->_builtin && !$object->public ) continue; - + if ( $object->_builtin && ! $object->public ) { + continue; + } + // append $post_types[] = $i; } - + // filter - $post_types = apply_filters('acf/get_post_types', $post_types, $args); - + $post_types = apply_filters( 'acf/get_post_types', $post_types, $args ); + // return return $post_types; } function acf_get_pretty_post_types( $post_types = array() ) { - + // get post types - if( empty($post_types) ) { - + if ( empty( $post_types ) ) { + // get all custom post types $post_types = acf_get_post_types(); - + } - - + // get labels $ref = array(); - $r = array(); - - foreach( $post_types as $post_type ) { - + $r = array(); + + foreach ( $post_types as $post_type ) { + // vars - $label = acf_get_post_type_label($post_type); - - + $label = acf_get_post_type_label( $post_type ); + // append to r $r[ $post_type ] = $label; - - + // increase counter - if( !isset($ref[ $label ]) ) { - + if ( ! isset( $ref[ $label ] ) ) { + $ref[ $label ] = 0; - + } - + $ref[ $label ]++; } - - + // get slugs - foreach( array_keys($r) as $i ) { - + foreach ( array_keys( $r ) as $i ) { + // vars $post_type = $r[ $i ]; - - if( $ref[ $post_type ] > 1 ) { - + + if ( $ref[ $post_type ] > 1 ) { + $r[ $i ] .= ' (' . $i . ')'; - + } - } - - + // return return $r; - + } @@ -729,33 +717,31 @@ function acf_get_pretty_post_types( $post_types = array() ) { * * This function will return a pretty label for a specific post_type * -* @type function -* @date 5/07/2016 -* @since 5.4.0 +* @type function +* @date 5/07/2016 +* @since 5.4.0 * -* @param $post_type (string) -* @return (string) +* @param $post_type (string) +* @return (string) */ function acf_get_post_type_label( $post_type ) { - + // vars $label = $post_type; - - + // check that object exists // - case exists when importing field group from another install and post type does not exist - if( post_type_exists($post_type) ) { - - $obj = get_post_type_object($post_type); + if ( post_type_exists( $post_type ) ) { + + $obj = get_post_type_object( $post_type ); $label = $obj->labels->singular_name; - + } - - + // return return $label; - + } @@ -764,31 +750,30 @@ function acf_get_post_type_label( $post_type ) { * * This function will look at the $_POST['_acf_nonce'] value and return true or false * -* @type function -* @date 15/10/13 -* @since 5.0.0 +* @type function +* @date 15/10/13 +* @since 5.0.0 * -* @param $nonce (string) -* @return (boolean) +* @param $nonce (string) +* @return (boolean) */ -function acf_verify_nonce( $value) { - +function acf_verify_nonce( $value ) { + // vars - $nonce = acf_maybe_get_POST('_acf_nonce'); - - + $nonce = acf_maybe_get_POST( '_acf_nonce' ); + // bail early nonce does not match (post|user|comment|term) - if( !$nonce || !wp_verify_nonce($nonce, $value) ) return false; - - + if ( ! $nonce || ! wp_verify_nonce( $nonce, $value ) ) { + return false; + } + // reset nonce (only allow 1 save) $_POST['_acf_nonce'] = false; - - + // return return true; - + } @@ -798,27 +783,27 @@ function acf_verify_nonce( $value) { * This function will return true if the current AJAX request is valid * It's action will also allow WPML to set the lang and avoid AJAX get_posts issues * -* @type function -* @date 7/08/2015 -* @since 5.2.3 +* @type function +* @date 7/08/2015 +* @since 5.2.3 * -* @param n/a -* @return (boolean) +* @param n/a +* @return (boolean) */ function acf_verify_ajax() { - + // vars - $nonce = isset($_REQUEST['nonce']) ? $_REQUEST['nonce'] : ''; - + $nonce = isset( $_REQUEST['nonce'] ) ? $_REQUEST['nonce'] : ''; + // bail early if not acf nonce - if( !$nonce || !wp_verify_nonce($nonce, 'acf_nonce') ) { + if ( ! $nonce || ! wp_verify_nonce( $nonce, 'acf_nonce' ) ) { return false; } - + // action for 3rd party customization - do_action('acf/verify_ajax'); - + do_action( 'acf/verify_ajax' ); + // return return true; } @@ -829,101 +814,88 @@ function acf_verify_ajax() { * * This function will return an array of available image sizes * -* @type function -* @date 23/10/13 -* @since 5.0.0 +* @type function +* @date 23/10/13 +* @since 5.0.0 * -* @param n/a -* @return (array) +* @param n/a +* @return (array) */ function acf_get_image_sizes() { - + // vars $sizes = array( - 'thumbnail' => __("Thumbnail",'acf'), - 'medium' => __("Medium",'acf'), - 'large' => __("Large",'acf') + 'thumbnail' => __( 'Thumbnail', 'acf' ), + 'medium' => __( 'Medium', 'acf' ), + 'large' => __( 'Large', 'acf' ), ); - - + // find all sizes $all_sizes = get_intermediate_image_sizes(); - - + // add extra registered sizes - if( !empty($all_sizes) ) { - - foreach( $all_sizes as $size ) { - + if ( ! empty( $all_sizes ) ) { + + foreach ( $all_sizes as $size ) { + // bail early if already in array - if( isset($sizes[ $size ]) ) { - + if ( isset( $sizes[ $size ] ) ) { + continue; - + } - - + // append to array - $label = str_replace('-', ' ', $size); - $label = ucwords( $label ); + $label = str_replace( '-', ' ', $size ); + $label = ucwords( $label ); $sizes[ $size ] = $label; - + } - } - - + // add sizes - foreach( array_keys($sizes) as $s ) { - + foreach ( array_keys( $sizes ) as $s ) { + // vars - $data = acf_get_image_size($s); - - + $data = acf_get_image_size( $s ); + // append - if( $data['width'] && $data['height'] ) { - + if ( $data['width'] && $data['height'] ) { + $sizes[ $s ] .= ' (' . $data['width'] . ' x ' . $data['height'] . ')'; - + } - } - - + // add full end - $sizes['full'] = __("Full Size",'acf'); - - + $sizes['full'] = __( 'Full Size', 'acf' ); + // filter for 3rd party customization $sizes = apply_filters( 'acf/get_image_sizes', $sizes ); - - + // return return $sizes; - + } function acf_get_image_size( $s = '' ) { - + // global global $_wp_additional_image_sizes; - - + // rename for nicer code $_sizes = $_wp_additional_image_sizes; - - + // vars $data = array( - 'width' => isset($_sizes[$s]['width']) ? $_sizes[$s]['width'] : get_option("{$s}_size_w"), - 'height' => isset($_sizes[$s]['height']) ? $_sizes[$s]['height'] : get_option("{$s}_size_h") + 'width' => isset( $_sizes[ $s ]['width'] ) ? $_sizes[ $s ]['width'] : get_option( "{$s}_size_w" ), + 'height' => isset( $_sizes[ $s ]['height'] ) ? $_sizes[ $s ]['height'] : get_option( "{$s}_size_h" ), ); - - + // return return $data; - + } /** @@ -931,22 +903,22 @@ function acf_get_image_size( $s = '' ) { * * Similar to the version_compare() function but with extra functionality. * - * @date 21/11/16 - * @since 5.5.0 + * @date 21/11/16 + * @since 5.5.0 * - * @param string $left The left version number. - * @param string $compare The compare operator. - * @param string $right The right version number. - * @return bool + * @param string $left The left version number. + * @param string $compare The compare operator. + * @param string $right The right version number. + * @return bool */ function acf_version_compare( $left = '', $compare = '>', $right = '' ) { - + // Detect 'wp' placeholder. - if( $left === 'wp' ) { + if ( $left === 'wp' ) { global $wp_version; $left = $wp_version; } - + // Return result. return version_compare( $left, $right, $compare ); } @@ -957,27 +929,26 @@ function acf_version_compare( $left = '', $compare = '>', $right = '' ) { * * This function will remove any '-beta1' or '-RC1' strings from a version * -* @type function -* @date 24/11/16 -* @since 5.5.0 +* @type function +* @date 24/11/16 +* @since 5.5.0 * -* @param $version (string) -* @return (string) +* @param $version (string) +* @return (string) */ function acf_get_full_version( $version = '1' ) { - + // remove '-beta1' or '-RC1' - if( $pos = strpos($version, '-') ) { - - $version = substr($version, 0, $pos); - + if ( $pos = strpos( $version, '-' ) ) { + + $version = substr( $version, 0, $pos ); + } - - + // return return $version; - + } @@ -986,28 +957,31 @@ function acf_get_full_version( $version = '1' ) { * * This function is a wrapper for the get_terms() function * -* @type function -* @date 28/09/2016 -* @since 5.4.0 +* @type function +* @date 28/09/2016 +* @since 5.4.0 * -* @param $args (array) -* @return (array) +* @param $args (array) +* @return (array) */ function acf_get_terms( $args ) { - + // defaults - $args = wp_parse_args($args, array( - 'taxonomy' => null, - 'hide_empty' => false, - 'update_term_meta_cache' => false, - )); - + $args = wp_parse_args( + $args, + array( + 'taxonomy' => null, + 'hide_empty' => false, + 'update_term_meta_cache' => false, + ) + ); + // parameters changed in version 4.5 - if( acf_version_compare('wp', '<', '4.5') ) { + if ( acf_version_compare( 'wp', '<', '4.5' ) ) { return get_terms( $args['taxonomy'], $args ); } - + // return return get_terms( $args ); } @@ -1018,70 +992,65 @@ function acf_get_terms( $args ) { * * This function will return an array of available taxonomy terms * -* @type function -* @date 7/10/13 -* @since 5.0.0 +* @type function +* @date 7/10/13 +* @since 5.0.0 * -* @param $taxonomies (array) -* @return (array) +* @param $taxonomies (array) +* @return (array) */ function acf_get_taxonomy_terms( $taxonomies = array() ) { - + // force array $taxonomies = acf_get_array( $taxonomies ); - - + // get pretty taxonomy names $taxonomies = acf_get_pretty_taxonomies( $taxonomies ); - - + // vars $r = array(); - - + // populate $r - foreach( array_keys($taxonomies) as $taxonomy ) { - + foreach ( array_keys( $taxonomies ) as $taxonomy ) { + // vars - $label = $taxonomies[ $taxonomy ]; + $label = $taxonomies[ $taxonomy ]; $is_hierarchical = is_taxonomy_hierarchical( $taxonomy ); - $terms = acf_get_terms(array( - 'taxonomy' => $taxonomy, - 'hide_empty' => false - )); - - + $terms = acf_get_terms( + array( + 'taxonomy' => $taxonomy, + 'hide_empty' => false, + ) + ); + // bail early i no terms - if( empty($terms) ) continue; - - + if ( empty( $terms ) ) { + continue; + } + // sort into hierachial order! - if( $is_hierarchical ) { - + if ( $is_hierarchical ) { + $terms = _get_term_children( 0, $terms, $taxonomy ); - + } - - - // add placeholder + + // add placeholder $r[ $label ] = array(); - - + // add choices - foreach( $terms as $term ) { - - $k = "{$taxonomy}:{$term->slug}"; + foreach ( $terms as $term ) { + + $k = "{$taxonomy}:{$term->slug}"; $r[ $label ][ $k ] = acf_get_term_title( $term ); - + } - } - - + // return return $r; - + } @@ -1090,50 +1059,47 @@ function acf_get_taxonomy_terms( $taxonomies = array() ) { * * This function decodes the $taxonomy:$term strings into a nested array * -* @type function -* @date 27/02/2014 -* @since 5.0.0 +* @type function +* @date 27/02/2014 +* @since 5.0.0 * -* @param $terms (array) -* @return (array) +* @param $terms (array) +* @return (array) */ function acf_decode_taxonomy_terms( $strings = false ) { - + // bail early if no terms - if( empty($strings) ) return false; - - + if ( empty( $strings ) ) { + return false; + } + // vars $terms = array(); - - + // loop - foreach( $strings as $string ) { - + foreach ( $strings as $string ) { + // vars - $data = acf_decode_taxonomy_term( $string ); + $data = acf_decode_taxonomy_term( $string ); $taxonomy = $data['taxonomy']; - $term = $data['term']; - - + $term = $data['term']; + // create empty array - if( !isset($terms[ $taxonomy ]) ) { - + if ( ! isset( $terms[ $taxonomy ] ) ) { + $terms[ $taxonomy ] = array(); - + } - - + // append $terms[ $taxonomy ][] = $term; - + } - - + // return return $terms; - + } @@ -1142,80 +1108,76 @@ function acf_decode_taxonomy_terms( $strings = false ) { * * This function will return the taxonomy and term slug for a given value * -* @type function -* @date 31/03/2014 -* @since 5.0.0 +* @type function +* @date 31/03/2014 +* @since 5.0.0 * -* @param $string (string) -* @return (array) +* @param $string (string) +* @return (array) */ function acf_decode_taxonomy_term( $value ) { - + // vars $data = array( - 'taxonomy' => '', - 'term' => '' + 'taxonomy' => '', + 'term' => '', ); - - + // int - if( is_numeric($value) ) { - + if ( is_numeric( $value ) ) { + $data['term'] = $value; - - // string - } elseif( is_string($value) ) { - - $value = explode(':', $value); - $data['taxonomy'] = isset($value[0]) ? $value[0] : ''; - $data['term'] = isset($value[1]) ? $value[1] : ''; - - // error + + // string + } elseif ( is_string( $value ) ) { + + $value = explode( ':', $value ); + $data['taxonomy'] = isset( $value[0] ) ? $value[0] : ''; + $data['term'] = isset( $value[1] ) ? $value[1] : ''; + + // error } else { - + return false; - + } - - + // allow for term_id (Used by ACF v4) - if( is_numeric($data['term']) ) { - + if ( is_numeric( $data['term'] ) ) { + // global global $wpdb; - - + // find taxonomy - if( !$data['taxonomy'] ) { - - $data['taxonomy'] = $wpdb->get_var( $wpdb->prepare("SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d LIMIT 1", $data['term']) ); - + if ( ! $data['taxonomy'] ) { + + $data['taxonomy'] = $wpdb->get_var( $wpdb->prepare( "SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d LIMIT 1", $data['term'] ) ); + } - - + // find term (may have numeric slug '123') $term = get_term_by( 'slug', $data['term'], $data['taxonomy'] ); - - + // attempt get term via ID (ACF4 uses ID) - if( !$term ) $term = get_term( $data['term'], $data['taxonomy'] ); - - + if ( ! $term ) { + $term = get_term( $data['term'], $data['taxonomy'] ); + } + // bail early if no term - if( !$term ) return false; - - + if ( ! $term ) { + return false; + } + // update $data['taxonomy'] = $term->taxonomy; - $data['term'] = $term->slug; - + $data['term'] = $term->slug; + } - - + // return return $data; - + } /** @@ -1223,11 +1185,11 @@ function acf_decode_taxonomy_term( $value ) { * * Casts the value into an array. * - * @date 9/1/19 - * @since 5.7.10 + * @date 9/1/19 + * @since 5.7.10 * - * @param mixed $val The value to cast. - * @return array + * @param mixed $val The value to cast. + * @return array */ function acf_array( $val = array() ) { return (array) $val; @@ -1236,14 +1198,14 @@ function acf_array( $val = array() ) { /** * Returns a non-array value. * - * @date 11/05/2020 - * @since 5.8.10 + * @date 11/05/2020 + * @since 5.8.10 * - * @param mixed $val The value to review. - * @return mixed + * @param mixed $val The value to review. + * @return mixed */ function acf_unarray( $val ) { - if( is_array( $val ) ) { + if ( is_array( $val ) ) { return reset( $val ); } return $val; @@ -1254,37 +1216,34 @@ function acf_unarray( $val ) { * * This function will force a variable to become an array * -* @type function -* @date 4/02/2014 -* @since 5.0.0 +* @type function +* @date 4/02/2014 +* @since 5.0.0 * -* @param $var (mixed) -* @return (array) +* @param $var (mixed) +* @return (array) */ function acf_get_array( $var = false, $delimiter = '' ) { - + // array - if( is_array($var) ) { + if ( is_array( $var ) ) { return $var; } - - + // bail early if empty - if( acf_is_empty($var) ) { + if ( acf_is_empty( $var ) ) { return array(); } - - - // string - if( is_string($var) && $delimiter ) { - return explode($delimiter, $var); + + // string + if ( is_string( $var ) && $delimiter ) { + return explode( $delimiter, $var ); } - - + // place in array return (array) $var; - + } @@ -1293,40 +1252,41 @@ function acf_get_array( $var = false, $delimiter = '' ) { * * This function will return numeric values * -* @type function -* @date 15/07/2016 -* @since 5.4.0 +* @type function +* @date 15/07/2016 +* @since 5.4.0 * -* @param $value (mixed) -* @return (mixed) +* @param $value (mixed) +* @return (mixed) */ function acf_get_numeric( $value = '' ) { - + // vars - $numbers = array(); - $is_array = is_array($value); - - + $numbers = array(); + $is_array = is_array( $value ); + // loop - foreach( (array) $value as $v ) { - - if( is_numeric($v) ) $numbers[] = (int) $v; - + foreach ( (array) $value as $v ) { + + if ( is_numeric( $v ) ) { + $numbers[] = (int) $v; + } } - - + // bail early if is empty - if( empty($numbers) ) return false; - - + if ( empty( $numbers ) ) { + return false; + } + // convert array - if( !$is_array ) $numbers = $numbers[0]; - - + if ( ! $is_array ) { + $numbers = $numbers[0]; + } + // return return $numbers; - + } @@ -1335,53 +1295,56 @@ function acf_get_numeric( $value = '' ) { * * Similar to the get_posts() function but with extra functionality. * - * @date 3/03/15 - * @since 5.1.5 + * @date 3/03/15 + * @since 5.1.5 * - * @param array $args The query args. - * @return array + * @param array $args The query args. + * @return array */ function acf_get_posts( $args = array() ) { - + // Vars. $posts = array(); - + // Apply default args. - $args = wp_parse_args($args, array( - 'posts_per_page' => -1, - 'post_type' => '', - 'post_status' => 'any', - 'update_post_meta_cache' => false, - 'update_post_term_cache' => false - )); - + $args = wp_parse_args( + $args, + array( + 'posts_per_page' => -1, + 'post_type' => '', + 'post_status' => 'any', + 'update_post_meta_cache' => false, + 'update_post_term_cache' => false, + ) + ); + // Avoid default 'post' post_type by providing all public types. - if( !$args['post_type'] ) { + if ( ! $args['post_type'] ) { $args['post_type'] = acf_get_post_types(); } - + // Check if specifc post ID's have been provided. - if( $args['post__in'] ) { - + if ( $args['post__in'] ) { + // Clean value into an array of IDs. - $args['post__in'] = array_map('intval', acf_array($args['post__in'])); + $args['post__in'] = array_map( 'intval', acf_array( $args['post__in'] ) ); } - + // Query posts. $posts = get_posts( $args ); - + // Remove any potential empty results. $posts = array_filter( $posts ); - + // Manually order results. - if( $posts && $args['post__in'] ) { + if ( $posts && $args['post__in'] ) { $order = array(); - foreach( $posts as $i => $post ) { + foreach ( $posts as $i => $post ) { $order[ $i ] = array_search( $post->ID, $args['post__in'] ); } - array_multisort($order, $posts); + array_multisort( $order, $posts ); } - + // Return posts. return $posts; } @@ -1393,52 +1356,46 @@ function acf_get_posts( $args = array() ) { * This function will remove the 'wp_posts.post_type' WHERE clause completely * When using 'post__in', this clause is unneccessary and slow. * -* @type function -* @date 4/03/2015 -* @since 5.1.5 +* @type function +* @date 4/03/2015 +* @since 5.1.5 * -* @param $sql (string) -* @return $sql +* @param $sql (string) +* @return $sql */ function _acf_query_remove_post_type( $sql ) { - + // global global $wpdb; - - + // bail ealry if no 'wp_posts.ID IN' - if( strpos($sql, "$wpdb->posts.ID IN") === false ) { - + if ( strpos( $sql, "$wpdb->posts.ID IN" ) === false ) { + return $sql; - + } - - - // get bits + + // get bits $glue = 'AND'; - $bits = explode($glue, $sql); - - + $bits = explode( $glue, $sql ); + // loop through $where and remove any post_type queries - foreach( $bits as $i => $bit ) { - - if( strpos($bit, "$wpdb->posts.post_type") !== false ) { - + foreach ( $bits as $i => $bit ) { + + if ( strpos( $bit, "$wpdb->posts.post_type" ) !== false ) { + unset( $bits[ $i ] ); - + } - } - - + // join $where back together - $sql = implode($glue, $bits); - - - // return - return $sql; - + $sql = implode( $glue, $bits ); + + // return + return $sql; + } @@ -1448,303 +1405,277 @@ function _acf_query_remove_post_type( $sql ) { * This function will return all posts grouped by post_type * This is handy for select settings * -* @type function -* @date 27/02/2014 -* @since 5.0.0 +* @type function +* @date 27/02/2014 +* @since 5.0.0 * -* @param $args (array) -* @return (array) +* @param $args (array) +* @return (array) */ function acf_get_grouped_posts( $args ) { - + // vars $data = array(); - - - // defaults - $args = wp_parse_args( $args, array( - 'posts_per_page' => -1, - 'paged' => 0, - 'post_type' => 'post', - 'orderby' => 'menu_order title', - 'order' => 'ASC', - 'post_status' => 'any', - 'suppress_filters' => false, - 'update_post_meta_cache' => false, - )); - + // defaults + $args = wp_parse_args( + $args, + array( + 'posts_per_page' => -1, + 'paged' => 0, + 'post_type' => 'post', + 'orderby' => 'menu_order title', + 'order' => 'ASC', + 'post_status' => 'any', + 'suppress_filters' => false, + 'update_post_meta_cache' => false, + ) + ); + // find array of post_type - $post_types = acf_get_array( $args['post_type'] ); - $post_types_labels = acf_get_pretty_post_types($post_types); - $is_single_post_type = ( count($post_types) == 1 ); - - + $post_types = acf_get_array( $args['post_type'] ); + $post_types_labels = acf_get_pretty_post_types( $post_types ); + $is_single_post_type = ( count( $post_types ) == 1 ); + // attachment doesn't work if it is the only item in an array - if( $is_single_post_type ) { - $args['post_type'] = reset($post_types); + if ( $is_single_post_type ) { + $args['post_type'] = reset( $post_types ); } - - + // add filter to orderby post type - if( !$is_single_post_type ) { - add_filter('posts_orderby', '_acf_orderby_post_type', 10, 2); + if ( ! $is_single_post_type ) { + add_filter( 'posts_orderby', '_acf_orderby_post_type', 10, 2 ); } - - + // get posts $posts = get_posts( $args ); - - + // remove this filter (only once) - if( !$is_single_post_type ) { - remove_filter('posts_orderby', '_acf_orderby_post_type', 10, 2); + if ( ! $is_single_post_type ) { + remove_filter( 'posts_orderby', '_acf_orderby_post_type', 10, 2 ); } - - + // loop - foreach( $post_types as $post_type ) { - + foreach ( $post_types as $post_type ) { + // vars $this_posts = array(); $this_group = array(); - - + // populate $this_posts - foreach( $posts as $post ) { - if( $post->post_type == $post_type ) { + foreach ( $posts as $post ) { + if ( $post->post_type == $post_type ) { $this_posts[] = $post; } } - - + // bail early if no posts for this post type - if( empty($this_posts) ) continue; - - + if ( empty( $this_posts ) ) { + continue; + } + // sort into hierachial order! // this will fail if a search has taken place because parents wont exist - if( is_post_type_hierarchical($post_type) && empty($args['s'])) { - + if ( is_post_type_hierarchical( $post_type ) && empty( $args['s'] ) ) { + // vars - $post_id = $this_posts[0]->ID; - $parent_id = acf_maybe_get($args, 'post_parent', 0); - $offset = 0; - $length = count($this_posts); - - + $post_id = $this_posts[0]->ID; + $parent_id = acf_maybe_get( $args, 'post_parent', 0 ); + $offset = 0; + $length = count( $this_posts ); + // get all posts from this post type - $all_posts = get_posts(array_merge($args, array( - 'posts_per_page' => -1, - 'paged' => 0, - 'post_type' => $post_type - ))); - - + $all_posts = get_posts( + array_merge( + $args, + array( + 'posts_per_page' => -1, + 'paged' => 0, + 'post_type' => $post_type, + ) + ) + ); + // find starting point (offset) - foreach( $all_posts as $i => $post ) { - if( $post->ID == $post_id ) { + foreach ( $all_posts as $i => $post ) { + if ( $post->ID == $post_id ) { $offset = $i; break; } } - - + // order posts - $ordered_posts = get_page_children($parent_id, $all_posts); - - + $ordered_posts = get_page_children( $parent_id, $all_posts ); + // compare aray lengths // if $ordered_posts is smaller than $all_posts, WP has lost posts during the get_page_children() function - // this is possible when get_post( $args ) filter out parents (via taxonomy, meta and other search parameters) - if( count($ordered_posts) == count($all_posts) ) { - $this_posts = array_slice($ordered_posts, $offset, $length); + // this is possible when get_post( $args ) filter out parents (via taxonomy, meta and other search parameters) + if ( count( $ordered_posts ) == count( $all_posts ) ) { + $this_posts = array_slice( $ordered_posts, $offset, $length ); } - } - - + // populate $this_posts - foreach( $this_posts as $post ) { + foreach ( $this_posts as $post ) { $this_group[ $post->ID ] = $post; } - - + // group by post type - $label = $post_types_labels[ $post_type ]; + $label = $post_types_labels[ $post_type ]; $data[ $label ] = $this_group; - + } - - + // return return $data; - + } function _acf_orderby_post_type( $ordeby, $wp_query ) { - + // global global $wpdb; - - + // get post types - $post_types = $wp_query->get('post_type'); - + $post_types = $wp_query->get( 'post_type' ); // prepend SQL - if( is_array($post_types) ) { - - $post_types = implode("','", $post_types); - $ordeby = "FIELD({$wpdb->posts}.post_type,'$post_types')," . $ordeby; - + if ( is_array( $post_types ) ) { + + $post_types = implode( "','", $post_types ); + $ordeby = "FIELD({$wpdb->posts}.post_type,'$post_types')," . $ordeby; + } - - + // return return $ordeby; - + } function acf_get_post_title( $post = 0, $is_search = false ) { - + // vars - $post = get_post($post); - $title = ''; + $post = get_post( $post ); + $title = ''; $prepend = ''; - $append = ''; - - + $append = ''; + // bail early if no post - if( !$post ) return ''; - - + if ( ! $post ) { + return ''; + } + // title $title = get_the_title( $post->ID ); - - + // empty - if( $title === '' ) { - - $title = __('(no title)', 'acf'); - + if ( $title === '' ) { + + $title = __( '(no title)', 'acf' ); + } - - + // status - if( get_post_status( $post->ID ) != "publish" ) { - + if ( get_post_status( $post->ID ) != 'publish' ) { + $append .= ' (' . get_post_status( $post->ID ) . ')'; - + } - - + // ancestors - if( $post->post_type !== 'attachment' ) { - + if ( $post->post_type !== 'attachment' ) { + // get ancestors $ancestors = get_ancestors( $post->ID, $post->post_type ); - $prepend .= str_repeat('- ', count($ancestors)); - - + $prepend .= str_repeat( '- ', count( $ancestors ) ); + // add parent -/* + /* removed in 5.6.5 as not used by the UI if( $is_search && !empty($ancestors) ) { - + // reverse $ancestors = array_reverse($ancestors); - - + + // convert id's into titles foreach( $ancestors as $i => $id ) { - + $ancestors[ $i ] = get_the_title( $id ); - + } - - + + // append $append .= ' | ' . __('Parent', 'acf') . ': ' . implode(' / ', $ancestors); - + } -*/ - + */ + } - - + // merge $title = $prepend . $title . $append; - - + // return return $title; - + } function acf_order_by_search( $array, $search ) { - + // vars $weights = array(); - $needle = strtolower( $search ); - - - // add key prefix - foreach( array_keys($array) as $k ) { - - $array[ '_' . $k ] = acf_extract_var( $array, $k ); - - } + $needle = strtolower( $search ); + // add key prefix + foreach ( array_keys( $array ) as $k ) { + + $array[ '_' . $k ] = acf_extract_var( $array, $k ); + + } // add search weight - foreach( $array as $k => $v ) { - + foreach ( $array as $k => $v ) { + // vars - $weight = 0; + $weight = 0; $haystack = strtolower( $v ); - $strpos = strpos( $haystack, $needle ); - - + $strpos = strpos( $haystack, $needle ); + // detect search match - if( $strpos !== false ) { - + if ( $strpos !== false ) { + // set eright to length of match $weight = strlen( $search ); - - + // increase weight if match starts at begining of string - if( $strpos == 0 ) { - + if ( $strpos == 0 ) { + $weight++; - + } - } - - + // append to wights $weights[ $k ] = $weight; - + } - - + // sort the array with menu_order ascending array_multisort( $weights, SORT_DESC, $array ); - - + // remove key prefix - foreach( array_keys($array) as $k ) { - - $array[ substr($k,1) ] = acf_extract_var( $array, $k ); - + foreach ( array_keys( $array ) as $k ) { + + $array[ substr( $k, 1 ) ] = acf_extract_var( $array, $k ); + } - - + // return return $array; } @@ -1755,38 +1686,37 @@ function acf_order_by_search( $array, $search ) { * * description * -* @type function -* @date 23/02/2016 -* @since 5.3.2 +* @type function +* @date 23/02/2016 +* @since 5.3.2 * -* @param $post_id (int) -* @return $post_id (int) +* @param $post_id (int) +* @return $post_id (int) */ function acf_get_pretty_user_roles( $allowed = false ) { - + // vars $editable_roles = get_editable_roles(); - $allowed = acf_get_array($allowed); - $roles = array(); - - + $allowed = acf_get_array( $allowed ); + $roles = array(); + // loop - foreach( $editable_roles as $role_name => $role_details ) { - + foreach ( $editable_roles as $role_name => $role_details ) { + // bail early if not allowed - if( !empty($allowed) && !in_array($role_name, $allowed) ) continue; - - + if ( ! empty( $allowed ) && ! in_array( $role_name, $allowed ) ) { + continue; + } + // append $roles[ $role_name ] = translate_user_role( $role_details['name'] ); - + } - - + // return return $roles; - + } @@ -1796,153 +1726,142 @@ function acf_get_pretty_user_roles( $allowed = false ) { * This function will return all users grouped by role * This is handy for select settings * -* @type function -* @date 27/02/2014 -* @since 5.0.0 +* @type function +* @date 27/02/2014 +* @since 5.0.0 * -* @param $args (array) -* @return (array) +* @param $args (array) +* @return (array) */ function acf_get_grouped_users( $args = array() ) { - + // vars $r = array(); - - + // defaults - $args = wp_parse_args( $args, array( - 'users_per_page' => -1, - 'paged' => 0, - 'role' => '', - 'orderby' => 'login', - 'order' => 'ASC', - )); - - + $args = wp_parse_args( + $args, + array( + 'users_per_page' => -1, + 'paged' => 0, + 'role' => '', + 'orderby' => 'login', + 'order' => 'ASC', + ) + ); + // offset - $i = 0; - $min = 0; - $max = 0; - $users_per_page = acf_extract_var($args, 'users_per_page'); - $paged = acf_extract_var($args, 'paged'); - - if( $users_per_page > 0 ) { - + $i = 0; + $min = 0; + $max = 0; + $users_per_page = acf_extract_var( $args, 'users_per_page' ); + $paged = acf_extract_var( $args, 'paged' ); + + if ( $users_per_page > 0 ) { + // prevent paged from being -1 - $paged = max(0, $paged); - - + $paged = max( 0, $paged ); + // set min / max - $min = (($paged-1) * $users_per_page) + 1; // 1, 11 - $max = ($paged * $users_per_page); // 10, 20 - + $min = ( ( $paged - 1 ) * $users_per_page ) + 1; // 1, 11 + $max = ( $paged * $users_per_page ); // 10, 20 + } - - + // find array of post_type - $user_roles = acf_get_pretty_user_roles($args['role']); - - + $user_roles = acf_get_pretty_user_roles( $args['role'] ); + // fix role - if( is_array($args['role']) ) { - + if ( is_array( $args['role'] ) ) { + // global - global $wp_version, $wpdb; - - + global $wp_version, $wpdb; + // vars - $roles = acf_extract_var($args, 'role'); - - + $roles = acf_extract_var( $args, 'role' ); + // new WP has role__in - if( version_compare($wp_version, '4.4', '>=' ) ) { - + if ( version_compare( $wp_version, '4.4', '>=' ) ) { + $args['role__in'] = $roles; - - // old WP doesn't have role__in + + // old WP doesn't have role__in } else { - + // vars - $blog_id = get_current_blog_id(); + $blog_id = get_current_blog_id(); $meta_query = array( 'relation' => 'OR' ); - - + // loop - foreach( $roles as $role ) { - + foreach ( $roles as $role ) { + $meta_query[] = array( 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 'value' => '"' . $role . '"', 'compare' => 'LIKE', ); - + } - - + // append $args['meta_query'] = $meta_query; - + } - } - - + // get posts $users = get_users( $args ); - - + // loop - foreach( $user_roles as $user_role_name => $user_role_label ) { - + foreach ( $user_roles as $user_role_name => $user_role_label ) { + // vars $this_users = array(); $this_group = array(); - - + // populate $this_posts - foreach( array_keys($users) as $key ) { - + foreach ( array_keys( $users ) as $key ) { + // bail ealry if not correct role - if( !in_array($user_role_name, $users[ $key ]->roles) ) continue; - - + if ( ! in_array( $user_role_name, $users[ $key ]->roles ) ) { + continue; + } + // extract user $user = acf_extract_var( $users, $key ); - - + // increase $i++; - - + // bail ealry if too low - if( $min && $i < $min ) continue; - - + if ( $min && $i < $min ) { + continue; + } + // bail early if too high (don't bother looking at any more users) - if( $max && $i > $max ) break; - - + if ( $max && $i > $max ) { + break; + } + // group by post type $this_users[ $user->ID ] = $user; - - + } - - + // bail early if no posts for this post type - if( empty($this_users) ) continue; - - + if ( empty( $this_users ) ) { + continue; + } + // append $r[ $user_role_label ] = $this_users; - + } - - + // return return $r; - + } /** @@ -1950,14 +1869,14 @@ function acf_get_grouped_users( $args = array() ) { * * Returns json_encode() ready for file / database use. * - * @date 29/4/19 - * @since 5.0.0 + * @date 29/4/19 + * @since 5.0.0 * - * @param array $json The array of data to encode. - * @return string + * @param array $json The array of data to encode. + * @return string */ function acf_json_encode( $json ) { - return json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); + return json_encode( $json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE ); } @@ -1966,25 +1885,24 @@ function acf_json_encode( $json ) { * * This function will return true if a sub string is found * -* @type function -* @date 1/05/2014 -* @since 5.0.0 +* @type function +* @date 1/05/2014 +* @since 5.0.0 * -* @param $needle (string) -* @param $haystack (string) -* @return (boolean) +* @param $needle (string) +* @param $haystack (string) +* @return (boolean) */ function acf_str_exists( $needle, $haystack ) { - + // return true if $haystack contains the $needle - if( is_string($haystack) && strpos($haystack, $needle) !== false ) { - + if ( is_string( $haystack ) && strpos( $haystack, $needle ) !== false ) { + return true; - + } - - + // return return false; } @@ -1995,75 +1913,72 @@ function acf_str_exists( $needle, $haystack ) { * * description * -* @type function -* @date 2/05/2014 -* @since 5.0.0 +* @type function +* @date 2/05/2014 +* @since 5.0.0 * -* @param $post_id (int) -* @return $post_id (int) +* @param $post_id (int) +* @return $post_id (int) */ function acf_debug() { - + // vars $args = func_get_args(); - $s = array_shift($args); - $o = ''; - $nl = "\r\n"; - - + $s = array_shift( $args ); + $o = ''; + $nl = "\r\n"; + // start script $o .= '' . $nl; - - + // echo echo $o; } function acf_debug_start() { - - acf_update_setting( 'debug_start', memory_get_usage()); - + + acf_update_setting( 'debug_start', memory_get_usage() ); + } function acf_debug_end() { - + $start = acf_get_setting( 'debug_start' ); - $end = memory_get_usage(); - + $end = memory_get_usage(); + return $end - $start; - + } @@ -2072,124 +1987,116 @@ function acf_debug_end() { * * description * -* @type function -* @date 4/06/2014 -* @since 5.0.0 +* @type function +* @date 4/06/2014 +* @since 5.0.0 * -* @param $post_id (int) -* @return $post_id (int) +* @param $post_id (int) +* @return $post_id (int) */ function acf_encode_choices( $array = array(), $show_keys = true ) { - + // bail early if not array (maybe a single string) - if( !is_array($array) ) return $array; - - + if ( ! is_array( $array ) ) { + return $array; + } + // bail early if empty array - if( empty($array) ) return ''; - - + if ( empty( $array ) ) { + return ''; + } + // vars $string = ''; - - + // if allowed to show keys (good for choices, not for default values) - if( $show_keys ) { - + if ( $show_keys ) { + // loop - foreach( $array as $k => $v ) { - + foreach ( $array as $k => $v ) { + // ignore if key and value are the same - if( strval($k) == strval($v) ) continue; - - + if ( strval( $k ) == strval( $v ) ) { + continue; + } + // show key in the value $array[ $k ] = $k . ' : ' . $v; - - } - - } - - - // implode - $string = implode("\n", $array); - + } + } + + // implode + $string = implode( "\n", $array ); + // return return $string; - + } function acf_decode_choices( $string = '', $array_keys = false ) { - + // bail early if already array - if( is_array($string) ) { - + if ( is_array( $string ) ) { + return $string; - - // allow numeric values (same as string) - } elseif( is_numeric($string) ) { - + + // allow numeric values (same as string) + } elseif ( is_numeric( $string ) ) { + // do nothing - - // bail early if not a string - } elseif( !is_string($string) ) { - + + // bail early if not a string + } elseif ( ! is_string( $string ) ) { + return array(); - - // bail early if is empty string - } elseif( $string === '' ) { - + + // bail early if is empty string + } elseif ( $string === '' ) { + return array(); - + } - - + // vars $array = array(); - - + // explode - $lines = explode("\n", $string); - - + $lines = explode( "\n", $string ); + // key => value - foreach( $lines as $line ) { - + foreach ( $lines as $line ) { + // vars - $k = trim($line); - $v = trim($line); - - + $k = trim( $line ); + $v = trim( $line ); + // look for ' : ' - if( acf_str_exists(' : ', $line) ) { - - $line = explode(' : ', $line); - - $k = trim($line[0]); - $v = trim($line[1]); - + if ( acf_str_exists( ' : ', $line ) ) { + + $line = explode( ' : ', $line ); + + $k = trim( $line[0] ); + $v = trim( $line[1] ); + } - - + // append $array[ $k ] = $v; - + } - - + // return only array keys? (good for checkbox default_value) - if( $array_keys ) { - - return array_keys($array); - + if ( $array_keys ) { + + return array_keys( $array ); + } - - + // return return $array; - + } @@ -2200,48 +2107,46 @@ function acf_decode_choices( $string = '', $array_keys = false ) { * The difference is the extra logic to avoid replacing a string that has alread been replaced * This is very useful for replacing date characters as they overlap with eachother * -* @type function -* @date 21/06/2016 -* @since 5.3.8 +* @type function +* @date 21/06/2016 +* @since 5.3.8 * -* @param $post_id (int) -* @return $post_id (int) +* @param $post_id (int) +* @return $post_id (int) */ function acf_str_replace( $string = '', $search_replace = array() ) { - + // vars $ignore = array(); - - + // remove potential empty search to avoid PHP error - unset($search_replace['']); - - + unset( $search_replace[''] ); + // loop over conversions - foreach( $search_replace as $search => $replace ) { - + foreach ( $search_replace as $search => $replace ) { + // ignore this search, it was a previous replace - if( in_array($search, $ignore) ) continue; - - + if ( in_array( $search, $ignore ) ) { + continue; + } + // bail early if subsctring not found - if( strpos($string, $search) === false ) continue; - - + if ( strpos( $string, $search ) === false ) { + continue; + } + // replace - $string = str_replace($search, $replace, $string); - - + $string = str_replace( $search, $replace, $string ); + // append to ignore $ignore[] = $replace; - + } - - + // return return $string; - + } @@ -2250,52 +2155,58 @@ function acf_str_replace( $string = '', $search_replace = array() ) { * * These settings contain an association of format strings from PHP => JS * -* @type function -* @date 21/06/2016 -* @since 5.3.8 +* @type function +* @date 21/06/2016 +* @since 5.3.8 * -* @param n/a -* @return n/a +* @param n/a +* @return n/a */ -acf_update_setting('php_to_js_date_formats', array( +acf_update_setting( + 'php_to_js_date_formats', + array( + + // Year + 'Y' => 'yy', // Numeric, 4 digits 1999, 2003 + 'y' => 'y', // Numeric, 2 digits 99, 03 + - // Year - 'Y' => 'yy', // Numeric, 4 digits 1999, 2003 - 'y' => 'y', // Numeric, 2 digits 99, 03 - - // Month - 'm' => 'mm', // Numeric, with leading zeros 01–12 - 'n' => 'm', // Numeric, without leading zeros 1–12 - 'F' => 'MM', // Textual full January – December - 'M' => 'M', // Textual three letters Jan - Dec - - - // Weekday - 'l' => 'DD', // Full name (lowercase 'L') Sunday – Saturday - 'D' => 'D', // Three letter name Mon – Sun - - - // Day of Month - 'd' => 'dd', // Numeric, with leading zeros 01–31 - 'j' => 'd', // Numeric, without leading zeros 1–31 - 'S' => '', // The English suffix for the day of the month st, nd or th in the 1st, 2nd or 15th. - -)); + 'm' => 'mm', // Numeric, with leading zeros 01–12 + 'n' => 'm', // Numeric, without leading zeros 1–12 + 'F' => 'MM', // Textual full January – December + 'M' => 'M', // Textual three letters Jan - Dec -acf_update_setting('php_to_js_time_formats', array( - - 'a' => 'tt', // Lowercase Ante meridiem and Post meridiem am or pm - 'A' => 'TT', // Uppercase Ante meridiem and Post meridiem AM or PM - 'h' => 'hh', // 12-hour format of an hour with leading zeros 01 through 12 - 'g' => 'h', // 12-hour format of an hour without leading zeros 1 through 12 - 'H' => 'HH', // 24-hour format of an hour with leading zeros 00 through 23 - 'G' => 'H', // 24-hour format of an hour without leading zeros 0 through 23 - 'i' => 'mm', // Minutes with leading zeros 00 to 59 - 's' => 'ss', // Seconds, with leading zeros 00 through 59 - -)); + + // Weekday + 'l' => 'DD', // Full name (lowercase 'L') Sunday – Saturday + 'D' => 'D', // Three letter name Mon – Sun + + + // Day of Month + 'd' => 'dd', // Numeric, with leading zeros 01–31 + 'j' => 'd', // Numeric, without leading zeros 1–31 + 'S' => '', // The English suffix for the day of the month st, nd or th in the 1st, 2nd or 15th. + + ) +); + +acf_update_setting( + 'php_to_js_time_formats', + array( + + 'a' => 'tt', // Lowercase Ante meridiem and Post meridiem am or pm + 'A' => 'TT', // Uppercase Ante meridiem and Post meridiem AM or PM + 'h' => 'hh', // 12-hour format of an hour with leading zeros 01 through 12 + 'g' => 'h', // 12-hour format of an hour without leading zeros 1 through 12 + 'H' => 'HH', // 24-hour format of an hour with leading zeros 00 through 23 + 'G' => 'H', // 24-hour format of an hour without leading zeros 0 through 23 + 'i' => 'mm', // Minutes with leading zeros 00 to 59 + 's' => 'ss', // Seconds, with leading zeros 00 through 59 + + ) +); /* @@ -2303,60 +2214,55 @@ acf_update_setting('php_to_js_time_formats', array( * * This function will split a format string into seperate date and time * -* @type function -* @date 26/05/2016 -* @since 5.3.8 +* @type function +* @date 26/05/2016 +* @since 5.3.8 * -* @param $date_time (string) -* @return $formats (array) +* @param $date_time (string) +* @return $formats (array) */ function acf_split_date_time( $date_time = '' ) { - + // vars - $php_date = acf_get_setting('php_to_js_date_formats'); - $php_time = acf_get_setting('php_to_js_time_formats'); - $chars = str_split($date_time); - $type = 'date'; - - + $php_date = acf_get_setting( 'php_to_js_date_formats' ); + $php_time = acf_get_setting( 'php_to_js_time_formats' ); + $chars = str_split( $date_time ); + $type = 'date'; + // default $data = array( 'date' => '', - 'time' => '' + 'time' => '', ); - - + // loop - foreach( $chars as $i => $c ) { - + foreach ( $chars as $i => $c ) { + // find type // - allow misc characters to append to previous type - if( isset($php_date[ $c ]) ) { - + if ( isset( $php_date[ $c ] ) ) { + $type = 'date'; - - } elseif( isset($php_time[ $c ]) ) { - + + } elseif ( isset( $php_time[ $c ] ) ) { + $type = 'time'; - + } - - + // append char $data[ $type ] .= $c; - + } - - + // trim - $data['date'] = trim($data['date']); - $data['time'] = trim($data['time']); - - + $data['date'] = trim( $data['date'] ); + $data['time'] = trim( $data['time'] ); + // return - return $data; - + return $data; + } @@ -2365,24 +2271,23 @@ function acf_split_date_time( $date_time = '' ) { * * This fucntion converts a date format string from JS to PHP * -* @type function -* @date 20/06/2014 -* @since 5.0.0 +* @type function +* @date 20/06/2014 +* @since 5.0.0 * -* @param $date (string) -* @return (string) +* @param $date (string) +* @return (string) */ function acf_convert_date_to_php( $date = '' ) { - + // vars - $php_to_js = acf_get_setting('php_to_js_date_formats'); - $js_to_php = array_flip($php_to_js); - - + $php_to_js = acf_get_setting( 'php_to_js_date_formats' ); + $js_to_php = array_flip( $php_to_js ); + // return return acf_str_replace( $date, $js_to_php ); - + } /* @@ -2390,23 +2295,22 @@ function acf_convert_date_to_php( $date = '' ) { * * This fucntion converts a date format string from PHP to JS * -* @type function -* @date 20/06/2014 -* @since 5.0.0 +* @type function +* @date 20/06/2014 +* @since 5.0.0 * -* @param $date (string) -* @return (string) +* @param $date (string) +* @return (string) */ function acf_convert_date_to_js( $date = '' ) { - + // vars - $php_to_js = acf_get_setting('php_to_js_date_formats'); - - + $php_to_js = acf_get_setting( 'php_to_js_date_formats' ); + // return return acf_str_replace( $date, $php_to_js ); - + } @@ -2415,24 +2319,23 @@ function acf_convert_date_to_js( $date = '' ) { * * This fucntion converts a time format string from JS to PHP * -* @type function -* @date 20/06/2014 -* @since 5.0.0 +* @type function +* @date 20/06/2014 +* @since 5.0.0 * -* @param $time (string) -* @return (string) +* @param $time (string) +* @return (string) */ function acf_convert_time_to_php( $time = '' ) { - + // vars - $php_to_js = acf_get_setting('php_to_js_time_formats'); - $js_to_php = array_flip($php_to_js); - - + $php_to_js = acf_get_setting( 'php_to_js_time_formats' ); + $js_to_php = array_flip( $php_to_js ); + // return return acf_str_replace( $time, $js_to_php ); - + } @@ -2441,23 +2344,22 @@ function acf_convert_time_to_php( $time = '' ) { * * This fucntion converts a date format string from PHP to JS * -* @type function -* @date 20/06/2014 -* @since 5.0.0 +* @type function +* @date 20/06/2014 +* @since 5.0.0 * -* @param $time (string) -* @return (string) +* @param $time (string) +* @return (string) */ function acf_convert_time_to_js( $time = '' ) { - + // vars - $php_to_js = acf_get_setting('php_to_js_time_formats'); - - + $php_to_js = acf_get_setting( 'php_to_js_time_formats' ); + // return return acf_str_replace( $time, $php_to_js ); - + } @@ -2466,44 +2368,40 @@ function acf_convert_time_to_js( $time = '' ) { * * description * -* @type function -* @date 15/07/2014 -* @since 5.0.0 +* @type function +* @date 15/07/2014 +* @since 5.0.0 * -* @param $post_id (int) -* @return $post_id (int) +* @param $post_id (int) +* @return $post_id (int) */ function acf_update_user_setting( $name, $value ) { - + // get current user id $user_id = get_current_user_id(); - - + // get user settings $settings = get_user_meta( $user_id, 'acf_user_settings', true ); - - + // ensure array - $settings = acf_get_array($settings); - - + $settings = acf_get_array( $settings ); + // delete setting (allow 0 to save) - if( acf_is_empty($value) ) { - - unset($settings[ $name ]); - - // append setting + if ( acf_is_empty( $value ) ) { + + unset( $settings[ $name ] ); + + // append setting } else { - + $settings[ $name ] = $value; - + } - - + // update user data - return update_metadata('user', $user_id, 'acf_user_settings', $settings); - + return update_metadata( 'user', $user_id, 'acf_user_settings', $settings ); + } @@ -2512,35 +2410,33 @@ function acf_update_user_setting( $name, $value ) { * * description * -* @type function -* @date 15/07/2014 -* @since 5.0.0 +* @type function +* @date 15/07/2014 +* @since 5.0.0 * -* @param $post_id (int) -* @return $post_id (int) +* @param $post_id (int) +* @return $post_id (int) */ function acf_get_user_setting( $name = '', $default = false ) { - + // get current user id $user_id = get_current_user_id(); - - + // get user settings $settings = get_user_meta( $user_id, 'acf_user_settings', true ); - - + // ensure array - $settings = acf_get_array($settings); - - + $settings = acf_get_array( $settings ); + // bail arly if no settings - if( !isset($settings[$name]) ) return $default; - - + if ( ! isset( $settings[ $name ] ) ) { + return $default; + } + // return - return $settings[$name]; - + return $settings[ $name ]; + } @@ -2549,23 +2445,24 @@ function acf_get_user_setting( $name = '', $default = false ) { * * description * -* @type function -* @date 22/07/2014 -* @since 5.0.0 +* @type function +* @date 22/07/2014 +* @since 5.0.0 * -* @param $post_id (int) -* @return $post_id (int) +* @param $post_id (int) +* @return $post_id (int) */ function acf_in_array( $value = '', $array = false ) { - + // bail early if not array - if( !is_array($array) ) return false; - - + if ( ! is_array( $array ) ) { + return false; + } + // find value in array - return in_array($value, $array); - + return in_array( $value, $array ); + } @@ -2574,108 +2471,97 @@ function acf_in_array( $value = '', $array = false ) { * * This function will return a valid post_id based on the current screen / parameter * -* @type function -* @date 8/12/2013 -* @since 5.0.0 +* @type function +* @date 8/12/2013 +* @since 5.0.0 * -* @param $post_id (mixed) -* @return $post_id (mixed) +* @param $post_id (mixed) +* @return $post_id (mixed) */ function acf_get_valid_post_id( $post_id = 0 ) { - + // allow filter to short-circuit load_value logic - $preload = apply_filters( "acf/pre_load_post_id", null, $post_id ); - if( $preload !== null ) { - return $preload; - } - + $preload = apply_filters( 'acf/pre_load_post_id', null, $post_id ); + if ( $preload !== null ) { + return $preload; + } + // vars $_post_id = $post_id; - - + // if not $post_id, load queried object - if( !$post_id ) { - + if ( ! $post_id ) { + // try for global post (needed for setup_postdata) $post_id = (int) get_the_ID(); - - + // try for current screen - if( !$post_id ) { - + if ( ! $post_id ) { + $post_id = get_queried_object(); - + } - } - - + // $post_id may be an object. // todo: Compare class types instead. - if( is_object($post_id) ) { - + if ( is_object( $post_id ) ) { + // post - if( isset($post_id->post_type, $post_id->ID) ) { - + if ( isset( $post_id->post_type, $post_id->ID ) ) { + $post_id = $post_id->ID; - - // user - } elseif( isset($post_id->roles, $post_id->ID) ) { - + + // user + } elseif ( isset( $post_id->roles, $post_id->ID ) ) { + $post_id = 'user_' . $post_id->ID; - - // term - } elseif( isset($post_id->taxonomy, $post_id->term_id) ) { - + + // term + } elseif ( isset( $post_id->taxonomy, $post_id->term_id ) ) { + $post_id = 'term_' . $post_id->term_id; - - // comment - } elseif( isset($post_id->comment_ID) ) { - + + // comment + } elseif ( isset( $post_id->comment_ID ) ) { + $post_id = 'comment_' . $post_id->comment_ID; - - // default + + // default } else { - + $post_id = 0; - + } - } - - + // allow for option == options - if( $post_id === 'option' ) { - + if ( $post_id === 'option' ) { + $post_id = 'options'; - + } - - + // append language code - if( $post_id == 'options' ) { - - $dl = acf_get_setting('default_language'); - $cl = acf_get_setting('current_language'); - - if( $cl && $cl !== $dl ) { - + if ( $post_id == 'options' ) { + + $dl = acf_get_setting( 'default_language' ); + $cl = acf_get_setting( 'current_language' ); + + if ( $cl && $cl !== $dl ) { + $post_id .= '_' . $cl; - + } - } - - - + // filter for 3rd party - $post_id = apply_filters('acf/validate_post_id', $post_id, $_post_id); - - + $post_id = apply_filters( 'acf/validate_post_id', $post_id, $_post_id ); + // return return $post_id; - + } @@ -2685,86 +2571,82 @@ function acf_get_valid_post_id( $post_id = 0 ) { * * This function will return the type and id for a given $post_id string * -* @type function -* @date 2/07/2016 -* @since 5.4.0 +* @type function +* @date 2/07/2016 +* @since 5.4.0 * -* @param $post_id (mixed) -* @return $info (array) +* @param $post_id (mixed) +* @return $info (array) */ function acf_get_post_id_info( $post_id = 0 ) { - + // vars $info = array( - 'type' => 'post', - 'id' => 0 + 'type' => 'post', + 'id' => 0, ); - + // bail early if no $post_id - if( !$post_id ) return $info; - - + if ( ! $post_id ) { + return $info; + } + // check cache // - this function will most likely be called multiple times (saving loading fields from post) - //$cache_key = "get_post_id_info/post_id={$post_id}"; - - //if( acf_isset_cache($cache_key) ) return acf_get_cache($cache_key); - - + // $cache_key = "get_post_id_info/post_id={$post_id}"; + + // if( acf_isset_cache($cache_key) ) return acf_get_cache($cache_key); + // numeric - if( is_numeric($post_id) ) { - + if ( is_numeric( $post_id ) ) { + $info['id'] = (int) $post_id; - - // string - } elseif( is_string($post_id) ) { - + + // string + } elseif ( is_string( $post_id ) ) { + // vars $glue = '_'; - $type = explode($glue, $post_id); - $id = array_pop($type); - $type = implode($glue, $type); - $meta = array('post', 'user', 'comment', 'term'); - - + $type = explode( $glue, $post_id ); + $id = array_pop( $type ); + $type = implode( $glue, $type ); + $meta = array( 'post', 'user', 'comment', 'term' ); + // check if is taxonomy (ACF < 5.5) // - avoid scenario where taxonomy exists with name of meta type - if( !in_array($type, $meta) && acf_isset_termmeta($type) ) $type = 'term'; - - - // meta - if( is_numeric($id) && in_array($type, $meta) ) { - - $info['type'] = $type; - $info['id'] = (int) $id; - - // option - } else { - - $info['type'] = 'option'; - $info['id'] = $post_id; - + if ( ! in_array( $type, $meta ) && acf_isset_termmeta( $type ) ) { + $type = 'term'; + } + + // meta + if ( is_numeric( $id ) && in_array( $type, $meta ) ) { + + $info['type'] = $type; + $info['id'] = (int) $id; + + // option + } else { + + $info['type'] = 'option'; + $info['id'] = $post_id; + } - } - - + // update cache - //acf_set_cache($cache_key, $info); - - + // acf_set_cache($cache_key, $info); + // filter - $info = apply_filters("acf/get_post_id_info", $info, $post_id); - + $info = apply_filters( 'acf/get_post_id_info', $info, $post_id ); + // return return $info; - + } /* - acf_log( acf_get_post_id_info(4) ); acf_log( acf_get_post_id_info('post_4') ); @@ -2792,27 +2674,29 @@ acf_log( acf_get_post_id_info('options') ); * This function will return true if the termmeta table exists * https://developer.wordpress.org/reference/functions/get_term_meta/ * -* @type function -* @date 3/09/2016 -* @since 5.4.0 +* @type function +* @date 3/09/2016 +* @since 5.4.0 * -* @param $post_id (int) -* @return $post_id (int) +* @param $post_id (int) +* @return $post_id (int) */ function acf_isset_termmeta( $taxonomy = '' ) { - + // bail ealry if no table - if( get_option('db_version') < 34370 ) return false; - - + if ( get_option( 'db_version' ) < 34370 ) { + return false; + } + // check taxonomy - if( $taxonomy && !taxonomy_exists($taxonomy) ) return false; - - + if ( $taxonomy && ! taxonomy_exists( $taxonomy ) ) { + return false; + } + // return return true; - + } @@ -2821,86 +2705,77 @@ function acf_isset_termmeta( $taxonomy = '' ) { * * This function will walk througfh the $_FILES data and upload each found * -* @type function -* @date 25/10/2014 -* @since 5.0.9 +* @type function +* @date 25/10/2014 +* @since 5.0.9 * -* @param $ancestors (array) an internal parameter, not required -* @return n/a +* @param $ancestors (array) an internal parameter, not required +* @return n/a */ - + function acf_upload_files( $ancestors = array() ) { - + // vars $file = array( - 'name' => '', - 'type' => '', - 'tmp_name' => '', - 'error' => '', - 'size' => '' + 'name' => '', + 'type' => '', + 'tmp_name' => '', + 'error' => '', + 'size' => '', ); - - + // populate with $_FILES data - foreach( array_keys($file) as $k ) { - + foreach ( array_keys( $file ) as $k ) { + $file[ $k ] = $_FILES['acf'][ $k ]; - + } - - + // walk through ancestors - if( !empty($ancestors) ) { - - foreach( $ancestors as $a ) { - - foreach( array_keys($file) as $k ) { - + if ( ! empty( $ancestors ) ) { + + foreach ( $ancestors as $a ) { + + foreach ( array_keys( $file ) as $k ) { + $file[ $k ] = $file[ $k ][ $a ]; - + } - } - } - - + // is array? - if( is_array($file['name']) ) { - - foreach( array_keys($file['name']) as $k ) { - - $_ancestors = array_merge($ancestors, array($k)); - + if ( is_array( $file['name'] ) ) { + + foreach ( array_keys( $file['name'] ) as $k ) { + + $_ancestors = array_merge( $ancestors, array( $k ) ); + acf_upload_files( $_ancestors ); - + } - + return; - + } - - + // bail ealry if file has error (no file uploaded) - if( $file['error'] ) { - + if ( $file['error'] ) { + return; - + } - - + // assign global _acfuploader for media validation - $_POST['_acfuploader'] = end($ancestors); - - + $_POST['_acfuploader'] = end( $ancestors ); + // file found! $attachment_id = acf_upload_file( $file ); - - + // update $_POST - array_unshift($ancestors, 'acf'); + array_unshift( $ancestors, 'acf' ); acf_update_nested_array( $_POST, $ancestors, $attachment_id ); - + } @@ -2909,65 +2784,60 @@ function acf_upload_files( $ancestors = array() ) { * * This function will uploade a $_FILE * -* @type function -* @date 27/10/2014 -* @since 5.0.9 +* @type function +* @date 27/10/2014 +* @since 5.0.9 * -* @param $uploaded_file (array) array found from $_FILE data -* @return $id (int) new attachment ID +* @param $uploaded_file (array) array found from $_FILE data +* @return $id (int) new attachment ID */ function acf_upload_file( $uploaded_file ) { - + // required - //require_once( ABSPATH . "/wp-load.php" ); // WP should already be loaded - require_once( ABSPATH . "/wp-admin/includes/media.php" ); // video functions - require_once( ABSPATH . "/wp-admin/includes/file.php" ); - require_once( ABSPATH . "/wp-admin/includes/image.php" ); - - + // require_once( ABSPATH . "/wp-load.php" ); // WP should already be loaded + require_once ABSPATH . '/wp-admin/includes/media.php'; // video functions + require_once ABSPATH . '/wp-admin/includes/file.php'; + require_once ABSPATH . '/wp-admin/includes/image.php'; + // required for wp_handle_upload() to upload the file $upload_overrides = array( 'test_form' => false ); - - + // upload $file = wp_handle_upload( $uploaded_file, $upload_overrides ); - - + // bail ealry if upload failed - if( isset($file['error']) ) { - + if ( isset( $file['error'] ) ) { + return $file['error']; - + } - - + // vars - $url = $file['url']; - $type = $file['type']; - $file = $file['file']; - $filename = basename($file); - + $url = $file['url']; + $type = $file['type']; + $file = $file['file']; + $filename = basename( $file ); // Construct the object array $object = array( - 'post_title' => $filename, + 'post_title' => $filename, 'post_mime_type' => $type, - 'guid' => $url + 'guid' => $url, ); // Save the data - $id = wp_insert_attachment($object, $file); + $id = wp_insert_attachment( $object, $file ); // Add the meta-data wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); - + /** This action is documented in wp-admin/custom-header.php */ do_action( 'wp_create_file_in_uploads', $file, $id ); // For replication - + // return new ID return $id; - + } @@ -2976,42 +2846,39 @@ function acf_upload_file( $uploaded_file ) { * * This function will update a nested array value. Useful for modifying the $_POST array * -* @type function -* @date 27/10/2014 -* @since 5.0.9 +* @type function +* @date 27/10/2014 +* @since 5.0.9 * -* @param $array (array) target array to be updated -* @param $ancestors (array) array of keys to navigate through to find the child -* @param $value (mixed) The new value -* @return (boolean) +* @param $array (array) target array to be updated +* @param $ancestors (array) array of keys to navigate through to find the child +* @param $value (mixed) The new value +* @return (boolean) */ function acf_update_nested_array( &$array, $ancestors, $value ) { - + // if no more ancestors, update the current var - if( empty($ancestors) ) { - + if ( empty( $ancestors ) ) { + $array = $value; - + // return return true; - + } - - + // shift the next ancestor from the array $k = array_shift( $ancestors ); - - + // if exists - if( isset($array[ $k ]) ) { - + if ( isset( $array[ $k ] ) ) { + return acf_update_nested_array( $array[ $k ], $ancestors, $value ); - + } - - - // return + + // return return false; } @@ -3021,35 +2888,35 @@ function acf_update_nested_array( &$array, $ancestors, $value ) { * * This function will return true if all args are matched for the current screen * -* @type function -* @date 9/12/2014 -* @since 5.1.5 +* @type function +* @date 9/12/2014 +* @since 5.1.5 * -* @param $post_id (int) -* @return $post_id (int) +* @param $post_id (int) +* @return $post_id (int) */ function acf_is_screen( $id = '' ) { - + // bail early if not defined - if( !function_exists('get_current_screen') ) { + if ( ! function_exists( 'get_current_screen' ) ) { return false; } - + // vars $current_screen = get_current_screen(); - + // no screen - if( !$current_screen ) { + if ( ! $current_screen ) { return false; - - // array - } elseif( is_array($id) ) { - return in_array($current_screen->id, $id); - - // string + + // array + } elseif ( is_array( $id ) ) { + return in_array( $current_screen->id, $id ); + + // string } else { - return ($id === $current_screen->id); + return ( $id === $current_screen->id ); } } @@ -3059,65 +2926,65 @@ function acf_is_screen( $id = '' ) { * * This function will return a var if it exists in an array * -* @type function -* @date 9/12/2014 -* @since 5.1.5 +* @type function +* @date 9/12/2014 +* @since 5.1.5 * -* @param $array (array) the array to look within -* @param $key (key) the array key to look for. Nested values may be found using '/' -* @param $default (mixed) the value returned if not found -* @return $post_id (int) +* @param $array (array) the array to look within +* @param $key (key) the array key to look for. Nested values may be found using '/' +* @param $default (mixed) the value returned if not found +* @return $post_id (int) */ function acf_maybe_get( $array = array(), $key = 0, $default = null ) { - - return isset( $array[$key] ) ? $array[$key] : $default; - + + return isset( $array[ $key ] ) ? $array[ $key ] : $default; + } function acf_maybe_get_POST( $key = '', $default = null ) { - - return isset( $_POST[$key] ) ? $_POST[$key] : $default; - + + return isset( $_POST[ $key ] ) ? $_POST[ $key ] : $default; + } function acf_maybe_get_GET( $key = '', $default = null ) { - - return isset( $_GET[$key] ) ? $_GET[$key] : $default; - + + return isset( $_GET[ $key ] ) ? $_GET[ $key ] : $default; + } /** * Returns an array of attachment data. * - * @date 05/01/2015 - * @since 5.1.5 + * @date 05/01/2015 + * @since 5.1.5 * - * @param int|WP_Post The attachment ID or object. - * @return array|false + * @param int|WP_Post The attachment ID or object. + * @return array|false */ function acf_get_attachment( $attachment ) { - + // Allow filter to short-circuit load attachment logic. - // Alternatively, this filter may be used to switch blogs for multisite media functionality. - $response = apply_filters( "acf/pre_load_attachment", null, $attachment ); - if( $response !== null ) { + // Alternatively, this filter may be used to switch blogs for multisite media functionality. + $response = apply_filters( 'acf/pre_load_attachment', null, $attachment ); + if ( $response !== null ) { return $response; } // Get the attachment post object. $attachment = get_post( $attachment ); - if( !$attachment ) { + if ( ! $attachment ) { return false; } - if( $attachment->post_type !== 'attachment' ) { + if ( $attachment->post_type !== 'attachment' ) { return false; } - + // Load various attachment details. - $meta = wp_get_attachment_metadata( $attachment->ID ); + $meta = wp_get_attachment_metadata( $attachment->ID ); $attached_file = get_attached_file( $attachment->ID ); - if( strpos( $attachment->post_mime_type, '/' ) !== false ) { + if ( strpos( $attachment->post_mime_type, '/' ) !== false ) { list( $type, $subtype ) = explode( '/', $attachment->post_mime_type ); } else { list( $type, $subtype ) = array( $attachment->post_mime_type, '' ); @@ -3125,90 +2992,90 @@ function acf_get_attachment( $attachment ) { // Generate response. $response = array( - 'ID' => $attachment->ID, - 'id' => $attachment->ID, - 'title' => $attachment->post_title, - 'filename' => wp_basename( $attached_file ), - 'filesize' => 0, - 'url' => wp_get_attachment_url( $attachment->ID ), - 'link' => get_attachment_link( $attachment->ID ), - 'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ), - 'author' => $attachment->post_author, - 'description' => $attachment->post_content, - 'caption' => $attachment->post_excerpt, - 'name' => $attachment->post_name, - 'status' => $attachment->post_status, - 'uploaded_to' => $attachment->post_parent, - 'date' => $attachment->post_date_gmt, - 'modified' => $attachment->post_modified_gmt, - 'menu_order' => $attachment->menu_order, - 'mime_type' => $attachment->post_mime_type, - 'type' => $type, - 'subtype' => $subtype, - 'icon' => wp_mime_type_icon( $attachment->ID ) + 'ID' => $attachment->ID, + 'id' => $attachment->ID, + 'title' => $attachment->post_title, + 'filename' => wp_basename( $attached_file ), + 'filesize' => 0, + 'url' => wp_get_attachment_url( $attachment->ID ), + 'link' => get_attachment_link( $attachment->ID ), + 'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ), + 'author' => $attachment->post_author, + 'description' => $attachment->post_content, + 'caption' => $attachment->post_excerpt, + 'name' => $attachment->post_name, + 'status' => $attachment->post_status, + 'uploaded_to' => $attachment->post_parent, + 'date' => $attachment->post_date_gmt, + 'modified' => $attachment->post_modified_gmt, + 'menu_order' => $attachment->menu_order, + 'mime_type' => $attachment->post_mime_type, + 'type' => $type, + 'subtype' => $subtype, + 'icon' => wp_mime_type_icon( $attachment->ID ), ); - + // Append filesize data. - if( isset($meta['filesize']) ) { + if ( isset( $meta['filesize'] ) ) { $response['filesize'] = $meta['filesize']; - } elseif( file_exists($attached_file) ) { + } elseif ( file_exists( $attached_file ) ) { $response['filesize'] = filesize( $attached_file ); } - + // Restrict the loading of image "sizes". $sizes_id = 0; // Type specific logic. - switch( $type ) { + switch ( $type ) { case 'image': $sizes_id = $attachment->ID; - $src = wp_get_attachment_image_src( $attachment->ID, 'full' ); + $src = wp_get_attachment_image_src( $attachment->ID, 'full' ); if ( $src ) { - $response['url'] = $src[0]; - $response['width'] = $src[1]; + $response['url'] = $src[0]; + $response['width'] = $src[1]; $response['height'] = $src[2]; } break; case 'video': - $response['width'] = acf_maybe_get( $meta, 'width', 0 ); + $response['width'] = acf_maybe_get( $meta, 'width', 0 ); $response['height'] = acf_maybe_get( $meta, 'height', 0 ); - if( $featured_id = get_post_thumbnail_id( $attachment->ID ) ) { + if ( $featured_id = get_post_thumbnail_id( $attachment->ID ) ) { $sizes_id = $featured_id; } break; case 'audio': - if( $featured_id = get_post_thumbnail_id( $attachment->ID ) ) { + if ( $featured_id = get_post_thumbnail_id( $attachment->ID ) ) { $sizes_id = $featured_id; - } + } break; } // Load array of image sizes. - if( $sizes_id ) { - $sizes = get_intermediate_image_sizes(); + if ( $sizes_id ) { + $sizes = get_intermediate_image_sizes(); $sizes_data = array(); - foreach( $sizes as $size ) { + foreach ( $sizes as $size ) { $src = wp_get_attachment_image_src( $sizes_id, $size ); if ( $src ) { - $sizes_data[ $size ] = $src[0]; - $sizes_data[ $size . '-width' ] = $src[1]; + $sizes_data[ $size ] = $src[0]; + $sizes_data[ $size . '-width' ] = $src[1]; $sizes_data[ $size . '-height' ] = $src[2]; } } $response['sizes'] = $sizes_data; } - + /** * Filters the attachment $response after it has been loaded. * - * @date 16/06/2020 - * @since 5.9.0 + * @date 16/06/2020 + * @since 5.9.0 * - * @param array $response Array of loaded attachment data. - * @param WP_Post $attachment Attachment object. - * @param array|false $meta Array of attachment meta data, or false if there is none. + * @param array $response Array of loaded attachment data. + * @param WP_Post $attachment Attachment object. + * @param array|false $meta Array of attachment meta data, or false if there is none. */ - return apply_filters( "acf/load_attachment", $response, $attachment, $meta ); + return apply_filters( 'acf/load_attachment', $response, $attachment, $meta ); } @@ -3217,37 +3084,34 @@ function acf_get_attachment( $attachment ) { * * This function will truncate and return a string * -* @type function -* @date 8/08/2014 -* @since 5.0.0 +* @type function +* @date 8/08/2014 +* @since 5.0.0 * -* @param $text (string) -* @param $length (int) -* @return (string) +* @param $text (string) +* @param $length (int) +* @return (string) */ function acf_get_truncated( $text, $length = 64 ) { - + // vars - $text = trim($text); + $text = trim( $text ); $the_length = strlen( $text ); - - + // cut - $return = substr( $text, 0, ($length - 3) ); - - + $return = substr( $text, 0, ( $length - 3 ) ); + // ... - if( $the_length > ($length - 3) ) { - + if ( $the_length > ( $length - 3 ) ) { + $return .= '...'; - + } - - + // return return $return; - + } /* @@ -3255,26 +3119,25 @@ function acf_get_truncated( $text, $length = 64 ) { * * This function will return true if the current user can administrate the ACF field groups * -* @type function -* @date 9/02/2015 -* @since 5.1.5 +* @type function +* @date 9/02/2015 +* @since 5.1.5 * -* @param $post_id (int) -* @return $post_id (int) +* @param $post_id (int) +* @return $post_id (int) */ function acf_current_user_can_admin() { - - if( acf_get_setting('show_admin') && current_user_can(acf_get_setting('capability')) ) { - + + if ( acf_get_setting( 'show_admin' ) && current_user_can( acf_get_setting( 'capability' ) ) ) { + return true; - + } - - + // return return false; - + } @@ -3283,53 +3146,48 @@ function acf_current_user_can_admin() { * * This function will return a numeric value of bytes for a given filesize string * -* @type function -* @date 18/02/2015 -* @since 5.1.5 +* @type function +* @date 18/02/2015 +* @since 5.1.5 * -* @param $size (mixed) -* @return (int) +* @param $size (mixed) +* @return (int) */ function acf_get_filesize( $size = 1 ) { - + // vars - $unit = 'MB'; + $unit = 'MB'; $units = array( 'TB' => 4, 'GB' => 3, 'MB' => 2, 'KB' => 1, ); - - + // look for $unit within the $size parameter (123 KB) - if( is_string($size) ) { - + if ( is_string( $size ) ) { + // vars - $custom = strtoupper( substr($size, -2) ); - - foreach( $units as $k => $v ) { - - if( $custom === $k ) { - + $custom = strtoupper( substr( $size, -2 ) ); + + foreach ( $units as $k => $v ) { + + if ( $custom === $k ) { + $unit = $k; - $size = substr($size, 0, -2); - + $size = substr( $size, 0, -2 ); + } - } - } - - + // calc bytes - $bytes = floatval($size) * pow(1024, $units[$unit]); - - + $bytes = floatval( $size ) * pow( 1024, $units[ $unit ] ); + // return return $bytes; - + } @@ -3338,20 +3196,19 @@ function acf_get_filesize( $size = 1 ) { * * This function will return a formatted string containing the filesize and unit * -* @type function -* @date 18/02/2015 -* @since 5.1.5 +* @type function +* @date 18/02/2015 +* @since 5.1.5 * -* @param $size (mixed) -* @return (int) +* @param $size (mixed) +* @return (int) */ function acf_format_filesize( $size = 1 ) { - + // convert $bytes = acf_get_filesize( $size ); - - + // vars $units = array( 'TB' => 4, @@ -3359,25 +3216,22 @@ function acf_format_filesize( $size = 1 ) { 'MB' => 2, 'KB' => 1, ); - - + // loop through units - foreach( $units as $k => $v ) { - - $result = $bytes / pow(1024, $v); - - if( $result >= 1 ) { - + foreach ( $units as $k => $v ) { + + $result = $bytes / pow( 1024, $v ); + + if ( $result >= 1 ) { + return $result . ' ' . $k; - + } - } - - + // return return $bytes . ' B'; - + } @@ -3386,50 +3240,45 @@ function acf_format_filesize( $size = 1 ) { * * This function will replace old terms with new split term ids * -* @type function -* @date 27/02/2015 -* @since 5.1.5 +* @type function +* @date 27/02/2015 +* @since 5.1.5 * -* @param $terms (int|array) -* @param $taxonomy (string) -* @return $terms +* @param $terms (int|array) +* @param $taxonomy (string) +* @return $terms */ function acf_get_valid_terms( $terms = false, $taxonomy = 'category' ) { - + // force into array - $terms = acf_get_array($terms); - - + $terms = acf_get_array( $terms ); + // force ints - $terms = array_map('intval', $terms); - - + $terms = array_map( 'intval', $terms ); + // bail early if function does not yet exist or - if( !function_exists('wp_get_split_term') || empty($terms) ) { - + if ( ! function_exists( 'wp_get_split_term' ) || empty( $terms ) ) { + return $terms; - + } - - + // attempt to find new terms - foreach( $terms as $i => $term_id ) { - - $new_term_id = wp_get_split_term($term_id, $taxonomy); - - if( $new_term_id ) { - + foreach ( $terms as $i => $term_id ) { + + $new_term_id = wp_get_split_term( $term_id, $taxonomy ); + + if ( $new_term_id ) { + $terms[ $i ] = $new_term_id; - + } - } - - + // return return $terms; - + } @@ -3438,185 +3287,172 @@ function acf_get_valid_terms( $terms = false, $taxonomy = 'category' ) { * * This function will validate an attachment based on a field's restrictions and return an array of errors * -* @type function -* @date 3/07/2015 -* @since 5.2.3 +* @type function +* @date 3/07/2015 +* @since 5.2.3 * -* @param $attachment (array) attachment data. Changes based on context -* @param $field (array) field settings containing restrictions -* @param $context (string) $file is different when uploading / preparing -* @return $errors (array) +* @param $attachment (array) attachment data. Changes based on context +* @param $field (array) field settings containing restrictions +* @param $context (string) $file is different when uploading / preparing +* @return $errors (array) */ function acf_validate_attachment( $attachment, $field, $context = 'prepare' ) { - + // vars $errors = array(); - $file = array( - 'type' => '', - 'width' => 0, - 'height' => 0, - 'size' => 0 + $file = array( + 'type' => '', + 'width' => 0, + 'height' => 0, + 'size' => 0, ); - - + // upload - if( $context == 'upload' ) { - + if ( $context == 'upload' ) { + // vars - $file['type'] = pathinfo($attachment['name'], PATHINFO_EXTENSION); - $file['size'] = filesize($attachment['tmp_name']); - - if( strpos($attachment['type'], 'image') !== false ) { - - $size = getimagesize($attachment['tmp_name']); - $file['width'] = acf_maybe_get($size, 0); - $file['height'] = acf_maybe_get($size, 1); - + $file['type'] = pathinfo( $attachment['name'], PATHINFO_EXTENSION ); + $file['size'] = filesize( $attachment['tmp_name'] ); + + if ( strpos( $attachment['type'], 'image' ) !== false ) { + + $size = getimagesize( $attachment['tmp_name'] ); + $file['width'] = acf_maybe_get( $size, 0 ); + $file['height'] = acf_maybe_get( $size, 1 ); + } - - // prepare - } elseif( $context == 'prepare' ) { - - $use_path = isset($attachment['filename']) ? $attachment['filename'] : $attachment['url']; - $file['type'] = pathinfo($use_path, PATHINFO_EXTENSION); - $file['size'] = acf_maybe_get($attachment, 'filesizeInBytes', 0); - $file['width'] = acf_maybe_get($attachment, 'width', 0); - $file['height'] = acf_maybe_get($attachment, 'height', 0); - - // custom + + // prepare + } elseif ( $context == 'prepare' ) { + + $use_path = isset( $attachment['filename'] ) ? $attachment['filename'] : $attachment['url']; + $file['type'] = pathinfo( $use_path, PATHINFO_EXTENSION ); + $file['size'] = acf_maybe_get( $attachment, 'filesizeInBytes', 0 ); + $file['width'] = acf_maybe_get( $attachment, 'width', 0 ); + $file['height'] = acf_maybe_get( $attachment, 'height', 0 ); + + // custom } else { - - $file = array_merge($file, $attachment); - $use_path = isset($attachment['filename']) ? $attachment['filename'] : $attachment['url']; - $file['type'] = pathinfo($use_path, PATHINFO_EXTENSION); - + + $file = array_merge( $file, $attachment ); + $use_path = isset( $attachment['filename'] ) ? $attachment['filename'] : $attachment['url']; + $file['type'] = pathinfo( $use_path, PATHINFO_EXTENSION ); + } - - + // image - if( $file['width'] || $file['height'] ) { - + if ( $file['width'] || $file['height'] ) { + // width - $min_width = (int) acf_maybe_get($field, 'min_width', 0); - $max_width = (int) acf_maybe_get($field, 'max_width', 0); - - if( $file['width'] ) { - - if( $min_width && $file['width'] < $min_width ) { - + $min_width = (int) acf_maybe_get( $field, 'min_width', 0 ); + $max_width = (int) acf_maybe_get( $field, 'max_width', 0 ); + + if ( $file['width'] ) { + + if ( $min_width && $file['width'] < $min_width ) { + // min width - $errors['min_width'] = sprintf(__('Image width must be at least %dpx.', 'acf'), $min_width ); - - } elseif( $max_width && $file['width'] > $max_width ) { - + $errors['min_width'] = sprintf( __( 'Image width must be at least %dpx.', 'acf' ), $min_width ); + + } elseif ( $max_width && $file['width'] > $max_width ) { + // min width - $errors['max_width'] = sprintf(__('Image width must not exceed %dpx.', 'acf'), $max_width ); - + $errors['max_width'] = sprintf( __( 'Image width must not exceed %dpx.', 'acf' ), $max_width ); + } - } - - + // height - $min_height = (int) acf_maybe_get($field, 'min_height', 0); - $max_height = (int) acf_maybe_get($field, 'max_height', 0); - - if( $file['height'] ) { - - if( $min_height && $file['height'] < $min_height ) { - + $min_height = (int) acf_maybe_get( $field, 'min_height', 0 ); + $max_height = (int) acf_maybe_get( $field, 'max_height', 0 ); + + if ( $file['height'] ) { + + if ( $min_height && $file['height'] < $min_height ) { + // min height - $errors['min_height'] = sprintf(__('Image height must be at least %dpx.', 'acf'), $min_height ); - - } elseif( $max_height && $file['height'] > $max_height ) { - + $errors['min_height'] = sprintf( __( 'Image height must be at least %dpx.', 'acf' ), $min_height ); + + } elseif ( $max_height && $file['height'] > $max_height ) { + // min height - $errors['max_height'] = sprintf(__('Image height must not exceed %dpx.', 'acf'), $max_height ); - + $errors['max_height'] = sprintf( __( 'Image height must not exceed %dpx.', 'acf' ), $max_height ); + } - } - } - - + // file size - if( $file['size'] ) { - - $min_size = acf_maybe_get($field, 'min_size', 0); - $max_size = acf_maybe_get($field, 'max_size', 0); - - if( $min_size && $file['size'] < acf_get_filesize($min_size) ) { - + if ( $file['size'] ) { + + $min_size = acf_maybe_get( $field, 'min_size', 0 ); + $max_size = acf_maybe_get( $field, 'max_size', 0 ); + + if ( $min_size && $file['size'] < acf_get_filesize( $min_size ) ) { + // min width - $errors['min_size'] = sprintf(__('File size must be at least %s.', 'acf'), acf_format_filesize($min_size) ); - - } elseif( $max_size && $file['size'] > acf_get_filesize($max_size) ) { - + $errors['min_size'] = sprintf( __( 'File size must be at least %s.', 'acf' ), acf_format_filesize( $min_size ) ); + + } elseif ( $max_size && $file['size'] > acf_get_filesize( $max_size ) ) { + // min width - $errors['max_size'] = sprintf(__('File size must not exceed %s.', 'acf'), acf_format_filesize($max_size) ); - + $errors['max_size'] = sprintf( __( 'File size must not exceed %s.', 'acf' ), acf_format_filesize( $max_size ) ); + } - } - - + // file type - if( $file['type'] ) { - - $mime_types = acf_maybe_get($field, 'mime_types', ''); - + if ( $file['type'] ) { + + $mime_types = acf_maybe_get( $field, 'mime_types', '' ); + // lower case - $file['type'] = strtolower($file['type']); - $mime_types = strtolower($mime_types); - - + $file['type'] = strtolower( $file['type'] ); + $mime_types = strtolower( $mime_types ); + // explode - $mime_types = str_replace(array(' ', '.'), '', $mime_types); - $mime_types = explode(',', $mime_types); // split pieces - $mime_types = array_filter($mime_types); // remove empty pieces - - if( !empty($mime_types) && !in_array($file['type'], $mime_types) ) { - + $mime_types = str_replace( array( ' ', '.' ), '', $mime_types ); + $mime_types = explode( ',', $mime_types ); // split pieces + $mime_types = array_filter( $mime_types ); // remove empty pieces + + if ( ! empty( $mime_types ) && ! in_array( $file['type'], $mime_types ) ) { + // glue together last 2 types - if( count($mime_types) > 1 ) { - - $last1 = array_pop($mime_types); - $last2 = array_pop($mime_types); - - $mime_types[] = $last2 . ' ' . __('or', 'acf') . ' ' . $last1; - + if ( count( $mime_types ) > 1 ) { + + $last1 = array_pop( $mime_types ); + $last2 = array_pop( $mime_types ); + + $mime_types[] = $last2 . ' ' . __( 'or', 'acf' ) . ' ' . $last1; + } - - $errors['mime_types'] = sprintf(__('File type must be %s.', 'acf'), implode(', ', $mime_types) ); - + + $errors['mime_types'] = sprintf( __( 'File type must be %s.', 'acf' ), implode( ', ', $mime_types ) ); + } - } - - + /** * Filters the errors for a file before it is uploaded or displayed in the media modal. * - * @date 3/07/2015 - * @since 5.2.3 + * @date 3/07/2015 + * @since 5.2.3 * - * @param array $errors An array of errors. - * @param array $file An array of data for a single file. - * @param array $attachment An array of attachment data which differs based on the context. - * @param array $field The field array. - * @param string $context The curent context (uploading, preparing) + * @param array $errors An array of errors. + * @param array $file An array of data for a single file. + * @param array $attachment An array of attachment data which differs based on the context. + * @param array $field The field array. + * @param string $context The curent context (uploading, preparing) */ - $errors = apply_filters( "acf/validate_attachment/type={$field['type']}", $errors, $file, $attachment, $field, $context ); - $errors = apply_filters( "acf/validate_attachment/name={$field['_name']}", $errors, $file, $attachment, $field, $context ); - $errors = apply_filters( "acf/validate_attachment/key={$field['key']}", $errors, $file, $attachment, $field, $context ); - $errors = apply_filters( "acf/validate_attachment", $errors, $file, $attachment, $field, $context ); - - + $errors = apply_filters( "acf/validate_attachment/type={$field['type']}", $errors, $file, $attachment, $field, $context ); + $errors = apply_filters( "acf/validate_attachment/name={$field['_name']}", $errors, $file, $attachment, $field, $context ); + $errors = apply_filters( "acf/validate_attachment/key={$field['key']}", $errors, $file, $attachment, $field, $context ); + $errors = apply_filters( 'acf/validate_attachment', $errors, $file, $attachment, $field, $context ); + // return return $errors; - + } @@ -3625,26 +3461,25 @@ function acf_validate_attachment( $attachment, $field, $context = 'prepare' ) { * * Dynamic logic for uploader setting * -* @type function -* @date 7/05/2015 -* @since 5.2.3 +* @type function +* @date 7/05/2015 +* @since 5.2.3 * -* @param $uploader (string) -* @return $uploader +* @param $uploader (string) +* @return $uploader */ -add_filter('acf/settings/uploader', '_acf_settings_uploader'); +add_filter( 'acf/settings/uploader', '_acf_settings_uploader' ); function _acf_settings_uploader( $uploader ) { - + // if can't upload files - if( !current_user_can('upload_files') ) { - + if ( ! current_user_can( 'upload_files' ) ) { + $uploader = 'basic'; - + } - - + // return return $uploader; } @@ -3655,37 +3490,37 @@ function _acf_settings_uploader( $uploader ) { * * description * -* @type function -* @date 7/12/2015 -* @since 5.3.2 +* @type function +* @date 7/12/2015 +* @since 5.3.2 * -* @param $post_id (int) -* @return $post_id (int) +* @param $post_id (int) +* @return $post_id (int) */ /* function acf_translate_keys( $array, $keys ) { - + // bail early if no keys if( empty($keys) ) return $array; - - + + // translate foreach( $keys as $k ) { - + // bail ealry if not exists if( !isset($array[ $k ]) ) continue; - - + + // translate $array[ $k ] = acf_translate( $array[ $k ] ); - + } - - + + // return return $array; - + } */ @@ -3696,61 +3531,63 @@ function acf_translate_keys( $array, $keys ) { * This function will translate a string using the new 'l10n_textdomain' setting * Also works for arrays which is great for fields - select -> choices * -* @type function -* @date 4/12/2015 -* @since 5.3.2 +* @type function +* @date 4/12/2015 +* @since 5.3.2 * -* @param $string (mixed) string or array containins strings to be translated -* @return $string +* @param $string (mixed) string or array containins strings to be translated +* @return $string */ function acf_translate( $string ) { - + // vars - $l10n = acf_get_setting('l10n'); - $textdomain = acf_get_setting('l10n_textdomain'); - - + $l10n = acf_get_setting( 'l10n' ); + $textdomain = acf_get_setting( 'l10n_textdomain' ); + // bail early if not enabled - if( !$l10n ) return $string; - - + if ( ! $l10n ) { + return $string; + } + // bail early if no textdomain - if( !$textdomain ) return $string; - - + if ( ! $textdomain ) { + return $string; + } + // is array - if( is_array($string) ) { - - return array_map('acf_translate', $string); - + if ( is_array( $string ) ) { + + return array_map( 'acf_translate', $string ); + } - - + // bail early if not string - if( !is_string($string) ) return $string; - - - // bail early if empty - if( $string === '' ) return $string; - - - // allow for var_export export - if( acf_get_setting('l10n_var_export') ){ - - // bail early if already translated - if( substr($string, 0, 7) === '!!__(!!' ) return $string; - - - // return - return "!!__(!!'" . $string . "!!', !!'" . $textdomain . "!!')!!"; - + if ( ! is_string( $string ) ) { + return $string; } - - + + // bail early if empty + if ( $string === '' ) { + return $string; + } + + // allow for var_export export + if ( acf_get_setting( 'l10n_var_export' ) ) { + + // bail early if already translated + if ( substr( $string, 0, 7 ) === '!!__(!!' ) { + return $string; + } + + // return + return "!!__(!!'" . $string . "!!', !!'" . $textdomain . "!!')!!"; + + } + // vars return __( $string, $textdomain ); - + } @@ -3759,29 +3596,29 @@ function acf_translate( $string ) { * * This function will determine if the action has already run before adding / calling the function * -* @type function -* @date 13/01/2016 -* @since 5.3.2 +* @type function +* @date 13/01/2016 +* @since 5.3.2 * -* @param $post_id (int) -* @return $post_id (int) +* @param $post_id (int) +* @return $post_id (int) */ function acf_maybe_add_action( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) { - + // if action has already run, execute it // - if currently doing action, allow $tag to be added as per usual to allow $priority ordering needed for 3rd party asset compatibility - if( did_action($tag) && !doing_action($tag) ) { - + if ( did_action( $tag ) && ! doing_action( $tag ) ) { + call_user_func( $function_to_add ); - - // if action has not yet run, add it + + // if action has not yet run, add it } else { - + add_action( $tag, $function_to_add, $priority, $accepted_args ); - + } - + } @@ -3790,41 +3627,37 @@ function acf_maybe_add_action( $tag, $function_to_add, $priority = 10, $accepted * * This function will return true if the field's row is collapsed * -* @type function -* @date 2/03/2016 -* @since 5.3.2 +* @type function +* @date 2/03/2016 +* @since 5.3.2 * -* @param $post_id (int) -* @return $post_id (int) +* @param $post_id (int) +* @return $post_id (int) */ function acf_is_row_collapsed( $field_key = '', $row_index = 0 ) { - + // collapsed - $collapsed = acf_get_user_setting('collapsed_' . $field_key, ''); - - + $collapsed = acf_get_user_setting( 'collapsed_' . $field_key, '' ); + // cookie fallback ( version < 5.3.2 ) - if( $collapsed === '' ) { - - $collapsed = acf_extract_var($_COOKIE, "acf_collapsed_{$field_key}", ''); - $collapsed = str_replace('|', ',', $collapsed); - - + if ( $collapsed === '' ) { + + $collapsed = acf_extract_var( $_COOKIE, "acf_collapsed_{$field_key}", '' ); + $collapsed = str_replace( '|', ',', $collapsed ); + // update acf_update_user_setting( 'collapsed_' . $field_key, $collapsed ); - + } - - + // explode - $collapsed = explode(',', $collapsed); - $collapsed = array_filter($collapsed, 'is_numeric'); - - + $collapsed = explode( ',', $collapsed ); + $collapsed = array_filter( $collapsed, 'is_numeric' ); + // collapsed class - return in_array($row_index, $collapsed); - + return in_array( $row_index, $collapsed ); + } @@ -3833,28 +3666,28 @@ function acf_is_row_collapsed( $field_key = '', $row_index = 0 ) { * * description * -* @type function -* @date 24/10/16 -* @since 5.5.0 +* @type function +* @date 24/10/16 +* @since 5.5.0 * -* @param $post_id (int) -* @return $post_id (int) +* @param $post_id (int) +* @return $post_id (int) */ function acf_get_attachment_image( $attachment_id = 0, $size = 'thumbnail' ) { - + // vars - $url = wp_get_attachment_image_src($attachment_id, 'thumbnail'); - $alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true); - - + $url = wp_get_attachment_image_src( $attachment_id, 'thumbnail' ); + $alt = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ); + // bail early if no url - if( !$url ) return ''; - - + if ( ! $url ) { + return ''; + } + // return $value = '' . $alt . ''; - + } @@ -3863,77 +3696,71 @@ function acf_get_attachment_image( $attachment_id = 0, $size = 'thumbnail' ) { * * This function will return a thumbail image url for a given post * -* @type function -* @date 3/05/2016 -* @since 5.3.8 +* @type function +* @date 3/05/2016 +* @since 5.3.8 * -* @param $post (obj) -* @param $size (mixed) -* @return (string) +* @param $post (obj) +* @param $size (mixed) +* @return (string) */ function acf_get_post_thumbnail( $post = null, $size = 'thumbnail' ) { - + // vars $data = array( - 'url' => '', - 'type' => '', - 'html' => '' + 'url' => '', + 'type' => '', + 'html' => '', ); - - + // post - $post = get_post($post); - - + $post = get_post( $post ); + // bail early if no post - if( !$post ) return $data; - - + if ( ! $post ) { + return $data; + } + // vars - $thumb_id = $post->ID; - $mime_type = acf_maybe_get(explode('/', $post->post_mime_type), 0); - - + $thumb_id = $post->ID; + $mime_type = acf_maybe_get( explode( '/', $post->post_mime_type ), 0 ); + // attachment - if( $post->post_type === 'attachment' ) { - + if ( $post->post_type === 'attachment' ) { + // change $thumb_id - if( $mime_type === 'audio' || $mime_type === 'video' ) { - - $thumb_id = get_post_thumbnail_id($post->ID); - + if ( $mime_type === 'audio' || $mime_type === 'video' ) { + + $thumb_id = get_post_thumbnail_id( $post->ID ); + } - - // post + + // post } else { - - $thumb_id = get_post_thumbnail_id($post->ID); - + + $thumb_id = get_post_thumbnail_id( $post->ID ); + } - - + // try url - $data['url'] = wp_get_attachment_image_src($thumb_id, $size); - $data['url'] = acf_maybe_get($data['url'], 0); - - + $data['url'] = wp_get_attachment_image_src( $thumb_id, $size ); + $data['url'] = acf_maybe_get( $data['url'], 0 ); + // default icon - if( !$data['url'] && $post->post_type === 'attachment' ) { - - $data['url'] = wp_mime_type_icon($post->ID); + if ( ! $data['url'] && $post->post_type === 'attachment' ) { + + $data['url'] = wp_mime_type_icon( $post->ID ); $data['type'] = 'icon'; - + } - - + // html $data['html'] = ''; - - + // return return $data; - + } /** @@ -3941,34 +3768,34 @@ function acf_get_post_thumbnail( $post = null, $size = 'thumbnail' ) { * * Returns the name of the current browser. * - * @date 17/01/2014 - * @since 5.0.0 + * @date 17/01/2014 + * @since 5.0.0 * - * @param void - * @return string + * @param void + * @return string */ function acf_get_browser() { - + // Check server var. - if( isset($_SERVER['HTTP_USER_AGENT']) ) { + if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) { $agent = $_SERVER['HTTP_USER_AGENT']; - + // Loop over search terms. $browsers = array( - 'Firefox' => 'firefox', - 'Trident' => 'msie', - 'MSIE' => 'msie', - 'Edge' => 'edge', - 'Chrome' => 'chrome', - 'Safari' => 'safari', + 'Firefox' => 'firefox', + 'Trident' => 'msie', + 'MSIE' => 'msie', + 'Edge' => 'edge', + 'Chrome' => 'chrome', + 'Safari' => 'safari', ); - foreach( $browsers as $k => $v ) { - if( strpos($agent, $k) !== false ) { + foreach ( $browsers as $k => $v ) { + if ( strpos( $agent, $k ) !== false ) { return $v; } } } - + // Return default. return ''; } @@ -3979,39 +3806,36 @@ function acf_get_browser() { * * This function will reutrn true if performing a wp ajax call * -* @type function -* @date 7/06/2016 -* @since 5.3.8 +* @type function +* @date 7/06/2016 +* @since 5.3.8 * -* @param n/a -* @return (boolean) +* @param n/a +* @return (boolean) */ function acf_is_ajax( $action = '' ) { - + // vars $is_ajax = false; - - + // check if is doing ajax - if( defined('DOING_AJAX') && DOING_AJAX ) { - + if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { + $is_ajax = true; - + } - - + // check $action - if( $action && acf_maybe_get($_POST, 'action') !== $action ) { - + if ( $action && acf_maybe_get( $_POST, 'action' ) !== $action ) { + $is_ajax = false; - + } - - + // return return $is_ajax; - + } @@ -4022,39 +3846,38 @@ function acf_is_ajax( $action = '' ) { * * This function will accept a date value and return it in a formatted string * -* @type function -* @date 16/06/2016 -* @since 5.3.8 +* @type function +* @date 16/06/2016 +* @since 5.3.8 * -* @param $value (string) -* @return $format (string) +* @param $value (string) +* @return $format (string) */ function acf_format_date( $value, $format ) { - + // bail early if no value - if( !$value ) return $value; - - + if ( ! $value ) { + return $value; + } + // vars $unixtimestamp = 0; - - + // numeric (either unix or YYYYMMDD) - if( is_numeric($value) && strlen($value) !== 8 ) { - + if ( is_numeric( $value ) && strlen( $value ) !== 8 ) { + $unixtimestamp = $value; - + } else { - - $unixtimestamp = strtotime($value); - + + $unixtimestamp = strtotime( $value ); + } - - + // return - return date_i18n($format, $unixtimestamp); - + return date_i18n( $format, $unixtimestamp ); + } /** @@ -4062,11 +3885,11 @@ function acf_format_date( $value, $format ) { * * Deletes the debug.log file. * - * @date 21/1/19 - * @since 5.7.10 + * @date 21/1/19 + * @since 5.7.10 * - * @param type $var Description. Default. - * @return type Description. + * @param type $var Description. Default. + * @return type Description. */ function acf_clear_log() { unlink( WP_CONTENT_DIR . '/debug.log' ); @@ -4077,53 +3900,53 @@ function acf_clear_log() { * * description * -* @type function -* @date 24/06/2016 -* @since 5.3.8 +* @type function +* @date 24/06/2016 +* @since 5.3.8 * -* @param $post_id (int) -* @return $post_id (int) +* @param $post_id (int) +* @return $post_id (int) */ function acf_log() { - + // vars $args = func_get_args(); - + // loop - foreach( $args as $i => $arg ) { - + foreach ( $args as $i => $arg ) { + // array | object - if( is_array($arg) || is_object($arg) ) { - $arg = print_r($arg, true); - - // bool - } elseif( is_bool($arg) ) { + if ( is_array( $arg ) || is_object( $arg ) ) { + $arg = print_r( $arg, true ); + + // bool + } elseif ( is_bool( $arg ) ) { $arg = 'bool(' . ( $arg ? 'true' : 'false' ) . ')'; } - + // update $args[ $i ] = $arg; } - + // log - error_log( implode(' ', $args) ); + error_log( implode( ' ', $args ) ); } /** -* acf_dev_log -* -* Used to log variables only if ACF_DEV is defined -* -* @date 25/8/18 -* @since 5.7.4 -* -* @param mixed -* @return void -*/ + * acf_dev_log + * + * Used to log variables only if ACF_DEV is defined + * + * @date 25/8/18 + * @since 5.7.4 + * + * @param mixed + * @return void + */ function acf_dev_log() { - if( defined('ACF_DEV') && ACF_DEV ) { - call_user_func_array('acf_log', func_get_args()); + if ( defined( 'ACF_DEV' ) && ACF_DEV ) { + call_user_func_array( 'acf_log', func_get_args() ); } } @@ -4132,20 +3955,20 @@ function acf_dev_log() { * * This function will tell ACF what task it is doing * -* @type function -* @date 28/06/2016 -* @since 5.3.8 +* @type function +* @date 28/06/2016 +* @since 5.3.8 * -* @param $event (string) -* @param context (string) -* @return n/a +* @param $event (string) +* @param context (string) +* @return n/a */ function acf_doing( $event = '', $context = '' ) { - + acf_update_setting( 'doing', $event ); acf_update_setting( 'doing_context', $context ); - + } @@ -4154,40 +3977,37 @@ function acf_doing( $event = '', $context = '' ) { * * This function can be used to state what ACF is doing, or to check * -* @type function -* @date 28/06/2016 -* @since 5.3.8 +* @type function +* @date 28/06/2016 +* @since 5.3.8 * -* @param $event (string) -* @param context (string) -* @return (boolean) +* @param $event (string) +* @param context (string) +* @return (boolean) */ function acf_is_doing( $event = '', $context = '' ) { - + // vars $doing = false; - - + // task - if( acf_get_setting('doing') === $event ) { - + if ( acf_get_setting( 'doing' ) === $event ) { + $doing = true; - + } - - + // context - if( $context && acf_get_setting('doing_context') !== $context ) { - + if ( $context && acf_get_setting( 'doing_context' ) !== $context ) { + $doing = false; - + } - - + // return return $doing; - + } @@ -4197,32 +4017,30 @@ function acf_is_doing( $event = '', $context = '' ) { * This function will return true if the ACF plugin is active * - May be included within a theme or other plugin * -* @type function -* @date 13/07/2016 -* @since 5.4.0 +* @type function +* @date 13/07/2016 +* @since 5.4.0 * -* @param $basename (int) -* @return $post_id (int) +* @param $basename (int) +* @return $post_id (int) */ function acf_is_plugin_active() { - + // vars - $basename = acf_get_setting('basename'); - - + $basename = acf_get_setting( 'basename' ); + // ensure is_plugin_active() exists (not on frontend) - if( !function_exists('is_plugin_active') ) { - - include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); - + if ( ! function_exists( 'is_plugin_active' ) ) { + + include_once ABSPATH . 'wp-admin/includes/plugin.php'; + } - - + // return - return is_plugin_active($basename); - + return is_plugin_active( $basename ); + } /* @@ -4230,59 +4048,56 @@ function acf_is_plugin_active() { * * This function will print JSON data for a Select2 AJAX query * -* @type function -* @date 19/07/2016 -* @since 5.4.0 +* @type function +* @date 19/07/2016 +* @since 5.4.0 * -* @param $response (array) -* @return n/a +* @param $response (array) +* @return n/a */ function acf_send_ajax_results( $response ) { - + // validate - $response = wp_parse_args($response, array( - 'results' => array(), - 'more' => false, - 'limit' => 0 - )); - - + $response = wp_parse_args( + $response, + array( + 'results' => array(), + 'more' => false, + 'limit' => 0, + ) + ); + // limit - if( $response['limit'] && $response['results']) { - + if ( $response['limit'] && $response['results'] ) { + // vars $total = 0; - - foreach( $response['results'] as $result ) { - + + foreach ( $response['results'] as $result ) { + // parent $total++; - - + // children - if( !empty($result['children']) ) { - + if ( ! empty( $result['children'] ) ) { + $total += count( $result['children'] ); - + } - } - - + // calc - if( $total >= $response['limit'] ) { - + if ( $total >= $response['limit'] ) { + $response['more'] = true; - + } - } - - + // return wp_send_json( $response ); - + } @@ -4291,33 +4106,34 @@ function acf_send_ajax_results( $response ) { * * This function will return true if the array contains only numeric keys * -* @source http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential -* @type function -* @date 9/09/2016 -* @since 5.4.0 +* @source http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential +* @type function +* @date 9/09/2016 +* @since 5.4.0 * -* @param $array (array) -* @return (boolean) +* @param $array (array) +* @return (boolean) */ function acf_is_sequential_array( $array ) { - + // bail ealry if not array - if( !is_array($array) ) return false; - - - // loop - foreach( $array as $key => $value ) { - - // bail ealry if is string - if( is_string($key) ) return false; - + if ( ! is_array( $array ) ) { + return false; } - - + + // loop + foreach ( $array as $key => $value ) { + + // bail ealry if is string + if ( is_string( $key ) ) { + return false; + } + } + // return return true; - + } @@ -4326,33 +4142,34 @@ function acf_is_sequential_array( $array ) { * * This function will return true if the array contains one or more string keys * -* @source http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential -* @type function -* @date 9/09/2016 -* @since 5.4.0 +* @source http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential +* @type function +* @date 9/09/2016 +* @since 5.4.0 * -* @param $array (array) -* @return (boolean) +* @param $array (array) +* @return (boolean) */ function acf_is_associative_array( $array ) { - + // bail ealry if not array - if( !is_array($array) ) return false; - - - // loop - foreach( $array as $key => $value ) { - - // bail ealry if is string - if( is_string($key) ) return true; - + if ( ! is_array( $array ) ) { + return false; } - - + + // loop + foreach ( $array as $key => $value ) { + + // bail ealry if is string + if ( is_string( $key ) ) { + return true; + } + } + // return return false; - + } @@ -4362,33 +4179,31 @@ function acf_is_associative_array( $array ) { * This function will add a prefix to all array keys * Useful to preserve numeric keys when performing array_multisort * -* @type function -* @date 15/09/2016 -* @since 5.4.0 +* @type function +* @date 15/09/2016 +* @since 5.4.0 * -* @param $array (array) -* @param $prefix (string) -* @return (array) +* @param $array (array) +* @param $prefix (string) +* @return (array) */ function acf_add_array_key_prefix( $array, $prefix ) { - + // vars $array2 = array(); - - + // loop - foreach( $array as $k => $v ) { - - $k2 = $prefix . $k; - $array2[ $k2 ] = $v; - + foreach ( $array as $k => $v ) { + + $k2 = $prefix . $k; + $array2[ $k2 ] = $v; + } - - + // return return $array2; - + } @@ -4398,56 +4213,54 @@ function acf_add_array_key_prefix( $array, $prefix ) { * This function will remove a prefix to all array keys * Useful to preserve numeric keys when performing array_multisort * -* @type function -* @date 15/09/2016 -* @since 5.4.0 +* @type function +* @date 15/09/2016 +* @since 5.4.0 * -* @param $array (array) -* @param $prefix (string) -* @return (array) +* @param $array (array) +* @param $prefix (string) +* @return (array) */ function acf_remove_array_key_prefix( $array, $prefix ) { - + // vars $array2 = array(); - $l = strlen($prefix); - - + $l = strlen( $prefix ); + // loop - foreach( $array as $k => $v ) { - - $k2 = (substr($k, 0, $l) === $prefix) ? substr($k, $l) : $k; - $array2[ $k2 ] = $v; - + foreach ( $array as $k => $v ) { + + $k2 = ( substr( $k, 0, $l ) === $prefix ) ? substr( $k, $l ) : $k; + $array2[ $k2 ] = $v; + } - - + // return return $array2; - + } /* * acf_strip_protocol * -* This function will remove the proticol from a url -* Used to allow licences to remain active if a site is switched to https +* This function will remove the proticol from a url +* Used to allow licences to remain active if a site is switched to https * -* @type function -* @date 10/01/2017 -* @since 5.5.4 -* @author Aaron +* @type function +* @date 10/01/2017 +* @since 5.5.4 +* @author Aaron * -* @param $url (string) -* @return (string) +* @param $url (string) +* @return (string) */ function acf_strip_protocol( $url ) { - - // strip the protical - return str_replace(array('http://','https://'), '', $url); + + // strip the protical + return str_replace( array( 'http://', 'https://' ), '', $url ); } @@ -4455,57 +4268,62 @@ function acf_strip_protocol( $url ) { /* * acf_connect_attachment_to_post * -* This function will connect an attacment (image etc) to the post +* This function will connect an attacment (image etc) to the post * Used to connect attachements uploaded directly to media that have not been attaced to a post * -* @type function -* @date 11/01/2017 -* @since 5.8.0 Added filter to prevent connection. -* @since 5.5.4 +* @type function +* @date 11/01/2017 +* @since 5.8.0 Added filter to prevent connection. +* @since 5.5.4 * -* @param int $attachment_id The attachment ID. -* @param int $post_id The post ID. -* @return bool True if attachment was connected. +* @param int $attachment_id The attachment ID. +* @param int $post_id The post ID. +* @return bool True if attachment was connected. */ function acf_connect_attachment_to_post( $attachment_id = 0, $post_id = 0 ) { - + // Bail ealry if $attachment_id is not valid. - if( !$attachment_id || !is_numeric($attachment_id) ) { + if ( ! $attachment_id || ! is_numeric( $attachment_id ) ) { return false; } - + // Bail ealry if $post_id is not valid. - if( !$post_id || !is_numeric($post_id) ) { + if ( ! $post_id || ! is_numeric( $post_id ) ) { return false; } - + /** * Filters whether or not to connect the attachment. * - * @date 8/11/18 - * @since 5.8.0 + * @date 8/11/18 + * @since 5.8.0 * - * @param bool $bool Returning false will prevent the connection. Default true. - * @param int $attachment_id The attachment ID. - * @param int $post_id The post ID. + * @param bool $bool Returning false will prevent the connection. Default true. + * @param int $attachment_id The attachment ID. + * @param int $post_id The post ID. */ - if( !apply_filters('acf/connect_attachment_to_post', true, $attachment_id, $post_id) ) { + if ( ! apply_filters( 'acf/connect_attachment_to_post', true, $attachment_id, $post_id ) ) { return false; } - - // vars + + // vars $post = get_post( $attachment_id ); - + // Check if is valid post. - if( $post && $post->post_type == 'attachment' && $post->post_parent == 0 ) { - + if ( $post && $post->post_type == 'attachment' && $post->post_parent == 0 ) { + // update - wp_update_post( array('ID' => $post->ID, 'post_parent' => $post_id) ); - + wp_update_post( + array( + 'ID' => $post->ID, + 'post_parent' => $post_id, + ) + ); + // return return true; } - + // return return true; } @@ -4517,36 +4335,34 @@ function acf_connect_attachment_to_post( $attachment_id = 0, $post_id = 0 ) { * This function will encrypt a string using PHP * https://bhoover.com/using-php-openssl_encrypt-openssl_decrypt-encrypt-decrypt-data/ * -* @type function -* @date 27/2/17 -* @since 5.5.8 +* @type function +* @date 27/2/17 +* @since 5.5.8 * -* @param $data (string) -* @return (string) +* @param $data (string) +* @return (string) */ function acf_encrypt( $data = '' ) { - + // bail ealry if no encrypt function - if( !function_exists('openssl_encrypt') ) return base64_encode($data); - - + if ( ! function_exists( 'openssl_encrypt' ) ) { + return base64_encode( $data ); + } + // generate a key - $key = wp_hash('acf_encrypt'); - - - // Generate an initialization vector - $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc')); - - - // Encrypt the data using AES 256 encryption in CBC mode using our encryption key and initialization vector. - $encrypted_data = openssl_encrypt($data, 'aes-256-cbc', $key, 0, $iv); - - - // The $iv is just as important as the key for decrypting, so save it with our encrypted data using a unique separator (::) - return base64_encode($encrypted_data . '::' . $iv); - + $key = wp_hash( 'acf_encrypt' ); + + // Generate an initialization vector + $iv = openssl_random_pseudo_bytes( openssl_cipher_iv_length( 'aes-256-cbc' ) ); + + // Encrypt the data using AES 256 encryption in CBC mode using our encryption key and initialization vector. + $encrypted_data = openssl_encrypt( $data, 'aes-256-cbc', $key, 0, $iv ); + + // The $iv is just as important as the key for decrypting, so save it with our encrypted data using a unique separator (::) + return base64_encode( $encrypted_data . '::' . $iv ); + } @@ -4556,209 +4372,208 @@ function acf_encrypt( $data = '' ) { * This function will decrypt an encrypted string using PHP * https://bhoover.com/using-php-openssl_encrypt-openssl_decrypt-encrypt-decrypt-data/ * -* @type function -* @date 27/2/17 -* @since 5.5.8 +* @type function +* @date 27/2/17 +* @since 5.5.8 * -* @param $data (string) -* @return (string) +* @param $data (string) +* @return (string) */ function acf_decrypt( $data = '' ) { - + // bail ealry if no decrypt function - if( !function_exists('openssl_decrypt') ) return base64_decode($data); - - + if ( ! function_exists( 'openssl_decrypt' ) ) { + return base64_decode( $data ); + } + // generate a key - $key = wp_hash('acf_encrypt'); - - - // To decrypt, split the encrypted data from our IV - our unique separator used was "::" - list($encrypted_data, $iv) = explode('::', base64_decode($data), 2); - - - // decrypt - return openssl_decrypt($encrypted_data, 'aes-256-cbc', $key, 0, $iv); - + $key = wp_hash( 'acf_encrypt' ); + + // To decrypt, split the encrypted data from our IV - our unique separator used was "::" + list($encrypted_data, $iv) = explode( '::', base64_decode( $data ), 2 ); + + // decrypt + return openssl_decrypt( $encrypted_data, 'aes-256-cbc', $key, 0, $iv ); + } /** -* acf_parse_markdown -* -* A very basic regex-based Markdown parser function based off [slimdown](https://gist.github.com/jbroadway/2836900). -* -* @date 6/8/18 -* @since 5.7.2 -* -* @param string $text The string to parse. -* @return string -*/ + * acf_parse_markdown + * + * A very basic regex-based Markdown parser function based off [slimdown](https://gist.github.com/jbroadway/2836900). + * + * @date 6/8/18 + * @since 5.7.2 + * + * @param string $text The string to parse. + * @return string + */ function acf_parse_markdown( $text = '' ) { - + // trim - $text = trim($text); - + $text = trim( $text ); + // rules - $rules = array ( - '/=== (.+?) ===/' => '

                $1

                ', // headings - '/== (.+?) ==/' => '

                $1

                ', // headings - '/= (.+?) =/' => '

                $1

                ', // headings - '/\[([^\[]+)\]\(([^\)]+)\)/' => '$1', // links - '/(\*\*)(.*?)\1/' => '$2', // bold - '/(\*)(.*?)\1/' => '$2', // intalic - '/`(.*?)`/' => '$1', // inline code - '/\n\*(.*)/' => "\n", // ul lists - '/\n[0-9]+\.(.*)/' => "\n
                  \n\t
                1. $1
                2. \n
                ", // ol lists - '/<\/ul>\s?