Merge branch 'release/5.4.4'

This commit is contained in:
I 2016-09-08 09:08:15 +02:00
commit c9dfff5b41
83 changed files with 11292 additions and 6326 deletions

69
acf.php
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.3.10 Version: 5.4.4
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.3.10', 'version' => '5.4.4',
// urls // urls
'basename' => plugin_basename( __FILE__ ), 'basename' => plugin_basename( __FILE__ ),
@ -81,7 +81,9 @@ class acf {
'l10n' => true, 'l10n' => true,
'l10n_textdomain' => '', 'l10n_textdomain' => '',
'google_api_key' => '', 'google_api_key' => '',
'google_api_client' => '' 'google_api_client' => '',
'enqueue_google_maps' => true,
'enqueue_select2' => true,
); );
@ -98,6 +100,8 @@ class acf {
// core // core
acf_include('core/ajax.php'); acf_include('core/ajax.php');
acf_include('core/cache.php');
acf_include('core/fields.php');
acf_include('core/field.php'); acf_include('core/field.php');
acf_include('core/input.php'); acf_include('core/input.php');
acf_include('core/validation.php'); acf_include('core/validation.php');
@ -441,11 +445,64 @@ class acf {
/* /*
function posts_request( $thing ) { * get_setting
*
* This function will return a value from the settings array found in the acf object
*
* @type function
* @date 28/09/13
* @since 5.0.0
*
* @param $name (string) the setting name to return
* @param $value (mixed) default value
* @return $value
*/
function get_setting( $name, $value = null ) {
// check settings
if( isset($this->settings[ $name ]) ) {
$value = $this->settings[ $name ];
}
// filter for 3rd party customization
if( substr($name, 0, 1) !== '_' ) {
$value = apply_filters( "acf/settings/{$name}", $value );
}
// return
return $value;
}
/*
* update_setting
*
* This function will update a value into the settings array found in the acf object
*
* @type function
* @date 28/09/13
* @since 5.0.0
*
* @param $name (string)
* @param $value (mixed)
* @return n/a
*/
function update_setting( $name, $value ) {
$this->settings[ $name ] = $value;
return true;
return $thing;
} }
*/
} }

View File

@ -102,8 +102,8 @@ class acf_admin_field_group {
if( !acf_is_screen('acf-field-group') ) return; if( !acf_is_screen('acf-field-group') ) return;
// disable JSON to avoid conflicts between DB and JSON // disable filters to ensure ACF loads raw data from DB
acf_disable_local(); acf_disable_filters();
// enqueue scripts // enqueue scripts
@ -219,7 +219,7 @@ class acf_admin_field_group {
// render post data // render post data
acf_form_data(array( acf_form_data(array(
'post_id' => $post->post_id, 'post_id' => $post->ID,
'nonce' => 'field_group', 'nonce' => 'field_group',
'ajax' => 0 'ajax' => 0
)); ));
@ -463,13 +463,11 @@ class acf_admin_field_group {
} }
// disable local to avoid conflicts between DB and local // disable filters to ensure ACF loads raw data from DB
acf_disable_local(); acf_disable_filters();
// save fields // save fields
unset( $_POST['acf_fields']['acfcloneindex'] );
if( !empty($_POST['acf_fields']) ) { if( !empty($_POST['acf_fields']) ) {
foreach( $_POST['acf_fields'] as $field ) { foreach( $_POST['acf_fields'] as $field ) {
@ -509,16 +507,20 @@ class acf_admin_field_group {
// delete fields // delete fields
if( $_POST['_acf_delete_fields'] ) { if( $_POST['_acf_delete_fields'] ) {
// clean
$ids = explode('|', $_POST['_acf_delete_fields']); $ids = explode('|', $_POST['_acf_delete_fields']);
$ids = array_map( 'intval', $ids ); $ids = array_map( 'intval', $ids );
// loop
foreach( $ids as $id ) { foreach( $ids as $id ) {
if( $id != 0 ) {
acf_delete_field( $id ); // bai early if no id
if( !$id ) continue;
}
// delete
acf_delete_field( $id );
} }
@ -560,7 +562,8 @@ class acf_admin_field_group {
// get fields // get fields
$view = array( $view = array(
'fields' => acf_get_fields_by_id( $field_group['ID'] ) 'fields' => acf_get_fields_by_id( $field_group['ID'] ),
'parent' => 0
); );
@ -1124,8 +1127,8 @@ class acf_admin_field_group {
function ajax_move_field() { function ajax_move_field() {
// disable JSON to avoid conflicts between DB and JSON // disable filters to ensure ACF loads raw data from DB
acf_disable_local(); acf_disable_filters();
$args = acf_parse_args($_POST, array( $args = acf_parse_args($_POST, array(

View File

@ -71,8 +71,8 @@ class acf_settings_tools {
function load() { function load() {
// all export pages should not load local fields // disable filters to ensure ACF loads raw data from DB
acf_disable_local(); acf_disable_filters();
// run import / export // run import / export

View File

@ -54,7 +54,7 @@ class acf_admin_update_network {
// loop through sites and find updates // loop through sites and find updates
$sites = wp_get_sites(); $sites = acf_get_sites();
if( $sites ) { if( $sites ) {
@ -177,7 +177,7 @@ class acf_admin_update_network {
// loop through sites and find updates // loop through sites and find updates
$sites = wp_get_sites(); $sites = acf_get_sites();
if( $sites ) { if( $sites ) {
@ -239,4 +239,49 @@ new acf_admin_update_network();
endif; endif;
/*
* acf_get_sites
*
* This function will return an array of site data
*
* @type function
* @date 29/08/2016
* @since 5.4.0
*
* @param n/a
* @return (array)
*/
function acf_get_sites() {
// vars
$sites = array();
// WP >= 4.6
if( function_exists('get_sites') ) {
$_sites = get_sites();
foreach( $_sites as $_site ) {
$_site = get_site( $_site );
$sites[] = $_site->to_array();
}
// WP < 4.6
} else {
$sites = wp_get_sites();
}
// return
return $sites;
}
?> ?>

View File

@ -1,7 +1,8 @@
<?php <?php
// global // vars
global $post; $field = false;
$i = 0;
// extract args // extract args

View File

@ -1,27 +1,15 @@
<?php <?php
// vars // vars
// Note: $args is always passed to this view from above $fields = false;
$fields = array();
$layout = false; $layout = false;
$parent = 0; $parent = 0;
$clone = false;
// use fields if passed in // use fields if passed in
extract( $args ); extract( $args );
// add clone
$fields[] = acf_get_valid_field(array(
'ID' => 'acfcloneindex',
'key' => 'acfcloneindex',
'label' => __('New Field','acf'),
'name' => 'new_field',
'type' => 'text',
'parent' => $parent
));
?> ?>
<div class="acf-field-list-wrap"> <div class="acf-field-list-wrap">
@ -32,18 +20,23 @@ $fields[] = acf_get_valid_field(array(
<li class="li-field-type"><?php _e('Type','acf'); ?></li> <li class="li-field-type"><?php _e('Type','acf'); ?></li>
</ul> </ul>
<div class="acf-field-list<?php if( $layout ){ echo " layout-{$layout}"; } ?>"> <div class="acf-field-list<?php if( $layout ){ echo " layout-{$layout}"; } ?>">
<?php
<?php foreach( $fields as $i => $field ): ?> if( $fields ) {
<?php acf_get_view('field-group-field', array( 'field' => $field, 'i' => $i )); ?> foreach( $fields as $i => $field ) {
<?php endforeach; ?> acf_get_view('field-group-field', array( 'field' => $field, 'i' => $i ));
}
<div class="no-fields-message" <?php if(count($fields) > 1){ echo 'style="display:none;"'; } ?>> }
?>
<div class="no-fields-message" <?php if( $fields ){ echo 'style="display:none;"'; } ?>>
<?php _e("No fields. Click the <strong>+ Add Field</strong> button to create your first field.",'acf'); ?> <?php _e("No fields. Click the <strong>+ Add Field</strong> button to create your first field.",'acf'); ?>
</div> </div>
</div> </div>
<ul class="acf-hl acf-tfoot"> <ul class="acf-hl acf-tfoot">
@ -51,5 +44,22 @@ $fields[] = acf_get_valid_field(array(
<a href="#" class="button button-primary button-large add-field"><?php _e('+ Add Field','acf'); ?></a> <a href="#" class="button button-primary button-large add-field"><?php _e('+ Add Field','acf'); ?></a>
</li> </li>
</ul> </ul>
<?php if( !$parent ):
// get clone
$clone = acf_get_valid_field(array(
'ID' => 'acfcloneindex',
'key' => 'acfcloneindex',
'label' => __('New Field','acf'),
'name' => 'new_field',
'type' => 'text'
));
?>
<script type="text/html" id="tmpl-acf-field">
<?php acf_get_view('field-group-field', array( 'field' => $clone )); ?>
</script>
<?php endif;?>
</div> </div>

View File

@ -14,7 +14,7 @@ $json = acf_extract_var( $args, 'json');
<?php foreach( $json as $addon ): <?php foreach( $json as $addon ):
$addon = acf_parse_args($addon, array( $addon = wp_parse_args($addon, array(
"title" => "", "title" => "",
"slug" => "", "slug" => "",
"description" => "", "description" => "",

View File

@ -53,7 +53,7 @@ function acf_is_field_group_key( $key = '' ) {
function acf_get_valid_field_group( $field_group = false ) { function acf_get_valid_field_group( $field_group = false ) {
// parse in defaults // parse in defaults
$field_group = acf_parse_args( $field_group, array( $field_group = wp_parse_args( $field_group, array(
'ID' => 0, 'ID' => 0,
'key' => '', 'key' => '',
'title' => '', 'title' => '',
@ -140,54 +140,71 @@ function acf_get_field_groups( $args = false ) {
// vars // vars
$field_groups = array(); $field_groups = array();
$post_ids = array();
$cache_key = "get_field_groups";
// cache // check cache for ids
$found = false; if( acf_isset_cache($cache_key) ) {
$cache = wp_cache_get( 'get_field_groups', 'acf', false, $found );
if( $found ) {
return acf_filter_field_groups( $cache, $args ); $post_ids = acf_get_cache($cache_key);
// query DB for child ids
} else {
// query
$posts = get_posts(array(
'post_type' => 'acf-field-group',
'posts_per_page' => -1,
'orderby' => 'menu_order title',
'order' => 'asc',
'suppress_filters' => false, // allow WPML to modify the query
'post_status' => array('publish', 'acf-disabled'),
'update_post_meta_cache' => false
));
// loop
if( $posts ) {
foreach( $posts as $post ) {
$post_ids[] = $post->ID;
}
}
// update cache
acf_set_cache($cache_key, $post_ids);
} }
// load from DB // load field groups
$posts = get_posts(array( foreach( $post_ids as $post_id ) {
'post_type' => 'acf-field-group',
'posts_per_page' => -1,
'orderby' => 'menu_order title',
'order' => 'asc',
'suppress_filters' => false, // allow WPML to modify the query
'post_status' => array('publish', 'acf-disabled'),
'update_post_meta_cache' => false
));
// loop through and load field groups
if( $posts ) {
foreach( $posts as $post ) { $field_groups[] = acf_get_field_group( $post_id );
// add to return array
$field_groups[] = acf_get_field_group( $post );
}
} }
// filter // filter
// - allows local field groups to be appended
$field_groups = apply_filters('acf/get_field_groups', $field_groups); $field_groups = apply_filters('acf/get_field_groups', $field_groups);
// set cache // filter via args
wp_cache_set( 'get_field_groups', $field_groups, 'acf' ); if( $args ) {
$field_groups = acf_filter_field_groups( $field_groups, $args );
}
// return // return
return acf_filter_field_groups( $field_groups, $args ); return $field_groups;
} }
@ -261,28 +278,29 @@ function acf_filter_field_groups( $field_groups, $args = false ) {
* @return $field_group (array) * @return $field_group (array)
*/ */
function acf_get_field_group( $selector = false ) { function acf_get_field_group( $selector = null ) {
// vars // vars
$field_group = false; $field_group = false;
$k = 'ID'; $type = 'ID';
$v = 0;
// $post_id or $key // ID
if( is_numeric($selector) ) { if( is_numeric($selector) ) {
$v = $selector; // do nothing
} elseif( is_string($selector) ) { // object
$k = 'key';
$v = $selector;
} elseif( is_object($selector) ) { } elseif( is_object($selector) ) {
$v = $selector->ID; $selector = $selector->ID;
// string
} elseif( is_string($selector) ) {
$type = 'key';
// other
} else { } else {
return false; return false;
@ -290,39 +308,50 @@ function acf_get_field_group( $selector = false ) {
} }
// get cache key // return early if cache is found
$cache_key = "get_field_group/{$k}={$v}"; $cache_key = "get_field_group/{$type}={$selector}";
if( acf_isset_cache($cache_key) ) {
// get cache
$found = false;
$cache = wp_cache_get( $cache_key, 'acf', false, $found );
if( $found ) return $cache;
// get field group from ID or key
if( $k == 'ID' ) {
$field_group = _acf_get_field_group_by_id( $v ); return acf_get_cache($cache_key);
} else {
$field_group = _acf_get_field_group_by_key( $v );
} }
// ID
if( $type == 'ID' ) {
$field_group = _acf_get_field_group_by_id( $selector );
// key
} else {
$field_group = _acf_get_field_group_by_key( $selector );
}
// bail early if no field
if( !$field_group ) return false;
// filter for 3rd party customization // filter for 3rd party customization
$field_group = apply_filters('acf/get_field_group', $field_group); $field_group = apply_filters('acf/get_field_group', $field_group);
// set cache // update cache
wp_cache_set( $cache_key, $field_group, 'acf' ); // - Use key instead of ID for best compatibility (not all field groups exist in the DB)
$cache_key = acf_set_cache("get_field_group/key={$field_group['key']}", $field_group);
// update cache reference
// - allow cache to return if using an ID selector
acf_set_cache_reference("get_field_group/ID={$field_group['ID']}", $cache_key);
// return // return
return $field_group; return $field_group;
} }
@ -487,6 +516,10 @@ function acf_update_field_group( $field_group = array() ) {
$field_group = wp_unslash( $field_group ); $field_group = wp_unslash( $field_group );
// parse types (converts string '0' to int 0)
$field_group = acf_parse_types( $field_group );
// locations may contain 'uniquid' array keys // locations may contain 'uniquid' array keys
$field_group['location'] = array_values( $field_group['location'] ); $field_group['location'] = array_values( $field_group['location'] );
@ -551,9 +584,7 @@ function acf_update_field_group( $field_group = array() ) {
// clear cache // clear cache
wp_cache_delete("get_field_group/ID={$field_group['ID']}", 'acf'); acf_delete_cache("get_field_group/key={$field_group['key']}");
wp_cache_delete("get_field_group/key={$field_group['key']}", 'acf');
wp_cache_delete("get_field_groups", 'acf');
// return // return
@ -589,8 +620,8 @@ function acf_update_field_group_wp_unique_post_slug( $slug, $post_ID, $post_stat
function acf_duplicate_field_group( $selector = 0, $new_post_id = 0 ) { function acf_duplicate_field_group( $selector = 0, $new_post_id = 0 ) {
// disable JSON to avoid conflicts between DB and JSON // disable filters to ensure ACF loads raw data from DB
acf_disable_local(); acf_disable_filters();
// load the origional field gorup // load the origional field gorup
@ -713,8 +744,8 @@ function acf_get_field_count( $field_group ) {
function acf_delete_field_group( $selector = 0 ) { function acf_delete_field_group( $selector = 0 ) {
// disable JSON to avoid conflicts between DB and JSON // disable filters to ensure ACF loads raw data from DB
acf_disable_local(); acf_disable_filters();
// load the origional field gorup // load the origional field gorup
@ -768,8 +799,8 @@ function acf_delete_field_group( $selector = 0 ) {
function acf_trash_field_group( $selector = 0 ) { function acf_trash_field_group( $selector = 0 ) {
// disable JSON to avoid conflicts between DB and JSON // disable filters to ensure ACF loads raw data from DB
acf_disable_local(); acf_disable_filters();
// load the origional field gorup // load the origional field gorup
@ -823,8 +854,8 @@ function acf_trash_field_group( $selector = 0 ) {
function acf_untrash_field_group( $selector = 0 ) { function acf_untrash_field_group( $selector = 0 ) {
// disable JSON to avoid conflicts between DB and JSON // disable filters to ensure ACF loads raw data from DB
acf_disable_local(); acf_disable_filters();
// load the origional field gorup // load the origional field gorup
@ -987,6 +1018,10 @@ function acf_get_field_group_style( $field_group ) {
function acf_import_field_group( $field_group ) { function acf_import_field_group( $field_group ) {
// disable filters to ensure ACF loads raw data from DB
acf_disable_filters();
// vars // vars
$ref = array(); $ref = array();
$order = array(); $order = array();
@ -1003,10 +1038,6 @@ function acf_import_field_group( $field_group ) {
// remove old fields // remove old fields
if( $field_group['ID'] ) { if( $field_group['ID'] ) {
// disable local - important as to avoid 'acf_get_fields_by_id' returning fields with ID = 0
acf_disable_local();
// load fields // load fields
$db_fields = acf_get_fields_by_id( $field_group['ID'] ); $db_fields = acf_get_fields_by_id( $field_group['ID'] );
$db_fields = acf_prepare_fields_for_import( $db_fields ); $db_fields = acf_prepare_fields_for_import( $db_fields );
@ -1036,12 +1067,12 @@ function acf_import_field_group( $field_group ) {
} }
// enable local - important as to allow local to find new fields and save json file
acf_enable_local();
} }
// enable local filter for JSON to be created
acf_enable_filter('local');
// save field group // save field group
$field_group = acf_update_field_group( $field_group ); $field_group = acf_update_field_group( $field_group );

View File

@ -147,7 +147,7 @@ function acf_get_valid_field( $field = false ) {
// defaults // defaults
$field = acf_parse_args($field, array( $field = wp_parse_args($field, array(
'ID' => 0, 'ID' => 0,
'key' => '', 'key' => '',
'label' => '', 'label' => '',
@ -238,6 +238,37 @@ function acf_translate_field( $field ) {
} }
/*
* acf_clone_field
*
* This function will allow customization to a field when it is cloned
* Cloning a field is the act of mimicing another. Some settings may need to be altered
*
* @type function
* @date 8/03/2016
* @since 5.3.2
*
* @param $field (array)
* @return $field
*/
function acf_clone_field( $field, $clone_field ) {
// add reference
$field['_clone'] = $clone_field['key'];
// filters
$field = apply_filters( "acf/clone_field", $field, $clone_field );
$field = apply_filters( "acf/clone_field/type={$field['type']}", $field, $clone_field );
// return
return $field;
}
/* /*
* acf_prepare_field * acf_prepare_field
* *
@ -407,10 +438,6 @@ function acf_render_fields( $post_id = 0, $fields, $el = 'div', $instruction = '
} }
// set prefix for correct post name (prefix + key)
$field['prefix'] = 'acf';
// render // render
acf_render_field_wrap( $field, $el, $instruction ); acf_render_field_wrap( $field, $el, $instruction );
@ -582,13 +609,7 @@ function acf_render_field_wrap( $field, $el = 'div', $instruction = 'label' ) {
// vars // vars
$show_label = true; $show_label = ($el !== 'td') ? true : false;
if( $el == 'td' ) {
$show_label = false;
}
?><<?php echo $el; ?> <?php echo acf_esc_attr($wrapper); ?>> ?><<?php echo $el; ?> <?php echo acf_esc_attr($wrapper); ?>>
@ -602,7 +623,6 @@ function acf_render_field_wrap( $field, $el = 'div', $instruction = 'label' ) {
<?php endif; ?> <?php endif; ?>
<<?php echo $elements[ $el ]; ?> class="acf-input"> <<?php echo $elements[ $el ]; ?> class="acf-input">
<?php acf_render_field( $field ); ?> <?php acf_render_field( $field ); ?>
<?php if( $instruction == 'field' && $field['instructions'] ): ?> <?php if( $instruction == 'field' && $field['instructions'] ): ?>
<p class="description"><?php echo $field['instructions']; ?></p> <p class="description"><?php echo $field['instructions']; ?></p>
<?php endif; ?> <?php endif; ?>
@ -655,11 +675,20 @@ function acf_render_field_setting( $field, $setting, $global = false ) {
$setting['value'] = $field[ $setting['name'] ]; $setting['value'] = $field[ $setting['name'] ];
} elseif( isset($setting['default_value']) ) {
// use the default value
$setting['value'] = $setting['default_value'];
} }
// vars
$instructions_placement = acf_extract_var( $setting, 'instructions_placement', 'label' );
// render // render
acf_render_field_wrap( $setting, 'tr', 'label' ); acf_render_field_wrap( $setting, 'tr', $instructions_placement );
} }
@ -707,8 +736,12 @@ function acf_get_fields( $parent = false ) {
} }
// filter
$fields = apply_filters('acf/get_fields', $fields, $parent);
// return // return
return apply_filters('acf/get_fields', $fields, $parent); return $fields;
} }
@ -726,53 +759,68 @@ function acf_get_fields( $parent = false ) {
* @return $fields (array) * @return $fields (array)
*/ */
function acf_get_fields_by_id( $id = 0 ) { function acf_get_fields_by_id( $parent_id = 0 ) {
// bail early if no ID
if( !$parent_id ) return false;
// vars // vars
$fields = array(); $fields = array();
$post_ids = array();
$cache_key = "get_fields/ID={$parent_id}";
// bail early if no ID // check cache for child ids
if( empty($id) ) return false; if( acf_isset_cache($cache_key) ) {
// cache
$found = false;
$cache = wp_cache_get( 'get_fields/parent=' . $id, 'acf', false, $found );
if( $found ) return $cache;
// args
$args = array(
'posts_per_page' => -1,
'post_type' => 'acf-field',
'orderby' => 'menu_order',
'order' => 'ASC',
'suppress_filters' => true, // DO NOT allow WPML to modify the query
'post_parent' => $id,
'post_status' => 'publish, trash', // 'any' won't get trashed fields
'update_post_meta_cache' => false
);
$post_ids = acf_get_cache($cache_key);
// load fields // query DB for child ids
$posts = get_posts( $args ); } else {
if( $posts ) {
foreach( $posts as $post ) { // query
$posts = get_posts(array(
$fields[] = acf_get_field( $post->ID ); 'posts_per_page' => -1,
'post_type' => 'acf-field',
'orderby' => 'menu_order',
'order' => 'ASC',
'suppress_filters' => true, // DO NOT allow WPML to modify the query
'post_parent' => $parent_id,
'post_status' => 'publish, trash', // 'any' won't get trashed fields
'update_post_meta_cache' => false
));
// loop
if( $posts ) {
foreach( $posts as $post ) {
$post_ids[] = $post->ID;
}
} }
// update cache
acf_set_cache($cache_key, $post_ids);
} }
// set cache // bail early if no children
wp_cache_set( 'get_fields/parent=' . $id, $fields, 'acf' ); if( empty($post_ids) ) return false;
// load fields
foreach( $post_ids as $post_id ) {
$fields[] = acf_get_field( $post_id );
}
// return // return
return $fields; return $fields;
@ -801,22 +849,22 @@ function acf_get_field( $selector = null, $db_only = false ) {
$type = 'ID'; $type = 'ID';
// is $selector an ID // ID
if( is_numeric($selector) ) { if( is_numeric($selector) ) {
// do nothing // do nothing
// is $selector a string (name|key) // object
} elseif( is_string($selector) ) {
$type = acf_is_field_key($selector) ? 'key' : 'name';
// is $selector an object
} elseif( is_object($selector) ) { } elseif( is_object($selector) ) {
$selector = $selector->ID; $selector = $selector->ID;
// selector not valid // string
} elseif( is_string($selector) ) {
$type = acf_is_field_key($selector) ? 'key' : 'name';
// other
} else { } else {
return false; return false;
@ -824,58 +872,65 @@ function acf_get_field( $selector = null, $db_only = false ) {
} }
// get cache key // return early if cache is found
$cache_key = "get_field/{$type}={$selector}"; $cache_key = "get_field/{$type}={$selector}";
if( !$db_only && acf_isset_cache($cache_key) ) {
// get cache
if( !$db_only ) {
$found = false; return acf_get_cache($cache_key);
$cache = wp_cache_get( $cache_key, 'acf', false, $found );
if( $found ) return $cache;
} }
// get field group from ID or key // ID
if( $type == 'ID' ) { if( $type == 'ID' ) {
$field = _acf_get_field_by_id( $selector, $db_only ); $field = _acf_get_field_by_id( $selector, $db_only );
// key
} elseif( $type == 'key' ) {
} elseif( $type == 'name' ) { $field = _acf_get_field_by_key( $selector, $db_only );
// name (rare case)
} else {
$field = _acf_get_field_by_name( $selector, $db_only ); $field = _acf_get_field_by_name( $selector, $db_only );
} else {
$field = _acf_get_field_by_key( $selector, $db_only );
} }
// bail early if no field
if( !$field ) return false;
// validate
$field = acf_get_valid_field( $field );
// set prefix (acf fields save with prefix 'acf')
$field['prefix'] = 'acf';
// bail early if db only value (no need to update cache) // bail early if db only value (no need to update cache)
if( $db_only ) { if( $db_only ) return $field;
return $field;
}
// filter for 3rd party customization // filter for 3rd party customization
if( $field ) { $field = apply_filters( "acf/load_field", $field);
$field = apply_filters( "acf/load_field/type={$field['type']}", $field );
$field = apply_filters( "acf/load_field", $field); $field = apply_filters( "acf/load_field/name={$field['name']}", $field );
$field = apply_filters( "acf/load_field/type={$field['type']}", $field ); $field = apply_filters( "acf/load_field/key={$field['key']}", $field );
$field = apply_filters( "acf/load_field/name={$field['name']}", $field );
$field = apply_filters( "acf/load_field/key={$field['key']}", $field );
}
// set cache // update cache
wp_cache_set( $cache_key, $field, 'acf' ); // - Use key instead of ID for best compatibility (not all fields exist in the DB)
$cache_key = acf_set_cache("get_field/key={$field['key']}", $field);
// update cache reference
// - allow cache to return if using an ID selector
acf_set_cache_reference("get_field/ID={$field['ID']}", $cache_key);
// return // return
@ -904,11 +959,7 @@ function _acf_get_field_by_id( $post_id = 0, $db_only = false ) {
// bail early if no post, or is not a field // bail early if no post, or is not a field
if( empty($post) || $post->post_type != 'acf-field' ) { if( empty($post) || $post->post_type != 'acf-field' ) return false;
return false;
}
// unserialize // unserialize
@ -927,27 +978,21 @@ function _acf_get_field_by_id( $post_id = 0, $db_only = false ) {
// override with JSON // override with JSON
if( !$db_only && acf_is_local_field($field['key']) ) { if( !$db_only && acf_is_local_field($field['key']) ) {
// extract some args
$backup = acf_extract_vars($field, array(
'ID',
'parent'
));
// load JSON field // load JSON field
$field = acf_get_local_field( $field['key'] ); $local = acf_get_local_field( $field['key'] );
// merge in backup // override IDs
$field = array_merge($field, $backup); $local['ID'] = $field['ID'];
$local['parent'] = $field['parent'];
// return
return $local;
} }
// validate
$field = acf_get_valid_field( $field );
// return // return
return $field; return $field;
@ -972,13 +1017,7 @@ function _acf_get_field_by_key( $key = '', $db_only = false ) {
// try JSON before DB to save query time // try JSON before DB to save query time
if( !$db_only && acf_is_local_field( $key ) ) { if( !$db_only && acf_is_local_field( $key ) ) {
$field = acf_get_local_field( $key ); return acf_get_local_field( $key );
// validate
$field = acf_get_valid_field( $field );
// return
return $field;
} }
@ -1183,6 +1222,10 @@ function acf_update_field( $field = false, $specific = false ) {
$field = wp_unslash( $field ); $field = wp_unslash( $field );
// parse types (converts string '0' to int 0)
$field = acf_parse_types( $field );
// clean up conditional logic keys // clean up conditional logic keys
if( !empty($field['conditional_logic']) ) { if( !empty($field['conditional_logic']) ) {
@ -1210,15 +1253,11 @@ function acf_update_field( $field = false, $specific = false ) {
} }
// find correct parent // parent may be a field key
// - lookup parent ID
if( acf_is_field_key($field['parent']) ) { if( acf_is_field_key($field['parent']) ) {
// get parent $field['parent'] = acf_get_field_id( $field['parent'] );
$parent = acf_get_field( $field['parent'] );
// update to ID
$field['parent'] = acf_maybe_get( $parent, 'ID', 0 );
} }
@ -1312,9 +1351,7 @@ function acf_update_field( $field = false, $specific = false ) {
// clear cache // clear cache
wp_cache_delete( "get_field/ID={$field['ID']}", 'acf' ); acf_delete_cache("get_field/key={$field['key']}");
wp_cache_delete( "get_field/key={$field['key']}", 'acf' );
wp_cache_delete( "get_fields/parent={$field['parent']}", 'acf' );
// return // return
@ -1394,8 +1431,8 @@ function acf_duplicate_fields( $fields, $new_parent = 0 ) {
function acf_duplicate_field( $selector = 0, $new_parent = 0 ){ function acf_duplicate_field( $selector = 0, $new_parent = 0 ){
// disable JSON to avoid conflicts between DB and JSON // disable filters to ensure ACF loads raw data from DB
acf_disable_local(); acf_disable_filters();
// load the origional field // load the origional field
@ -1520,8 +1557,8 @@ function acf_duplicate_field( $selector = 0, $new_parent = 0 ){
function acf_delete_field( $selector = 0 ) { function acf_delete_field( $selector = 0 ) {
// disable JSON to avoid conflicts between DB and JSON // disable filters to ensure ACF loads raw data from DB
acf_disable_local(); acf_disable_filters();
// load the origional field gorup // load the origional field gorup
@ -1542,13 +1579,12 @@ function acf_delete_field( $selector = 0 ) {
// clear cache // clear cache
wp_cache_delete( "get_field/ID={$field['ID']}", 'acf' ); acf_delete_cache("get_field/key={$field['key']}");
wp_cache_delete( "get_field/key={$field['key']}", 'acf' );
wp_cache_delete( "get_fields/parent={$field['parent']}", 'acf' );
// return // return
return true; return true;
} }
@ -1567,8 +1603,8 @@ function acf_delete_field( $selector = 0 ) {
function acf_trash_field( $selector = 0 ) { function acf_trash_field( $selector = 0 ) {
// disable JSON to avoid conflicts between DB and JSON // disable filters to ensure ACF loads raw data from DB
acf_disable_local(); acf_disable_filters();
// load the origional field gorup // load the origional field gorup
@ -1589,6 +1625,7 @@ function acf_trash_field( $selector = 0 ) {
// return // return
return true; return true;
} }
@ -1607,8 +1644,8 @@ function acf_trash_field( $selector = 0 ) {
function acf_untrash_field( $selector = 0 ) { function acf_untrash_field( $selector = 0 ) {
// disable JSON to avoid conflicts between DB and JSON // disable filters to ensure ACF loads raw data from DB
acf_disable_local(); acf_disable_filters();
// load the origional field gorup // load the origional field gorup
@ -1721,7 +1758,7 @@ function acf_prepare_field_for_export( $field ) {
function acf_prepare_fields_for_import( $fields = false ) { function acf_prepare_fields_for_import( $fields = false ) {
// validate // validate
if( empty($fields) ) return $fields; if( empty($fields) ) return array();
// re-index array // re-index array

File diff suppressed because it is too large Load Diff

View File

@ -243,29 +243,26 @@ function get_field_objects( $post_id = false, $format_value = true, $load_value
// filter post_id // filter post_id
$post_id = acf_get_valid_post_id( $post_id ); $post_id = acf_get_valid_post_id( $post_id );
$info = acf_get_post_id_info( $post_id );
// vars // vars
$meta = array(); $meta = array();
$fields = array(); $fields = array();
// get field_names // get field_names
if( is_numeric($post_id) ) { if( $info['type'] == 'post' ) {
$meta = get_post_meta( $post_id ); $meta = get_post_meta( $info['id'] );
} elseif( strpos($post_id, 'user_') !== false ) { } elseif( $info['type'] == 'user' ) {
$user_id = (int) str_replace('user_', '', $post_id); $meta = get_user_meta( $info['id'] );
$meta = get_user_meta( $user_id ); } elseif( $info['type'] == 'comment' ) {
} elseif( strpos($post_id, 'comment_') !== false ) { $meta = get_comment_meta( $info['id'] );
$comment_id = (int) str_replace('comment_', '', $post_id);
$meta = get_comment_meta( $comment_id );
} else { } else {
@ -279,7 +276,24 @@ function get_field_objects( $post_id = false, $format_value = true, $load_value
foreach( $rows as $row ) { foreach( $rows as $row ) {
$meta[ $row['option_name'] ][] = $row['option_value']; // vars
$name = $row['option_name'];
$prefix = $post_id . '_';
$_prefix = '_' . $prefix;
// remove prefix from name
if( strpos($name, $prefix) === 0 ) {
$name = substr($name, strlen($prefix));
} elseif( strpos($name, $_prefix) === 0 ) {
$name = '_' . substr($name, strlen($_prefix));
}
$meta[ $name ][] = $row['option_value'];
} }
@ -308,8 +322,9 @@ function get_field_objects( $post_id = false, $format_value = true, $load_value
$field = acf_get_field( $field_key ); $field = acf_get_field( $field_key );
// bail early if not a parent field // bail early if no field, or if the field's name is different to $k
if( !$field || acf_is_sub_field($field) ) continue; // - solves problem where sub fields (and clone fields) are incorrectly allowed
if( !$field || $field['name'] !== $k ) continue;
// load value // load value
@ -994,12 +1009,16 @@ add_shortcode( 'acf', 'acf_shortcode' );
function acf_form_head() { function acf_form_head() {
// register local fields
_acf_form_register_fields();
// verify nonce // verify nonce
if( acf_verify_nonce('acf_form') ) { if( acf_verify_nonce('acf_form') ) {
// add actions // add actions
add_action('acf/validate_save_post', '_validate_save_post'); add_action('acf/validate_save_post', '_acf_form_validate_save_post');
add_filter('acf/pre_save_post', '_acf_pre_save_post', 5, 2); add_filter('acf/pre_save_post', '_acf_form_pre_save_post', 5, 2);
// validate data // validate data
@ -1055,10 +1074,57 @@ function acf_form_head() {
} }
/*
* _acf_form_register_fields
*
* This function will register some local fields used by the acf_form function
*
* @type function
* @date 15/08/2016
* @since 5.4.0
*
* @param n/a
* @return n/a
*/
function _acf_form_register_fields() {
acf_add_local_field(array(
'prefix' => 'acf',
'name' => '_post_title',
'key' => '_post_title',
'label' => __('Title', 'acf'),
'type' => 'text',
'required' => true,
));
acf_add_local_field(array(
'prefix' => 'acf',
'name' => '_post_content',
'key' => '_post_content',
'label' => __('Content', 'acf'),
'type' => 'wysiwyg',
));
acf_add_local_field(array(
'prefix' => 'acf',
'name' => '_validate_email',
'key' => '_validate_email',
'label' => __('Validate Email', 'acf'),
'type' => 'text',
'value' => '',
'wrapper' => array(
'style' => 'display:none !important;'
)
));
}
/* /*
* _validate_save_post * _validate_save_post
* *
* description * This function will perfrom extra validation for acf_form
* *
* @type function * @type function
* @date 16/06/2014 * @date 16/06/2014
@ -1068,25 +1134,7 @@ function acf_form_head() {
* @return $post_id (int) * @return $post_id (int)
*/ */
function _validate_save_post() { function _acf_form_validate_save_post() {
// save post_title
if( isset($_POST['acf']['_post_title']) ) {
// get field
$field = acf_get_valid_field(array(
'name' => '_post_title',
'label' => __('Title', 'acf'),
'type' => 'text',
'required' => true
));
// validate
acf_validate_value( $_POST['acf']['_post_title'], $field, "acf[_post_title]" );
}
// honeypot // honeypot
if( !empty($_POST['acf']['_validate_email']) ) { if( !empty($_POST['acf']['_validate_email']) ) {
@ -1099,7 +1147,7 @@ function _validate_save_post() {
/* /*
* _acf_pre_save_post * _acf_form_pre_save_post
* *
* This filter will save post data for the acf_form function * This filter will save post data for the acf_form function
* *
@ -1111,7 +1159,7 @@ function _validate_save_post() {
* @return $post_id (int) * @return $post_id (int)
*/ */
function _acf_pre_save_post( $post_id, $form ) { function _acf_form_pre_save_post( $post_id, $form ) {
// vars // vars
$save = array( $save = array(
@ -1128,7 +1176,7 @@ function _acf_pre_save_post( $post_id, $form ) {
} elseif( $post_id == 'new_post' ) { } elseif( $post_id == 'new_post' ) {
// new post // new post
$form['new_post'] = acf_parse_args( $form['new_post'], array( $form['new_post'] = wp_parse_args( $form['new_post'], array(
'post_type' => 'post', 'post_type' => 'post',
'post_status' => 'draft', 'post_status' => 'draft',
)); ));
@ -1267,7 +1315,7 @@ function acf_form( $args = array() ) {
// new post defaults // new post defaults
$args['new_post'] = acf_parse_args( $args['new_post'], array( $args['new_post'] = wp_parse_args( $args['new_post'], array(
'post_type' => 'post', 'post_type' => 'post',
'post_status' => 'draft', 'post_status' => 'draft',
)); ));
@ -1287,13 +1335,13 @@ function acf_form( $args = array() ) {
// post_title // post_title
if( $args['post_title'] ) { if( $args['post_title'] ) {
$fields[] = acf_get_valid_field(array( // load local field
'name' => '_post_title', $_post_title = acf_get_field('_post_title');
'label' => __('Title', 'acf'), $_post_title['value'] = $post_id ? get_post_field('post_title', $post_id) : '';
'type' => 'text',
'value' => $post_id ? get_post_field('post_title', $post_id) : '',
'required' => true // append
)); $fields[] = $_post_title;
} }
@ -1301,13 +1349,14 @@ function acf_form( $args = array() ) {
// post_content // post_content
if( $args['post_content'] ) { if( $args['post_content'] ) {
$fields[] = acf_get_valid_field(array( // load local field
'name' => '_post_content', $_post_content = acf_get_field('_post_content');
'label' => __('Content', 'acf'), $_post_content['value'] = $post_id ? get_post_field('post_content', $post_id) : '';
'type' => 'wysiwyg',
'value' => $post_id ? get_post_field('post_content', $post_id) : ''
));
// append
$fields[] = $_post_content;
} }
@ -1366,15 +1415,7 @@ function acf_form( $args = array() ) {
// honeypot // honeypot
if( $args['honeypot'] ) { if( $args['honeypot'] ) {
$fields[] = acf_get_valid_field(array( $fields[] = acf_get_field('_validate_email');
'name' => '_validate_email',
'label' => __('Validate Email', 'acf'),
'type' => 'text',
'value' => '',
'wrapper' => array(
'style' => 'display:none;'
)
));
} }
@ -1824,20 +1865,24 @@ function delete_row( $selector, $row = 1, $post_id = false ) {
if( empty($rows) ) return false; if( empty($rows) ) return false;
// deincrement // vars
if( $row == count($rows) ) { $i = $row-1;
acf_update_metadata( $post_id, $field['name'], $row-1 );
}
// update sub field values // bail early if row doesn't exist
foreach( $rows[0] as $k => $v ) { if( empty($rows[ $i ]) ) return false;
update_sub_field( array( $field['key'], $row, $k ), null, $post_id );
// unset
} unset( $rows[ $i ] );
// reindex
$rows = array_values($rows);
// update
acf_update_value( $rows, $post_id, $field );
// return // return

View File

@ -19,71 +19,37 @@ function acf_get_metadata( $post_id = 0, $name = '', $hidden = false ) {
// vars // vars
$value = null; $value = null;
$prefix = $hidden ? '_' : '';
// get post_id info
$info = acf_get_post_id_info($post_id);
// bail early if no $post_id (acf_form - new_post) // bail early if no $post_id (acf_form - new_post)
if( !$post_id ) return $value; if( !$info['id'] ) return $value;
// add prefix for hidden meta // option
if( $hidden ) { if( $info['type'] === 'option' ) {
$name = '_' . $name; $name = $prefix . $post_id . '_' . $name;
$value = get_option( $name, null );
} // meta
// post
if( is_numeric($post_id) ) {
$meta = get_metadata( 'post', $post_id, $name, false );
if( isset($meta[0]) ) {
$value = $meta[0];
}
// user
} elseif( substr($post_id, 0, 5) == 'user_' ) {
$user_id = (int) substr($post_id, 5);
$meta = get_metadata( 'user', $user_id, $name, false );
if( isset($meta[0]) ) {
$value = $meta[0];
}
// comment
} elseif( substr($post_id, 0, 8) == 'comment_' ) {
$comment_id = (int) substr($post_id, 8);
$meta = get_metadata( 'comment', $comment_id, $name, false );
if( isset($meta[0]) ) {
$value = $meta[0];
}
} else { } else {
// modify prefix for hidden meta $name = $prefix . $name;
if( $hidden ) { $meta = get_metadata( $info['type'], $info['id'], $name, false );
$post_id = '_' . $post_id;
$name = substr($name, 1);
}
$value = get_option( $post_id . '_' . $name, null ); if( isset($meta[0]) ) {
$value = $meta[0];
}
} }
// return // return
return $value; return $value;
@ -111,53 +77,34 @@ function acf_update_metadata( $post_id = 0, $name = '', $value = '', $hidden = f
// vars // vars
$return = false; $return = false;
$prefix = $hidden ? '_' : '';
// add prefix for hidden meta // get post_id info
if( $hidden ) { $info = acf_get_post_id_info($post_id);
$name = '_' . $name;
}
// postmeta // bail early if no $post_id (acf_form - new_post)
if( is_numeric($post_id) ) { if( !$info['id'] ) return $return;
$return = update_metadata('post', $post_id, $name, $value );
// usermeta
} elseif( substr($post_id, 0, 5) == 'user_' ) {
$user_id = (int) substr($post_id, 5);
$return = update_metadata('user', $user_id, $name, $value);
// commentmeta
} elseif( substr($post_id, 0, 8) == 'comment_' ) {
$comment_id = (int) substr($post_id, 8);
$return = update_metadata('comment', $comment_id, $name, $value);
// options // option
if( $info['type'] === 'option' ) {
$name = $prefix . $post_id . '_' . $name;
$return = acf_update_option( $name, $value );
// meta
} else { } else {
// modify prefix for hidden meta $name = $prefix . $name;
if( $hidden ) { $return = update_metadata( $info['type'], $info['id'], $name, $value );
$post_id = '_' . $post_id;
$name = substr($name, 1);
}
$return = acf_update_option( $post_id . '_' . $name, $value );
} }
// return // return
return (boolean) $return; return $return;
} }
@ -181,47 +128,28 @@ function acf_delete_metadata( $post_id = 0, $name = '', $hidden = false ) {
// vars // vars
$return = false; $return = false;
$prefix = $hidden ? '_' : '';
// add prefix for hidden meta // get post_id info
if( $hidden ) { $info = acf_get_post_id_info($post_id);
$name = '_' . $name;
}
// postmeta // bail early if no $post_id (acf_form - new_post)
if( is_numeric($post_id) ) { if( !$info['id'] ) return $return;
$return = delete_metadata('post', $post_id, $name );
// usermeta
} elseif( substr($post_id, 0, 5) == 'user_' ) {
$user_id = (int) substr($post_id, 5);
$return = delete_metadata('user', $user_id, $name);
// commentmeta
} elseif( substr($post_id, 0, 8) == 'comment_' ) {
$comment_id = (int) substr($post_id, 8);
$return = delete_metadata('comment', $comment_id, $name);
// options // option
if( $info['type'] === 'option' ) {
$name = $prefix . $post_id . '_' . $name;
$return = delete_option( $name );
// meta
} else { } else {
// modify prefix for hidden meta $name = $prefix . $name;
if( $hidden ) { $return = delete_metadata( $info['type'], $info['id'], $name );
$post_id = '_' . $post_id;
$name = substr($name, 1);
}
$return = delete_option( $post_id . '_' . $name );
} }
@ -302,14 +230,16 @@ function acf_update_option( $option = '', $value = '', $autoload = null ) {
function acf_get_value( $post_id = 0, $field ) { function acf_get_value( $post_id = 0, $field ) {
// cache // vars
$found = false; $cache_key = "get_value/post_id={$post_id}/name={$field['name']}";
$cache_slug = "load_value/post_id={$post_id}/name={$field['name']}";
$cache = wp_cache_get($cache_slug, 'acf', false, $found);
// return cache if found // return early if cache is found
if( $found ) return $cache; if( acf_isset_cache($cache_key) ) {
return acf_get_cache($cache_key);
}
// load value // load value
@ -336,7 +266,7 @@ function acf_get_value( $post_id = 0, $field ) {
// update cache // update cache
wp_cache_set($cache_slug, $value, 'acf'); acf_set_cache($cache_key, $value);
// return // return
@ -362,14 +292,16 @@ function acf_get_value( $post_id = 0, $field ) {
function acf_format_value( $value, $post_id, $field ) { function acf_format_value( $value, $post_id, $field ) {
// try cache // vars
$found = false; $cache_key = "format_value/post_id={$post_id}/name={$field['name']}";
$cache_slug = "format_value/post_id={$post_id}/name={$field['name']}";
$cache = wp_cache_get($cache_slug, 'acf', false, $found);
// return cache if found // return early if cache is found
if( $found ) return $cache; if( acf_isset_cache($cache_key) ) {
return acf_get_cache($cache_key);
}
// apply filters // apply filters
@ -380,7 +312,7 @@ function acf_format_value( $value, $post_id, $field ) {
// update cache // update cache
wp_cache_set($cache_slug, $value, 'acf'); acf_set_cache($cache_key, $value);
// return // return
@ -429,8 +361,8 @@ function acf_update_value( $value = null, $post_id = 0, $field ) {
// clear cache // clear cache
wp_cache_delete( "load_value/post_id={$post_id}/name={$field['name']}", 'acf' ); acf_delete_cache("get_value/post_id={$post_id}/name={$field['name']}");
wp_cache_delete( "format_value/post_id={$post_id}/name={$field['name']}", 'acf' ); acf_delete_cache("format_value/post_id={$post_id}/name={$field['name']}");
// return // return
@ -471,8 +403,8 @@ function acf_delete_value( $post_id = 0, $field ) {
// clear cache // clear cache
wp_cache_delete( "load_value/post_id={$post_id}/name={$field['name']}", 'acf' ); acf_delete_cache("get_value/post_id={$post_id}/name={$field['name']}");
wp_cache_delete( "format_value/post_id={$post_id}/name={$field['name']}", 'acf' ); acf_delete_cache("format_value/post_id={$post_id}/name={$field['name']}");
// return // return
@ -480,4 +412,72 @@ function acf_delete_value( $post_id = 0, $field ) {
} }
/*
* acf_copy_postmeta
*
* This function will copy postmeta from one post to another.
* Very useful for saving and restoring revisions
*
* @type function
* @date 25/06/2016
* @since 5.3.8
*
* @param $from_post_id (int)
* @param $to_post_id (int)
* @return n/a
*/
function acf_copy_postmeta( $from_post_id, $to_post_id ) {
// get all postmeta
$meta = get_post_meta( $from_post_id );
// bail early if no meta
if( !$meta ) return;
// loop
foreach( $meta as $name => $value ) {
// attempt to find key value
$key = acf_maybe_get( $meta, '_'.$name );
// bail ealry if no key
if( !$key ) continue;
// update vars
$value = $value[0];
$key = $key[0];
// bail early if $key is a not a field_key
if( !acf_is_field_key($key) ) continue;
// get_post_meta will return array before running maybe_unserialize
$value = maybe_unserialize( $value );
// add in slashes
// - update_post_meta will unslash the value, so we must first slash it to avoid losing backslashes
// - https://codex.wordpress.org/Function_Reference/update_post_meta#Character_Escaping
if( is_string($value) ) {
$value = wp_slash($value);
}
// update value
acf_update_metadata( $to_post_id, $name, $value );
acf_update_metadata( $to_post_id, $name, $key, true );
}
}
?> ?>

View File

@ -348,6 +348,16 @@ html[dir="rtl"] .acf-c0 {
.acf-field textarea { .acf-field textarea {
resize: vertical; resize: vertical;
} }
/* disabled */
.acf-field input:disabled,
.acf-field select:disabled,
.acf-field textarea:disabled {
background: #f8f8f8;
}
.acf-field input[readonly],
.acf-field textarea[readonly] {
background: #f8f8f8;
}
/*--------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------
* *
* Text * Text
@ -458,6 +468,10 @@ html[dir="rtl"] input.acf-is-prepended.acf-is-appended {
* Select2 (v3) * Select2 (v3)
* *
*---------------------------------------------------------------------------------------------*/ *---------------------------------------------------------------------------------------------*/
.select2-container.-acf {
/* open */
/* single open */
}
.select2-container.-acf .select2-choices { .select2-container.-acf .select2-choices {
background: #fff; background: #fff;
border-color: #ddd; border-color: #ddd;
@ -483,13 +497,6 @@ html[dir="rtl"] input.acf-is-prepended.acf-is-appended {
.select2-container.-acf .select2-search-choice-close { .select2-container.-acf .select2-search-choice-close {
margin-top: -1px; margin-top: -1px;
} }
/* open */
.select2-container.-acf.select2-container-active .select2-choices,
.select2-container.-acf.select2-dropdown-open .select2-choices {
border-color: #5B9DD9;
border-radius: 3px 3px 0 0;
}
/* single */
.select2-container.-acf .select2-choice { .select2-container.-acf .select2-choice {
border-color: #BBBBBB; border-color: #BBBBBB;
} }
@ -498,11 +505,38 @@ html[dir="rtl"] input.acf-is-prepended.acf-is-appended {
border-left-color: #DFDFDF; border-left-color: #DFDFDF;
padding-left: 1px; padding-left: 1px;
} }
/* single open */ .select2-container.-acf .select2-choice .select2-result-description {
display: none;
}
.select2-container.-acf.select2-container-active .select2-choices,
.select2-container.-acf.select2-dropdown-open .select2-choices {
border-color: #5B9DD9;
border-radius: 3px 3px 0 0;
}
.select2-container.-acf.select2-dropdown-open .select2-choice { .select2-container.-acf.select2-dropdown-open .select2-choice {
background: #fff; background: #fff;
border-color: #5B9DD9; border-color: #5B9DD9;
} }
/* description */
.select2-drop {
/* search*/
/* result */
}
.select2-drop .select2-search {
padding: 4px 4px 0;
}
.select2-drop .select2-result {
/* hover*/
}
.select2-drop .select2-result .select2-result-description {
color: #999;
font-size: 12px;
margin-left: 5px;
}
.select2-drop .select2-result.select2-highlighted .select2-result-description {
color: #fff;
opacity: 0.75;
}
/*--------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------
* *
* Select2 (v4) * Select2 (v4)
@ -1425,6 +1459,14 @@ html[dir="rtl"] .acf-file-uploader .file-info ul {
} }
/*--------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------
* *
* Clone field
*
*---------------------------------------------------------------------------------------------*/
.acf-clone-fields {
border: #dfdfdf solid 1px;
}
/*---------------------------------------------------------------------------------------------
*
* Taxonomy * Taxonomy
* *
*---------------------------------------------------------------------------------------------*/ *---------------------------------------------------------------------------------------------*/

View File

@ -11,10 +11,6 @@
'ready': 'init' 'ready': 'init'
}, },
filters: {
'get_fields 99': 'get_fields'
},
events: { events: {
'submit #post': 'submit', 'submit #post': 'submit',
'click a[href="#"]': 'preventDefault', 'click a[href="#"]': 'preventDefault',
@ -101,27 +97,6 @@
}, },
/*
* get_fields
*
* This function will remove fields from the clone index
* Without this, field JS such as Select2 may run on fields which are used as a template
*
* @type function
* @date 15/08/2015
* @since 5.2.3
*
* @param $fields (selection)
* @return $fields
*/
get_fields: function( $fields ) {
return $fields.not('.acf-field-object[data-id="acfcloneindex"] .acf-field');
},
/* /*
* preventDefault * preventDefault
* *
@ -165,7 +140,7 @@
$('.acf-field-list').each(function(){ $('.acf-field-list').each(function(){
// vars // vars
var $fields = $(this).children('.acf-field-object').not('[data-id="acfcloneindex"]'); var $fields = $(this).children('.acf-field-object');
// loop over fields // loop over fields
@ -456,15 +431,6 @@
open = $(this).hasClass('open'); open = $(this).hasClass('open');
// clone
if( ID == 'acfcloneindex' ) {
$(this).remove();
return;
}
// close // close
if( open ) { if( open ) {
@ -745,8 +711,7 @@
add_field: function( $fields ){ add_field: function( $fields ){
// clone tr // clone tr
var $clone = $fields.children('.acf-field-object[data-id="acfcloneindex"]'), var $el = $( $('#tmpl-acf-field').html() ),
$el = $clone.clone(),
$label = $el.find('.field-label:first'), $label = $el.find('.field-label:first'),
$name = $el.find('.field-name:first'); $name = $el.find('.field-name:first');
@ -756,7 +721,7 @@
// append to table // append to table
$clone.before( $el ); $fields.append( $el );
// clear name // clear name
@ -926,7 +891,7 @@
} else { } else {
// Case: sub field's settings have changed // Case: sub field's settings have changed
$field.find('.acf-field-object').not('[data-id="acfcloneindex"]').each(function(){ $field.find('.acf-field-object').each(function(){
if( !self.get_field_meta( $(this), 'ID' ) ) { if( !self.get_field_meta( $(this), 'ID' ) ) {
@ -1069,14 +1034,6 @@
var id = this.get_field_meta($el, 'ID'); var id = this.get_field_meta($el, 'ID');
// bail early if cloneindex
if( id == 'acfcloneindex' ) {
return;
}
// add to remove list // add to remove list
if( id ) { if( id ) {
@ -1650,10 +1607,6 @@
return; return;
} else if( this_key == 'acfcloneindex' ) {
return;
} else if( this_key == key ) { } else if( this_key == key ) {
return; return;
@ -2519,15 +2472,19 @@
render: function( $el ){ render: function( $el ){
// bail early if not correct field type // bail early if not correct field type
if( $el.attr('data-type') != 'tab' ) { if( $el.attr('data-type') != 'tab' ) return;
return;
// vars
} var id = $el.data('id');
// clear name // clear name
$el.find('.acf-field[data-name="name"] input').val('').trigger('change'); $('#acf_fields-' + id + '-name').val('').trigger('change');
// clear required
$('#acf_fields-' + id + '-required-0').trigger('click');
} }
@ -2557,17 +2514,207 @@
render: function( $el ){ render: function( $el ){
// bail early if not correct field type // bail early if not correct field type
if( $el.attr('data-type') != 'message' ) { if( $el.attr('data-type') != 'message' ) return;
// vars
var id = $el.data('id');
// clear name
$('#acf_fields-' + id + '-name').val('').trigger('change');
// clear required
$('#acf_fields-' + id + '-required-0').trigger('click');
}
});
/*
* clone
*
* This field type requires some extra logic for its settings
*
* @type function
* @date 24/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
var acf_settings_clone = acf.model.extend({
actions: {
'open_field': 'render',
'change_field_type': 'render'
},
filters: {
'select2_args': 'select2_args',
'select2_ajax_data': 'select2_ajax_data'
},
events: {
'change .acf-field-object-clone .setting-display': 'render_display',
'change .acf-field-object-clone .setting-prefix-label input': 'render_prefix_label',
'change .acf-field-object-clone .setting-prefix-name input': 'render_prefix_name',
},
event: function( e ){
// override
return e.$el.closest('.acf-field-object');
},
return; render: function( $el ){
// bail early if not correct field type
if( $el.attr('data-type') != 'clone' ) return;
// render
this.render_display( $el );
this.render_prefix_label( $el );
this.render_prefix_name( $el );
},
render_display: function( $el ){
// vars
var $layout = $el.find('.acf-field[data-name="layout"]'),
$display = $el.find('.acf-field[data-name="display"] select'),
$conditional = $el.find('.acf-field[data-name="conditional_logic"]'),
$wrapper = $el.find('.acf-field[data-name="wrapper"]');
// hide conditional logic
if( $display.val() == 'seamless' ) {
$conditional.hide();
$wrapper.hide();
$layout.hide();
} else {
$conditional.show();
$wrapper.show();
$layout.show();
}
},
render_prefix_label: function( $el ){
// vars
var $prefix_label = $el.find('.setting-prefix-label input:checked'),
$field_label = $el.find('.field-label'),
$code = $el.find('.prefix-label-code-1');
// html
var html = '%field_label%';
if( $prefix_label.val() === '1' ) {
html = $field_label.val() + ' ' + html;
} }
// clear name // update code
$el.find('.acf-field[data-name="name"] input').val('').trigger('change'); $code.html( html );
},
render_prefix_name: function( $el ){
// vars
var $prefix_name = $el.find('.setting-prefix-name input:checked'),
$field_name = $el.find('.field-name'),
$code = $el.find('.prefix-name-code-1');
// html
var label = '%field_name%';
if( $prefix_name.val() === '1' ) {
label = $field_name.val() + '_' + label;
}
// html
$code.html( label );
},
select2_args: function( select2_args, $select, args ){
// bail early if not clone
if( args.ajax_action !== 'acf/fields/clone/query' ) return select2_args;
// remain open on select
select2_args.closeOnSelect = false;
// return
return select2_args;
},
select2_ajax_data: function( data, args, params ){
// bail early if not clone
if( args.ajax_action !== 'acf/fields/clone/query' ) return select2_args;
// find current fields
var fields = {};
// loop
$('.acf-field-object').each(function(){
// vars
var $el = $(this),
key = $el.data('key'),
type = $el.data('type'),
label = $el.find('.field-label:first').val(),
$ancestors = $el.parents('.acf-field-object');
// label
fields[ key ] = {
'key': key,
'type': type,
'label': label,
'ancestors': $ancestors.length
};
});
// append fields
data.fields = fields;
// append title
data.title = $('#title').val();
// return
return data;
}
}
}); });

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -53,7 +53,7 @@ class acf_ajax {
function update_user_setting() { function update_user_setting() {
// options // options
$options = acf_parse_args( $_POST, array( $options = wp_parse_args( $_POST, array(
'name' => '', 'name' => '',
'value' => '', 'value' => '',
'nonce' => '', 'nonce' => '',

300
core/cache.php Normal file
View File

@ -0,0 +1,300 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_cache') ) :
class acf_cache {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.4.0
*
* @param n/a
* @return n/a
*/
function __construct() {
// vars
$this->cache = array();
$this->reference = array();
// prevent ACF from persistent cache
wp_cache_add_non_persistent_groups('acf');
}
/*
* get_key
*
* This function will check for references and modify the key
*
* @type function
* @date 30/06/2016
* @since 5.4.0
*
* @param $key (string)
* @return $key
*/
function get_key( $key = '' ) {
// check for reference
if( isset($this->reference[ $key ]) ) {
$key = $this->reference[ $key ];
}
// return
return $key;
}
/*
* isset_cache
*
* This function will return true if a cached data exists for the given key
*
* @type function
* @date 30/06/2016
* @since 5.4.0
*
* @param $key (string)
* @return (boolean)
*/
function isset_cache( $key = '' ) {
// vars
$key = $this->get_key($key);
$found = false;
// get cache
$cache = wp_cache_get($key, 'acf', false, $found);
// return
return $found;
}
/*
* get_cache
*
* This function will return cached data for a given key
*
* @type function
* @date 30/06/2016
* @since 5.4.0
*
* @param $key (string)
* @return (mixed)
*/
function get_cache( $key = '' ) {
// vars
$key = $this->get_key($key);
$found = false;
// get cache
$cache = wp_cache_get($key, 'acf', false, $found);
// return
return $cache;
}
/*
* set_cache
*
* This function will set cached data for a given key
*
* @type function
* @date 30/06/2016
* @since 5.4.0
*
* @param $key (string)
* @param $data (mixed)
* @return n/a
*/
function set_cache( $key = '', $data = '' ) {
wp_cache_set($key, $data, 'acf');
return $key;
}
/*
* set_cache_reference
*
* This function will set a reference to cached data for a given key
*
* @type function
* @date 30/06/2016
* @since 5.4.0
*
* @param $key (string)
* @param $reference (string)
* @return n/a
*/
function set_cache_reference( $key = '', $reference = '' ) {
$this->reference[ $key ] = $reference;
return $key;
}
/*
* delete_cache
*
* This function will delete cached data for a given key
*
* @type function
* @date 30/06/2016
* @since 5.4.0
*
* @param $key (string)
* @return n/a
*/
function delete_cache( $key = '' ) {
return wp_cache_delete( $key, 'acf' );
}
}
// initialize
acf()->cache = new acf_cache();
endif; // class_exists check
/*
* acf_isset_cache
*
* alias of acf()->cache->isset_cache()
*
* @type function
* @date 30/06/2016
* @since 5.4.0
*
* @param n/a
* @return n/a
*/
function acf_isset_cache( $key = '' ) {
return acf()->cache->isset_cache( $key );
}
/*
* acf_get_cache
*
* alias of acf()->cache->get_cache()
*
* @type function
* @date 30/06/2016
* @since 5.4.0
*
* @param n/a
* @return n/a
*/
function acf_get_cache( $key = '' ) {
return acf()->cache->get_cache( $key );
}
/*
* acf_set_cache
*
* alias of acf()->cache->set_cache()
*
* @type function
* @date 30/06/2016
* @since 5.4.0
*
* @param n/a
* @return n/a
*/
function acf_set_cache( $key = '', $data ) {
return acf()->cache->set_cache( $key, $data );
}
/*
* acf_set_cache_reference
*
* alias of acf()->cache->set_cache_reference()
*
* @type function
* @date 30/06/2016
* @since 5.4.0
*
* @param n/a
* @return n/a
*/
function acf_set_cache_reference( $key = '', $reference = '' ) {
return acf()->cache->set_cache_reference( $key, $reference );
}
/*
* acf_delete_cache
*
* alias of acf()->cache->delete_cache()
*
* @type function
* @date 30/06/2016
* @since 5.4.0
*
* @param n/a
* @return n/a
*/
function acf_delete_cache( $key = '' ) {
return acf()->cache->delete_cache( $key );
}
?>

138
core/fields.php Normal file
View File

@ -0,0 +1,138 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_fields') ) :
class acf_fields {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.4.0
*
* @param n/a
* @return n/a
*/
function __construct() {
// vars
$this->types = array();
}
/*
* register_field_type
*
* This function will store a field type class
*
* @type function
* @date 6/07/2016
* @since 5.4.0
*
* @param $instance (object)
* @return n/a
*/
function register_field_type( $instance ) {
// bail ealry if no field name
if( !$instance->name ) return false;
// bail ealry if already exists
if( isset($this->types[ $instance->name ]) ) return false;
// append
$this->types[ $instance->name ] = $instance;
// return
return true;
}
/*
* get_field_type
*
* This function will return a field type class
*
* @type function
* @date 6/07/2016
* @since 5.4.0
*
* @param $name (string)
* @return (mixed)
*/
function get_field_type( $name ) {
// bail ealry if doesn't exist
if( !isset($this->types[ $name ]) ) return false;
// return
return $this->types[ $name ];
}
}
// initialize
acf()->fields = new acf_fields();
endif; // class_exists check
/*
* acf_register_field_type
*
* alias of acf()->fields->register_field_type()
*
* @type function
* @date 6/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_register_field_type( $instance ) {
return acf()->fields->register_field_type( $instance );
}
/*
* acf_get_field_type
*
* alias of acf()->fields->get_field_type()
*
* @type function
* @date 6/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_get_field_type( $name ) {
return acf()->fields->get_field_type( $name );
}
?>

View File

@ -426,7 +426,7 @@ function acf_enqueue_uploader() {
// create dummy editor // create dummy editor
?><div class="acf-hidden"><?php wp_editor( '', 'acf_content' ); ?></div><?php ?><div id="acf-hidden-wp-editor" class="acf-hidden"><?php wp_editor( '', 'acf_content' ); ?></div><?php
} }

View File

@ -36,11 +36,7 @@ class acf_json {
function update_field_group( $field_group ) { function update_field_group( $field_group ) {
// validate // validate
if( !acf_get_setting('json') ) { if( !acf_get_setting('json') ) return;
return;
}
// get fields // get fields

File diff suppressed because it is too large Load Diff

View File

@ -1137,7 +1137,12 @@ new acf_location();
function acf_get_field_group_visibility( $field_group, $args = array() ) { function acf_get_field_group_visibility( $field_group, $args = array() ) {
// bail early if not active
if( !$field_group['active'] ) return false;
// vars // vars
$visibility = false;
$args = acf_parse_args($args, array( $args = acf_parse_args($args, array(
'post_id' => 0, 'post_id' => 0,
'post_type' => 0, 'post_type' => 0,
@ -1163,14 +1168,6 @@ function acf_get_field_group_visibility( $field_group, $args = array() ) {
$args = apply_filters('acf/location/screen', $args, $field_group); $args = apply_filters('acf/location/screen', $args, $field_group);
// bail early if not active
if( !$field_group['active'] ) return false;
// vars
$visibility = false;
// loop through location rules // loop through location rules
foreach( $field_group['location'] as $group_id => $group ) { foreach( $field_group['location'] as $group_id => $group ) {

View File

@ -51,9 +51,9 @@ class acf_media {
// append // append
$l10n['media'] = array( $l10n['media'] = array(
'select' => __("Select",'acf'), 'select' => _x('Select', 'verb', 'acf'),
'edit' => __("Edit",'acf'), 'edit' => _x('Edit', 'verb', 'acf'),
'update' => __("Update",'acf'), 'update' => _x('Update', 'verb', 'acf'),
'uploadedTo' => __("Uploaded to this post",'acf'), 'uploadedTo' => __("Uploaded to this post",'acf'),
'default_icon' => wp_mime_type_icon() 'default_icon' => wp_mime_type_icon()
); );

View File

@ -14,16 +14,80 @@ class acf_revisions {
* @return N/A * @return N/A
*/ */
function __construct() function __construct() {
{
// actions // actions
add_action('save_post', array($this, 'save_post'), 99, 3);
add_action('wp_restore_post_revision', array($this, 'wp_restore_post_revision'), 10, 2 ); add_action('wp_restore_post_revision', array($this, 'wp_restore_post_revision'), 10, 2 );
// filters // filters
add_filter('_wp_post_revision_fields', array($this, 'wp_preview_post_fields') ); add_filter('wp_save_post_revision_check_for_changes', array($this, 'wp_save_post_revision_check_for_changes'), 10, 3);
add_filter('_wp_post_revision_fields', array($this, 'wp_post_revision_fields') ); add_filter('_wp_post_revision_fields', array($this, 'wp_preview_post_fields'), 10, 2 );
add_filter('wp_save_post_revision_check_for_changes', array($this, 'force_save_revision'), 10, 3); add_filter('_wp_post_revision_fields', array($this, 'wp_post_revision_fields'), 10, 2 );
}
/*
* get_post_latest_revision
*
* This function will return the latest revision for a given post
*
* @type function
* @date 25/06/2016
* @since 5.3.8
*
* @param $post_id (int)
* @return $post_id (int)
*/
function get_post_latest_revision( $post_id ) {
// vars
$revisions = wp_get_post_revisions( $post_id );
// shift off and return first revision (will return null if no revisions)
$revision = array_shift($revisions);
// return
return $revision;
}
/*
* save_post
*
* description
*
* @type function
* @date 25/06/2016
* @since 5.3.8
*
* @param $post_id (int)
* @return $post_id (int)
*/
function save_post( $post_id, $post, $update ) {
// bail ealry if post type does not support revision
if( !post_type_supports($post->post_type, 'revisions') ) return $post_id;
// get latest revision
$revision = $this->get_post_latest_revision( $post_id );
// save
if( $revision ) {
acf_copy_postmeta( $post_id, $revision->ID );
}
} }
@ -44,12 +108,12 @@ class acf_revisions {
function wp_preview_post_fields( $fields ) { function wp_preview_post_fields( $fields ) {
// vars
$wp_preview = acf_maybe_get($_POST, 'wp-preview');
// bail early if not previewing a post // bail early if not previewing a post
if( empty($_POST['wp-preview']) || $_POST['wp-preview'] != 'dopreview') { if( $wp_preview !== 'dopreview' ) return $fields;
return $fields;
}
// add to fields if ACF has changed // add to fields if ACF has changed
@ -67,7 +131,7 @@ class acf_revisions {
/* /*
* force_save_revision * wp_save_post_revision_check_for_changes
* *
* This filter will return false and force WP to save a revision. This is required due to * This filter will return false and force WP to save a revision. This is required due to
* WP checking only post_title, post_excerpt and post_content values, not custom fields. * WP checking only post_title, post_excerpt and post_content values, not custom fields.
@ -81,17 +145,20 @@ class acf_revisions {
* @return $return (boolean) * @return $return (boolean)
*/ */
function force_save_revision( $return, $last_revision, $post ) function wp_save_post_revision_check_for_changes( $return, $last_revision, $post ) {
{
// preview hack
if( isset($_POST['_acfchanged']) && $_POST['_acfchanged'] == '1' ) // look for _acfchanged
{ if( acf_maybe_get($_POST, '_acfchanged') === '1' ) {
$return = false; $return = false;
} }
// return // return
return $return; return $return;
} }
@ -109,112 +176,112 @@ class acf_revisions {
* @return $post_id (int) * @return $post_id (int)
*/ */
function wp_post_revision_fields( $return ) { function wp_post_revision_fields( $fields, $post = null ) {
// validate page
//globals if( acf_is_screen('revision') || acf_is_ajax('get-revision-diffs') ) {
global $post, $pagenow;
// allow
// validate } else {
$allowed = false;
// bail early (most likely saving a post)
return $fields;
// Normal revisions page
if( $pagenow == 'revision.php' )
{
$allowed = true;
}
// WP 3.6 AJAX revision
if( $pagenow == 'admin-ajax.php' && isset($_POST['action']) && $_POST['action'] == 'get-revision-diffs' )
{
$allowed = true;
}
// bail
if( !$allowed )
{
return $return;
} }
// vars // vars
$post_id = 0; $append = array();
$order = array();
$post_id = acf_maybe_get($post, 'ID');
// determine $post_id // compatibility with WP < 4.5 (test)
if( isset($_POST['post_id']) ) if( !$post_id ) {
{
$post_id = $_POST['post_id']; global $post;
}
elseif( isset($post->ID) )
{
$post_id = $post->ID; $post_id = $post->ID;
}
else
{
return $return;
} }
// setup global array // get all postmeta
$GLOBALS['acf_revisions_fields'] = array(); $meta = get_post_meta( $post_id );
// get field objects // bail early if no meta
$custom_fields = get_post_custom( $post_id ); if( !$meta ) return $fields;
// populate vars // loop
if( !empty($custom_fields) ) foreach( $meta as $name => $value ) {
{
foreach( $custom_fields as $k => $v ) // attempt to find key value
{ $key = acf_maybe_get( $meta, '_'.$name );
// value is always an array
$v = $v[0];
// bail ealry if no key
if( !$key ) continue;
// bail early if $value is not is a field_key
if( !acf_is_field_key($v) )
{ // update vars
continue; $value = $value[0];
} $key = $key[0];
// remove prefix '_' field from reference
$field_name = substr($k, 1);
// get field
//$field = acf_get_field($v);
// append to return
$return[ $field_name ] = $field_name;
// load value
add_filter("_wp_post_revision_field_{$field_name}", array($this, 'wp_post_revision_field'), 10, 4);
// WP 3.5: left vs right
// Add a value of the revision ID (as there is no way to determine this within the '_wp_post_revision_field_' filter!)
if( isset($_GET['action'], $_GET['left'], $_GET['right']) && $_GET['action'] == 'diff' )
{
global $left_revision, $right_revision;
$left_revision->$field_name = 'revision_id=' . $_GET['left']; // bail early if $key is a not a field_key
$right_revision->$field_name = 'revision_id=' . $_GET['right']; if( !acf_is_field_key($key) ) continue;
}
// get field
$field = acf_get_field( $key );
$field_title = $field['label'] . ' (' . $name . ')';
$field_order = $field['menu_order'];
$ancestors = acf_get_field_ancestors( $field );
// ancestors
if( !empty($ancestors) ) {
// vars
$count = count($ancestors);
$oldest = acf_get_field( $ancestors[$count-1] );
// update vars
$field_title = str_repeat('- ', $count) . $field_title;
$field_order = $oldest['menu_order'] . '.1';
} }
// append
$append[ $name ] = $field_title;
$order[ $name ] = $field_order;
// hook into specific revision field filter and return local value
add_filter("_wp_post_revision_field_{$name}", array($this, 'wp_post_revision_field'), 10, 4);
} }
return $return;
// append
if( !empty($append) ) {
// sort by name (orders sub field values correctly)
array_multisort($order, $append);
// append
$fields = array_merge($fields, $append);
}
// return
return $fields;
} }
@ -234,60 +301,48 @@ class acf_revisions {
* @return $value (string) * @return $value (string)
*/ */
function wp_post_revision_field( $value, $field_name, $post = null, $direction = false) function wp_post_revision_field( $value, $field_name, $post = null, $direction = false) {
{
// bail ealry if is empty
if( empty($value) ) return $value;
// value has not yet been 'maybe_unserialize'
$value = maybe_unserialize( $value );
// vars // vars
$post_id = 0; $post_id = $post->ID;
// determine $post_id
if( isset($post->ID) )
{
// WP 3.6
$post_id = $post->ID;
}
elseif( isset($_GET['revision']) )
{
// WP 3.5
$post_id = (int) $_GET['revision'];
}
elseif( strpos($value, 'revision_id=') !== false )
{
// WP 3.5 (left vs right)
$post_id = (int) str_replace('revision_id=', '', $value);
}
// load field // load field
$field = acf_maybe_get_field( $field_name, $post_id ); $field = acf_maybe_get_field( $field_name, $post_id );
// update value
//$value = $field['value'];
// default formatting // default formatting
if( is_array($value) ) { if( is_array($value) ) {
$value = implode(', ', $value); $value = implode(', ', $value);
} elseif( is_object($value) ) {
$value = serialize($value);
} }
// format // image
if( !empty($value) ) if( $field['type'] == 'image' || $field['type'] == 'file' ) {
{
// image || file? $url = wp_get_attachment_url($value);
if( $field['type'] == 'image' || $field['type'] == 'file' ) $value = $value . ' (' . $url . ')';
{
$url = wp_get_attachment_url($value);
$value = $value . ' (' . $url . ')';
}
} }
// return // return
return $value; return $value;
} }
@ -304,49 +359,23 @@ class acf_revisions {
*/ */
function wp_restore_post_revision( $post_id, $revision_id ) { function wp_restore_post_revision( $post_id, $revision_id ) {
// global // copy postmeta from revision to post (restore from revision)
global $wpdb; acf_copy_postmeta( $revision_id, $post_id );
// get field objects // Make sure the latest revision is also updated to match the new $post data
$custom_fields = get_post_custom( $revision_id ); // get latest revision
$revision = $this->get_post_latest_revision( $post_id );
// populate vars // save
if( !empty($custom_fields) ) if( $revision ) {
{
foreach( $custom_fields as $k => $v ) // copy postmeta from revision to latest revision (potentialy may be the same, but most likely are different)
{ acf_copy_postmeta( $revision_id, $revision->ID );
// value is always an array
$v = $v[0];
// bail early if $value is not is a field_key
if( !acf_is_field_key($v) )
{
continue;
}
// remove prefix '_' field from reference
$field_name = substr($k, 1);
// bail early if value could not be found
if( !isset($custom_fields[ $field_name ][0]) )
{
continue;
}
update_post_meta( $post_id, $field_name, $custom_fields[ $field_name ][0] );
}
} }
} }

View File

@ -59,7 +59,7 @@ class acf_updates {
// validate // validate
if( isset($args->slug) && $args->slug == $slug ) { if( isset($args->slug) && $args->slug === $slug && acf_is_plugin_active() ) {
// filter // filter
$result = apply_filters('acf/updates/plugin_details', $result, $action, $args); $result = apply_filters('acf/updates/plugin_details', $result, $action, $args);
@ -89,7 +89,7 @@ class acf_updates {
function modify_plugin_update( $transient ) { function modify_plugin_update( $transient ) {
// bail early if no response (dashboard showed an error) // bail early if no response (dashboard showed an error)
if( empty($transient->response) ) return $transient; if( !isset($transient->response) ) return $transient;
// vars // vars
@ -97,16 +97,8 @@ class acf_updates {
$show_updates = acf_get_setting('show_updates'); $show_updates = acf_get_setting('show_updates');
// ensure is_plugin_active() exists (not on frontend)
if( !function_exists('is_plugin_active') ) {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
// bail early if not a plugin (included in theme) // bail early if not a plugin (included in theme)
if( !is_plugin_active($basename) ) $show_updates = false; if( !acf_is_plugin_active() ) $show_updates = false;
// bail early if no show_updates // bail early if no show_updates
@ -381,4 +373,38 @@ function acf_get_wporg_remote_plugin_info() {
} }
/*
* acf_refresh_plugin_updates_transient
*
* This function will refresh teh WP transient containing plugin update data
*
* @type function
* @date 11/08/2016
* @since 5.4.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function acf_refresh_plugin_updates_transient() {
// vars
$transient = get_site_transient('update_plugins');
// bail early if no transient
if( empty($transient) ) return;
// update transient
$transient = acf()->updates->modify_plugin_update( $transient );
// update
set_site_transient( 'update_plugins', $transient );
}
?> ?>

View File

@ -36,10 +36,11 @@ class acf_field_checkbox extends acf_field {
$this->label = __("Checkbox",'acf'); $this->label = __("Checkbox",'acf');
$this->category = 'choice'; $this->category = 'choice';
$this->defaults = array( $this->defaults = array(
'layout' => 'vertical', 'layout' => 'vertical',
'choices' => array(), 'choices' => array(),
'default_value' => '', 'default_value' => '',
'toggle' => 0 'toggle' => 0,
'return_format' => 'value'
); );
@ -246,6 +247,20 @@ class acf_field_checkbox extends acf_field {
)); ));
// return_format
acf_render_field_setting( $field, array(
'label' => __('Return Value','acf'),
'instructions' => __('Specify the returned value on front end','acf'),
'type' => 'radio',
'name' => 'return_format',
'layout' => 'horizontal',
'choices' => array(
'value' => __('Value','acf'),
'label' => __('Label','acf'),
'array' => __('Both (Array)','acf')
)
));
} }
@ -266,13 +281,8 @@ class acf_field_checkbox extends acf_field {
function update_field( $field ) { function update_field( $field ) {
// decode choices (convert to array) return acf_get_field_type('select')->update_field( $field );
$field['choices'] = acf_decode_choices($field['choices']);
$field['default_value'] = acf_decode_choices($field['default_value'], true);
// return
return $field;
} }
@ -294,25 +304,7 @@ class acf_field_checkbox extends acf_field {
function update_value( $value, $post_id, $field ) { function update_value( $value, $post_id, $field ) {
// validate return acf_get_field_type('select')->update_value( $value, $post_id, $field );
if( empty($value) ) {
return $value;
}
// array
if( is_array($value) ) {
// save value as strings, so we can clearly search for them in SQL LIKE statements
$value = array_map('strval', $value);
}
// return
return $value;
} }
@ -331,12 +323,30 @@ class acf_field_checkbox extends acf_field {
function translate_field( $field ) { function translate_field( $field ) {
// translate return acf_get_field_type('select')->translate_field( $field );
$field['choices'] = acf_translate( $field['choices'] );
}
/*
* format_value()
*
* This filter is appied to the $value after it is loaded from the db and before it is returned to the template
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $value (mixed) the value which was loaded from 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 (mixed) the modified value
*/
function format_value( $value, $post_id, $field ) {
// return return acf_get_field_type('select')->format_value( $value, $post_id, $field );
return $field;
} }

View File

@ -155,8 +155,10 @@ class acf_field_color_picker extends acf_field {
} }
new acf_field_color_picker();
endif; // initialize
acf_register_field_type( new acf_field_color_picker() );
endif; // class_exists check
?> ?>

View File

@ -233,6 +233,41 @@ 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()
* *
@ -255,10 +290,44 @@ 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;
}
} }
new acf_field_date_picker();
endif; // initialize
acf_register_field_type( new acf_field_date_picker() );
endif; // class_exists check
?> ?>

View File

@ -51,6 +51,7 @@ class acf_field_date_and_time_picker extends acf_field {
'timezoneText' => _x('Time Zone', 'Date Time Picker JS timezoneText', 'acf'), 'timezoneText' => _x('Time Zone', 'Date Time Picker JS timezoneText', 'acf'),
'currentText' => _x('Now', 'Date Time Picker JS currentText', 'acf'), 'currentText' => _x('Now', 'Date Time Picker JS currentText', 'acf'),
'closeText' => _x('Done', 'Date Time Picker JS closeText', 'acf'), 'closeText' => _x('Done', 'Date Time Picker JS closeText', 'acf'),
'selectText' => _x('Select', 'Date Time Picker JS selectText', 'acf'),
'amNames' => array( 'amNames' => array(
_x('AM', 'Date Time Picker JS amText', 'acf'), _x('AM', 'Date Time Picker JS amText', 'acf'),
_x('A', 'Date Time Picker JS amTextShort', 'acf'), _x('A', 'Date Time Picker JS amTextShort', 'acf'),
@ -96,63 +97,6 @@ class acf_field_date_and_time_picker extends acf_field {
} }
/*
* _split_date_time
*
* This function will split a format string into seperate date and time
*
* @type function
* @date 26/05/2016
* @since 5.3.8
*
* @param $format (string)
* @return $formats (array)
*/
function _split_date_time( $date_time = '' ) {
// vars
$time = array( 'a', 'A', 'h', 'g', 'H', 'G', 'i', 's' );
$chars = str_split($date_time);
$index = false;
// default
$data = array(
'date' => $date_time,
'time' => ''
);
// loop
foreach( $chars as $i => $c ) {
// i is set, break loop
if( in_array($c, $time) ) {
$index = $i;
break;
}
}
// if index found
if( $index !== false ) {
$data['date'] = trim(substr($date_time, 0, $i));
$data['time'] = trim(substr($date_time, $i));
}
// return
return $data;
}
/* /*
* render_field() * render_field()
* *
@ -179,7 +123,7 @@ class acf_field_date_and_time_picker extends acf_field {
// convert display_format to date and time // convert display_format to date and time
// the letter 'm' is used for date and minute in JS, so this must be done here in PHP // the letter 'm' is used for date and minute in JS, so this must be done here in PHP
$formats = $this->_split_date_time($field['display_format']); $formats = acf_split_date_time($field['display_format']);
// vars // vars
@ -303,8 +247,10 @@ class acf_field_date_and_time_picker extends acf_field {
} }
new acf_field_date_and_time_picker();
endif; // initialize
acf_register_field_type( new acf_field_date_and_time_picker() );
endif; // class_exists check
?> ?>

View File

@ -62,7 +62,9 @@ class acf_field_email extends acf_field {
function render_field( $field ) { function render_field( $field ) {
// vars // vars
$atts = array();
$o = array( 'type', 'id', 'class', 'name', 'value', 'placeholder' ); $o = array( 'type', 'id', 'class', 'name', 'value', 'placeholder' );
$s = array( 'readonly', 'disabled' );
$e = ''; $e = '';
@ -84,8 +86,7 @@ class acf_field_email extends acf_field {
} }
// populate atts // append atts
$atts = array();
foreach( $o as $k ) { foreach( $o as $k ) {
$atts[ $k ] = $field[ $k ]; $atts[ $k ] = $field[ $k ];
@ -93,6 +94,14 @@ class acf_field_email extends acf_field {
} }
// append special atts
foreach( $s as $k ) {
if( !empty($field[ $k ]) ) $atts[ $k ] = $k;
}
// render // render
$e .= '<div class="acf-input-wrap">'; $e .= '<div class="acf-input-wrap">';
$e .= '<input ' . acf_esc_attr( $atts ) . ' />'; $e .= '<input ' . acf_esc_attr( $atts ) . ' />';
@ -158,8 +167,10 @@ class acf_field_email extends acf_field {
} }
new acf_field_email();
endif; // initialize
acf_register_field_type( new acf_field_email() );
endif; // class_exists check
?> ?>

View File

@ -417,8 +417,10 @@ class acf_field_file extends acf_field {
} }
new acf_field_file();
endif; // initialize
acf_register_field_type( new acf_field_file() );
endif; // class_exists check
?> ?>

View File

@ -81,7 +81,7 @@ class acf_field_google_map extends acf_field {
// value // value
$field['value'] = acf_parse_args($field['value'], array( $field['value'] = wp_parse_args($field['value'], array(
'address' => '', 'address' => '',
'lat' => '', 'lat' => '',
'lng' => '' 'lng' => ''
@ -292,11 +292,17 @@ class acf_field_google_map extends acf_field {
function input_admin_footer() { function input_admin_footer() {
// bail ealry if no qneueu
if( !acf_get_setting('enqueue_google_maps') ) return;
// vars // vars
$api = array( $api = array(
'libraries' => 'places', 'key' => acf_get_setting('google_api_key'),
'key' => acf_get_setting('google_api_key'), 'client' => acf_get_setting('google_api_client'),
'client' => acf_get_setting('google_api_client') 'libraries' => 'places',
'ver' => 3,
'callback' => ''
); );
@ -309,17 +315,23 @@ class acf_field_google_map extends acf_field {
if( empty($api['client']) ) unset($api['client']); if( empty($api['client']) ) unset($api['client']);
// construct url
$url = add_query_arg($api, 'https://maps.googleapis.com/maps/api/js');
?> ?>
<script type="text/javascript"> <script type="text/javascript">
acf.fields.google_map.api = <?php echo json_encode($api); ?>; acf.fields.google_map.url = '<?php echo $url; ?>';
</script> </script>
<?php <?php
} }
} }
new acf_field_google_map();
endif; // initialize
acf_register_field_type( new acf_field_google_map() );
endif; // class_exists check
?> ?>

View File

@ -482,8 +482,10 @@ class acf_field_image extends acf_field {
} }
new acf_field_image();
endif; // initialize
acf_register_field_type( new acf_field_image() );
endif; // class_exists check
?> ?>

View File

@ -36,7 +36,7 @@ class acf_field_message extends acf_field {
$this->label = __("Message",'acf'); $this->label = __("Message",'acf');
$this->category = 'layout'; $this->category = 'layout';
$this->defaults = array( $this->defaults = array(
'value' => false, // prevents acf_render_fields() from attempting to load value 'value' => false, // prevents ACF from attempting to load value
'message' => '', 'message' => '',
'esc_html' => 0, 'esc_html' => 0,
'new_lines' => 'wpautop', 'new_lines' => 'wpautop',
@ -150,6 +150,33 @@ class acf_field_message extends acf_field {
} }
/*
* update_field()
*
* This filter is appied to the $field before it is saved to the database
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $field - the field array holding all the field options
* @param $post_id - the field group ID (post_type = acf)
*
* @return $field - the modified field
*/
function update_field( $field ) {
// remove name
$field['name'] = '';
$field['required'] = 0;
// return
return $field;
}
/* /*
* translate_field * translate_field
* *
@ -176,8 +203,10 @@ class acf_field_message extends acf_field {
} }
new acf_field_message();
endif; // initialize
acf_register_field_type( new acf_field_message() );
endif; // class_exists check
?> ?>

View File

@ -41,9 +41,7 @@ class acf_field_number extends acf_field {
'step' => '', 'step' => '',
'placeholder' => '', 'placeholder' => '',
'prepend' => '', 'prepend' => '',
'append' => '', 'append' => ''
'readonly' => 0,
'disabled' => 0,
); );
@ -67,7 +65,9 @@ class acf_field_number extends acf_field {
function render_field( $field ) { function render_field( $field ) {
// vars // vars
$atts = array();
$o = array( 'type', 'id', 'class', 'min', 'max', 'step', 'name', 'value', 'placeholder' ); $o = array( 'type', 'id', 'class', 'min', 'max', 'step', 'name', 'value', 'placeholder' );
$s = array( 'readonly', 'disabled' );
$e = ''; $e = '';
@ -80,7 +80,7 @@ class acf_field_number extends acf_field {
// prepend // prepend
if( $field['prepend'] !== "" ) { if( $field['prepend'] !== '' ) {
$field['class'] .= ' acf-is-prepended'; $field['class'] .= ' acf-is-prepended';
$e .= '<div class="acf-input-prepend">' . $field['prepend'] . '</div>'; $e .= '<div class="acf-input-prepend">' . $field['prepend'] . '</div>';
@ -89,7 +89,7 @@ class acf_field_number extends acf_field {
// append // append
if( $field['append'] !== "" ) { if( $field['append'] !== '' ) {
$field['class'] .= ' acf-is-appended'; $field['class'] .= ' acf-is-appended';
$e .= '<div class="acf-input-append">' . $field['append'] . '</div>'; $e .= '<div class="acf-input-append">' . $field['append'] . '</div>';
@ -97,8 +97,7 @@ class acf_field_number extends acf_field {
} }
// populate atts // append atts
$atts = array();
foreach( $o as $k ) { foreach( $o as $k ) {
$atts[ $k ] = $field[ $k ]; $atts[ $k ] = $field[ $k ];
@ -106,14 +105,10 @@ class acf_field_number extends acf_field {
} }
// special atts // append special atts
foreach( array( 'readonly', 'disabled' ) as $k ) { foreach( $s as $k ) {
if( $field[ $k ] ) { if( !empty($field[ $k ]) ) $atts[ $k ] = $k;
$atts[ $k ] = $k;
}
} }
@ -317,8 +312,10 @@ class acf_field_number extends acf_field {
} }
new acf_field_number();
endif; // initialize
acf_register_field_type( new acf_field_number() );
endif; // class_exists check
?> ?>

View File

@ -320,8 +320,10 @@ class acf_field_oembed extends acf_field {
} }
new acf_field_oembed();
endif; // initialize
acf_register_field_type( new acf_field_oembed() );
endif; // class_exists check
?> ?>

View File

@ -36,10 +36,11 @@ class acf_field_page_link extends acf_field {
$this->label = __("Page Link",'acf'); $this->label = __("Page Link",'acf');
$this->category = 'relational'; $this->category = 'relational';
$this->defaults = array( $this->defaults = array(
'post_type' => array(), 'post_type' => array(),
'taxonomy' => array(), 'taxonomy' => array(),
'allow_null' => 0, 'allow_null' => 0,
'multiple' => 0, 'multiple' => 0,
'allow_archives' => 1
); );
@ -55,33 +56,38 @@ class acf_field_page_link extends acf_field {
/* /*
* get_choices * ajax_query
* *
* This function will return an array of data formatted for use in a select2 AJAX response * description
* *
* @type function * @type function
* @date 15/10/2014 * @date 24/10/13
* @since 5.0.9 * @since 5.0.0
* *
* @param $options (array) * @param $post_id (int)
* @return (array) * @return $post_id (int)
*/ */
function get_choices( $options = array() ) { function ajax_query() {
// validate
if( !acf_verify_ajax() ) die();
// defaults // defaults
$options = acf_parse_args($options, array( $options = acf_parse_args($_POST, array(
'post_id' => 0, 'post_id' => 0,
's' => '', 's' => '',
'lang' => false,
'field_key' => '', 'field_key' => '',
'paged' => 1 'paged' => 1
)); ));
// vars // vars
$r = array(); $results = array();
$args = array(); $args = array();
$s = false;
$is_search = false;
// paged // paged
@ -89,10 +95,23 @@ class acf_field_page_link extends acf_field {
$args['paged'] = $options['paged']; $args['paged'] = $options['paged'];
// search
if( $options['s'] !== '' ) {
// strip slashes (search may be integer)
$s = wp_unslash( strval($options['s']) );
// update vars
$args['s'] = $s;
$is_search = true;
}
// load field // load field
$field = acf_get_field( $options['field_key'] ); $field = acf_get_field( $options['field_key'] );
if( !$field ) die();
if( !$field ) return false;
// update $args // update $args
@ -129,14 +148,6 @@ class acf_field_page_link extends acf_field {
} }
} }
// search
if( $options['s'] ) {
$args['s'] = $options['s'];
}
// filters // filters
$args = apply_filters('acf/fields/page_link/query', $args, $field, $options['post_id']); $args = apply_filters('acf/fields/page_link/query', $args, $field, $options['post_id']);
@ -144,12 +155,8 @@ class acf_field_page_link extends acf_field {
$args = apply_filters('acf/fields/page_link/query/key=' . $field['key'], $args, $field, $options['post_id'] ); $args = apply_filters('acf/fields/page_link/query/key=' . $field['key'], $args, $field, $options['post_id'] );
// is search // add archives to $results
$is_search = !empty( $args['s'] ); if( $field['allow_archives'] && $args['paged'] == 1 ) {
// add archives to $r
if( $args['paged'] == 1 ) {
$archives = array(); $archives = array();
$archives[] = array( $archives[] = array(
@ -159,60 +166,47 @@ class acf_field_page_link extends acf_field {
foreach( $args['post_type'] as $post_type ) { foreach( $args['post_type'] as $post_type ) {
// vars
$archive_link = get_post_type_archive_link( $post_type ); $archive_link = get_post_type_archive_link( $post_type );
if( $archive_link ) {
$archives[] = array( // bail ealry if no link
'id' => $archive_link, if( !$archive_link ) continue;
'text' => $archive_link
);
}
}
// search
if( $is_search ) {
foreach( array_keys($archives) as $i ) { // bail early if no search match
if( $is_search && stripos($archive_link, $s) === false ) continue;
if( strpos( $archives[$i]['text'], $args['s'] ) === false ) {
unset($archives[$i]);
}
}
$archives = array_values($archives);
} // append
$archives[] = array(
'id' => $archive_link,
if( !empty($archives) ) { 'text' => $archive_link
$r[] = array(
'text' => __('Archives', 'acf'),
'children' => $archives
); );
} }
// append
$results[] = array(
'text' => __('Archives', 'acf'),
'children' => $archives
);
} }
// get posts grouped by post type // get posts grouped by post type
$groups = acf_get_grouped_posts( $args ); $groups = acf_get_grouped_posts( $args );
// loop
if( !empty($groups) ) { if( !empty($groups) ) {
foreach( array_keys($groups) as $group_title ) { foreach( array_keys($groups) as $group_title ) {
// vars // vars
$posts = acf_extract_var( $groups, $group_title ); $posts = acf_extract_var( $groups, $group_title );
$titles = array();
// data // data
@ -222,16 +216,16 @@ class acf_field_page_link extends acf_field {
); );
// convert post objects to post titles
foreach( array_keys($posts) as $post_id ) { foreach( array_keys($posts) as $post_id ) {
// override data $posts[ $post_id ] = $this->get_post_title( $posts[ $post_id ], $field, $options['post_id'], $is_search );
$posts[ $post_id ] = $this->get_post_title( $posts[ $post_id ], $field, $options['post_id'] );
}; }
// order by search // order posts by search
if( $is_search ) { if( $is_search && empty($args['orderby']) ) {
$posts = acf_order_by_search( $posts, $args['s'] ); $posts = acf_order_by_search( $posts, $args['s'] );
@ -241,66 +235,65 @@ class acf_field_page_link extends acf_field {
// append to $data // append to $data
foreach( array_keys($posts) as $post_id ) { foreach( array_keys($posts) as $post_id ) {
$data['children'][] = array( $data['children'][] = $this->get_post_result( $post_id, $posts[ $post_id ]);
'id' => $post_id,
'text' => $posts[ $post_id ]
);
} }
// append to $r // append to $results
$r[] = $data; $results[] = $data;
} }
} }
// return // return
return $r; acf_send_ajax_results(array(
'results' => $results,
'limit' => $args['posts_per_page']
));
} }
/* /*
* ajax_query * get_post_result
* *
* description * This function will return an array containing id, text and maybe description data
* *
* @type function * @type function
* @date 24/10/13 * @date 7/07/2016
* @since 5.0.0 * @since 5.4.0
* *
* @param $post_id (int) * @param $id (mixed)
* @return $post_id (int) * @param $text (string)
* @return (array)
*/ */
function ajax_query() { function get_post_result( $id, $text ) {
// validate // vars
if( !acf_verify_ajax() ) { $result = array(
'id' => $id,
'text' => $text
);
die();
// look for parent
$search = '| ' . __('Parent', 'acf') . ':';
$pos = strpos($text, $search);
if( $pos !== false ) {
$result['description'] = substr($text, $pos+2);
$result['text'] = substr($text, 0, $pos);
} }
// get choices // return
$choices = $this->get_choices( $_POST ); return $result;
// validate
if( !$choices ) {
die();
}
// return JSON
echo json_encode( $choices );
die();
} }
@ -338,6 +331,7 @@ class acf_field_page_link extends acf_field {
// return // return
return $title; return $title;
} }
@ -543,6 +537,20 @@ class acf_field_page_link extends acf_field {
)); ));
// allow_archives
acf_render_field_setting( $field, array(
'label' => __('Allow Archives URLs','acf'),
'instructions' => '',
'type' => 'radio',
'name' => 'allow_archives',
'choices' => array(
1 => __("Yes",'acf'),
0 => __("No",'acf'),
),
'layout' => 'horizontal',
));
// multiple // multiple
acf_render_field_setting( $field, array( acf_render_field_setting( $field, array(
'label' => __('Select multiple values?','acf'), 'label' => __('Select multiple values?','acf'),
@ -690,8 +698,10 @@ class acf_field_page_link extends acf_field {
} }
new acf_field_page_link();
endif; // initialize
acf_register_field_type( new acf_field_page_link() );
endif; // class_exists check
?> ?>

View File

@ -63,12 +63,14 @@ class acf_field_password extends acf_field {
function render_field( $field ) { function render_field( $field ) {
// vars // vars
$atts = array();
$o = array( 'type', 'id', 'class', 'name', 'value', 'placeholder' ); $o = array( 'type', 'id', 'class', 'name', 'value', 'placeholder' );
$s = array( 'readonly', 'disabled' );
$e = ''; $e = '';
// prepend // prepend
if( $field['prepend'] !== "" ) { if( $field['prepend'] !== '' ) {
$field['class'] .= ' acf-is-prepended'; $field['class'] .= ' acf-is-prepended';
$e .= '<div class="acf-input-prepend">' . $field['prepend'] . '</div>'; $e .= '<div class="acf-input-prepend">' . $field['prepend'] . '</div>';
@ -77,7 +79,7 @@ class acf_field_password extends acf_field {
// append // append
if( $field['append'] !== "" ) { if( $field['append'] !== '' ) {
$field['class'] .= ' acf-is-appended'; $field['class'] .= ' acf-is-appended';
$e .= '<div class="acf-input-append">' . $field['append'] . '</div>'; $e .= '<div class="acf-input-append">' . $field['append'] . '</div>';
@ -85,8 +87,7 @@ class acf_field_password extends acf_field {
} }
// populate atts // append atts
$atts = array();
foreach( $o as $k ) { foreach( $o as $k ) {
$atts[ $k ] = $field[ $k ]; $atts[ $k ] = $field[ $k ];
@ -94,14 +95,10 @@ class acf_field_password extends acf_field {
} }
// special atts // append special atts
foreach( array( 'readonly', 'disabled' ) as $k ) { foreach( $s as $k ) {
if( $field[ $k ] ) { if( !empty($field[ $k ]) ) $atts[ $k ] = $k;
$atts[ $k ] = $k;
}
} }
@ -161,8 +158,10 @@ class acf_field_password extends acf_field {
} }
new acf_field_password();
endif; // initialize
acf_register_field_type( new acf_field_password() );
endif; // class_exists check
?> ?>

View File

@ -56,173 +56,6 @@ class acf_field_post_object extends acf_field {
} }
/*
* get_choices
*
* This function will return an array of data formatted for use in a select2 AJAX response
*
* @type function
* @date 15/10/2014
* @since 5.0.9
*
* @param $options (array)
* @return (array)
*/
function get_choices( $options = array() ) {
// defaults
$options = acf_parse_args($options, array(
'post_id' => 0,
's' => '',
'field_key' => '',
'paged' => 1
));
// vars
$r = array();
$args = array();
// paged
$args['posts_per_page'] = 20;
$args['paged'] = $options['paged'];
// load field
$field = acf_get_field( $options['field_key'] );
// bail early if no field
if( !$field ) return false;
// update $args
if( !empty($field['post_type']) ) {
$args['post_type'] = acf_get_array( $field['post_type'] );
} else {
$args['post_type'] = acf_get_post_types();
}
// create tax queries
if( !empty($field['taxonomy']) ) {
// append to $args
$args['tax_query'] = array();
// decode terms
$taxonomies = acf_decode_taxonomy_terms( $field['taxonomy'] );
// now create the tax queries
foreach( $taxonomies as $taxonomy => $terms ) {
$args['tax_query'][] = array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $terms,
);
}
}
// search
if( $options['s'] ) {
$args['s'] = $options['s'];
}
// filters
$args = apply_filters('acf/fields/post_object/query', $args, $field, $options['post_id']);
$args = apply_filters('acf/fields/post_object/query/name=' . $field['name'], $args, $field, $options['post_id'] );
$args = apply_filters('acf/fields/post_object/query/key=' . $field['key'], $args, $field, $options['post_id'] );
// is search
$is_search = !empty( $args['s'] );
// get posts grouped by post type
$groups = acf_get_grouped_posts( $args );
// bail early if no posts
if( empty($groups) ) return false;
// loop
foreach( array_keys($groups) as $group_title ) {
// vars
$posts = acf_extract_var( $groups, $group_title );
$titles = array();
// data
$data = array(
'text' => $group_title,
'children' => array()
);
foreach( array_keys($posts) as $post_id ) {
// override data
$posts[ $post_id ] = $this->get_post_title( $posts[ $post_id ], $field, $options['post_id'] );
};
// order by search
if( $is_search ) {
$posts = acf_order_by_search( $posts, $args['s'] );
}
// append to $data
foreach( array_keys($posts) as $post_id ) {
$data['children'][] = array(
'id' => $post_id,
'text' => $posts[ $post_id ]
);
}
// append to $r
$r[] = $data;
}
// optgroup or single
if( count($args['post_type']) == 1 ) {
$r = $r[0]['children'];
}
// return
return $r;
}
/* /*
* ajax_query * ajax_query
* *
@ -239,28 +72,227 @@ class acf_field_post_object extends acf_field {
function ajax_query() { function ajax_query() {
// validate // validate
if( !acf_verify_ajax() ) { if( !acf_verify_ajax() ) die();
die();
}
// get choices // get choices
$choices = $this->get_choices( $_POST ); $response = $this->get_ajax_query( $_POST );
// validate // return
if( !$choices ) { acf_send_ajax_results($response);
die(); }
/*
* get_ajax_query
*
* This function will return an array of data formatted for use in a select2 AJAX response
*
* @type function
* @date 15/10/2014
* @since 5.0.9
*
* @param $options (array)
* @return (array)
*/
function get_ajax_query( $options = array() ) {
// defaults
$options = acf_parse_args($options, array(
'post_id' => 0,
's' => '',
'field_key' => '',
'paged' => 1
));
// load field
$field = acf_get_field( $options['field_key'] );
if( !$field ) return false;
// vars
$results = array();
$args = array();
$s = false;
$is_search = false;
// paged
$args['posts_per_page'] = 20;
$args['paged'] = $options['paged'];
// search
if( $options['s'] !== '' ) {
// strip slashes (search may be integer)
$s = wp_unslash( strval($options['s']) );
// update vars
$args['s'] = $s;
$is_search = true;
}
// post_type
if( !empty($field['post_type']) ) {
$args['post_type'] = acf_get_array( $field['post_type'] );
} else {
$args['post_type'] = acf_get_post_types();
} }
// return JSON // taxonomy
echo json_encode( $choices ); if( !empty($field['taxonomy']) ) {
die();
// vars
$terms = acf_decode_taxonomy_terms( $field['taxonomy'] );
// append to $args
$args['tax_query'] = array();
// now create the tax queries
foreach( $terms as $k => $v ) {
$args['tax_query'][] = array(
'taxonomy' => $k,
'field' => 'slug',
'terms' => $v,
);
}
}
// filters
$args = apply_filters('acf/fields/post_object/query', $args, $field, $options['post_id']);
$args = apply_filters('acf/fields/post_object/query/name=' . $field['name'], $args, $field, $options['post_id'] );
$args = apply_filters('acf/fields/post_object/query/key=' . $field['key'], $args, $field, $options['post_id'] );
// get posts grouped by post type
$groups = acf_get_grouped_posts( $args );
// bail early if no posts
if( empty($groups) ) return false;
// loop
foreach( array_keys($groups) as $group_title ) {
// vars
$posts = acf_extract_var( $groups, $group_title );
// data
$data = array(
'text' => $group_title,
'children' => array()
);
// convert post objects to post titles
foreach( array_keys($posts) as $post_id ) {
$posts[ $post_id ] = $this->get_post_title( $posts[ $post_id ], $field, $options['post_id'], $is_search );
}
// order posts by search
if( $is_search && empty($args['orderby']) ) {
$posts = acf_order_by_search( $posts, $args['s'] );
}
// append to $data
foreach( array_keys($posts) as $post_id ) {
$data['children'][] = $this->get_post_result( $post_id, $posts[ $post_id ]);
}
// append to $results
$results[] = $data;
}
// optgroup or single
if( count($args['post_type']) == 1 ) {
$results = $results[0]['children'];
}
// vars
$response = array(
'results' => $results,
'limit' => $args['posts_per_page']
);
// return
return $response;
}
/*
* get_post_result
*
* This function will return an array containing id, text and maybe description data
*
* @type function
* @date 7/07/2016
* @since 5.4.0
*
* @param $id (mixed)
* @param $text (string)
* @return (array)
*/
function get_post_result( $id, $text ) {
// vars
$result = array(
'id' => $id,
'text' => $text
);
// look for parent
$search = '| ' . __('Parent', 'acf') . ':';
$pos = strpos($text, $search);
if( $pos !== false ) {
$result['description'] = substr($text, $pos+2);
$result['text'] = substr($text, 0, $pos);
}
// return
return $result;
} }
@ -322,29 +354,19 @@ class acf_field_post_object extends acf_field {
$field['choices'] = array(); $field['choices'] = array();
// populate choices if value exists // load posts
if( !empty($field['value']) ) { $posts = $this->get_posts( $field['value'], $field );
// get posts if( $posts ) {
$posts = acf_get_posts(array(
'post__in' => $field['value'],
'post_type' => $field['post_type']
));
// set choices
if( !empty($posts) ) {
foreach( array_keys($posts) as $i ) { foreach( array_keys($posts) as $i ) {
// vars // vars
$post = acf_extract_var( $posts, $i ); $post = acf_extract_var( $posts, $i );
// append to choices // append to choices
$field['choices'][ $post->ID ] = $this->get_post_title( $post, $field ); $field['choices'][ $post->ID ] = $this->get_post_title( $post, $field );
}
} }
@ -353,6 +375,7 @@ class acf_field_post_object extends acf_field {
// render // render
acf_render_field( $field ); acf_render_field( $field );
} }
@ -461,15 +484,12 @@ class acf_field_post_object extends acf_field {
function load_value( $value, $post_id, $field ) { function load_value( $value, $post_id, $field ) {
// ACF4 null // ACF4 null
if( $value === 'null' ) { if( $value === 'null' ) return false;
return false;
}
// return // return
return $value; return $value;
} }
@ -491,38 +511,26 @@ class acf_field_post_object extends acf_field {
function format_value( $value, $post_id, $field ) { function format_value( $value, $post_id, $field ) {
// numeric
$value = acf_get_numeric($value);
// bail early if no value // bail early if no value
if( empty($value) ) { if( empty($value) ) return false;
return $value;
}
// force value to array
$value = acf_get_array( $value );
// convert values to int
$value = array_map('intval', $value);
// load posts if needed // load posts if needed
if( $field['return_format'] == 'object' ) { if( $field['return_format'] == 'object' ) {
// get posts $value = $this->get_posts( $value, $field );
$value = acf_get_posts(array(
'post__in' => $value,
'post_type' => $field['post_type']
));
} }
// convert back from array if neccessary // convert back from array if neccessary
if( !$field['multiple'] ) { if( !$field['multiple'] && acf_is_array($value) ) {
$value = array_shift($value); $value = current($value);
} }
@ -591,10 +599,48 @@ class acf_field_post_object extends acf_field {
} }
/*
* get_posts
*
* This function will return an array of posts for a given field value
*
* @type function
* @date 13/06/2014
* @since 5.0.0
*
* @param $value (array)
* @return $value
*/
function get_posts( $value, $field ) {
// numeric
$value = acf_get_numeric($value);
// bail early if no value
if( empty($value) ) return false;
// get posts
$posts = acf_get_posts(array(
'post__in' => $value,
'post_type' => $field['post_type']
));
// return
return $posts;
}
} }
new acf_field_post_object();
endif; // initialize
acf_register_field_type( new acf_field_post_object() );
endif; // class_exists check
?> ?>

View File

@ -41,7 +41,8 @@ class acf_field_radio extends acf_field {
'default_value' => '', 'default_value' => '',
'other_choice' => 0, 'other_choice' => 0,
'save_other_choice' => 0, 'save_other_choice' => 0,
'allow_null' => 0 'allow_null' => 0,
'return_format' => 'value'
); );
@ -301,6 +302,20 @@ class acf_field_radio extends acf_field {
)); ));
// return_format
acf_render_field_setting( $field, array(
'label' => __('Return Value','acf'),
'instructions' => __('Specify the returned value on front end','acf'),
'type' => 'radio',
'name' => 'return_format',
'layout' => 'horizontal',
'choices' => array(
'value' => __('Value','acf'),
'label' => __('Label','acf'),
'array' => __('Both (Array)','acf')
)
));
} }
@ -433,19 +448,39 @@ class acf_field_radio extends acf_field {
function translate_field( $field ) { function translate_field( $field ) {
// translate return acf_get_field_type('select')->translate_field( $field );
$field['choices'] = acf_translate( $field['choices'] );
}
/*
* format_value()
*
* This filter is appied to the $value after it is loaded from the db and before it is returned to the template
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $value (mixed) the value which was loaded from 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 (mixed) the modified value
*/
function format_value( $value, $post_id, $field ) {
// return return acf_get_field_type('select')->format_value( $value, $post_id, $field );
return $field;
} }
} }
new acf_field_radio();
endif; // initialize
acf_register_field_type( new acf_field_radio() );
endif; // class_exists check
?> ?>

View File

@ -63,195 +63,6 @@ class acf_field_relationship extends acf_field {
} }
/*
* get_choices
*
* This function will return an array of data formatted for use in a select2 AJAX response
*
* @type function
* @date 15/10/2014
* @since 5.0.9
*
* @param $options (array)
* @return (array)
*/
function get_choices( $options = array() ) {
// defaults
$options = acf_parse_args($options, array(
'post_id' => 0,
's' => '',
'post_type' => '',
'taxonomy' => '',
'lang' => false,
'field_key' => '',
'paged' => 1
));
// vars
$r = array();
$args = array();
// paged
$args['posts_per_page'] = 20;
$args['paged'] = $options['paged'];
// load field
$field = acf_get_field( $options['field_key'] );
if( !$field ) return false;
// update $args
if( !empty($options['post_type']) ) {
$args['post_type'] = acf_get_array( $options['post_type'] );
} elseif( !empty($field['post_type']) ) {
$args['post_type'] = acf_get_array( $field['post_type'] );
} else {
$args['post_type'] = acf_get_post_types();
}
// update taxonomy
$taxonomies = array();
if( !empty($options['taxonomy']) ) {
$term = acf_decode_taxonomy_term($options['taxonomy']);
// append to $args
$args['tax_query'] = array(
array(
'taxonomy' => $term['taxonomy'],
'field' => 'slug',
'terms' => $term['term'],
)
);
} elseif( !empty($field['taxonomy']) ) {
$taxonomies = acf_decode_taxonomy_terms( $field['taxonomy'] );
// append to $args
$args['tax_query'] = array();
// now create the tax queries
foreach( $taxonomies as $taxonomy => $terms ) {
$args['tax_query'][] = array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $terms,
);
}
}
// search
if( $options['s'] ) {
$args['s'] = $options['s'];
}
// filters
$args = apply_filters('acf/fields/relationship/query', $args, $field, $options['post_id']);
$args = apply_filters('acf/fields/relationship/query/name=' . $field['name'], $args, $field, $options['post_id'] );
$args = apply_filters('acf/fields/relationship/query/key=' . $field['key'], $args, $field, $options['post_id'] );
// is search
$is_search = !empty( $args['s'] );
// get posts grouped by post type
$groups = acf_get_grouped_posts( $args );
// bail early if no posts
if( empty($groups) ) return false;
// loop
foreach( array_keys($groups) as $group_title ) {
// vars
$posts = acf_extract_var( $groups, $group_title );
$titles = array();
// data
$data = array(
'text' => $group_title,
'children' => array()
);
foreach( array_keys($posts) as $post_id ) {
// override data
$posts[ $post_id ] = $this->get_post_title( $posts[ $post_id ], $field, $options['post_id'] );
};
// order by search
if( $is_search ) {
$posts = acf_order_by_search( $posts, $args['s'] );
}
// append to $data
foreach( array_keys($posts) as $post_id ) {
$data['children'][] = array(
'id' => $post_id,
'text' => $posts[ $post_id ]
);
}
// append to $r
$r[] = $data;
}
// add as optgroup or results
if( count($args['post_type']) == 1 ) {
$r = $r[0]['children'];
}
// return
return $r;
}
/* /*
* ajax_query * ajax_query
* *
@ -268,28 +79,239 @@ class acf_field_relationship extends acf_field {
function ajax_query() { function ajax_query() {
// validate // validate
if( !acf_verify_ajax() ) { if( !acf_verify_ajax() ) die();
die();
// get choices
$response = $this->get_ajax_query( $_POST );
// return
acf_send_ajax_results($response);
}
/*
* get_ajax_query
*
* This function will return an array of data formatted for use in a select2 AJAX response
*
* @type function
* @date 15/10/2014
* @since 5.0.9
*
* @param $options (array)
* @return (array)
*/
function get_ajax_query( $options = array() ) {
// defaults
$options = acf_parse_args($options, array(
'post_id' => 0,
's' => '',
'field_key' => '',
'paged' => 1,
'post_type' => '',
'taxonomy' => ''
));
// load field
$field = acf_get_field( $options['field_key'] );
if( !$field ) return false;
// vars
$results = array();
$args = array();
$s = false;
$is_search = false;
// paged
$args['posts_per_page'] = 20;
$args['paged'] = $options['paged'];
// search
if( $options['s'] !== '' ) {
// strip slashes (search may be integer)
$s = wp_unslash( strval($options['s']) );
// update vars
$args['s'] = $s;
$is_search = true;
} }
// get posts // post_type
$posts = $this->get_choices( $_POST ); if( !empty($options['post_type']) ) {
// validate
if( !$posts ) {
die(); $args['post_type'] = acf_get_array( $options['post_type'] );
} elseif( !empty($field['post_type']) ) {
$args['post_type'] = acf_get_array( $field['post_type'] );
} else {
$args['post_type'] = acf_get_post_types();
} }
// return JSON // taxonomy
echo json_encode( $posts ); if( !empty($options['taxonomy']) ) {
die();
// vars
$term = acf_decode_taxonomy_term($options['taxonomy']);
// tax query
$args['tax_query'] = array();
// append
$args['tax_query'][] = array(
'taxonomy' => $term['taxonomy'],
'field' => 'slug',
'terms' => $term['term'],
);
} elseif( !empty($field['taxonomy']) ) {
// vars
$terms = acf_decode_taxonomy_terms( $field['taxonomy'] );
// append to $args
$args['tax_query'] = array();
// now create the tax queries
foreach( $terms as $k => $v ) {
$args['tax_query'][] = array(
'taxonomy' => $k,
'field' => 'slug',
'terms' => $v,
);
}
}
// filters
$args = apply_filters('acf/fields/relationship/query', $args, $field, $options['post_id']);
$args = apply_filters('acf/fields/relationship/query/name=' . $field['name'], $args, $field, $options['post_id'] );
$args = apply_filters('acf/fields/relationship/query/key=' . $field['key'], $args, $field, $options['post_id'] );
// get posts grouped by post type
$groups = acf_get_grouped_posts( $args );
// bail early if no posts
if( empty($groups) ) return false;
// loop
foreach( array_keys($groups) as $group_title ) {
// vars
$posts = acf_extract_var( $groups, $group_title );
// data
$data = array(
'text' => $group_title,
'children' => array()
);
// convert post objects to post titles
foreach( array_keys($posts) as $post_id ) {
$posts[ $post_id ] = $this->get_post_title( $posts[ $post_id ], $field, $options['post_id'] );
}
// order posts by search
if( $is_search && empty($args['orderby']) ) {
$posts = acf_order_by_search( $posts, $args['s'] );
}
// append to $data
foreach( array_keys($posts) as $post_id ) {
$data['children'][] = $this->get_post_result( $post_id, $posts[ $post_id ]);
}
// append to $results
$results[] = $data;
}
// add as optgroup or results
if( count($args['post_type']) == 1 ) {
$results = $results[0]['children'];
}
// vars
$response = array(
'results' => $results,
'limit' => $args['posts_per_page']
);
// return
return $response;
}
/*
* get_post_result
*
* This function will return an array containing id, text and maybe description data
*
* @type function
* @date 7/07/2016
* @since 5.4.0
*
* @param $id (mixed)
* @param $text (string)
* @return (array)
*/
function get_post_result( $id, $text ) {
// vars
$result = array(
'id' => $id,
'text' => $text
);
// return
return $result;
} }
@ -917,8 +939,10 @@ class acf_field_relationship extends acf_field {
} }
new acf_field_relationship();
endif; // initialize
acf_register_field_type( new acf_field_relationship() );
endif; // class_exists check
?> ?>

View File

@ -33,7 +33,7 @@ class acf_field_select extends acf_field {
// vars // vars
$this->name = 'select'; $this->name = 'select';
$this->label = __("Select",'acf'); $this->label = _x('Select', 'noun', 'acf');
$this->category = 'choice'; $this->category = 'choice';
$this->defaults = array( $this->defaults = array(
'multiple' => 0, 'multiple' => 0,
@ -43,8 +43,7 @@ class acf_field_select extends acf_field {
'ui' => 0, 'ui' => 0,
'ajax' => 0, 'ajax' => 0,
'placeholder' => '', 'placeholder' => '',
'disabled' => 0, 'return_format' => 'value'
'readonly' => 0,
); );
$this->l10n = array( $this->l10n = array(
'matches_1' => _x('One result is available, press enter to select it.', 'Select2 JS matches_1', 'acf'), 'matches_1' => _x('One result is available, press enter to select it.', 'Select2 JS matches_1', 'acf'),
@ -113,7 +112,7 @@ class acf_field_select extends acf_field {
/* /*
* query_posts * ajax_query
* *
* description * description
* *
@ -121,76 +120,106 @@ class acf_field_select extends acf_field {
* @date 24/10/13 * @date 24/10/13
* @since 5.0.0 * @since 5.0.0
* *
* @param n/a * @param $post_id (int)
* @return n/a * @return $post_id (int)
*/ */
function ajax_query() { function ajax_query() {
// options // validate
$options = acf_parse_args( $_POST, array( if( !acf_verify_ajax() ) die();
'post_id' => 0,
's' => '',
'field_key' => '', // get choices
'nonce' => '', $response = $this->get_ajax_query( $_POST );
// return
acf_send_ajax_results($response);
}
/*
* get_ajax_query
*
* This function will return an array of data formatted for use in a select2 AJAX response
*
* @type function
* @date 15/10/2014
* @since 5.0.9
*
* @param $options (array)
* @return (array)
*/
function get_ajax_query( $options = array() ) {
// defaults
$options = acf_parse_args($options, array(
'post_id' => 0,
's' => '',
'field_key' => '',
'paged' => 1
)); ));
// load field // load field
$field = acf_get_field( $options['field_key'] ); $field = acf_get_field( $options['field_key'] );
if( !$field ) return false;
if( !$field ) {
die(); // vars
$results = array();
$s = false;
$is_search = false;
// search
if( $options['s'] !== '' ) {
// strip slashes (search may be integer)
$s = wp_unslash( strval($options['s']) );
// update vars
$is_search = true;
}
// bail ealry if no choices
if( empty($field['choices']) ) return false;
// loop
foreach( $field['choices'] as $k => $v ) {
// ensure $v is a string
$v = strval( $v );
// if searching, but doesn't exist
if( $is_search && stripos($v, $s) === false ) continue;
// append
$results[] = array(
'id' => $k,
'text' => $v
);
} }
// vars // vars
$r = array(); $response = array(
$s = false; 'results' => $results
);
// search // return
if( $options['s'] !== '' ) { return $response;
// search may be integer
$s = strval($options['s']);
// strip slashes
$s = wp_unslash($s);
}
// loop through choices
if( !empty($field['choices']) ) {
foreach( $field['choices'] as $k => $v ) {
// if searching, but doesn't exist
if( $s !== false && stripos($v, $s) === false ) {
continue;
}
// append
$r[] = array(
'id' => $k,
'text' => strval( $v )
);
}
}
// return JSON
echo json_encode( $r );
die();
} }
@ -217,7 +246,7 @@ class acf_field_select extends acf_field {
// placeholder // placeholder
if( empty($field['placeholder']) ) { if( empty($field['placeholder']) ) {
$field['placeholder'] = __("Select",'acf'); $field['placeholder'] = _x('Select', 'verb', 'acf');
} }
@ -231,6 +260,7 @@ class acf_field_select extends acf_field {
// null // null
// - have tried array_merge but this causes keys to re-index if is numeric (post ID's)
if( $field['allow_null'] && !$field['multiple'] ) { if( $field['allow_null'] && !$field['multiple'] ) {
$prepend = array('' => '- ' . $field['placeholder'] . ' -'); $prepend = array('' => '- ' . $field['placeholder'] . ' -');
@ -239,6 +269,7 @@ class acf_field_select extends acf_field {
} }
// vars // vars
$atts = array( $atts = array(
'id' => $field['id'], 'id' => $field['id'],
@ -482,6 +513,21 @@ class acf_field_select extends acf_field {
), ),
'layout' => 'horizontal', 'layout' => 'horizontal',
)); ));
// return_format
acf_render_field_setting( $field, array(
'label' => __('Return Format','acf'),
'instructions' => __('Specify the value returned','acf'),
'type' => 'radio',
'name' => 'return_format',
'layout' => 'horizontal',
'choices' => array(
'value' => __('Value','acf'),
'label' => __('Label','acf'),
'array' => __('Both (Array)','acf')
)
));
} }
@ -603,10 +649,89 @@ class acf_field_select extends acf_field {
} }
/*
* format_value()
*
* This filter is appied to the $value after it is loaded from the db and before it is returned to the template
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $value (mixed) the value which was loaded from 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 (mixed) the modified value
*/
function format_value( $value, $post_id, $field ) {
// array
if( acf_is_array($value) ) {
foreach( $value as $i => $v ) {
$value[ $i ] = $this->format_value_single( $v, $post_id, $field );
}
} else {
$value = $this->format_value_single( $value, $post_id, $field );
}
// return
return $value;
}
function format_value_single( $value, $post_id, $field ) {
// bail ealry if is empty
if( acf_is_empty($value) ) return $value;
// vars
$label = acf_maybe_get($field['choices'], $value, $value);
// value
if( $field['return_format'] == 'value' ) {
// do nothing
// label
} elseif( $field['return_format'] == 'label' ) {
$value = $label;
// array
} elseif( $field['return_format'] == 'array' ) {
$value = array(
'value' => $value,
'label' => $label
);
}
// return
return $value;
}
} }
new acf_field_select();
endif; // initialize
acf_register_field_type( new acf_field_select() );
endif; // class_exists check
?> ?>

View File

@ -36,7 +36,7 @@ class acf_field_tab extends acf_field {
$this->label = __("Tab",'acf'); $this->label = __("Tab",'acf');
$this->category = 'layout'; $this->category = 'layout';
$this->defaults = array( $this->defaults = array(
'value' => false, // prevents acf_render_fields() from attempting to load value 'value' => false, // prevents ACF from attempting to load value
'placement' => 'top', 'placement' => 'top',
'endpoint' => 0 // added in 5.2.8 'endpoint' => 0 // added in 5.2.8
); );
@ -135,10 +135,39 @@ class acf_field_tab extends acf_field {
} }
/*
* update_field()
*
* This filter is appied to the $field before it is saved to the database
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $field - the field array holding all the field options
* @param $post_id - the field group ID (post_type = acf)
*
* @return $field - the modified field
*/
function update_field( $field ) {
// remove name
$field['name'] = '';
$field['required'] = 0;
// return
return $field;
}
} }
new acf_field_tab();
endif; // initialize
acf_register_field_type( new acf_field_tab() );
endif; // class_exists check
?> ?>

View File

@ -66,7 +66,36 @@ class acf_field_taxonomy extends acf_field {
/* /*
* get_choices * ajax_query
*
* description
*
* @type function
* @date 24/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function ajax_query() {
// validate
if( !acf_verify_ajax() ) die();
// get choices
$response = $this->get_ajax_query( $_POST );
// return
acf_send_ajax_results($response);
}
/*
* get_ajax_query
* *
* This function will return an array of data formatted for use in a select2 AJAX response * This function will return an array of data formatted for use in a select2 AJAX response
* *
@ -78,7 +107,7 @@ class acf_field_taxonomy extends acf_field {
* @return (array) * @return (array)
*/ */
function get_choices( $options = array() ) { function get_ajax_query( $options = array() ) {
// defaults // defaults
$options = acf_parse_args($options, array( $options = acf_parse_args($options, array(
@ -91,19 +120,15 @@ class acf_field_taxonomy extends acf_field {
// load field // load field
$field = acf_get_field( $options['field_key'] ); $field = acf_get_field( $options['field_key'] );
if( !$field ) return false;
if( !$field ) {
return false;
}
// vars // vars
$r = array(); $results = array();
$args = 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;
$limit = 20; $limit = 20;
$offset = 20 * ($options['paged'] - 1); $offset = 20 * ($options['paged'] - 1);
@ -114,19 +139,25 @@ class acf_field_taxonomy extends acf_field {
// pagination // pagination
// - don't bother for hierarchial terms, we will need to load all terms anyway // - don't bother for hierarchial terms, we will need to load all terms anyway
if( !$is_hierarchical && $is_pagination ) { if( $is_pagination && !$is_hierarchical ) {
$args['offset'] = $offset;
$args['number'] = $limit; $args['number'] = $limit;
$args['offset'] = $offset;
} }
// search // search
if( $options['s'] ) { if( $options['s'] !== '' ) {
$args['search'] = $options['s']; // strip slashes (search may be integer)
$s = wp_unslash( strval($options['s']) );
// update vars
$args['search'] = $s;
$is_search = true;
} }
@ -134,7 +165,7 @@ class acf_field_taxonomy extends acf_field {
$args = apply_filters('acf/fields/taxonomy/query', $args, $field, $options['post_id']); $args = apply_filters('acf/fields/taxonomy/query', $args, $field, $options['post_id']);
$args = apply_filters('acf/fields/taxonomy/query/name=' . $field['name'], $args, $field, $options['post_id'] ); $args = apply_filters('acf/fields/taxonomy/query/name=' . $field['name'], $args, $field, $options['post_id'] );
$args = apply_filters('acf/fields/taxonomy/query/key=' . $field['key'], $args, $field, $options['post_id'] ); $args = apply_filters('acf/fields/taxonomy/query/key=' . $field['key'], $args, $field, $options['post_id'] );
// get terms // get terms
$terms = get_terms( $field['taxonomy'], $args ); $terms = get_terms( $field['taxonomy'], $args );
@ -143,13 +174,18 @@ class acf_field_taxonomy extends acf_field {
// sort into hierachial order! // sort into hierachial order!
if( $is_hierarchical ) { if( $is_hierarchical ) {
// update vars
$limit = acf_maybe_get( $args, 'number', $limit );
$offset = acf_maybe_get( $args, 'offset', $offset );
// get parent // get parent
$parent = acf_maybe_get( $args, 'parent', 0 ); $parent = acf_maybe_get( $args, 'parent', 0 );
$parent = acf_maybe_get( $args, 'child_of', $parent ); $parent = acf_maybe_get( $args, 'child_of', $parent );
// this will fail if a search has taken place because parents wont exist // this will fail if a search has taken place because parents wont exist
if( empty($args['search']) ) { if( !$is_search ) {
$terms = _get_term_children( $parent, $terms, $field['taxonomy'] ); $terms = _get_term_children( $parent, $terms, $field['taxonomy'] );
@ -170,7 +206,7 @@ class acf_field_taxonomy extends acf_field {
foreach( $terms as $term ) { foreach( $terms as $term ) {
// add to json // add to json
$r[] = array( $results[] = array(
'id' => $term->term_id, 'id' => $term->term_id,
'text' => $this->get_term_title( $term, $field, $options['post_id'] ) 'text' => $this->get_term_title( $term, $field, $options['post_id'] )
); );
@ -178,42 +214,15 @@ class acf_field_taxonomy extends acf_field {
} }
// vars
$response = array(
'results' => $results,
'limit' => $limit
);
// return // return
return $r; return $response;
}
/*
* ajax_query
*
* description
*
* @type function
* @date 24/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function ajax_query() {
// validate
if( !acf_verify_ajax() ) die();
// get choices
$choices = $this->get_choices( $_POST );
// validate
if( !$choices ) die();
// return JSON
echo json_encode( $choices );
die();
} }
@ -337,7 +346,8 @@ class acf_field_taxonomy extends acf_field {
if( $field['load_terms'] ) { if( $field['load_terms'] ) {
// get terms // get terms
$term_ids = wp_get_object_terms($post_id, $field['taxonomy'], array('fields' => 'ids', 'orderby' => 'none')); $info = acf_get_post_id_info($post_id);
$term_ids = wp_get_object_terms($info['id'], $field['taxonomy'], array('fields' => 'ids', 'orderby' => 'none'));
// bail early if no terms // bail early if no terms
@ -421,16 +431,6 @@ class acf_field_taxonomy extends acf_field {
$term_ids = array_map('intval', $term_ids); $term_ids = array_map('intval', $term_ids);
// if called directly from frontend update_field()
if( !did_action('acf/save_post') ) {
wp_set_object_terms( $post_id, $term_ids, $taxonomy, false );
return $value;
}
// get existing term id's (from a previously saved field) // get existing term id's (from a previously saved field)
$old_term_ids = isset($this->save_post_terms[ $taxonomy ]) ? $this->save_post_terms[ $taxonomy ] : array(); $old_term_ids = isset($this->save_post_terms[ $taxonomy ]) ? $this->save_post_terms[ $taxonomy ] : array();
@ -438,6 +438,16 @@ class acf_field_taxonomy extends acf_field {
// append // append
$this->save_post_terms[ $taxonomy ] = array_merge($old_term_ids, $term_ids); $this->save_post_terms[ $taxonomy ] = array_merge($old_term_ids, $term_ids);
// if called directly from frontend update_field()
if( !did_action('acf/save_post') ) {
$this->save_post( $post_id );
return $value;
}
} }
@ -466,12 +476,15 @@ class acf_field_taxonomy extends acf_field {
if( empty($this->save_post_terms) ) return; if( empty($this->save_post_terms) ) return;
// vars
$info = acf_get_post_id_info($post_id);
// loop over terms
// loop
foreach( $this->save_post_terms as $taxonomy => $term_ids ){ foreach( $this->save_post_terms as $taxonomy => $term_ids ){
wp_set_object_terms( $post_id, $term_ids, $taxonomy, false ); // save
wp_set_object_terms( $info['id'], $term_ids, $taxonomy, false );
} }
@ -756,7 +769,7 @@ class acf_field_taxonomy extends acf_field {
), ),
__("Single Value",'acf') => array( __("Single Value",'acf') => array(
'radio' => __('Radio Buttons', 'acf'), 'radio' => __('Radio Buttons', 'acf'),
'select' => __('Select', 'acf') 'select' => _x('Select', 'noun', 'acf')
) )
) )
)); ));
@ -960,11 +973,11 @@ class acf_field_taxonomy extends acf_field {
if( is_taxonomy_hierarchical( $field['taxonomy'] ) ) { if( is_taxonomy_hierarchical( $field['taxonomy'] ) ) {
$choices = array(); $choices = array();
$choices2 = $this->get_choices(array( 'field_key' => $field['key'] )); $response = $this->get_ajax_query($args);
if( $choices2 ) { if( $response ) {
foreach( $choices2 as $v) { foreach( $response['results'] as $v ) {
$choices[ $v['id'] ] = $v['text']; $choices[ $v['id'] ] = $v['text'];
@ -995,9 +1008,13 @@ class acf_field_taxonomy extends acf_field {
} }
new acf_field_taxonomy();
endif; // initialize
acf_register_field_type( new acf_field_taxonomy() );
endif; // class_exists check
if( ! class_exists('acf_taxonomy_field_walker') ) : if( ! class_exists('acf_taxonomy_field_walker') ) :

View File

@ -39,9 +39,7 @@ class acf_field_text extends acf_field {
'maxlength' => '', 'maxlength' => '',
'placeholder' => '', 'placeholder' => '',
'prepend' => '', 'prepend' => '',
'append' => '', 'append' => ''
'readonly' => 0,
'disabled' => 0,
); );
@ -65,13 +63,14 @@ class acf_field_text extends acf_field {
function render_field( $field ) { function render_field( $field ) {
// vars // vars
$atts = array();
$o = array( 'type', 'id', 'class', 'name', 'value', 'placeholder' ); $o = array( 'type', 'id', 'class', 'name', 'value', 'placeholder' );
$s = array( 'readonly', 'disabled' ); $s = array( 'readonly', 'disabled' );
$e = ''; $e = '';
// maxlength // maxlength
if( $field['maxlength'] !== "" ) { if( $field['maxlength'] ) {
$o[] = 'maxlength'; $o[] = 'maxlength';
@ -79,7 +78,7 @@ class acf_field_text extends acf_field {
// prepend // prepend
if( $field['prepend'] !== "" ) { if( $field['prepend'] !== '' ) {
$field['class'] .= ' acf-is-prepended'; $field['class'] .= ' acf-is-prepended';
$e .= '<div class="acf-input-prepend">' . $field['prepend'] . '</div>'; $e .= '<div class="acf-input-prepend">' . $field['prepend'] . '</div>';
@ -88,7 +87,7 @@ class acf_field_text extends acf_field {
// append // append
if( $field['append'] !== "" ) { if( $field['append'] !== '' ) {
$field['class'] .= ' acf-is-appended'; $field['class'] .= ' acf-is-appended';
$e .= '<div class="acf-input-append">' . $field['append'] . '</div>'; $e .= '<div class="acf-input-append">' . $field['append'] . '</div>';
@ -96,8 +95,7 @@ class acf_field_text extends acf_field {
} }
// populate atts // append atts
$atts = array();
foreach( $o as $k ) { foreach( $o as $k ) {
$atts[ $k ] = $field[ $k ]; $atts[ $k ] = $field[ $k ];
@ -105,14 +103,10 @@ class acf_field_text extends acf_field {
} }
// special atts // append special atts
foreach( $s as $k ) { foreach( $s as $k ) {
if( $field[ $k ] ) { if( !empty($field[ $k ]) ) $atts[ $k ] = $k;
$atts[ $k ] = $k;
}
} }
@ -191,8 +185,10 @@ class acf_field_text extends acf_field {
} }
new acf_field_text();
endif; // initialize
acf_register_field_type( new acf_field_text() );
endif; // class_exists check
?> ?>

View File

@ -39,8 +39,6 @@ class acf_field_textarea extends acf_field {
'new_lines' => '', 'new_lines' => '',
'maxlength' => '', 'maxlength' => '',
'placeholder' => '', 'placeholder' => '',
'readonly' => 0,
'disabled' => 0,
'rows' => '' 'rows' => ''
); );
@ -65,13 +63,14 @@ class acf_field_textarea extends acf_field {
function render_field( $field ) { function render_field( $field ) {
// vars // vars
$atts = array();
$o = array( 'id', 'class', 'name', 'placeholder', 'rows' ); $o = array( 'id', 'class', 'name', 'placeholder', 'rows' );
$s = array( 'readonly', 'disabled' ); $s = array( 'readonly', 'disabled' );
$e = ''; $e = '';
// maxlength // maxlength
if( $field['maxlength'] !== '' ) { if( $field['maxlength'] ) {
$o[] = 'maxlength'; $o[] = 'maxlength';
@ -86,8 +85,7 @@ class acf_field_textarea extends acf_field {
} }
// populate atts // append atts
$atts = array();
foreach( $o as $k ) { foreach( $o as $k ) {
$atts[ $k ] = $field[ $k ]; $atts[ $k ] = $field[ $k ];
@ -95,14 +93,10 @@ class acf_field_textarea extends acf_field {
} }
// special atts // append special atts
foreach( $s as $k ) { foreach( $s as $k ) {
if( $field[ $k ] ) { if( !empty($field[ $k ]) ) $atts[ $k ] = $k;
$atts[ $k ] = $k;
}
} }
@ -237,8 +231,10 @@ class acf_field_textarea extends acf_field {
} }
new acf_field_textarea();
endif; // initialize
acf_register_field_type( new acf_field_textarea() );
endif; // class_exists check
?> ?>

View File

@ -175,8 +175,10 @@ class acf_field_time_picker extends acf_field {
} }
new acf_field_time_picker();
endif; // initialize
acf_register_field_type( new acf_field_time_picker() );
endif; // class_exists check
?> ?>

View File

@ -207,8 +207,10 @@ class acf_field_true_false extends acf_field {
} }
new acf_field_true_false();
endif; // initialize
acf_register_field_type( new acf_field_true_false() );
endif; // class_exists check
?> ?>

View File

@ -60,12 +60,13 @@ class acf_field_url extends acf_field {
function render_field( $field ) { function render_field( $field ) {
// vars // vars
$atts = array();
$o = array( 'type', 'id', 'class', 'name', 'value', 'placeholder' ); $o = array( 'type', 'id', 'class', 'name', 'value', 'placeholder' );
$s = array( 'readonly', 'disabled' );
$e = ''; $e = '';
// populate atts // append atts
$atts = array();
foreach( $o as $k ) { foreach( $o as $k ) {
$atts[ $k ] = $field[ $k ]; $atts[ $k ] = $field[ $k ];
@ -73,14 +74,10 @@ class acf_field_url extends acf_field {
} }
// special atts // append special atts
foreach( array( 'readonly', 'disabled' ) as $k ) { foreach( $s as $k ) {
if( !empty($field[ $k ]) ) { if( !empty($field[ $k ]) ) $atts[ $k ] = $k;
$atts[ $k ] = $k;
}
} }
@ -177,8 +174,10 @@ class acf_field_url extends acf_field {
} }
new acf_field_url();
endif; // initialize
acf_register_field_type( new acf_field_url() );
endif; // class_exists check
?> ?>

View File

@ -54,32 +54,38 @@ class acf_field_user extends acf_field {
/* /*
* get_choices * ajax_query
* *
* This function will return an array of data formatted for use in a select2 AJAX response * description
* *
* @type function * @type function
* @date 15/10/2014 * @date 24/10/13
* @since 5.0.9 * @since 5.0.0
* *
* @param $options (array) * @param $post_id (int)
* @return (array) * @return $post_id (int)
*/ */
function get_choices( $options = array() ) { function ajax_query() {
// defaults // validate
$options = acf_parse_args($options, array( if( !acf_verify_ajax() ) die();
// defaults
$options = acf_parse_args($_POST, array(
'post_id' => 0, 'post_id' => 0,
's' => '', 's' => '',
'field_key' => '', 'field_key' => '',
'paged' => 1, 'paged' => 1
)); ));
// vars // vars
$r = array(); $results = array();
$args = array(); $args = array();
$s = false;
$is_search = false;
// paged // paged
@ -87,15 +93,26 @@ class acf_field_user extends acf_field {
$args['paged'] = $options['paged']; $args['paged'] = $options['paged'];
// search
if( $options['s'] !== '' ) {
// strip slashes (search may be integer)
$s = wp_unslash( strval($options['s']) );
// update vars
$args['s'] = $s;
$is_search = true;
}
// load field // load field
$field = acf_get_field( $options['field_key'] ); $field = acf_get_field( $options['field_key'] );
if( !$field ) die();
// bail early if no field // role
if( !$field ) return false;
// update $args
if( !empty($field['role']) ) { if( !empty($field['role']) ) {
$args['role'] = acf_get_array( $field['role'] ); $args['role'] = acf_get_array( $field['role'] );
@ -104,7 +121,7 @@ class acf_field_user extends acf_field {
// search // search
if( $options['s'] ) { if( $is_search ) {
// append to $args // append to $args
$args['search'] = '*' . $options['s'] . '*'; $args['search'] = '*' . $options['s'] . '*';
@ -130,101 +147,71 @@ class acf_field_user extends acf_field {
$groups = acf_get_grouped_users( $args ); $groups = acf_get_grouped_users( $args );
// bail early if no groups
if( empty($groups) ) return false;
// loop // loop
foreach( array_keys($groups) as $group_title ) { if( !empty($groups) ) {
// vars foreach( array_keys($groups) as $group_title ) {
$users = acf_extract_var( $groups, $group_title );
$data = array(
'text' => $group_title,
'children' => array()
);
// append users
foreach( array_keys($users) as $user_id ) {
$users[ $user_id ] = $this->get_result( $users[ $user_id ], $field, $options['post_id'] ); // vars
$users = acf_extract_var( $groups, $group_title );
}; $data = array(
'text' => $group_title,
'children' => array()
// order by search
if( !empty($args['s']) ) {
$users = acf_order_by_search( $users, $args['s'] );
}
// append to $data
foreach( $users as $id => $title ) {
$data['children'][] = array(
'id' => $id,
'text' => $title
); );
// append users
foreach( array_keys($users) as $user_id ) {
$users[ $user_id ] = $this->get_result( $users[ $user_id ], $field, $options['post_id'] );
};
// order by search
if( $is_search && empty($args['orderby']) ) {
$users = acf_order_by_search( $users, $args['s'] );
}
// append to $data
foreach( $users as $id => $title ) {
$data['children'][] = array(
'id' => $id,
'text' => $title
);
}
// append to $r
$results[] = $data;
} }
// append to $r
$r[] = $data;
} }
// optgroup or single // optgroup or single
if( !empty($args['role']) && count($args['role']) == 1 ) { if( !empty($args['role']) && count($args['role']) == 1 ) {
$r = $r[0]['children']; $results = $results[0]['children'];
} }
// return // return
return $r; acf_send_ajax_results(array(
'results' => $results,
'limit' => $args['users_per_page']
));
} }
/*
* ajax_query
*
* description
*
* @type function
* @date 24/10/13
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function ajax_query() {
// validate
if( !acf_verify_ajax() ) die();
// get choices
$choices = $this->get_choices( $_POST );
// validate
if( !$choices ) die();
// return JSON
echo json_encode( $choices );
die();
}
/* /*
* get_result * get_result
@ -244,11 +231,7 @@ class acf_field_user extends acf_field {
function get_result( $user, $field, $post_id = 0 ) { function get_result( $user, $field, $post_id = 0 ) {
// get post_id // get post_id
if( !$post_id ) { if( !$post_id ) $post_id = acf_get_form_data('post_id');
$post_id = acf_get_setting('form_data/post_id', get_the_ID());
}
// vars // vars
@ -588,8 +571,10 @@ class acf_field_user extends acf_field {
} }
new acf_field_user();
endif; // initialize
acf_register_field_type( new acf_field_user() );
endif; // class_exists check
?> ?>

View File

@ -259,7 +259,11 @@ acf.fields.wysiwyg.toolbars = <?php echo json_encode($json); ?>;
// detect mode // detect mode
if( $field['tabs'] == 'visual' ) { if( !user_can_richedit() ) {
$show_tabs = false;
} elseif( $field['tabs'] == 'visual' ) {
// case: visual tab only // case: visual tab only
$default_editor = 'tinymce'; $default_editor = 'tinymce';
@ -462,8 +466,10 @@ acf.fields.wysiwyg.toolbars = <?php echo json_encode($json); ?>;
} }
new acf_field_wysiwyg();
endif; // initialize
acf_register_field_type( new acf_field_wysiwyg() );
endif; // class_exists check
?> ?>

View File

@ -167,20 +167,14 @@ acf.unload.active = 0;
function edit_attachment( $form_fields, $post ) { function edit_attachment( $form_fields, $post ) {
// vars // vars
$el = 'tr'; $is_page = $this->validate_page();
$post_id = $post->ID; $post_id = $post->ID;
$el = 'tr';
$args = array( $args = array(
'attachment' => $post_id 'attachment' => $post_id
); );
// $el
if( $this->validate_page() ) {
//$el = 'div';
}
// get field groups // get field groups
$field_groups = acf_get_field_groups( $args ); $field_groups = acf_get_field_groups( $args );
@ -201,6 +195,7 @@ acf.unload.active = 0;
if( $this->validate_page() ) { if( $this->validate_page() ) {
echo '<style type="text/css"> echo '<style type="text/css">
.compat-attachment-fields, .compat-attachment-fields,
.compat-attachment-fields > tbody, .compat-attachment-fields > tbody,
.compat-attachment-fields > tbody > tr, .compat-attachment-fields > tbody > tr,
@ -208,46 +203,60 @@ acf.unload.active = 0;
.compat-attachment-fields > tbody > tr > td { .compat-attachment-fields > tbody > tr > td {
display: block; display: block;
} }
tr.acf-field {
display: block; .compat-attachment-fields > tbody > tr.acf-field {
margin: 0 0 13px; margin: 0 0 15px;
} }
tr.acf-field td.acf-label {
display: block; .compat-attachment-fields > tbody > tr.acf-field > td.acf-label {
margin: 0; margin: 0;
} }
tr.acf-field td.acf-input {
display: block; .compat-attachment-fields > tbody > tr.acf-field > td.acf-label label {
margin: 0;
padding: 0;
}
.compat-attachment-fields > tbody > tr.acf-field > td.acf-label p {
margin: 0 0 3px !important;
}
.compat-attachment-fields > tbody > tr.acf-field > td.acf-input {
margin: 0; margin: 0;
} }
</style>'; </style>';
} }
// $el // open
//if( $el == 'tr' ) { echo '</td></tr>';
echo '</td></tr>';
//}
// loop
foreach( $field_groups as $field_group ) { foreach( $field_groups as $field_group ) {
// load fields
$fields = acf_get_fields( $field_group ); $fields = acf_get_fields( $field_group );
acf_render_fields( $post_id, $fields, $el, 'field' );
// override instruction placement for modal
if( !$is_page ) {
$field_group['instruction_placement'] = 'field';
}
// render
acf_render_fields( $post_id, $fields, $el, $field_group['instruction_placement'] );
} }
// $el // close
//if( $el == 'tr' ) { echo '<tr class="compat-field-acf-blank"><td>';
echo '<tr class="compat-field-acf-blank"><td>';
//}
$html = ob_get_contents(); $html = ob_get_contents();

View File

@ -483,6 +483,49 @@ if( typeof acf !== 'undefined' ) {
} }
/*
* allow_save_post
*
* This function will return true if the post is allowed to be saved
*
* @type function
* @date 26/06/2016
* @since 5.3.8
*
* @param $post_id (int)
* @return $post_id (int)
*/
function allow_save_post( $post ) {
// vars
$allow = true;
$reject = array( 'auto-draft', 'revision', 'acf-field', 'acf-field-group' );
$wp_preview = acf_maybe_get($_POST, 'wp-preview');
// check post type
if( in_array($post->post_type, $reject) ) {
$allow = false;
}
// allow preview
if( $post->post_type == 'revision' && $wp_preview === 'dopreview' ) {
$allow = true;
}
// return
return $allow;
}
/* /*
* save_post * save_post
* *
@ -498,50 +541,30 @@ if( typeof acf !== 'undefined' ) {
function save_post( $post_id, $post ) { function save_post( $post_id, $post ) {
// do not save if this is an auto save routine // bail ealry if no allowed to save this post type
if( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) { if( !$this->allow_save_post($post) ) return $post_id;
return $post_id;
}
// bail early if is acf-field-group or acf-field // ensure saving to the correct post
if( in_array($post->post_type, array('acf-field', 'acf-field-group'))) { if( !acf_verify_nonce('post', $post_id) ) return $post_id;
return $post_id;
}
// verify and remove nonce // validate for published post (allow draft to save without validation)
if( !acf_verify_nonce('post', $post_id) ) {
return $post_id;
}
// validate and save
if( get_post_status($post_id) == 'publish' ) { if( get_post_status($post_id) == 'publish' ) {
if( acf_validate_save_post(true) ) { // show errors
acf_validate_save_post( true );
acf_save_post( $post_id );
}
} else {
acf_save_post( $post_id );
} }
// save
acf_save_post( $post_id );
// return // return
return $post_id; return $post_id;
} }

View File

@ -105,7 +105,7 @@ class acf_form_user {
return; return;
} }
// load acf scripts // load acf scripts
acf_enqueue_scripts(); acf_enqueue_scripts();
@ -302,11 +302,11 @@ class acf_form_user {
.acf-field input[type="email"], .acf-field input[type="email"],
.acf-field input[type="url"], .acf-field input[type="url"],
.acf-field select { .acf-field select {
width: 25em; max-width: 25em;
} }
.acf-field textarea { .acf-field textarea {
width: 500px; max-width: 500px;
} }
@ -319,7 +319,7 @@ class acf_form_user {
.acf-field .acf-field input[type="url"], .acf-field .acf-field input[type="url"],
.acf-field .acf-field textarea, .acf-field .acf-field textarea,
.acf-field .acf-field select { .acf-field .acf-field select {
width: 100%; max-width: none;
} }
<?php else: ?> <?php else: ?>

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -79,6 +79,7 @@ class acf_pro {
acf_include('pro/fields/repeater.php'); acf_include('pro/fields/repeater.php');
acf_include('pro/fields/flexible-content.php'); acf_include('pro/fields/flexible-content.php');
acf_include('pro/fields/gallery.php'); acf_include('pro/fields/gallery.php');
acf_include('pro/fields/clone.php');
} }

View File

@ -41,10 +41,6 @@ class acf_settings_updates {
function admin_menu() { function admin_menu() {
// vars
$basename = acf_get_setting('basename');
// bail early if no show_admin // bail early if no show_admin
if( !acf_get_setting('show_admin') ) return; if( !acf_get_setting('show_admin') ) return;
@ -54,7 +50,7 @@ class acf_settings_updates {
// bail early if not a plugin (included in theme) // bail early if not a plugin (included in theme)
if( !is_plugin_active($basename) ) return; if( !acf_is_plugin_active() ) return;
// add page // add page
@ -67,6 +63,48 @@ class acf_settings_updates {
} }
/*
* show_remote_response_error
*
* This function will show an admin notice if server connection fails
*
* @type function
* @date 25/07/2016
* @since 5.4.0
*
* @param n/a
* @return n/a
*/
function show_remote_response_error() {
// only run once
if( acf_has_done('show_remote_response_error') ) return false;
// vars
$error = acf_get_setting('remote_response_error');
$notice = __('<b>Error</b>. Could not connect to update server', 'acf');
// append error
if( $error ) {
$notice .= ' <span class="description">(' . $error . ')</span>';
}
// add notice
acf_add_admin_notice( $notice, 'error' );
// return
return false;
}
/* /*
* load * load
* *
@ -121,9 +159,8 @@ class acf_settings_updates {
// validate // validate
if( empty($info) ) { if( empty($info) ) {
acf_add_admin_notice( __('<b>Error</b>. Could not connect to update server', 'acf'), 'error'); return $this->show_remote_response_error();
return;
} }
@ -141,6 +178,10 @@ class acf_settings_updates {
} }
// update transient
acf_refresh_plugin_updates_transient();
} }
@ -200,8 +241,7 @@ class acf_settings_updates {
// validate // validate
if( empty($response) ) { if( empty($response) ) {
acf_add_admin_notice( __('<b>Connection Error</b>. Sorry, please try again', 'acf'), 'error'); return $this->show_remote_response_error();
return;
} }
@ -271,8 +311,7 @@ class acf_settings_updates {
// validate // validate
if( empty($response) ) { if( empty($response) ) {
acf_add_admin_notice(__('<b>Connection Error</b>. Sorry, please try again', 'acf'), 'error'); return $this->show_remote_response_error();
return;
} }

View File

@ -36,7 +36,7 @@ function acf_get_valid_options_page( $page = '' ) {
// defaults // defaults
$page = acf_parse_args($page, array( $page = wp_parse_args($page, array(
'page_title' => '', 'page_title' => '',
'menu_title' => '', 'menu_title' => '',
'menu_slug' => '', 'menu_slug' => '',

View File

@ -84,8 +84,27 @@ function acf_pro_get_remote_response( $action = '', $post = array() ) {
)); ));
// return body // error
if( !is_wp_error($request) || wp_remote_retrieve_response_code($request) === 200) { if( is_wp_error($request) ) {
// loop
foreach( $request->errors as $k => $v ) {
// bail early if no error
if( empty($v[0]) ) continue;
// save
acf_update_setting('remote_response_error', $k . ': ' . $v[0]);
// only run once
break;
}
// success
} elseif( wp_remote_retrieve_response_code($request) === 200) {
return $request['body']; return $request['body'];

View File

@ -348,13 +348,11 @@ html[dir="rtl"] .acf-flexible-content .layout .acf-fc-layout-controlls {
/* main */ /* main */
/* attachments */ /* attachments */
/* attachment */ /* attachment */
/* hide attachment actions when sidebar is open */
/* toolbar */ /* toolbar */
/* sidebar */ /* sidebar */
/* side info */ /* side info */
/* side data */ /* side data */
/* column widths */ /* column widths */
/* column widths clear */
/* resizable */ /* resizable */
} }
.acf-gallery .acf-gallery-main { .acf-gallery .acf-gallery-main {
@ -374,16 +372,15 @@ html[dir="rtl"] .acf-flexible-content .layout .acf-fc-layout-controlls {
left: 0; left: 0;
padding: 5px; padding: 5px;
overflow: auto; overflow: auto;
overflow-x: hidden;
} }
.acf-gallery .acf-gallery-attachment { .acf-gallery .acf-gallery-attachment {
width: 25%; width: 25%;
float: left; float: left;
cursor: pointer; cursor: pointer;
position: relative; position: relative;
background: #fff;
/* sortable */ /* sortable */
/* active */ /* active */
/* audio, video */
/* icon */ /* icon */
/* rtl */ /* rtl */
} }
@ -392,16 +389,27 @@ html[dir="rtl"] .acf-flexible-content .layout .acf-fc-layout-controlls {
border: #DFDFDF solid 1px; border: #DFDFDF solid 1px;
position: relative; position: relative;
overflow: hidden; overflow: hidden;
background: #eee;
} }
.acf-gallery .acf-gallery-attachment img { .acf-gallery .acf-gallery-attachment .margin:before {
content: "";
display: block;
padding-top: 100%;
}
.acf-gallery .acf-gallery-attachment .thumbnail {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transform: translate(50%, 50%);
}
.acf-gallery .acf-gallery-attachment .thumbnail img {
display: block; display: block;
height: auto; height: auto;
max-height: 100%;
width: auto; width: auto;
max-width: 100%; transform: translate(-50%, -50%);
margin: 0 auto;
}
.acf-gallery .acf-gallery-attachment img[src$="svg"] {
background: #f9f9f9;
} }
.acf-gallery .acf-gallery-attachment .filename { .acf-gallery .acf-gallery-attachment .filename {
position: absolute; position: absolute;
@ -417,50 +425,42 @@ html[dir="rtl"] .acf-flexible-content .layout .acf-fc-layout-controlls {
word-wrap: break-word; word-wrap: break-word;
max-height: 90%; max-height: 90%;
overflow: hidden; overflow: hidden;
display: none;
} }
.acf-gallery .acf-gallery-attachment .actions { .acf-gallery .acf-gallery-attachment .actions {
position: absolute; position: absolute;
top: 0; top: 0;
right: 0; right: 0;
} }
.acf-gallery .acf-gallery-attachment.ui-sortable-placeholder { .acf-gallery .acf-gallery-attachment.ui-sortable-helper .margin {
visibility: visible !important; border: none;
background: #F1F1F1; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
} }
.acf-gallery .acf-gallery-attachment.ui-sortable-placeholder .margin { .acf-gallery .acf-gallery-attachment.ui-sortable-placeholder .margin {
visibility: hidden !important; background: #F1F1F1;
border: none;
}
.acf-gallery .acf-gallery-attachment.ui-sortable-placeholder .margin * {
display: none !important;
} }
.acf-gallery .acf-gallery-attachment.active .margin { .acf-gallery .acf-gallery-attachment.active .margin {
box-shadow: 0 0 0 1px #FFFFFF, 0 0 0 5px #1E8CBE; box-shadow: 0 0 0 1px #FFFFFF, 0 0 0 5px #1E8CBE;
} }
.acf-gallery .acf-gallery-attachment.-audio .filename, .acf-gallery .acf-gallery-attachment.-icon .thumbnail img {
.acf-gallery .acf-gallery-attachment.-video .filename { transform: translate(-50%, -70%);
display: block;
}
.acf-gallery .acf-gallery-attachment.-icon .margin:before {
content: "";
display: block;
padding-top: 100%;
}
.acf-gallery .acf-gallery-attachment.-icon .thumbnail {
position: absolute;
top: 35%;
left: 50%;
max-width: 40%;
}
.acf-gallery .acf-gallery-attachment.-icon img {
margin: -50% 0 0 -50%;
}
.acf-gallery .acf-gallery-attachment.-icon .filename {
display: block;
} }
html[dir="rtl"] .acf-gallery .acf-gallery-attachment { html[dir="rtl"] .acf-gallery .acf-gallery-attachment {
float: right; float: right;
} }
.acf-gallery.sidebar-open {
/* hide attachment actions when sidebar is open */
/* allow sidebar to move over main for small widths (widget edit box) */
}
.acf-gallery.sidebar-open .acf-gallery-attachment .actions { .acf-gallery.sidebar-open .acf-gallery-attachment .actions {
display: none; display: none;
} }
.acf-gallery.sidebar-open .acf-gallery-side {
z-index: 2;
}
.acf-gallery .acf-gallery-toolbar { .acf-gallery .acf-gallery-toolbar {
position: absolute; position: absolute;
right: 0; right: 0;
@ -608,15 +608,6 @@ html[dir="rtl"] .acf-gallery .acf-gallery-side-data th.label {
.acf-gallery[data-columns="8"] .acf-gallery-attachment { .acf-gallery[data-columns="8"] .acf-gallery-attachment {
width: 12.5%; width: 12.5%;
} }
.acf-gallery[data-columns="2"] .acf-gallery-attachment:nth-child(2n+1),
.acf-gallery[data-columns="3"] .acf-gallery-attachment:nth-child(3n+1),
.acf-gallery[data-columns="4"] .acf-gallery-attachment:nth-child(4n+1),
.acf-gallery[data-columns="5"] .acf-gallery-attachment:nth-child(5n+1),
.acf-gallery[data-columns="6"] .acf-gallery-attachment:nth-child(6n+1),
.acf-gallery[data-columns="7"] .acf-gallery-attachment:nth-child(7n+1),
.acf-gallery[data-columns="8"] .acf-gallery-attachment:nth-child(8n+1) {
clear: both;
}
.acf-gallery .ui-resizable-handle { .acf-gallery .ui-resizable-handle {
display: block; display: block;
position: absolute; position: absolute;

View File

@ -1191,6 +1191,7 @@
$main: null, $main: null,
$side: null, $side: null,
$attachments: null, $attachments: null,
$input: null,
//$attachment: null, //$attachment: null,
actions: { actions: {
@ -1235,6 +1236,7 @@
this.$main = this.$el.children('.acf-gallery-main'); this.$main = this.$el.children('.acf-gallery-main');
this.$side = this.$el.children('.acf-gallery-side'); this.$side = this.$el.children('.acf-gallery-side');
this.$attachments = this.$main.children('.acf-gallery-attachments'); this.$attachments = this.$main.children('.acf-gallery-attachments');
this.$input = this.$el.find('input:first');
// get options // get options
@ -1610,14 +1612,14 @@
* @return $post_id (int) * @return $post_id (int)
*/ */
render_attachment: function( id, data ){ render_attachment: function( data ){
// prepare // prepare
data = this.prepare(data); data = this.prepare(data);
// vars // vars
var $attachment = this.get_attachment(id), var $attachment = this.get_attachment(data.id),
$margin = $attachment.find('.margin'), $margin = $attachment.find('.margin'),
$img = $attachment.find('img'), $img = $attachment.find('img'),
$filename = $attachment.find('.filename'), $filename = $attachment.find('.filename'),
@ -1628,11 +1630,29 @@
var thumbnail = data.url; var thumbnail = data.url;
// icon // image
if( data.type !== 'image' ) { if( data.type == 'image' ) {
// remove filename
$filename.remove();
// other (video)
} else {
// attempt to find attachment thumbnail
thumbnail = acf.maybe_get(data, 'thumb.src');
// update filenmae text
$filename.text( data.filename );
}
// default icon
if( !thumbnail ) {
thumbnail = acf._e('media', 'default_icon'); thumbnail = acf._e('media', 'default_icon');
$attachment.addClass('-icon'); $attachment.addClass('-icon');
} }
@ -1644,23 +1664,10 @@
'alt': data.alt, 'alt': data.alt,
'title': data.title 'title': data.title
}); });
$filename.text(data.filename);
// vars
var val = '';
// WP attachment
if( data.id ) {
val = data.id;
}
// update val // update val
acf.val( $input, val ); acf.val( $input, data.id );
}, },
@ -1792,12 +1799,16 @@
// render data // render data
this.render_attachment( data.id, data ); this.render_attachment( data );
// render // render
this.render(); this.render();
// trigger change
this.$input.trigger('change');
}, },
@ -1910,7 +1921,7 @@
// maybe get preview size // maybe get preview size
data.url = acf.maybe_get(data, 'sizes.'+this.o.preview_size+'.url', data.url); data.url = acf.maybe_get(data, 'sizes.medium.url', data.url);
} }
@ -2226,6 +2237,10 @@
// render (update classes) // render (update classes)
this.render(); this.render();
// trigger change
this.$input.trigger('change');
}, },
@ -2274,21 +2289,16 @@
$field = this.$field; $field = this.$field;
// vars
var attachment = id,
$attachment = this.get_attachment(id);
// popup // popup
var frame = acf.media.popup({ var frame = acf.media.popup({
mode: 'edit', mode: 'edit',
title: acf._e('image', 'edit'), title: acf._e('image', 'edit'),
button: acf._e('image', 'update'), button: acf._e('image', 'update'),
attachment: attachment, attachment: id,
select: function( attachment ){ select: function( attachment ){
// render attachment // render attachment
self.set('$field', $field).render_attachment( id, attachment ); self.set('$field', $field).render_attachment( attachment );
// render sidebar // render sidebar

File diff suppressed because one or more lines are too long

1275
pro/fields/clone.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -59,6 +59,10 @@ class acf_field_flexible_content extends acf_field {
add_action('wp_ajax_nopriv_acf/fields/flexible_content/layout_title', array($this, 'ajax_layout_title')); add_action('wp_ajax_nopriv_acf/fields/flexible_content/layout_title', array($this, 'ajax_layout_title'));
// filters
add_filter('acf/clone_field', array($this, 'acf_clone_field'), 10, 2);
// do not delete! // do not delete!
parent::__construct(); parent::__construct();
@ -707,6 +711,10 @@ class acf_field_flexible_content extends acf_field {
$sub_field = $layout[ $j ]; $sub_field = $layout[ $j ];
// bail ealry if no name (tab)
if( acf_is_empty($sub_field['name']) ) continue;
// update full name // update full name
$sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}"; $sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}";
@ -795,14 +803,18 @@ class acf_field_flexible_content extends acf_field {
$sub_field = $layout[ $j ]; $sub_field = $layout[ $j ];
// update $sub_field name // bail ealry if no name (tab)
$sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}"; if( acf_is_empty($sub_field['name']) ) continue;
// extract value // extract value
$sub_value = acf_extract_var( $value[ $i ], $sub_field['key'] ); $sub_value = acf_extract_var( $value[ $i ], $sub_field['key'] );
// update $sub_field name
$sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}";
// format value // format value
$sub_value = acf_format_value( $sub_value, $post_id, $sub_field ); $sub_value = acf_format_value( $sub_value, $post_id, $sub_field );
@ -1058,7 +1070,7 @@ class acf_field_flexible_content extends acf_field {
// save false for empty value // save false for empty value
if( empty($order) ) { if( empty($order) ) {
$order = false; $order = '';
} }
@ -1291,10 +1303,10 @@ class acf_field_flexible_content extends acf_field {
// options // options
$options = acf_parse_args( $_POST, array( $options = acf_parse_args( $_POST, array(
'post_id' => 0, 'post_id' => 0,
'i' => 0, 'i' => 0,
'field_key' => '', 'field_key' => '',
'nonce' => '', 'nonce' => '',
'layout' => '', 'layout' => '',
'acf' => array() 'acf' => array()
)); ));
@ -1393,10 +1405,47 @@ class acf_field_flexible_content extends acf_field {
} }
/*
* acf_clone_field
*
* This function will update clone field settings based on the origional field
*
* @type function
* @date 28/06/2016
* @since 5.3.8
*
* @param $clone (array)
* @param $field (array)
* @return $clone
*/
function acf_clone_field( $field, $clone_field ) {
// remove parent_layout
// - allows a sub field to be rendered as a normal field
unset($field['parent_layout']);
// attempt to merger parent_layout
if( isset($clone_field['parent_layout']) ) {
$field['parent_layout'] = $clone_field['parent_layout'];
}
// return
return $field;
}
} }
new acf_field_flexible_content();
endif; // initialize
acf_register_field_type( new acf_field_flexible_content() );
endif; // class_exists check
?> ?>

View File

@ -36,7 +36,6 @@ class acf_field_gallery extends acf_field {
$this->label = __("Gallery",'acf'); $this->label = __("Gallery",'acf');
$this->category = 'content'; $this->category = 'content';
$this->defaults = array( $this->defaults = array(
'preview_size' => 'thumbnail',
'library' => 'all', 'library' => 'all',
'min' => 0, 'min' => 0,
'max' => 0, 'max' => 0,
@ -225,10 +224,10 @@ class acf_field_gallery extends acf_field {
$r = array(); $r = array();
$order = 'DESC'; $order = 'DESC';
$args = acf_parse_args( $_POST, array( $args = acf_parse_args( $_POST, array(
'ids' => 0, 'ids' => 0,
'sort' => 'date', 'sort' => 'date',
'field_key' => '', 'field_key' => '',
'nonce' => '', 'nonce' => '',
)); ));
@ -467,7 +466,6 @@ class acf_field_gallery extends acf_field {
$atts = array( $atts = array(
'id' => $field['id'], 'id' => $field['id'],
'class' => "acf-gallery {$field['class']}", 'class' => "acf-gallery {$field['class']}",
'data-preview_size' => $field['preview_size'],
'data-library' => $field['library'], 'data-library' => $field['library'],
'data-min' => $field['min'], 'data-min' => $field['min'],
'data-max' => $field['max'], 'data-max' => $field['max'],
@ -516,10 +514,14 @@ class acf_field_gallery extends acf_field {
// thumbnail // thumbnail
$thumbnail = acf_get_post_thumbnail($a['ID'], $field['preview_size']); $thumbnail = acf_get_post_thumbnail($a['ID'], 'medium');
// icon // remove filename if is image
if( $a['type'] == 'image' ) $a['filename'] = '';
// class
$a['class'] .= ' -' . $a['type']; $a['class'] .= ' -' . $a['type'];
if( $thumbnail['type'] == 'icon' ) { if( $thumbnail['type'] == 'icon' ) {
@ -536,18 +538,18 @@ class acf_field_gallery extends acf_field {
<div class="thumbnail"> <div class="thumbnail">
<img src="<?php echo $thumbnail['url']; ?>" alt="" title="<?php echo $a['title']; ?>"/> <img src="<?php echo $thumbnail['url']; ?>" alt="" title="<?php echo $a['title']; ?>"/>
</div> </div>
<div class="filename"><?php echo acf_get_truncated($a['filename'], 30); ?></div> <?php if( $a['filename'] ): ?>
<div class="filename"><?php echo acf_get_truncated($a['filename'], 30); ?></div>
<?php endif; ?>
</div> </div>
<div class="actions acf-soh-target"> <div class="actions acf-soh-target">
<a class="acf-icon -cancel dark acf-gallery-remove" href="#" data-id="<?php echo $a['ID']; ?>" title="<?php _e('Remove', 'acf'); ?>"></a> <a class="acf-icon -cancel dark acf-gallery-remove" href="#" data-id="<?php echo $a['ID']; ?>" title="<?php _e('Remove', 'acf'); ?>"></a>
</div> </div>
</div> </div>
<?php endforeach; ?> <?php endforeach; ?>
<?php endif; ?> <?php endif; ?>
</div> </div>
<div class="acf-gallery-toolbar"> <div class="acf-gallery-toolbar">
@ -650,16 +652,6 @@ class acf_field_gallery extends acf_field {
)); ));
// preview_size
acf_render_field_setting( $field, array(
'label' => __('Preview Size','acf'),
'instructions' => __('Shown when entering data','acf'),
'type' => 'select',
'name' => 'preview_size',
'choices' => acf_get_image_sizes()
));
// insert // insert
acf_render_field_setting( $field, array( acf_render_field_setting( $field, array(
'label' => __('Insert','acf'), 'label' => __('Insert','acf'),
@ -913,8 +905,10 @@ class acf_field_gallery extends acf_field {
} }
new acf_field_gallery();
endif; // initialize
acf_register_field_type( new acf_field_gallery() );
endif; // class_exists check
?> ?>

View File

@ -70,9 +70,18 @@ class acf_field_repeater extends acf_field {
function load_field( $field ) { function load_field( $field ) {
$field['sub_fields'] = acf_get_fields( $field ); // vars
$sub_fields = acf_get_fields( $field );
// append
if( $sub_fields ) {
$field['sub_fields'] = $sub_fields;
}
// return // return
return $field; return $field;
} }
@ -531,6 +540,10 @@ class acf_field_repeater extends acf_field {
$sub_field = $field['sub_fields'][ $j ]; $sub_field = $field['sub_fields'][ $j ];
// bail ealry if no name (tab)
if( acf_is_empty($sub_field['name']) ) continue;
// update $sub_field name // update $sub_field name
$sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}"; $sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}";
@ -594,14 +607,18 @@ class acf_field_repeater extends acf_field {
$sub_field = $field['sub_fields'][ $j ]; $sub_field = $field['sub_fields'][ $j ];
// update $sub_field name // bail ealry if no name (tab)
$sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}"; if( acf_is_empty($sub_field['name']) ) continue;
// extract value // extract value
$sub_value = acf_extract_var( $value[ $i ], $sub_field['key'] ); $sub_value = acf_extract_var( $value[ $i ], $sub_field['key'] );
// update $sub_field name
$sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}";
// format value // format value
$sub_value = acf_format_value( $sub_value, $post_id, $sub_field ); $sub_value = acf_format_value( $sub_value, $post_id, $sub_field );
@ -707,6 +724,10 @@ class acf_field_repeater extends acf_field {
$total = 0; $total = 0;
// bail early if no sub fields
if( empty($field['sub_fields']) ) return $value;
// remove acfcloneindex // remove acfcloneindex
if( isset($value['acfcloneindex']) ) { if( isset($value['acfcloneindex']) ) {
@ -733,14 +754,6 @@ class acf_field_repeater extends acf_field {
$total++; $total++;
// continue if no sub fields
if( !$field['sub_fields'] ) {
continue;
}
// loop through sub fields // loop through sub fields
foreach( $field['sub_fields'] as $sub_field ) { foreach( $field['sub_fields'] as $sub_field ) {
@ -812,6 +825,14 @@ class acf_field_repeater extends acf_field {
$value = $total; $value = $total;
// save false for empty value
if( empty($value) ) {
$value = '';
}
// return // return
return $value; return $value;
} }
@ -837,7 +858,7 @@ class acf_field_repeater extends acf_field {
// bail early if no rows or no sub fields // bail early if no rows or no sub fields
if( !$old_total || !$field['sub_fields'] ) { if( !$old_total || empty($field['sub_fields']) ) {
return; return;
@ -878,14 +899,14 @@ class acf_field_repeater extends acf_field {
function delete_field( $field ) { function delete_field( $field ) {
// loop through sub fields // bail early if no sub fields
if( !empty($field['sub_fields']) ) { if( empty($field['sub_fields']) ) return;
foreach( $field['sub_fields'] as $sub_field ) {
// loop through sub fields
acf_delete_field( $sub_field['ID'] ); foreach( $field['sub_fields'] as $sub_field ) {
} acf_delete_field( $sub_field['ID'] );
} }
@ -952,8 +973,10 @@ class acf_field_repeater extends acf_field {
} }
new acf_field_repeater();
endif; // initialize
acf_register_field_type( new acf_field_repeater() );
endif; // class_exists check
?> ?>

View File

@ -2,7 +2,7 @@
Contributors: elliotcondon Contributors: elliotcondon
Tags: acf, advanced, custom, field, fields, custom field, custom fields, simple fields, magic fields, more fields, repeater, edit Tags: acf, advanced, custom, field, fields, custom field, custom fields, simple fields, magic fields, more fields, repeater, edit
Requires at least: 3.6.0 Requires at least: 3.6.0
Tested up to: 4.5.2 Tested up to: 4.6.0
License: GPLv2 or later License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html License URI: http://www.gnu.org/licenses/gpl-2.0.html
@ -106,6 +106,42 @@ http://support.advancedcustomfields.com/
== Changelog == == Changelog ==
= 5.4.4 =
* WYSIWYG field: Fixed JS error when 'Disable the visual editor when writing' is checked
= 5.4.3 =
* WYSIWYG field: Fixed JS bug (since WP 4.6) causing conflicts with editor plugins
* Google Maps field: Fixed JS error conflict with Divi theme
* Radio field: Fixed bug (Chrome only) ignoring default values in cloned sub fields
* Core: Fixed `wp_get_sites()` deprecated error (since WP 4.6) shown in network admin
= 5.4.2 =
* API: Fixed bug preventing post_title and post_content values saving in `acf_form()`
= 5.4.1 =
* API: Fixed bug causing `get_fields('options')` to return false
* Core: Fixed bug causing `get_current_screen()` to throw PHP error
* Core: Fixed bug causing 'Preview Post' to load empty field values
= 5.4.0 =
* Clone field: Added new field type (https://www.advancedcustomfields.com/resources/clone/)
* Gallery field: Removed 'Preview Size' setting and improved UI
* Taxonomy field: Added compatibility to save/load terms to user object
* Select field: Added new 'Return Format' setting
* Radio field: Added new 'Return Format' setting
* Checkbox field: Added new 'Return Format' setting
* Page link field: Added new 'Allow Archives URLs' setting
* Core: Fixed plugin update bug delaying updates
* Core: Fixed bug when editing field settings in Chrome causing required setting to self toggle
* Core: Improved speed and fixed bugs when creating and restoring revisions
* Core: Minor fixes and improvements
* Language: Updated Portuguese translation - thanks to Pedro Mendonca
* Language: Updated Brazilian Portuguese translation - thanks to Augusto Simão
* Language: Updated Dutch translation - thanks to Derk Oosterveld
* Language: Updated Persian translation - thanks to Kamel
* Language: Updated German translation - thanks to Ralf Koller
* Language: Updated Swiss German translation - thanks to Raphael Hüni
= 5.3.10 = = 5.3.10 =
* Core: Added new 'google_api_key' and 'google_api_client' global settings * Core: Added new 'google_api_key' and 'google_api_client' global settings
* Google Map: Added new 'acf/fields/google_map/api' filter * Google Map: Added new 'acf/fields/google_map/api' filter