This commit is contained in:
Elliot Condon 2019-09-12 10:11:00 +02:00 committed by Remco Tolsma
parent b429a3fb8f
commit 9bcadd0a39
11 changed files with 548 additions and 400 deletions

600
acf.php
View File

@ -3,7 +3,7 @@
Plugin Name: Advanced Custom Fields PRO
Plugin URI: https://www.advancedcustomfields.com
Description: Customize WordPress with powerful, professional and intuitive fields.
Version: 5.8.3
Version: 5.8.4
Author: Elliot Condon
Author URI: https://www.advancedcustomfields.com
Text Domain: acf
@ -16,77 +16,62 @@ if( ! class_exists('ACF') ) :
class ACF {
/** @var string The plugin version number */
var $version = '5.8.3';
/** @var string The plugin version number. */
var $version = '5.8.4';
/** @var array The plugin settings array */
/** @var array The plugin settings array. */
var $settings = array();
/** @var array The plugin data array */
/** @var array The plugin data array. */
var $data = array();
/** @var array Storage for class instances */
/** @var array Storage for class instances. */
var $instances = array();
/*
* __construct
*
* A dummy constructor to ensure ACF is only initialized once
*
* @type function
* @date 23/06/12
* @since 5.0.0
*
* @param N/A
* @return N/A
*/
/**
* __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 here */
// Do nothing.
}
/*
* initialize
*
* The real constructor to initialize ACF
*
* @type function
* @date 28/09/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
/**
* initialize
*
* Sets up the ACF plugin.
*
* @date 28/09/13
* @since 5.0.0
*
* @param void
* @return void
*/
function initialize() {
// vars
$version = $this->version;
$basename = plugin_basename( __FILE__ );
$path = plugin_dir_path( __FILE__ );
$url = plugin_dir_url( __FILE__ );
$slug = dirname($basename);
// 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 );
// settings
// Define settings.
$this->settings = array(
// basic
'name' => __('Advanced Custom Fields', 'acf'),
'version' => $version,
// urls
'file' => __FILE__,
'basename' => $basename,
'path' => $path,
'url' => $url,
'slug' => $slug,
// options
'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,
@ -112,12 +97,6 @@ class ACF {
'remove_wp_meta_box' => true
);
// constants
$this->define( 'ACF', true );
$this->define( 'ACF_VERSION', $version );
$this->define( 'ACF_PATH', $path );
// Include utility functions.
include_once( ACF_PATH . 'includes/acf-utility-functions.php');
@ -128,6 +107,8 @@ class ACF {
// Include classes.
acf_include('includes/class-acf-data.php');
acf_include('includes/fields/class-acf-field.php');
acf_include('includes/locations/class-acf-location.php');
// Include functions.
acf_include('includes/acf-helper-functions.php');
@ -141,17 +122,9 @@ class ACF {
acf_include('includes/acf-value-functions.php');
acf_include('includes/acf-input-functions.php');
// fields
// Include core.
acf_include('includes/fields.php');
acf_include('includes/fields/class-acf-field.php');
// locations
acf_include('includes/locations.php');
acf_include('includes/locations/class-acf-location.php');
// core
acf_include('includes/assets.php');
acf_include('includes/compatibility.php');
acf_include('includes/deprecated.php');
@ -166,13 +139,13 @@ class ACF {
acf_include('includes/upgrades.php');
acf_include('includes/validation.php');
// ajax
// 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');
// forms
// Include forms.
acf_include('includes/forms/form-attachment.php');
acf_include('includes/forms/form-comment.php');
acf_include('includes/forms/form-customizer.php');
@ -184,8 +157,7 @@ class ACF {
acf_include('includes/forms/form-user.php');
acf_include('includes/forms/form-widget.php');
// admin
// Include admin.
if( is_admin() ) {
acf_include('includes/admin/admin.php');
acf_include('includes/admin/admin-field-group.php');
@ -196,8 +168,7 @@ class ACF {
acf_include('includes/admin/settings-info.php');
}
// pro
// Include PRO.
acf_include('pro/acf-pro.php');
// Include tests.
@ -205,63 +176,53 @@ class ACF {
acf_include('tests/tests.php');
}
// 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 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 );
// filters
add_filter('posts_where', array($this, 'posts_where'), 10, 2 );
//add_filter('posts_request', array($this, 'posts_request'), 10, 1 );
// Add filters.
add_filter( 'posts_where', array($this, 'posts_where'), 10, 2 );
}
/*
* init
*
* This function will run after all plugins and theme functions have been included
*
* @type action (init)
* @date 28/09/13
* @since 5.0.0
*
* @param N/A
* @return N/A
*/
/**
* 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 too early
// ensures all plugins have a chance to add fields, etc
if( !did_action('plugins_loaded') ) return;
// 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;
}
// bail early if already init
if( acf_has_done('init') ) return;
// Update url setting. Allows other plugins to modify the URL (force SSL).
acf_update_setting( 'url', plugin_dir_url( __FILE__ ) );
// vars
$major = intval( acf_get_setting('version') );
// update url
// - allow another plugin to modify dir (maybe force SSL)
acf_update_setting('url', plugin_dir_url( __FILE__ ));
// textdomain
// Load textdomain file.
acf_load_textdomain();
// include 3rd party support
// Include 3rd party compatiblity.
acf_include('includes/third-party.php');
// include wpml support
// Include wpml support.
if( defined('ICL_SITEPRESS_VERSION') ) {
acf_include('includes/wpml.php');
}
// fields
// 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');
@ -269,39 +230,42 @@ class ACF {
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');
do_action('acf/include_field_types', $major);
/**
* 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 );
// locations
// 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');
@ -323,38 +287,55 @@ class ACF {
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');
do_action('acf/include_location_rules', $major);
/**
* 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 );
// local fields
do_action('acf/include_fields', $major);
/**
* 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 );
// action for 3rd party
do_action('acf/init');
/**
* 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
*
* This function will register post types and statuses
*
* @type function
* @date 22/10/2015
* @since 5.3.2
*
* @param n/a
* @return n/a
*/
/**
* 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
// Vars.
$cap = acf_get_setting('capability');
// register post type 'acf-field-group'
// Register the Field Group post type.
register_post_type('acf-field-group', array(
'labels' => array(
'name' => __( 'Field Groups', 'acf' ),
@ -369,7 +350,9 @@ class 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(
@ -378,15 +361,13 @@ class ACF {
'edit_posts' => $cap,
'delete_posts' => $cap,
),
'hierarchical' => true,
'supports' => array('title'),
'rewrite' => false,
'query_var' => false,
'supports' => array('title'),
'show_in_menu' => false,
));
// register post type 'acf-field'
// Register the Field post type.
register_post_type('acf-field', array(
'labels' => array(
'name' => __( 'Fields', 'acf' ),
@ -401,7 +382,9 @@ class 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(
@ -410,32 +393,26 @@ class ACF {
'edit_posts' => $cap,
'delete_posts' => $cap,
),
'hierarchical' => true,
'supports' => array('title'),
'rewrite' => false,
'query_var' => false,
'supports' => array('title'),
'show_in_menu' => false,
));
}
/*
* register_post_status
*
* This function will register custom post statuses
*
* @type function
* @date 22/10/2015
* @since 5.3.2
*
* @param $post_id (int)
* @return $post_id (int)
*/
/**
* register_post_status
*
* Registers the ACF post statuses.
*
* @date 22/10/2015
* @since 5.3.2
*
* @param void
* @return void
*/
function register_post_status() {
// acf-disabled
// Register the Disabled post status.
register_post_status('acf-disabled', array(
'label' => __( 'Inactive', 'acf' ),
'public' => true,
@ -444,237 +421,198 @@ class ACF {
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', 'acf' ),
));
}
/*
* posts_where
*
* This function will add in some new parameters to the WP_Query args allowing fields to be found via key / name
*
* @type filter
* @date 5/12/2013
* @since 5.0.0
*
* @param $where (string)
* @param $wp_query (object)
* @return $where (string)
*/
/**
* 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
global $wpdb;
// acf_field_key
// 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 );
}
// acf_field_name
// 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 );
}
// acf_group_key
// 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.
return $where;
}
/*
* define
*
* This function will safely define a constant
*
* @type function
* @date 3/5/17
* @since 5.5.13
*
* @param $name (string)
* @param $value (mixed)
* @return n/a
*/
function define( $name, $value = true ) {
if( !defined($name) ) {
define( $name, $value );
}
}
/**
* has_setting
*
* Returns true if has setting.
*
* @date 2/2/18
* @since 5.6.5
*
* @param string $name
* @return boolean
*/
* 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.
*
* @date 28/09/13
* @since 5.0.0
*
* @param string $name
* @return mixed
*/
* 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.
*
* @date 28/09/13
* @since 5.0.0
*
* @param string $name
* @param mixed $value
* @return n/a
*/
* 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.
*
* @date 28/09/13
* @since 5.0.0
*
* @param string $name
* @return mixed
*/
* 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.
*
* @date 28/09/13
* @since 5.0.0
*
* @param string $name
* @param mixed $value
* @return n/a
*/
* 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.
*
* @date 13/2/18
* @since 5.6.9
*
* @param string $class The instance class name.
* @return object
*/
* 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.
*
* @date 13/2/18
* @since 5.6.9
*
* @param string $class The instance class name.
* @return object
*/
* 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;
}
}
/*
* 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: <?php $acf = acf(); ?>
*
* @type function
* @date 4/09/13
* @since 4.3.0
*
* @param N/A
* @return (object)
*/
* 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: <?php $acf = acf(); ?>
*
* @date 4/09/13
* @since 4.3.0
*
* @param void
* @return ACF
*/
function acf() {
// globals
global $acf;
// initialize
// Instantiate only once.
if( !isset($acf) ) {
$acf = new ACF();
$acf->initialize();
}
// return
return $acf;
}
// initialize
// Instantiate.
acf();
endif; // class_exists check
?>

View File

@ -2103,6 +2103,168 @@
});
};
/**
* acf.debounce
*
* Returns a debounced version of the passed function which will postpone its execution until after `wait` milliseconds have elapsed since the last time it was invoked.
*
* @date 28/8/19
* @since 5.8.1
*
* @param function callback The callback function.
* @return int wait The number of milliseconds to wait.
*/
acf.debounce = function( callback, wait ){
var timeout;
return function(){
var context = this;
var args = arguments;
var later = function(){
callback.apply( context, args );
};
clearTimeout( timeout );
timeout = setTimeout( later, wait );
};
};
/**
* acf.throttle
*
* Returns a throttled version of the passed function which will allow only one execution per `limit` time period.
*
* @date 28/8/19
* @since 5.8.1
*
* @param function callback The callback function.
* @return int wait The number of milliseconds to wait.
*/
acf.throttle = function( callback, limit ){
var busy = false;
return function(){
if( busy ) return;
busy = true;
setTimeout(function(){
busy = false;
}, limit);
callback.apply( this, arguments );
};
};
/**
* acf.isInView
*
* Returns true if the given element is in view.
*
* @date 29/8/19
* @since 5.8.1
*
* @param elem el The dom element to inspect.
* @return bool
*/
acf.isInView = function( el ){
var rect = el.getBoundingClientRect();
return (
rect.top !== rect.bottom &&
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
};
/**
* acf.onceInView
*
* Watches for a dom element to become visible in the browser and then excecutes the passed callback.
*
* @date 28/8/19
* @since 5.8.1
*
* @param dom el The dom element to inspect.
* @param function callback The callback function.
*/
acf.onceInView = (function() {
// Define list.
var items = [];
var id = 0;
// Define check function.
var check = function() {
items.forEach(function( item ){
if( acf.isInView(item.el) ) {
item.callback.apply( this );
pop( item.id );
}
});
};
// And create a debounced version.
var debounced = acf.debounce( check, 300 );
// Define add function.
var push = function( el, callback ) {
// Add event listener.
if( !items.length ) {
$(window).on( 'scroll resize', debounced ).on( 'acfrefresh orientationchange', check );
}
// Append to list.
items.push({ id: id++, el: el, callback: callback });
}
// Define remove function.
var pop = function( id ) {
// Remove from list.
items = items.filter(function(item) {
return (item.id !== id);
});
// Clean up listener.
if( !items.length ) {
$(window).off( 'scroll resize', debounced ).off( 'acfrefresh orientationchange', check );
}
}
// Define returned function.
return function( el, callback ){
// Allow jQuery object.
if( el instanceof jQuery )
el = el[0];
// Execute callback if already in view or add to watch list.
if( acf.isInView(el) ) {
callback.apply( this );
} else {
push( el, callback );
}
}
})();
/**
* acf.once
*
* Creates a function that is restricted to invoking `func` once.
*
* @date 2/9/19
* @since 5.8.1
*
* @param function func The function to restrict.
* @return function
*/
acf.once = function( func ){
var i = 0;
return function(){
if( i++ > 0 ) {
return (func = undefined);
}
return func.apply(this, arguments);
}
}
/*
* exists
*
@ -6828,7 +6990,7 @@
getNodeValue: function(){
var $node = this.get('node');
return {
title: $node.html(),
title: acf.decode( $node.html() ),
url: $node.attr('href'),
target: $node.attr('target')
};
@ -6836,7 +6998,7 @@
setNodeValue: function( val ){
var $node = this.get('node');
$node.html( val.title );
$node.text( val.title );
$node.attr('href', val.url);
$node.attr('target', val.target);
$node.trigger('change');
@ -7205,8 +7367,7 @@
'change [data-filter]': 'onChangeFilter',
'keyup [data-filter]': 'onChangeFilter',
'click .choices-list .acf-rel-item': 'onClickAdd',
'click [data-name="remove_item"]': 'onClickRemove',
'mouseover': 'onHover'
'click [data-name="remove_item"]': 'onClickRemove',
},
$control: function(){
@ -7252,60 +7413,59 @@
].join('');
},
addSortable: function( self ){
// sortable
this.$list('values').sortable({
items: 'li',
forceHelperSize: true,
forcePlaceholderSize: true,
scroll: true,
update: function(){
self.$input().trigger('change');
}
});
},
initialize: function(){
// scroll
var onScroll = this.proxy(function(e){
// Delay initialization until "interacted with" or "in view".
var delayed = this.proxy(acf.once(function(){
// bail early if no more results
if( this.get('loading') || !this.get('more') ) {
return;
}
// Add sortable.
this.$list('values').sortable({
items: 'li',
forceHelperSize: true,
forcePlaceholderSize: true,
scroll: true,
update: this.proxy(function(){
this.$input().trigger('change');
})
});
// Scrolled to bottom
var $list = this.$list('choices');
var scrollTop = Math.ceil( $list.scrollTop() );
var scrollHeight = Math.ceil( $list[0].scrollHeight );
var innerHeight = Math.ceil( $list.innerHeight() );
var paged = this.get('paged') || 1;
if( (scrollTop + innerHeight) >= scrollHeight ) {
// update paged
this.set('paged', (paged+1));
// fetch
this.fetch();
}
// Avoid browser remembering old scroll position and add event.
this.$list('choices').scrollTop(0).on('scroll', this.proxy(this.onScrollChoices));
});
// Fetch choices.
this.fetch();
}));
this.$list('choices').scrollTop(0).on('scroll', onScroll);
// Bind "interacted with".
this.$el.one( 'mouseover', delayed );
this.$el.one( 'focus', 'input', delayed );
// fetch
this.fetch();
// Bind "in view".
acf.onceInView( this.$el, delayed );
},
onHover: function( e ){
onScrollChoices: function(e){
// bail early if no more results
if( this.get('loading') || !this.get('more') ) {
return;
}
// only once
$().off(e);
// add sortable
this.addSortable( this );
// Scrolled to bottom
var $list = this.$list('choices');
var scrollTop = Math.ceil( $list.scrollTop() );
var scrollHeight = Math.ceil( $list[0].scrollHeight );
var innerHeight = Math.ceil( $list.innerHeight() );
var paged = this.get('paged') || 1;
if( (scrollTop + innerHeight) >= scrollHeight ) {
// update paged
this.set('paged', (paged+1));
// fetch
this.fetch();
}
},
onKeypressFilter: function( e, $el ){
@ -13260,6 +13420,10 @@
*/
addInputEvents: function( $el ){
// Bug exists in Safari where custom "invalid" handeling prevents draft from saving.
if( acf.get('browser') === 'safari' )
return;
// vars
var $inputs = $('.acf-field [name]', $el);
@ -13492,6 +13656,7 @@
clearTimeout( this.timeout );
this.timeout = setTimeout(function(){
acf.doAction('refresh');
$(window).trigger('acfrefresh');
}, 0);
}
});

File diff suppressed because one or more lines are too long

View File

@ -233,6 +233,10 @@ function acf_validate_field( $field = array() ) {
//'attributes' => array()
));
// Convert types.
$field['ID'] = (int) $field['ID'];
$field['menu_order'] = (int) $field['menu_order'];
// Add backwards compatibility for wrapper attributes.
// Todo: Remove need for this.
$field['wrapper'] = wp_parse_args($field['wrapper'], array(

View File

@ -221,6 +221,10 @@ function acf_validate_field_group( $field_group = array() ) {
'description' => '',
));
// Convert types.
$field_group['ID'] = (int) $field_group['ID'];
$field_group['menu_order'] = (int) $field_group['menu_order'];
// Field group is now valid.
$field_group['_valid'] = 1;
@ -515,6 +519,8 @@ function acf_update_field_group( $field_group ) {
'post_excerpt' => sanitize_title( $field_group['title'] ),
'post_content' => maybe_serialize( $_field_group ),
'menu_order' => $field_group['menu_order'],
'comment_status' => 'closed',
'ping_status' => 'closed',
);
// Unhook wp_targeted_link_rel() filter from WP 5.1 corrupting serialized data.

View File

@ -362,4 +362,26 @@ function acf_punctify( $str = '' ) {
return trim($str, '.') . '.';
}
/**
* acf_did
*
* Returns true if ACF already did an event.
*
* @date 30/8/19
* @since 5.8.1
*
* @param string $name The name of the event.
* @return bool
*/
function acf_did( $name ) {
// Return true if already did the event (preventing event).
if( acf_get_data("acf_did_$name") ) {
return true;
// Otherwise, update store and return false (alowing event).
} else {
acf_set_data("acf_did_$name", true);
return false;
}
}

View File

@ -92,12 +92,14 @@ function acf_get_meta( $post_id = 0 ) {
// Loop over meta and check that a reference exists for each value.
$meta = array();
foreach( $allmeta as $key => $value ) {
// If a reference exists for this value, add it to the meta array.
if( isset($allmeta["_$key"]) ) {
$meta[ $key ] = $allmeta[ $key ][0];
$meta[ "_$key" ] = $allmeta[ "_$key" ][0];
if( $allmeta ) {
foreach( $allmeta as $key => $value ) {
// If a reference exists for this value, add it to the meta array.
if( isset($allmeta["_$key"]) ) {
$meta[ $key ] = $allmeta[ $key ][0];
$meta[ "_$key" ] = $allmeta[ "_$key" ][0];
}
}
}

View File

@ -15,17 +15,14 @@
<h2><?php _e("A Smoother Experience", 'acf'); ?> </h2>
<div class="acf-three-col">
<div>
<p><img src="https://assets.advancedcustomfields.com/info/5.0.0/select2.png" /></p>
<h3><?php _e("Improved Usability", 'acf'); ?></h3>
<p><?php _e("Including the popular Select2 library has improved both usability and speed across a number of field types including post object, page link, taxonomy and select.", 'acf'); ?></p>
</div>
<div>
<p><img src="https://assets.advancedcustomfields.com/info/5.0.0/design.png" /></p>
<h3><?php _e("Improved Design", 'acf'); ?></h3>
<p><?php _e("Many fields have undergone a visual refresh to make ACF look better than ever! Noticeable changes are seen on the gallery, relationship and oEmbed (new) fields!", 'acf'); ?></p>
</div>
<div>
<p><img src="https://assets.advancedcustomfields.com/info/5.0.0/sub-fields.png" /></p>
<h3><?php _e("Improved Data", 'acf'); ?></h3>
<p><?php _e("Redesigning the data architecture has allowed sub fields to live independently from their parents. This allows you to drag and drop fields in and out of parent fields!", 'acf'); ?></p>
</div>

View File

@ -557,8 +557,16 @@ class acf_field_checkbox extends acf_field {
function format_value( $value, $post_id, $field ) {
return acf_get_field_type('select')->format_value( $value, $post_id, $field );
// Bail early if is empty.
if( acf_is_empty($value) ) {
return array();
}
// Always convert to array of items.
$value = acf_array($value);
// Return.
return acf_get_field_type('select')->format_value( $value, $post_id, $field );
}
}

View File

@ -12,9 +12,6 @@ class ACF_Updates {
/** @var array The array of registered plugins */
var $plugins = array();
/** @var boolean Dev mode */
var $dev = false;
/** @var int Counts the number of plugin update checks */
var $checked = 0;
@ -114,10 +111,9 @@ class ACF_Updates {
// vars
$url = 'https://connect.advancedcustomfields.com/' . $query;
// development mode
if( $this->dev ) {
// Development mode
if( defined('ACF_DEV') && ACF_DEV ) {
$url = 'http://connect/' . $query;
acf_log('acf connect: '. $url, $body);
}
// post

View File

@ -67,6 +67,16 @@ From your WordPress dashboard
== Changelog ==
= 5.8.4 =
*Release Date - 3 September 2019*
* New - Optimized Relationship field by delaying AJAX call until UI is visible.
* Fix - Fixed bug incorrectly escaping HTML in the Link field title.
* Fix - Fixed bug showing Discussion and Comment metaboxes for newly imported field groups.
* Fix - Fixed PHP warning when loading meta from Post 0.
* Dev - Ensure Checkbox field value is an array even when empty.
* Dev - Added new `ACF_MAJOR_VERSION` constant.
= 5.8.3 =
*Release Date - 7 August 2019*