Merge branch 'release/5.4.7'

This commit is contained in:
I 2016-10-14 11:50:54 +02:00
commit c59481f90e
22 changed files with 801 additions and 641 deletions

View File

@ -3,7 +3,7 @@
Plugin Name: Advanced Custom Fields PRO Plugin Name: Advanced Custom Fields PRO
Plugin URI: https://www.advancedcustomfields.com/ Plugin URI: https://www.advancedcustomfields.com/
Description: Customise WordPress with powerful, professional and intuitive fields Description: Customise WordPress with powerful, professional and intuitive fields
Version: 5.4.6 Version: 5.4.7
Author: Elliot Condon Author: Elliot Condon
Author URI: http://www.elliotcondon.com/ Author URI: http://www.elliotcondon.com/
Copyright: Elliot Condon Copyright: Elliot Condon
@ -58,7 +58,7 @@ class acf {
// basic // basic
'name' => __('Advanced Custom Fields', 'acf'), 'name' => __('Advanced Custom Fields', 'acf'),
'version' => '5.4.6', 'version' => '5.4.7',
// urls // urls
'basename' => plugin_basename( __FILE__ ), 'basename' => plugin_basename( __FILE__ ),

View File

@ -1133,17 +1133,14 @@ class acf_admin_field_group {
$args = acf_parse_args($_POST, array( $args = acf_parse_args($_POST, array(
'nonce' => '', 'nonce' => '',
'post_id' => 0,
'field_id' => 0, 'field_id' => 0,
'field_group_id' => 0 'field_group_id' => 0
)); ));
// verify nonce // verify nonce
if( ! wp_verify_nonce($args['nonce'], 'acf_nonce') ) { if( !wp_verify_nonce($args['nonce'], 'acf_nonce') ) die();
die();
}
// confirm? // confirm?
@ -1183,15 +1180,22 @@ class acf_admin_field_group {
$choices = array(); $choices = array();
// check
if( !empty($field_groups) ) { if( !empty($field_groups) ) {
// loop
foreach( $field_groups as $field_group ) { foreach( $field_groups as $field_group ) {
if( $field_group['ID'] ) { // bail early if no ID
if( !$field_group['ID'] ) continue;
$choices[ $field_group['ID'] ] = $field_group['title'];
} // bail ealry if is current
if( $field_group['ID'] == $args['post_id'] ) continue;
// append
$choices[ $field_group['ID'] ] = $field_group['title'];
} }

View File

@ -150,52 +150,51 @@ class acf_admin_field_groups {
} }
// import field group // vars
$ids = array();
// check single
if( $id = acf_maybe_get($_GET, 'acfduplicate') ) { if( $id = acf_maybe_get($_GET, 'acfduplicate') ) {
$ids[] = $id;
// check multiple
} elseif( acf_maybe_get($_GET, 'action2') === 'acfduplicate' ) {
$ids = acf_maybe_get($_GET, 'post');
}
// sync
if( !empty($ids) ) {
// validate // validate
check_admin_referer('bulk-posts'); check_admin_referer('bulk-posts');
// duplicate // vars
$field_group = acf_duplicate_field_group( $id ); $new_ids = array();
// loop
foreach( $ids as $id ) {
// duplicate
$field_group = acf_duplicate_field_group( $id );
// increase counter
$new_ids[] = $field_group['ID'];
}
// redirect // redirect
wp_redirect( admin_url( $this->url . '&acfduplicatecomplete=' . $field_group['ID'] ) ); wp_redirect( admin_url( $this->url . '&acfduplicatecomplete=' . implode(',', $new_ids)) );
exit; exit;
} elseif( acf_maybe_get($_GET, 'action2') === 'acfduplicate' ) {
// validate
check_admin_referer('bulk-posts');
// get ids
$ids = acf_maybe_get($_GET, 'post');
if( !empty($ids) ) {
// vars
$new_ids = array();
foreach( $ids as $id ) {
// duplicate
$field_group = acf_duplicate_field_group( $id );
// increase counter
$new_ids[] = $field_group['ID'];
}
// redirect
wp_redirect( admin_url( $this->url . '&acfduplicatecomplete=' . implode(',', $new_ids)) );
exit;
}
} }
} }
@ -241,11 +240,7 @@ class acf_admin_field_groups {
// bail early if no field groups // bail early if no field groups
if( empty($groups) ) { if( empty($groups) ) return;
return;
}
// find JSON field groups which have not yet been imported // find JSON field groups which have not yet been imported
@ -276,85 +271,72 @@ class acf_admin_field_groups {
// bail if no sync needed // bail if no sync needed
if( empty($this->sync) ) { if( empty($this->sync) ) return;
// maybe sync
$sync_keys = array();
// check single
if( $key = acf_maybe_get($_GET, 'acfsync') ) {
return; $sync_keys[] = $key;
// check multiple
} elseif( acf_maybe_get($_GET, 'action2') === 'acfsync' ) {
$sync_keys = acf_maybe_get($_GET, 'post');
} }
// import field group
if( $key = acf_maybe_get($_GET, 'acfsync') ) { // sync
if( !empty($sync_keys) ) {
// validate
check_admin_referer('bulk-posts');
// disable filters to ensure ACF loads raw data from DB
acf_disable_filters();
acf_enable_filter('local');
// disable JSON // disable JSON
// - this prevents a new JSON file being created and causing a 'change' to theme files - solves git anoyance // - this prevents a new JSON file being created and causing a 'change' to theme files - solves git anoyance
acf_update_setting('json', false); acf_update_setting('json', false);
// validate // vars
check_admin_referer('bulk-posts'); $new_ids = array();
// append fields
if( acf_have_local_fields( $key ) ) {
$this->sync[ $key ]['fields'] = acf_get_local_fields( $key );
}
// import
$field_group = acf_import_field_group( $this->sync[ $key ] );
// redirect
wp_redirect( admin_url( $this->url . '&acfsynccomplete=' . $field_group['ID'] ) );
exit;
} elseif( acf_maybe_get($_GET, 'action2') === 'acfsync' ) {
// validate
check_admin_referer('bulk-posts');
// get ids // loop
$keys = acf_maybe_get($_GET, 'post'); foreach( $sync_keys as $key ) {
if( !empty($keys) ) {
// disable JSON // append fields
// - this prevents a new JSON file being created and causing a 'change' to theme files - solves git anoyance if( acf_have_local_fields($key) ) {
acf_update_setting('json', false);
// vars
$new_ids = array();
foreach( $keys as $key ) {
// append fields $this->sync[ $key ]['fields'] = acf_get_local_fields( $key );
if( acf_have_local_fields( $key ) ) {
$this->sync[ $key ]['fields'] = acf_get_local_fields( $key );
}
// import
$field_group = acf_import_field_group( $this->sync[ $key ] );
// append
$new_ids[] = $field_group['ID'];
} }
// redirect // import
wp_redirect( admin_url( $this->url . '&acfsynccomplete=' . implode(',', $new_ids)) ); $field_group = acf_import_field_group( $this->sync[ $key ] );
exit;
// append
$new_ids[] = $field_group['ID'];
} }
// redirect
wp_redirect( admin_url( $this->url . '&acfsynccomplete=' . implode(',', $new_ids)) );
exit;
} }

View File

@ -1856,82 +1856,17 @@ function acf_prepare_field_for_import( $field ) {
function acf_get_sub_field( $selector, $field ) { function acf_get_sub_field( $selector, $field ) {
// sub fields // vars
if( $field['type'] == 'repeater' ) { $sub_field = false;
// extract sub fields
$sub_fields = acf_extract_var( $field, 'sub_fields'); // filter for 3rd party customization
$sub_field = apply_filters( "acf/get_sub_field", $sub_field, $selector, $field );
if( !empty($sub_fields) ) { $sub_field = apply_filters( "acf/get_sub_field/type={$field['type']}", $sub_field, $selector, $field );
foreach( $sub_fields as $sub_field ) {
if( $sub_field['name'] == $selector || $sub_field['key'] == $selector ) {
// return
return $sub_field;
}
// if
}
// foreach
}
// if
} elseif( $field['type'] == 'flexible_content' ) {
// vars
$layouts = acf_extract_var( $field, 'layouts');
$current = get_row_layout();
if( !empty($layouts) ) {
foreach( $layouts as $layout ) {
// skip layout if the current layout key does not match
if( $current && $current !== $layout['name'] ) {
continue;
}
// extract sub fields
$sub_fields = acf_extract_var( $layout, 'sub_fields');
if( !empty($sub_fields) ) {
foreach( $sub_fields as $sub_field ) {
if( $sub_field['name'] == $selector || $sub_field['key'] == $selector ) {
// return
return $sub_field;
}
// if
}
// foreach
}
// if
}
// foreach
}
// if
}
// if
// return // return
return false; return $sub_field;
} }
@ -1970,4 +1905,66 @@ function acf_get_field_ancestors( $field ) {
} }
/*
* acf_maybe_get_sub_field
*
* This function will attempt to find a sub field
*
* @type function
* @date 3/10/2016
* @since 5.4.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function acf_maybe_get_sub_field( $selectors, $post_id = false, $strict = true ) {
// bail ealry if not enough selectors
if( !is_array($selectors) || count($selectors) < 3 ) return false;
// vars
$selector = acf_extract_var( $selectors, 0 );
$selectors = array_values( $selectors ); // reset keys
// attempt get field
$field = acf_maybe_get_field( $selector, $post_id, $strict );
// bail early if no field
if( !$field ) return false;
// loop
for( $j = 0; $j < count($selectors); $j+=2 ) {
// vars
$sub_i = $selectors[ $j ];
$sub_s = $selectors[ $j+1 ];
$field_name = $field['name'];
// find sub field
$field = acf_get_sub_field( $sub_s, $field );
// bail early if no sub field
if( !$field ) return false;
// add to name
$field['name'] = $field_name . '_' . ($sub_i-1) . '_' . $field['name'];
}
// return
return $field;
}
?> ?>

View File

@ -1033,6 +1033,48 @@ function acf_get_image_size( $s = '' ) {
} }
/*
* acf_get_terms
*
* This function is a wrapper for the get_terms() function
*
* @type function
* @date 28/09/2016
* @since 5.4.0
*
* @param $args (array)
* @return (array)
*/
function acf_get_terms( $args ) {
// global
global $wp_version;
// vars
$terms = array();
// WP 4.5+
if( version_compare($wp_version, '4.5', '>=' ) ) {
$terms = get_terms( $args );
// WP < 4.5
} else {
$terms = get_terms( $args['taxonomy'], $args );
}
// return
return $terms;
}
/* /*
* acf_get_taxonomies * acf_get_taxonomies
* *
@ -1164,8 +1206,11 @@ function acf_get_taxonomy_terms( $taxonomies = array() ) {
// vars // vars
$label = $taxonomies[ $taxonomy ]; $label = $taxonomies[ $taxonomy ];
$terms = get_terms( $taxonomy, array( 'hide_empty' => false ) );
$is_hierarchical = is_taxonomy_hierarchical( $taxonomy ); $is_hierarchical = is_taxonomy_hierarchical( $taxonomy );
$terms = acf_get_terms(array(
'taxonomy' => $taxonomy,
'hide_empty' => false
));
// bail early i no terms // bail early i no terms
@ -3200,7 +3245,7 @@ function acf_upload_files( $ancestors = array() ) {
function acf_upload_file( $uploaded_file ) { function acf_upload_file( $uploaded_file ) {
// required // required
require_once( ABSPATH . "/wp-load.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/media.php" ); // video functions
require_once( ABSPATH . "/wp-admin/includes/file.php" ); require_once( ABSPATH . "/wp-admin/includes/file.php" );
require_once( ABSPATH . "/wp-admin/includes/image.php" ); require_once( ABSPATH . "/wp-admin/includes/image.php" );
@ -4368,29 +4413,18 @@ function acf_format_date( $value, $format ) {
if( !$value ) return $value; if( !$value ) return $value;
// attempt strtotime for standard date value // vars
$unixtimestamp = strtotime($value); $unixtimestamp = 0;
// check strtotime // numeric (either unix or YYYYMMDD)
if( !$unixtimestamp ) { if( is_numeric($value) && strlen($value) !== 8 ) {
// $value may already be a timestamp $unixtimestamp = $value;
if( is_numeric($value) ) {
$unixtimestamp = $value;
// $value may be Unix epoch (1970-01-01) } else {
} elseif( $value === '1970-01-01' ) {
$unixtimestamp = strtotime($value);
$unixtimestamp = 0;
// error
} else {
return $value;
}
} }

View File

@ -796,47 +796,18 @@ function has_sub_fields( $field_name, $post_id = false ) {
* @return (mixed) * @return (mixed)
*/ */
function get_sub_field( $selector, $format_value = true ) { function get_sub_field( $selector = '', $format_value = true ) {
// vars // get sub field
$row = acf_get_loop('active'); $sub_field = get_sub_field_object( $selector, $format_value );
// bail early if no row // bail early if no sub field
if( !$row ) return null; if( !$sub_field ) return false;
// attempt to find sub field
$sub_field = get_row_sub_field( $selector );
// update selector
if( $sub_field ) {
$selector = $sub_field['key'];
} else {
$format_value = false;
}
// load value
$value = get_row_sub_value( $selector );
// format value
if( $format_value ) {
// get value for field
$value = acf_format_value( $value, $row['post_id'], $sub_field );
}
// return // return
return $value; return $sub_field['value'];
} }
@ -900,7 +871,11 @@ function get_sub_field_object( $selector, $format_value = true, $load_value = tr
// load value // load value
$sub_field['value'] = get_row_sub_value( $sub_field['key'] ); if( $load_value ) {
$sub_field['value'] = get_row_sub_value( $sub_field['key'] );
}
// format value // format value
@ -1634,118 +1609,32 @@ function update_field( $selector, $value, $post_id = false ) {
function update_sub_field( $selector, $value, $post_id = false ) { function update_sub_field( $selector, $value, $post_id = false ) {
// vars
$sub_field = false;
// filter post_id // filter post_id
$post_id = acf_get_valid_post_id( $post_id ); $post_id = acf_get_valid_post_id( $post_id );
// vars // get sub field
$field = false; if( is_array($selector) ) {
$sub_field = acf_maybe_get_sub_field( $selector, $post_id, false );
} else {
// within a have_rows loop
if( is_string($selector) ) {
// get current row $sub_field = get_row_sub_field( $selector );
$row = acf_get_loop('active');
// override $post_id
$post_id = $row['post_id'];
// attempt to find sub field
$field = get_row_sub_field($selector);
// create dummy field
if( !$field ) {
$field = acf_get_valid_field(array(
'name' => "{$row['name']}_{$row['i']}_{$selector}",
'key' => '',
'type' => '',
));
}
} elseif( is_array($selector) ) {
// validate
if( count($selector) < 3 ) {
return false;
}
// vars
$parent_name = acf_extract_var( $selector, 0 );
// load parent
$field = acf_maybe_get_field( $parent_name, $post_id );
// add to name
$name = $field['name'];
// sub fields
foreach( $selector as $s ) {
if( is_numeric($s) ) {
// get row index
$row_i = intval($s) - 1;
// add to name
$name .= "_{$row_i}";
} else {
// update parent
$field = acf_get_sub_field( $s, $field );
// create dummy field
if( !$field ) {
$field = acf_get_valid_field(array(
'name' => $s,
'key' => '',
'type' => '',
));
}
// add to name
$name .= "_{$field['name']}";
}
// if
}
// foreach
// update name
$field['name'] = $name;
}
// delete
if( $value === null ) {
return acf_delete_value( $post_id, $field );
} }
// bail early if no sub field
if( !$sub_field ) return false;
// update // update
return acf_update_value( $value, $post_id, $field ); return acf_update_value( $value, $post_id, $sub_field );
} }
@ -1805,17 +1694,19 @@ function delete_sub_field( $selector, $post_id = false ) {
/* /*
* add_row * add_row
* *
* description * This function will add a row of data to a field
* *
* @type function * @type function
* @date 16/10/2015 * @date 16/10/2015
* @since 5.2.3 * @since 5.2.3
* *
* @param $post_id (int) * @param $selector (string)
* @return $post_id (int) * @param $row (array)
* @param $post_id (mixed)
* @return (boolean)
*/ */
function add_row( $selector, $value, $post_id = false ) { function add_row( $selector, $row = false, $post_id = false ) {
// filter post_id // filter post_id
$post_id = acf_get_valid_post_id( $post_id ); $post_id = acf_get_valid_post_id( $post_id );
@ -1826,73 +1717,106 @@ function add_row( $selector, $value, $post_id = false ) {
// bail early if no field // bail early if no field
if( !$field ) { if( !$field ) return false;
// get raw value
$value = acf_get_value( $post_id, $field );
// ensure array
$value = acf_get_array($value);
// append
$value[] = $row;
// update value
return acf_update_value( $value, $post_id, $field );
return false; }
/*
* add_sub_row
*
* This function will add a row of data to a field
*
* @type function
* @date 16/10/2015
* @since 5.2.3
*
* @param $selector (string)
* @param $row (array)
* @param $post_id (mixed)
* @return (boolean)
*/
function add_sub_row( $selector, $row = false, $post_id = false ) {
// vars
$sub_field = false;
// filter post_id
$post_id = acf_get_valid_post_id( $post_id );
// get sub field
if( is_array($selector) ) {
$sub_field = acf_maybe_get_sub_field( $selector, $post_id, false );
} else {
$sub_field = get_row_sub_field( $selector );
} }
// get row count // bail early if no sub field
$i = (int) acf_get_metadata( $post_id, $field['name'] ); if( !$sub_field ) return false;
// if no rows, save this field via update_field() so that the reference field is created
if( !$i ) {
// acf_update_value will return boolean, simply convert this to int for 1 | 0 (the number of rows!) // get raw value
return (int) acf_update_value( array( $value ), $post_id, $field ); $value = acf_get_value( $post_id, $sub_field );
// ensure array
$value = acf_get_array( $value );
// append
$value[] = $row;
// update
return acf_update_value( $value, $post_id, $sub_field );
}
// increase $i
$i++;
// update meta
$result = acf_update_metadata( $post_id, $field['name'], $i );
// update sub fields
if( $value ) {
foreach( $value as $k => $v ) {
update_sub_field( array( $field['key'], $i, $k ), $v, $post_id );
}
}
// return
return $i;
} }
/* /*
* update_row * update_row
* *
* description * This function will update a row of data to a field
* *
* @type function * @type function
* @date 19/10/2015 * @date 19/10/2015
* @since 5.2.3 * @since 5.2.3
* *
* @param $post_id (int) * @param $selector (string)
* @return $post_id (int) * @param $i (int)
* @param $row (array)
* @param $post_id (mixed)
* @return (boolean)
*/ */
function update_row( $selector, $row = 1, $value = false, $post_id = false ) { function update_row( $selector, $i = 1, $row = false, $post_id = false ) {
// bail early if no value // vars
if( empty($value) ) { $i--;
return false;
}
// filter post_id // filter post_id
@ -1907,34 +1831,104 @@ function update_row( $selector, $row = 1, $value = false, $post_id = false ) {
if( !$field ) return false; if( !$field ) return false;
// update sub fields // get raw value
foreach( $value as $k => $v ) { $value = acf_get_value( $post_id, $field );
// ensure array
$value = acf_get_array($value);
// update
$value[ $i ] = $row;
// update value
return acf_update_value( $value, $post_id, $field );
}
/*
* update_sub_row
*
* This function will add a row of data to a field
*
* @type function
* @date 16/10/2015
* @since 5.2.3
*
* @param $selector (string)
* @param $row (array)
* @param $post_id (mixed)
* @return (boolean)
*/
function update_sub_row( $selector, $i = 1, $row = false, $post_id = false ) {
// vars
$sub_field = false;
$i--;
// filter post_id
$post_id = acf_get_valid_post_id( $post_id );
// get sub field
if( is_array($selector) ) {
update_sub_field( array( $field['key'], $row, $k ), $v, $post_id ); $sub_field = acf_maybe_get_sub_field( $selector, $post_id, false );
} else {
$sub_field = get_row_sub_field( $selector );
} }
// return // bail early if no sub field
return true; if( !$sub_field ) return false;
// get raw value
$value = acf_get_value( $post_id, $sub_field );
// ensure array
$value = acf_get_array( $value );
// append
$value[ $i ] = $row;
// update
return acf_update_value( $value, $post_id, $sub_field );
} }
/* /*
* delete_row * delete_row
* *
* description * This function will delete a row of data from a field
* *
* @type function * @type function
* @date 19/10/2015 * @date 19/10/2015
* @since 5.2.3 * @since 5.2.3
* *
* @param $post_id (int) * @param $selector (string)
* @return $post_id (int) * @param $i (int)
* @param $post_id (mixed)
* @return (boolean)
*/ */
function delete_row( $selector, $row = 1, $post_id = false ) { function delete_row( $selector, $i = 1, $post_id = false ) {
// vars
$i--;
// filter post_id // filter post_id
$post_id = acf_get_valid_post_id( $post_id ); $post_id = acf_get_valid_post_id( $post_id );
@ -1949,36 +1943,80 @@ function delete_row( $selector, $row = 1, $post_id = false ) {
// get value // get value
$rows = acf_get_value( $post_id, $field ); $value = acf_get_value( $post_id, $field );
// bail early if no value // ensure array
if( empty($rows) ) return false; $value = acf_get_array($value);
// vars
$i = $row-1;
// bail early if row doesn't exist
if( empty($rows[ $i ]) ) return false;
// unset // unset
unset( $rows[ $i ] ); unset( $value[ $i ] );
// reindex
$rows = array_values($rows);
// update // update
acf_update_value( $rows, $post_id, $field ); return acf_update_value( $value, $post_id, $field );
}
/*
* delete_sub_row
*
* This function will add a row of data to a field
*
* @type function
* @date 16/10/2015
* @since 5.2.3
*
* @param $selector (string)
* @param $row (array)
* @param $post_id (mixed)
* @return (boolean)
*/
function delete_sub_row( $selector, $i = 1, $post_id = false ) {
// vars
$sub_field = false;
$i--;
// return // filter post_id
return true; $post_id = acf_get_valid_post_id( $post_id );
// get sub field
if( is_array($selector) ) {
$sub_field = acf_maybe_get_sub_field( $selector, $post_id, false );
} else {
$sub_field = get_row_sub_field( $selector );
}
// bail early if no sub field
if( !$sub_field ) return false;
// get raw value
$value = acf_get_value( $post_id, $sub_field );
// ensure array
$value = acf_get_array( $value );
// append
unset( $value[ $i ] );
// update
return acf_update_value( $value, $post_id, $sub_field );
} }

View File

@ -882,11 +882,15 @@
else { else {
this.$timeObj.val($.datepicker.formatTime(pickerTimeFormat, this, o) + pickerTimeSuffix); this.$timeObj.val($.datepicker.formatTime(pickerTimeFormat, this, o) + pickerTimeSuffix);
} }
/*
// Input loses focus when typing with picker open
// https://github.com/trentrichardson/jQuery-Timepicker-Addon/issues/848
if (this.$timeObj[0].setSelectionRange) { if (this.$timeObj[0].setSelectionRange) {
var sPos = this.$timeObj[0].selectionStart; var sPos = this.$timeObj[0].selectionStart;
var ePos = this.$timeObj[0].selectionEnd; var ePos = this.$timeObj[0].selectionEnd;
this.$timeObj[0].setSelectionRange(sPos, ePos); this.$timeObj[0].setSelectionRange(sPos, ePos);
} }
*/
} }
this.timeDefined = true; this.timeDefined = true;

File diff suppressed because one or more lines are too long

View File

@ -868,8 +868,8 @@
// AJAX data // AJAX data
var ajax_data = acf.prepare_for_ajax({ var ajax_data = acf.prepare_for_ajax({
'action': 'acf/field_group/move_field', action: 'acf/field_group/move_field',
'field_id': this.get_field_meta( $field, 'ID' ) field_id: this.get_field_meta( $field, 'ID' )
}); });
@ -970,12 +970,11 @@
// AJAX data // AJAX data
var ajax_data = { var ajax_data = acf.prepare_for_ajax({
'action' : 'acf/field_group/move_field', 'action' : 'acf/field_group/move_field',
'nonce' : acf.get('nonce'),
'field_id' : this.get_field_meta($field, 'ID'), 'field_id' : this.get_field_meta($field, 'ID'),
'field_group_id' : 0 'field_group_id' : 0
}; });
// submit form // submit form

File diff suppressed because one or more lines are too long

View File

@ -1592,8 +1592,9 @@ var acf;
prepare_for_ajax : function( args ) { prepare_for_ajax : function( args ) {
// nonce // vars
args.nonce = acf.get('nonce'); args.nonce = acf.get('nonce');
args.post_id = acf.get('post_id');
// filter for 3rd party customization // filter for 3rd party customization
@ -4527,11 +4528,6 @@ var acf;
'ready 1': 'ready', 'ready 1': 'ready',
}, },
filters: {
'date_time_picker_args': 'customize_onClose',
'time_picker_args': 'customize_onClose'
},
ready: function(){ ready: function(){
// vars // vars
@ -4608,58 +4604,6 @@ var acf;
}, },
/*
* customize_onClose
*
* This function will add a custom onClose function to the datetime and time picker args
*
* @type function
* @date 5/07/2016
* @since 5.4.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
customize_onClose: function( args ){
// change button text
args.closeText = acf._e('date_time_picker', 'selectText');
// add custom 'Close = Select' functionality
args.onClose = function( value, instance ){
// vars
var $div = instance.dpDiv,
$close = $div.find('.ui-datepicker-close');
// if clicking close button
if( !value && $close.is(':hover') ) {
// attempt to find new value
value = acf.maybe_get(instance, 'settings.timepicker.formattedTime');
// bail early if no value
if( !value ) return;
// update value
acf.val( instance.input, value );
}
}
// return
return args;
}
}); });
@ -5168,6 +5112,7 @@ var acf;
// get options // get options
this.o = acf.get_data( this.$el ); this.o = acf.get_data( this.$el );
this.o.id = this.$el.attr('id');
// get map // get map
@ -7155,8 +7100,31 @@ var acf;
}, },
/*
* toggleSelection
*
* This function is called before an attachment is selected
* A good place to check for errors and prevent the 'select' function from being fired
*
* @type function
* @date 29/09/2016
* @since 5.4.0
*
* @param options (object)
* @return n/a
*/
toggleSelection: function( options ) { toggleSelection: function( options ) {
// vars
// source: wp-includes/js/media-views.js:2880
var collection = this.collection,
selection = this.options.selection,
model = this.model,
single = selection.single();
// vars // vars
var frame = acf.media.frame(), var frame = acf.media.frame(),
errors = acf.maybe_get(this, 'model.attributes.acf_errors'), errors = acf.maybe_get(this, 'model.attributes.acf_errors'),
@ -7192,36 +7160,25 @@ var acf;
'</div>' '</div>'
].join('')); ].join(''));
// reset selection (unselects all attachments)
selection.reset();
// set single (attachment displayed in sidebar)
selection.single( model );
// return and prevent 'select' form being fired
return;
} }
// return // return
AttachmentLibrary.prototype.toggleSelection.apply( this, arguments ); AttachmentLibrary.prototype.toggleSelection.apply( this, arguments );
},
select: function( model, collection ) {
// vars
var frame = acf.media.frame(),
state = this.controller.state(),
selection = state.get('selection'),
errors = acf.maybe_get(this, 'model.attributes.acf_errors');
// prevent selection
if( frame && errors ) {
return selection.remove( model );
}
//return
return AttachmentLibrary.prototype.select.apply( this, arguments );
} }
}); });
@ -7255,9 +7212,6 @@ var acf;
render: function() { render: function() {
//console.log('AttachmentCompat.render', this);
// reference // reference
var self = this; var self = this;
@ -7333,8 +7287,6 @@ var acf;
dispose: function() { dispose: function() {
//console.log('AttachmentCompat.dispose', this);
// remove // remove
acf.do_action('remove', this.$el); acf.do_action('remove', this.$el);
@ -7347,8 +7299,6 @@ var acf;
save: function( e ) { save: function( e ) {
//console.log('AttachmentCompat.save', this);
if( e ) { if( e ) {
e.preventDefault(); e.preventDefault();
@ -7402,13 +7352,12 @@ var acf;
// AJAX data // AJAX data
var ajax_data = { var ajax_data = acf.prepare_for_ajax({
'action' : 'acf/fields/oembed/search', 'action' : 'acf/fields/oembed/search',
'nonce' : acf.get('nonce'),
's' : s, 's' : s,
'width' : acf.get_data($el, 'width'), 'width' : acf.get_data($el, 'width'),
'height' : acf.get_data($el, 'height') 'height' : acf.get_data($el, 'height')
}; });
// abort XHR if this field is already loading AJAX data // abort XHR if this field is already loading AJAX data
@ -8573,7 +8522,6 @@ var acf;
var data = acf.prepare_for_ajax({ var data = acf.prepare_for_ajax({
action: args.ajax_action, action: args.ajax_action,
field_key: args.key, field_key: args.key,
post_id: acf.get('post_id'),
s: params.term, s: params.term,
paged: params.page paged: params.page
}); });
@ -8764,8 +8712,12 @@ var acf;
// add hidden input to each multiple selection // add hidden input to each multiple selection
select2_args.formatSelection = function( object, $div ){ select2_args.formatSelection = function( object, $div ){
// vars
var html = '<input type="hidden" class="select2-search-choice-hidden" name="' + name + '" value="' + object.id + '"' + ($input.prop('disabled') ? 'disabled="disabled"' : '') + ' />';
// append input // append input
$div.parent().append('<input type="hidden" class="select2-search-choice-hidden" name="' + name + '" value="' + object.id + '" />'); $div.parent().append(html);
// return // return
@ -9829,6 +9781,34 @@ var acf;
showButtonPanel: true, showButtonPanel: true,
controlType: 'select', controlType: 'select',
oneLine: true, oneLine: true,
closeText: acf._e('date_time_picker', 'selectText')
};
// add custom 'Close = Select' functionality
args.onClose = function( value, instance ){
// vars
var $div = instance.dpDiv,
$close = $div.find('.ui-datepicker-close');
// if clicking close button
if( !value && $close.is(':hover') ) {
// attempt to find new value
value = acf.maybe_get(instance, 'settings.timepicker.formattedTime');
// bail early if no value
if( !value ) return;
// update value
$.datepicker._setTime(instance);
}
}; };
@ -10718,6 +10698,10 @@ var acf;
data.action = 'acf/validate_save_post'; data.action = 'acf/validate_save_post';
// prepare
data = acf.prepare_for_ajax(data);
// set busy // set busy
this.busy = 1; this.busy = 1;
@ -11662,7 +11646,7 @@ ed.on('ResizeEditor', function(e) {
}, },
ready: function(){ ready: function(){
// vars // vars
this.$div = $('#acf-hidden-wp-editor'); this.$div = $('#acf-hidden-wp-editor');
@ -11686,18 +11670,18 @@ ed.on('ResizeEditor', function(e) {
var editor = data.editor; var editor = data.editor;
// update WP var to match tinymce // bail early if not 'acf'
if( editor.id.substr(0, 3) !== 'acf' ) return;
// override if 'content' exists
editor = tinymce.editors.content || editor;
// update vars
tinymce.activeEditor = editor;
wpActiveEditor = editor.id; wpActiveEditor = editor.id;
// bail early if not acf_content
if( editor.id !== 'acf_content' ) return;
// update global vars
tinymce.activeEditor = tinymce.editors.content || null;
wpActiveEditor = tinymce.editors.content ? 'content' : null;
}); });
} }

File diff suppressed because one or more lines are too long

View File

@ -79,12 +79,43 @@ class acf_field {
* @return n/a * @return n/a
*/ */
function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) { function add_filter( $tag = '', $function_to_add = '', $priority = 10, $accepted_args = 1 ) {
// bail early if no callable
if( !is_callable($function_to_add) ) return;
// add
add_filter( $tag, $function_to_add, $priority, $accepted_args );
}
/*
* add_field_filter
*
* This function will add a field type specific filter
*
* @type function
* @date 29/09/2016
* @since 5.4.0
*
* @param $tag (string)
* @param $function_to_add (string)
* @param $priority (int)
* @param $accepted_args (int)
* @return n/a
*/
function add_field_filter( $tag = '', $function_to_add = '', $priority = 10, $accepted_args = 1 ) {
// append
$tag .= '/type=' . $this->name;
// add
$this->add_filter( $tag, $function_to_add, $priority, $accepted_args );
if( is_callable($function_to_add) )
{
add_filter($tag, $function_to_add, $priority, $accepted_args);
}
} }
@ -104,12 +135,43 @@ class acf_field {
* @return n/a * @return n/a
*/ */
function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) { function add_action( $tag = '', $function_to_add = '', $priority = 10, $accepted_args = 1 ) {
// bail early if no callable
if( !is_callable($function_to_add) ) return;
// add
add_action( $tag, $function_to_add, $priority, $accepted_args );
}
/*
* add_field_action
*
* This function will add a field type specific filter
*
* @type function
* @date 29/09/2016
* @since 5.4.0
*
* @param $tag (string)
* @param $function_to_add (string)
* @param $priority (int)
* @param $accepted_args (int)
* @return n/a
*/
function add_field_action( $tag = '', $function_to_add = '', $priority = 10, $accepted_args = 1 ) {
// append
$tag .= '/type=' . $this->name;
// add
$this->add_action( $tag, $function_to_add, $priority, $accepted_args );
if( is_callable($function_to_add) )
{
add_action($tag, $function_to_add, $priority, $accepted_args);
}
} }

View File

@ -129,10 +129,12 @@ class acf_field_date_picker extends acf_field {
function render_field( $field ) { function render_field( $field ) {
// format value // format value
$hidden_value = '';
$display_value = ''; $display_value = '';
if( $field['value'] ) { if( $field['value'] ) {
$hidden_value = acf_format_date( $field['value'], 'Ymd' );
$display_value = acf_format_date( $field['value'], $field['display_format'] ); $display_value = acf_format_date( $field['value'], $field['display_format'] );
} }
@ -150,7 +152,7 @@ class acf_field_date_picker extends acf_field {
'class' => 'input-alt', 'class' => 'input-alt',
'type' => 'hidden', 'type' => 'hidden',
'name' => $field['name'], 'name' => $field['name'],
'value' => $field['value'], 'value' => $hidden_value,
); );
$input = array( $input = array(
'class' => 'input', 'class' => 'input',
@ -233,41 +235,6 @@ class acf_field_date_picker extends acf_field {
} }
/*
* load_value()
*
* This filter is applied to the $value after it is loaded from the db
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $value (mixed) the value found in the database
* @param $post_id (mixed) the $post_id from which the value was loaded
* @param $field (array) the field array holding all the field options
* @return $value
*/
function load_value( $value, $post_id, $field ) {
// bail ealry if no $value
if( !$value ) return $value;
// date field is currently saved as Ymd (not Y-m-d). Convert it
if( strlen($value) == 8 ) {
$value = substr($value, 0, 4) . '-' . substr($value, 4, 2) . '-' . substr($value, 6, 2);
}
// return
return $value;
}
/* /*
* format_value() * format_value()
* *
@ -290,38 +257,6 @@ class acf_field_date_picker extends acf_field {
} }
/*
* update_value()
*
* This filter is appied to the $value before it is updated in the db
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $value - the value which will be saved in the database
* @param $post_id - the $post_id of which the value will be saved
* @param $field - the field array holding all the field options
*
* @return $value - the modified value
*/
function update_value( $value, $post_id, $field ) {
// bail ealry if no $value
if( !$value ) return $value;
// remove '-'
$value = str_replace('-', '', $value);
// return
return $value;
}
} }

View File

@ -112,10 +112,12 @@ class acf_field_date_and_time_picker extends acf_field {
function render_field( $field ) { function render_field( $field ) {
// format value // format value
$hidden_value = '';
$display_value = ''; $display_value = '';
if( $field['value'] ) { if( $field['value'] ) {
$hidden_value = acf_format_date( $field['value'], 'Y-m-d H:i:s' );
$display_value = acf_format_date( $field['value'], $field['display_format'] ); $display_value = acf_format_date( $field['value'], $field['display_format'] );
} }
@ -139,7 +141,7 @@ class acf_field_date_and_time_picker extends acf_field {
'class' => 'input-alt', 'class' => 'input-alt',
'type' => 'hidden', 'type' => 'hidden',
'name' => $field['name'], 'name' => $field['name'],
'value' => $field['value'], 'value' => $hidden_value,
); );
$input = array( $input = array(
'class' => 'input', 'class' => 'input',

View File

@ -104,7 +104,6 @@ class acf_field_google_map extends acf_field {
$atts = array( $atts = array(
'id' => $field['id'], 'id' => $field['id'],
'class' => "acf-google-map {$field['class']}", 'class' => "acf-google-map {$field['class']}",
'data-id' => $field['id'] . '-' . uniqid(),
'data-lat' => $field['center_lat'], 'data-lat' => $field['center_lat'],
'data-lng' => $field['center_lng'], 'data-lng' => $field['center_lng'],
'data-zoom' => $field['zoom'], 'data-zoom' => $field['zoom'],

View File

@ -129,7 +129,6 @@ class acf_field_taxonomy extends acf_field {
// vars // vars
$results = array(); $results = array();
$args = array();
$is_hierarchical = is_taxonomy_hierarchical( $field['taxonomy'] ); $is_hierarchical = is_taxonomy_hierarchical( $field['taxonomy'] );
$is_pagination = ($options['paged'] > 0); $is_pagination = ($options['paged'] > 0);
$is_search = false; $is_search = false;
@ -137,8 +136,11 @@ class acf_field_taxonomy extends acf_field {
$offset = 20 * ($options['paged'] - 1); $offset = 20 * ($options['paged'] - 1);
// hide empty // args
$args['hide_empty'] = false; $args = array(
'taxonomy' => $field['taxonomy'],
'hide_empty' => false
);
// pagination // pagination
@ -172,7 +174,7 @@ class acf_field_taxonomy extends acf_field {
// get terms // get terms
$terms = get_terms( $field['taxonomy'], $args ); $terms = acf_get_terms( $args );
// sort into hierachial order! // sort into hierachial order!
@ -299,9 +301,10 @@ class acf_field_taxonomy extends acf_field {
// load terms in 1 query to save multiple DB calls from following code // load terms in 1 query to save multiple DB calls from following code
if( count($value) > 1 ) { if( count($value) > 1 ) {
$terms = get_terms($taxonomy, array( $terms = acf_get_terms(array(
'hide_empty' => false, 'taxonomy' => $taxonomy,
'include' => $value, 'include' => $value,
'hide_empty' => false
)); ));
} }

View File

@ -636,25 +636,28 @@
render_layout_title: function( $layout ){ render_layout_title: function( $layout ){
// vars // vars
var data = acf.serialize( $layout ); var ajax_data = acf.serialize( $layout );
// append // append
$.extend(data, { ajax_data = acf.parse_args( ajax_data, {
action: 'acf/fields/flexible_content/layout_title', action: 'acf/fields/flexible_content/layout_title',
field_key: this.$field.data('key'), field_key: this.$field.data('key'),
post_id: acf.get('post_id'),
i: $layout.index(), i: $layout.index(),
layout: $layout.data('layout'), layout: $layout.data('layout'),
}); });
// prepare
ajax_data = acf.prepare_for_ajax(ajax_data);
// ajax get title HTML // ajax get title HTML
$.ajax({ $.ajax({
url : acf.get('ajaxurl'), url : acf.get('ajaxurl'),
dataType : 'html', dataType : 'html',
type : 'post', type : 'post',
data : data, data : ajax_data,
success: function( html ){ success: function( html ){
// bail early if no html // bail early if no html
@ -1144,6 +1147,11 @@
var $layout = e.$el.closest('.layout'); var $layout = e.$el.closest('.layout');
// render
// - do this before calling actions to avoif focusing on the wrong field
this.render_layout_title( $layout );
// open // open
if( $layout.hasClass('-collapsed') ) { if( $layout.hasClass('-collapsed') ) {
@ -1164,10 +1172,6 @@
// sync collapsed order // sync collapsed order
this.sync(); this.sync();
// render
this.render_layout_title( $layout );
} }
}); });
@ -1947,8 +1951,6 @@
var data = acf.prepare_for_ajax({ var data = acf.prepare_for_ajax({
action : 'acf/fields/gallery/get_attachment', action : 'acf/fields/gallery/get_attachment',
field_key : this.$field.data('key'), field_key : this.$field.data('key'),
nonce : acf.get('nonce'),
post_id : acf.get('post_id'),
id : id id : id
}); });
@ -2058,7 +2060,6 @@
var data = acf.prepare_for_ajax({ var data = acf.prepare_for_ajax({
action : 'acf/fields/gallery/get_sort_order', action : 'acf/fields/gallery/get_sort_order',
field_key : this.$field.data('key'), field_key : this.$field.data('key'),
post_id : acf.get('post_id'),
ids : [], ids : [],
sort : sort sort : sort
}); });

File diff suppressed because one or more lines are too long

View File

@ -63,6 +63,10 @@ class acf_field_flexible_content extends acf_field {
add_filter('acf/clone_field', array($this, 'acf_clone_field'), 10, 2); add_filter('acf/clone_field', array($this, 'acf_clone_field'), 10, 2);
// field filters
$this->add_field_filter('acf/get_sub_field', array($this, 'get_sub_field'), 10, 3);
// do not delete! // do not delete!
parent::__construct(); parent::__construct();
@ -177,6 +181,64 @@ class acf_field_flexible_content extends acf_field {
} }
/*
* get_sub_field
*
* This function will return a specific sub field
*
* @type function
* @date 29/09/2016
* @since 5.4.0
*
* @param $sub_field
* @param $selector (string)
* @param $field (array)
* @return $post_id (int)
*/
function get_sub_field( $sub_field, $selector, $field ) {
// bail early if no layouts
if( empty($field['layouts']) ) return false;
// vars
$active = get_row_layout();
// loop
foreach( $field['layouts'] as $layout ) {
// bail early if active layout does not match
if( $active && $active !== $layout['name'] ) continue;
// bail early if no sub fields
if( empty($layout['sub_fields']) ) continue;
// loop
foreach( $layout['sub_fields'] as $sub_field ) {
// check name and key
if( $sub_field['name'] == $selector || $sub_field['key'] == $selector ) {
// return
return $sub_field;
}
}
}
// return
return false;
}
/* /*
* render_field() * render_field()
* *
@ -1339,16 +1401,18 @@ class acf_field_flexible_content extends acf_field {
while( is_array($value) ) { while( is_array($value) ) {
// get first key // move to end of array
$k = key($value); // - avoids 'acf_fc_layout' value
end( $value );
// update value // vars
$value = array_pop( $value[ $k ] ); $key = key($value);
$value = current($value);
// stop looking if we have found the correct field's value // stop looking if we have found the correct field's value
if( $k === $options['field_key'] ) break; if( $key === $options['field_key'] ) break;
} }

View File

@ -49,6 +49,10 @@ class acf_field_repeater extends acf_field {
); );
// field filters
$this->add_field_filter('acf/get_sub_field', array($this, 'get_sub_field'), 10, 3);
// do not delete! // do not delete!
parent::__construct(); parent::__construct();
} }
@ -85,7 +89,47 @@ class acf_field_repeater extends acf_field {
// return // return
return $field; return $field;
} }
/*
* get_sub_field
*
* This function will return a specific sub field
*
* @type function
* @date 29/09/2016
* @since 5.4.0
*
* @param $sub_field
* @param $selector (string)
* @param $field (array)
* @return $post_id (int)
*/
function get_sub_field( $sub_field, $selector, $field ) {
// bail early if no sub fields
if( empty($field['sub_fields']) ) return false;
// loop
foreach( $field['sub_fields'] as $sub_field ) {
// check name and key
if( $sub_field['name'] == $selector || $sub_field['key'] == $selector ) {
// return
return $sub_field;
}
}
// return
return false;
}
/* /*

View File

@ -106,6 +106,17 @@ http://support.advancedcustomfields.com/
== Changelog == == Changelog ==
= 5.4.7 =
* Time Picker field: Fixed bug preventing default time from being selected
* Date Picker field: Improved compatibility with unix timestamp values
* File field: Fixed validation bugs when used as a sub field (multiple selection)
* Select field: Fixed bug incorrectly allowing a disabled field (hidden by conditional logic) to save values
* API: Added new `add_sub_row()` function
* API: Added new `update_sub_row()` function
* API: Added new `delete_sub_row()` function
* Core: Fixed bug causing 'sync' issues with sub clone fields
* Core: Minor fixes and improvements
= 5.4.6 = = 5.4.6 =
* Gallery field: Fixed bug where open sidebar fields were saved to post * Gallery field: Fixed bug where open sidebar fields were saved to post
* Flexible Content field: Fixed bug causing Google map render issue within collapsed layout * Flexible Content field: Fixed bug causing Google map render issue within collapsed layout