Merge branch 'release/5.5.10'
This commit is contained in:
commit
a3321fa848
13
acf.php
13
acf.php
|
|
@ -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.5.3
|
Version: 5.5.10
|
||||||
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.5.3',
|
'version' => '5.5.10',
|
||||||
|
|
||||||
// urls
|
// urls
|
||||||
'basename' => plugin_basename( __FILE__ ),
|
'basename' => plugin_basename( __FILE__ ),
|
||||||
|
|
@ -86,7 +86,8 @@ class acf {
|
||||||
'enqueue_select2' => true,
|
'enqueue_select2' => true,
|
||||||
'enqueue_datepicker' => true,
|
'enqueue_datepicker' => true,
|
||||||
'enqueue_datetimepicker' => true,
|
'enqueue_datetimepicker' => true,
|
||||||
'select2_version' => 3
|
'select2_version' => 3,
|
||||||
|
'row_index_offset' => 1
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -104,8 +105,11 @@ class acf {
|
||||||
// core
|
// core
|
||||||
acf_include('core/ajax.php');
|
acf_include('core/ajax.php');
|
||||||
acf_include('core/cache.php');
|
acf_include('core/cache.php');
|
||||||
acf_include('core/fields.php');
|
acf_include('core/compatibility.php');
|
||||||
|
acf_include('core/deprecated.php');
|
||||||
acf_include('core/field.php');
|
acf_include('core/field.php');
|
||||||
|
acf_include('core/fields.php');
|
||||||
|
acf_include('core/form.php');
|
||||||
acf_include('core/input.php');
|
acf_include('core/input.php');
|
||||||
acf_include('core/validation.php');
|
acf_include('core/validation.php');
|
||||||
acf_include('core/json.php');
|
acf_include('core/json.php');
|
||||||
|
|
@ -114,7 +118,6 @@ class acf {
|
||||||
acf_include('core/loop.php');
|
acf_include('core/loop.php');
|
||||||
acf_include('core/media.php');
|
acf_include('core/media.php');
|
||||||
acf_include('core/revisions.php');
|
acf_include('core/revisions.php');
|
||||||
acf_include('core/compatibility.php');
|
|
||||||
acf_include('core/third_party.php');
|
acf_include('core/third_party.php');
|
||||||
acf_include('core/updates.php');
|
acf_include('core/updates.php');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -697,8 +697,9 @@ class acf_admin_field_group {
|
||||||
case "post_type" :
|
case "post_type" :
|
||||||
|
|
||||||
// get post types
|
// get post types
|
||||||
|
// - removed show_ui to allow 3rd party code to register a post type using a custom admin edit page
|
||||||
$post_types = acf_get_post_types(array(
|
$post_types = acf_get_post_types(array(
|
||||||
'show_ui' => 1,
|
//'show_ui' => 1,
|
||||||
'exclude' => array('attachment')
|
'exclude' => array('attachment')
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -768,6 +768,11 @@ class acf_admin_field_groups {
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</script>
|
</script>
|
||||||
|
<script type="text/html" id="tmpl-acf-bulk-actions">
|
||||||
|
<?php // source: bulk_actions() wp-admin/includes/class-wp-list-table.php ?>
|
||||||
|
<select name="action2" id="bulk-action-selector-bottom"></select>
|
||||||
|
<?php submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction2" ) ); ?>
|
||||||
|
</script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
(function($){
|
(function($){
|
||||||
|
|
||||||
|
|
@ -775,9 +780,16 @@ class acf_admin_field_groups {
|
||||||
$('#the-list').html( $('#tmpl-acf-json-tbody').html() );
|
$('#the-list').html( $('#tmpl-acf-json-tbody').html() );
|
||||||
|
|
||||||
|
|
||||||
// modify bulk actions
|
// bulk may not exist if no field groups in DB
|
||||||
$('#bulk-action-selector-bottom option[value="edit"]').attr('value','acfsync').text('<?php _e('Sync', 'acf'); ?>');
|
if( !$('#bulk-action-selector-bottom').exists() ) {
|
||||||
$('#bulk-action-selector-bottom option[value="trash"]').remove();
|
|
||||||
|
$('.tablenav.bottom .actions.alignleft').html( $('#tmpl-acf-bulk-actions').html() );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// set only options
|
||||||
|
$('#bulk-action-selector-bottom').html('<option value="-1"><?php _e('Bulk Actions'); ?></option><option value="acfsync"><?php _e('Sync', 'acf'); ?></option>');
|
||||||
|
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -347,16 +347,6 @@ function acf_update_550() { //acf_log('acf_update_550');
|
||||||
do_action('acf/update_550');
|
do_action('acf/update_550');
|
||||||
|
|
||||||
|
|
||||||
// bail early if no table
|
|
||||||
if( !acf_isset_termmeta() ) {
|
|
||||||
|
|
||||||
update_option('acf_update_550_termmeta', 1);
|
|
||||||
echo __('Term meta upgrade not possible (termmeta table does not exist)', 'acf');
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// termmeta
|
// termmeta
|
||||||
acf_update_550_termmeta();
|
acf_update_550_termmeta();
|
||||||
|
|
||||||
|
|
@ -383,6 +373,16 @@ function acf_update_550() { //acf_log('acf_update_550');
|
||||||
|
|
||||||
function acf_update_550_termmeta() { //acf_log('acf_update_550_termmeta');
|
function acf_update_550_termmeta() { //acf_log('acf_update_550_termmeta');
|
||||||
|
|
||||||
|
// bail early if no table
|
||||||
|
if( !acf_isset_termmeta() ) {
|
||||||
|
|
||||||
|
update_option('acf_update_550_termmeta', 1); // no longer used
|
||||||
|
//echo __('Term meta upgrade not possible (termmeta table does not exist)', 'acf');
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
$taxonomies = get_taxonomies(false, 'objects');
|
$taxonomies = get_taxonomies(false, 'objects');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -288,8 +288,13 @@ class acf_admin_install {
|
||||||
|
|
||||||
function wp_upgrade( $wp_db_version, $wp_current_db_version ) {
|
function wp_upgrade( $wp_db_version, $wp_current_db_version ) {
|
||||||
|
|
||||||
// termmeta was added in 34370
|
// vars
|
||||||
if( $wp_db_version >= 34370 && $wp_current_db_version < 34370 && get_option('acf_update_550_termmeta') ) {
|
$acf_db_version = acf_get_db_version();
|
||||||
|
|
||||||
|
|
||||||
|
// termmeta was added in WP 4.4 (34370)
|
||||||
|
// if website has already updated to ACF 5.5.0, termmeta will not have yet been migrated
|
||||||
|
if( $wp_db_version >= 34370 && $wp_current_db_version < 34370 && acf_version_compare($acf_db_version, '>=', '5.5.0') ) {
|
||||||
|
|
||||||
$this->run_update('acf_update_550_termmeta');
|
$this->run_update('acf_update_550_termmeta');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ $rule_operators = apply_filters( 'acf/location/rule_operators', array(
|
||||||
<div class="acf-field">
|
<div class="acf-field">
|
||||||
<div class="acf-label">
|
<div class="acf-label">
|
||||||
<label><?php _e("Rules",'acf'); ?></label>
|
<label><?php _e("Rules",'acf'); ?></label>
|
||||||
<p><?php _e("Create a set of rules to determine which edit screens will use these advanced custom fields",'acf'); ?></p>
|
<p class="description"><?php _e("Create a set of rules to determine which edit screens will use these advanced custom fields",'acf'); ?></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="acf-input">
|
<div class="acf-input">
|
||||||
<div class="rule-groups">
|
<div class="rule-groups">
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,10 @@ $field_groups = acf_extract_var( $args, 'field_groups');
|
||||||
|
|
||||||
// replace
|
// replace
|
||||||
$str_replace = array(
|
$str_replace = array(
|
||||||
" " => "\t",
|
" " => "\t",
|
||||||
"!!\'" => "'",
|
"'!!__(!!\'" => "__('",
|
||||||
"'!!" => "",
|
"!!\', !!\'" => "', '",
|
||||||
"!!'" => ""
|
"!!\')!!'" => "')"
|
||||||
);
|
);
|
||||||
|
|
||||||
$preg_replace = array(
|
$preg_replace = array(
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ function acf_get_valid_field_group( $field_group = false ) {
|
||||||
|
|
||||||
|
|
||||||
// filter
|
// filter
|
||||||
$field_group = apply_filters('acf/get_valid_field_group', $field_group);
|
$field_group = apply_filters('acf/validate_field_group', $field_group);
|
||||||
|
|
||||||
|
|
||||||
// translate
|
// translate
|
||||||
|
|
@ -335,6 +335,10 @@ function acf_get_field_group( $selector = null ) {
|
||||||
if( !$field_group ) return false;
|
if( !$field_group ) return false;
|
||||||
|
|
||||||
|
|
||||||
|
// validate
|
||||||
|
$field_group = acf_get_valid_field_group( $field_group );
|
||||||
|
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
||||||
|
|
@ -375,11 +379,7 @@ function _acf_get_field_group_by_id( $post_id = 0 ) {
|
||||||
|
|
||||||
|
|
||||||
// bail early if no post, or is not a field group
|
// bail early if no post, or is not a field group
|
||||||
if( empty($post) || $post->post_type != 'acf-field-group' ) {
|
if( empty($post) || $post->post_type != 'acf-field-group' ) return false;
|
||||||
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// modify post_status (new field-group starts as auto-draft)
|
// modify post_status (new field-group starts as auto-draft)
|
||||||
|
|
@ -406,22 +406,22 @@ function _acf_get_field_group_by_id( $post_id = 0 ) {
|
||||||
$field_group['active'] = ($post->post_status === 'publish') ? 1 : 0;
|
$field_group['active'] = ($post->post_status === 'publish') ? 1 : 0;
|
||||||
|
|
||||||
|
|
||||||
// is JSON
|
// override with JSON
|
||||||
if( acf_is_local_field_group( $field_group['key'] ) ) {
|
if( acf_is_local_field_group( $field_group['key'] ) ) {
|
||||||
|
|
||||||
// override
|
// load JSON field
|
||||||
$field_group = acf_get_local_field_group( $field_group['key'] );
|
$local = acf_get_local_field_group( $field_group['key'] );
|
||||||
|
|
||||||
|
|
||||||
// restore ID
|
// restore ID
|
||||||
$field_group['ID'] = $post->ID;
|
$local['ID'] = $post->ID;
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return $local;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// validate
|
|
||||||
$field_group = acf_get_valid_field_group( $field_group );
|
|
||||||
|
|
||||||
|
|
||||||
// return
|
// return
|
||||||
return $field_group;
|
return $field_group;
|
||||||
|
|
@ -444,23 +444,43 @@ function _acf_get_field_group_by_id( $post_id = 0 ) {
|
||||||
|
|
||||||
function _acf_get_field_group_by_key( $key = '' ) {
|
function _acf_get_field_group_by_key( $key = '' ) {
|
||||||
|
|
||||||
// vars
|
|
||||||
$field_group = false;
|
|
||||||
|
|
||||||
|
|
||||||
// try JSON before DB to save query time
|
// try JSON before DB to save query time
|
||||||
if( acf_is_local_field_group( $key ) ) {
|
if( acf_is_local_field_group( $key ) ) {
|
||||||
|
|
||||||
$field_group = acf_get_local_field_group( $key );
|
return acf_get_local_field_group( $key );
|
||||||
|
|
||||||
// validate
|
|
||||||
$field_group = acf_get_valid_field_group( $field_group );
|
|
||||||
|
|
||||||
// return
|
|
||||||
return $field_group;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// vars
|
||||||
|
$post_id = acf_get_field_group_id( $key );
|
||||||
|
|
||||||
|
|
||||||
|
// bail early if no post_id
|
||||||
|
if( !$post_id ) return false;
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return _acf_get_field_group_by_id( $post_id );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* acf_get_field_group_id
|
||||||
|
*
|
||||||
|
* This function will lookup a field group's ID from the DB
|
||||||
|
* Useful for local fields to find DB sibling
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 25/06/2015
|
||||||
|
* @since 5.5.8
|
||||||
|
*
|
||||||
|
* @param $key (string)
|
||||||
|
* @return $post_id (int)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function acf_get_field_group_id( $key = '' ) {
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
$args = array(
|
$args = array(
|
||||||
|
|
@ -479,19 +499,11 @@ function _acf_get_field_group_by_key( $key = '' ) {
|
||||||
|
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
if( empty($posts[0]) ) {
|
if( empty($posts) ) return 0;
|
||||||
|
|
||||||
return $field_group;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// load from ID
|
|
||||||
$field_group = _acf_get_field_group_by_id( $posts[0]->ID );
|
|
||||||
|
|
||||||
|
|
||||||
// return
|
// return
|
||||||
return $field_group;
|
return $posts[0]->ID;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1153,8 +1165,11 @@ function acf_import_field_group( $field_group ) {
|
||||||
|
|
||||||
function acf_prepare_field_group_for_export( $field_group ) {
|
function acf_prepare_field_group_for_export( $field_group ) {
|
||||||
|
|
||||||
// extract field group ID
|
// extract some args
|
||||||
$id = acf_extract_var( $field_group, 'ID' );
|
$extract = acf_extract_vars($field_group, array(
|
||||||
|
'ID',
|
||||||
|
'local' // local may have added 'php' or 'json'
|
||||||
|
));
|
||||||
|
|
||||||
|
|
||||||
// prepare fields
|
// prepare fields
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ function acf_is_field_key( $key = '' ) {
|
||||||
|
|
||||||
|
|
||||||
// special - allow local field key to be any string
|
// special - allow local field key to be any string
|
||||||
if( acf_is_local_field($key) ) return true;
|
if( acf_is_local_field_key($key) ) return true;
|
||||||
|
|
||||||
|
|
||||||
// return
|
// return
|
||||||
|
|
@ -76,16 +76,18 @@ function acf_get_valid_field( $field = false ) {
|
||||||
'class' => '',
|
'class' => '',
|
||||||
'conditional_logic' => 0,
|
'conditional_logic' => 0,
|
||||||
'parent' => 0,
|
'parent' => 0,
|
||||||
'wrapper' => array(
|
'wrapper' => array(),
|
||||||
'width' => '',
|
|
||||||
'class' => '',
|
|
||||||
'id' => ''
|
|
||||||
),
|
|
||||||
'_name' => '',
|
'_name' => '',
|
||||||
'_prepare' => 0,
|
'_prepare' => 0,
|
||||||
'_valid' => 0,
|
'_valid' => 0,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$field['wrapper'] = wp_parse_args($field['wrapper'], array(
|
||||||
|
'width' => '',
|
||||||
|
'class' => '',
|
||||||
|
'id' => ''
|
||||||
|
));
|
||||||
|
|
||||||
|
|
||||||
// _name
|
// _name
|
||||||
$field['_name'] = $field['name'];
|
$field['_name'] = $field['name'];
|
||||||
|
|
@ -96,8 +98,8 @@ function acf_get_valid_field( $field = false ) {
|
||||||
|
|
||||||
|
|
||||||
// field specific defaults
|
// field specific defaults
|
||||||
$field = apply_filters( "acf/get_valid_field", $field );
|
$field = apply_filters( "acf/validate_field", $field );
|
||||||
$field = apply_filters( "acf/get_valid_field/type={$field['type']}", $field );
|
$field = apply_filters( "acf/validate_field/type={$field['type']}", $field );
|
||||||
|
|
||||||
|
|
||||||
// translate
|
// translate
|
||||||
|
|
@ -973,6 +975,14 @@ function _acf_get_field_by_key( $key = '', $db_only = false ) {
|
||||||
|
|
||||||
function _acf_get_field_by_name( $name = '', $db_only = false ) {
|
function _acf_get_field_by_name( $name = '', $db_only = false ) {
|
||||||
|
|
||||||
|
// try JSON before DB to save query time
|
||||||
|
if( !$db_only && acf_is_local_field( $name ) ) {
|
||||||
|
|
||||||
|
return acf_get_local_field( $name );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
$args = array(
|
$args = array(
|
||||||
'posts_per_page' => 1,
|
'posts_per_page' => 1,
|
||||||
|
|
@ -1657,6 +1667,7 @@ function acf_prepare_field_for_export( $field ) {
|
||||||
|
|
||||||
// filter for 3rd party customization
|
// filter for 3rd party customization
|
||||||
$field = apply_filters( "acf/prepare_field_for_export", $field );
|
$field = apply_filters( "acf/prepare_field_for_export", $field );
|
||||||
|
$field = apply_filters( "acf/prepare_field_for_export/type={$field['type']}", $field );
|
||||||
|
|
||||||
|
|
||||||
// return
|
// return
|
||||||
|
|
@ -1755,6 +1766,7 @@ function acf_prepare_field_for_import( $field ) {
|
||||||
|
|
||||||
// filter for 3rd party customization
|
// filter for 3rd party customization
|
||||||
$field = apply_filters( "acf/prepare_field_for_import", $field );
|
$field = apply_filters( "acf/prepare_field_for_import", $field );
|
||||||
|
$field = apply_filters( "acf/prepare_field_for_import/type={$field['type']}", $field );
|
||||||
|
|
||||||
|
|
||||||
// return
|
// return
|
||||||
|
|
@ -1847,6 +1859,7 @@ function acf_maybe_get_sub_field( $selectors, $post_id = false, $strict = true )
|
||||||
|
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
|
$offset = acf_get_setting('row_index_offset');
|
||||||
$selector = acf_extract_var( $selectors, 0 );
|
$selector = acf_extract_var( $selectors, 0 );
|
||||||
$selectors = array_values( $selectors ); // reset keys
|
$selectors = array_values( $selectors ); // reset keys
|
||||||
|
|
||||||
|
|
@ -1866,7 +1879,7 @@ function acf_maybe_get_sub_field( $selectors, $post_id = false, $strict = true )
|
||||||
$sub_i = $selectors[ $j ];
|
$sub_i = $selectors[ $j ];
|
||||||
$sub_s = $selectors[ $j+1 ];
|
$sub_s = $selectors[ $j+1 ];
|
||||||
$field_name = $field['name'];
|
$field_name = $field['name'];
|
||||||
|
|
||||||
|
|
||||||
// find sub field
|
// find sub field
|
||||||
$field = acf_get_sub_field( $sub_s, $field );
|
$field = acf_get_sub_field( $sub_s, $field );
|
||||||
|
|
@ -1877,7 +1890,7 @@ function acf_maybe_get_sub_field( $selectors, $post_id = false, $strict = true )
|
||||||
|
|
||||||
|
|
||||||
// add to name
|
// add to name
|
||||||
$field['name'] = $field_name . '_' . ($sub_i-1) . '_' . $field['name'];
|
$field['name'] = $field_name . '_' . ($sub_i-$offset) . '_' . $field['name'];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -238,6 +238,73 @@ function acf_include( $file ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* acf_get_external_path
|
||||||
|
*
|
||||||
|
* This function will return the path to a file within an external folder
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 22/2/17
|
||||||
|
* @since 5.5.8
|
||||||
|
*
|
||||||
|
* @param $file (string)
|
||||||
|
* @param $path (string)
|
||||||
|
* @return (string)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function acf_get_external_path( $file, $path = '' ) {
|
||||||
|
|
||||||
|
return trailingslashit( dirname( $file ) ) . $path;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* acf_get_external_dir
|
||||||
|
*
|
||||||
|
* This function will return the url to a file within an external folder
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 22/2/17
|
||||||
|
* @since 5.5.8
|
||||||
|
*
|
||||||
|
* @param $file (string)
|
||||||
|
* @param $path (string)
|
||||||
|
* @return (string)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function acf_get_external_dir( $file, $path = '' ) {
|
||||||
|
|
||||||
|
// vars
|
||||||
|
$external_url = '';
|
||||||
|
$external_path = acf_get_external_path( $file, $path );
|
||||||
|
$wp_plugin_path = wp_normalize_path(WP_PLUGIN_DIR);
|
||||||
|
$wp_content_path = wp_normalize_path(WP_CONTENT_DIR);
|
||||||
|
$wp_path = wp_normalize_path(ABSPATH);
|
||||||
|
|
||||||
|
|
||||||
|
// wp-content/plugins
|
||||||
|
if( strpos($external_path, $wp_plugin_path) === 0 ) {
|
||||||
|
|
||||||
|
return str_replace($wp_plugin_path, plugins_url(), $external_path);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// wp-content
|
||||||
|
if( strpos($external_path, $wp_content_path) === 0 ) {
|
||||||
|
|
||||||
|
return str_replace($wp_content_path, content_url(), $external_path);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return str_replace($wp_path, home_url(), $external_path);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* acf_parse_args
|
* acf_parse_args
|
||||||
*
|
*
|
||||||
|
|
@ -626,7 +693,7 @@ function acf_get_post_types( $args = array() ) {
|
||||||
$exclude[] = 'acf-field';
|
$exclude[] = 'acf-field';
|
||||||
$exclude[] = 'acf-field-group';
|
$exclude[] = 'acf-field-group';
|
||||||
|
|
||||||
|
|
||||||
// loop
|
// loop
|
||||||
foreach( $post_types as $i => $post_type ) {
|
foreach( $post_types as $i => $post_type ) {
|
||||||
|
|
||||||
|
|
@ -1339,7 +1406,7 @@ function acf_decode_taxonomy_terms( $strings = false ) {
|
||||||
/*
|
/*
|
||||||
* acf_decode_taxonomy_term
|
* acf_decode_taxonomy_term
|
||||||
*
|
*
|
||||||
* This function will convert a term string into an array of term data
|
* This function will return the taxonomy and term slug for a given value
|
||||||
*
|
*
|
||||||
* @type function
|
* @type function
|
||||||
* @date 31/03/2014
|
* @date 31/03/2014
|
||||||
|
|
@ -1349,34 +1416,71 @@ function acf_decode_taxonomy_terms( $strings = false ) {
|
||||||
* @return (array)
|
* @return (array)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function acf_decode_taxonomy_term( $string ) {
|
function acf_decode_taxonomy_term( $value ) {
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
$r = array();
|
$data = array(
|
||||||
|
'taxonomy' => '',
|
||||||
|
'term' => ''
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
// vars
|
// int
|
||||||
$data = explode(':', $string);
|
if( is_numeric($value) ) {
|
||||||
$taxonomy = 'category';
|
|
||||||
$term = '';
|
|
||||||
|
|
||||||
|
|
||||||
// check data
|
|
||||||
if( isset($data[1]) ) {
|
|
||||||
|
|
||||||
$taxonomy = $data[0];
|
$data['term'] = $value;
|
||||||
$term = $data[1];
|
|
||||||
|
// string
|
||||||
|
} elseif( is_string($value) ) {
|
||||||
|
|
||||||
|
$value = explode(':', $value);
|
||||||
|
$data['taxonomy'] = isset($value[0]) ? $value[0] : '';
|
||||||
|
$data['term'] = isset($value[1]) ? $value[1] : '';
|
||||||
|
|
||||||
|
// error
|
||||||
|
} else {
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// add data to $r
|
// allow for term_id (Used by ACF v4)
|
||||||
$r['taxonomy'] = $taxonomy;
|
if( is_numeric($data['term']) ) {
|
||||||
$r['term'] = $term;
|
|
||||||
|
// global
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
|
|
||||||
|
// find taxonomy
|
||||||
|
if( !$data['taxonomy'] ) {
|
||||||
|
|
||||||
|
$data['taxonomy'] = $wpdb->get_var( $wpdb->prepare("SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d LIMIT 1", $data['term']) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// find term (may have numeric slug '123')
|
||||||
|
$term = get_term_by( 'slug', $data['term'], $data['taxonomy'] );
|
||||||
|
|
||||||
|
|
||||||
|
// attempt get term via ID (ACF4 uses ID)
|
||||||
|
if( !$term ) $term = get_term( $data['term'], $data['taxonomy'] );
|
||||||
|
|
||||||
|
|
||||||
|
// bail early if no term
|
||||||
|
if( !$term ) return false;
|
||||||
|
|
||||||
|
|
||||||
|
// update
|
||||||
|
$data['taxonomy'] = $term->taxonomy;
|
||||||
|
$data['term'] = $term->slug;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// return
|
// return
|
||||||
return $r;
|
return $data;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1490,9 +1594,11 @@ function acf_get_posts( $args = array() ) {
|
||||||
// defaults
|
// defaults
|
||||||
// leave suppress_filters as true becuase we don't want any plugins to modify the query as we know exactly what
|
// leave suppress_filters as true becuase we don't want any plugins to modify the query as we know exactly what
|
||||||
$args = wp_parse_args( $args, array(
|
$args = wp_parse_args( $args, array(
|
||||||
'posts_per_page' => -1,
|
'posts_per_page' => -1,
|
||||||
'post_type' => '',
|
'post_type' => '',
|
||||||
'post_status' => 'any'
|
'post_status' => 'any',
|
||||||
|
'update_post_meta_cache' => false,
|
||||||
|
'update_post_term_cache' => false
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -2145,7 +2251,7 @@ function acf_json_encode( $json ) {
|
||||||
// PHP at least 5.4
|
// PHP at least 5.4
|
||||||
if( version_compare(PHP_VERSION, '5.4.0', '>=') ) {
|
if( version_compare(PHP_VERSION, '5.4.0', '>=') ) {
|
||||||
|
|
||||||
return json_encode($json, JSON_PRETTY_PRINT);
|
return json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2837,6 +2943,10 @@ function acf_in_array( $value = '', $array = false ) {
|
||||||
|
|
||||||
function acf_get_valid_post_id( $post_id = 0 ) {
|
function acf_get_valid_post_id( $post_id = 0 ) {
|
||||||
|
|
||||||
|
// vars
|
||||||
|
$_post_id = $post_id;
|
||||||
|
|
||||||
|
|
||||||
// if not $post_id, load queried object
|
// if not $post_id, load queried object
|
||||||
if( !$post_id ) {
|
if( !$post_id ) {
|
||||||
|
|
||||||
|
|
@ -2869,8 +2979,8 @@ function acf_get_valid_post_id( $post_id = 0 ) {
|
||||||
|
|
||||||
// term
|
// term
|
||||||
} elseif( isset($post_id->taxonomy, $post_id->term_id) ) {
|
} elseif( isset($post_id->taxonomy, $post_id->term_id) ) {
|
||||||
|
|
||||||
$post_id = 'term_' . $post_id->term_id;
|
$post_id = acf_get_term_post_id( $post_id->taxonomy, $post_id->term_id );
|
||||||
|
|
||||||
// comment
|
// comment
|
||||||
} elseif( isset($post_id->comment_ID) ) {
|
} elseif( isset($post_id->comment_ID) ) {
|
||||||
|
|
@ -2910,43 +3020,9 @@ function acf_get_valid_post_id( $post_id = 0 ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Override for preview
|
|
||||||
*
|
|
||||||
* If the $_GET['preview_id'] is set, then the user wants to see the preview data.
|
|
||||||
* There is also the case of previewing a page with post_id = 1, but using get_field
|
|
||||||
* to load data from another post_id.
|
|
||||||
* In this case, we need to make sure that the autosave revision is actually related
|
|
||||||
* to the $post_id variable. If they match, then the autosave data will be used, otherwise,
|
|
||||||
* the user wants to load data from a completely different post_id
|
|
||||||
*/
|
|
||||||
|
|
||||||
if( isset($_GET['preview_id']) ) {
|
|
||||||
|
|
||||||
$autosave = wp_get_post_autosave( $_GET['preview_id'] );
|
|
||||||
|
|
||||||
if( $autosave && $autosave->post_parent == $post_id ) {
|
|
||||||
|
|
||||||
$post_id = (int) $autosave->ID;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} elseif( isset($_GET['p']) && isset($_GET['preview']) ) {
|
|
||||||
|
|
||||||
$revision = acf_get_post_latest_revision( $_GET['p'] );
|
|
||||||
|
|
||||||
// save
|
|
||||||
if( $revision && $revision->post_parent == $post_id) {
|
|
||||||
|
|
||||||
$post_id = (int) $revision->ID;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// filter for 3rd party
|
// filter for 3rd party
|
||||||
$post_id = apply_filters('acf/get_valid_post_id', $post_id);
|
$post_id = apply_filters('acf/validate_post_id', $post_id, $_post_id);
|
||||||
|
|
||||||
|
|
||||||
// return
|
// return
|
||||||
|
|
@ -3001,7 +3077,7 @@ function acf_get_post_id_info( $post_id = 0 ) {
|
||||||
$type = explode($glue, $post_id);
|
$type = explode($glue, $post_id);
|
||||||
$id = array_pop($type);
|
$id = array_pop($type);
|
||||||
$type = implode($glue, $type);
|
$type = implode($glue, $type);
|
||||||
$meta = array('post', 'user', 'comment', 'term'); // add in 'term'
|
$meta = array('post', 'user', 'comment', 'term');
|
||||||
|
|
||||||
|
|
||||||
// check if is taxonomy (ACF < 5.5)
|
// check if is taxonomy (ACF < 5.5)
|
||||||
|
|
@ -3035,6 +3111,7 @@ function acf_get_post_id_info( $post_id = 0 ) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
acf_log( acf_get_post_id_info(4) );
|
acf_log( acf_get_post_id_info(4) );
|
||||||
|
|
@ -3088,6 +3165,36 @@ function acf_isset_termmeta( $taxonomy = '' ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* acf_get_term_post_id
|
||||||
|
*
|
||||||
|
* This function will return a valid post_id string for a given term and taxonomy
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 6/2/17
|
||||||
|
* @since 5.5.6
|
||||||
|
*
|
||||||
|
* @param $taxonomy (string)
|
||||||
|
* @param $term_id (int)
|
||||||
|
* @return (string)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function acf_get_term_post_id( $taxonomy, $term_id ) {
|
||||||
|
|
||||||
|
// WP < 4.4
|
||||||
|
if( !acf_isset_termmeta() ) {
|
||||||
|
|
||||||
|
return $taxonomy . '_' . $term_id;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return 'term_' . $term_id;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* acf_upload_files
|
* acf_upload_files
|
||||||
*
|
*
|
||||||
|
|
@ -3845,7 +3952,8 @@ function acf_validate_attachment( $attachment, $field, $context = 'prepare' ) {
|
||||||
// custom
|
// custom
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$file = wp_parse_args($file, $attachment);
|
$file = array_merge($file, $attachment);
|
||||||
|
$file['type'] = pathinfo($attachment['url'], PATHINFO_EXTENSION);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -4105,7 +4213,8 @@ function acf_translate( $string ) {
|
||||||
function acf_maybe_add_action( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) {
|
function acf_maybe_add_action( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) {
|
||||||
|
|
||||||
// if action has already run, execute it
|
// if action has already run, execute it
|
||||||
if( did_action($tag) ) {
|
// - if currently doing action, allow $tag to be added as per usual to allow $priority ordering needed for 3rd party asset compatibility
|
||||||
|
if( did_action($tag) && !doing_action($tag) ) {
|
||||||
|
|
||||||
call_user_func( $function_to_add );
|
call_user_func( $function_to_add );
|
||||||
|
|
||||||
|
|
@ -4913,4 +5022,151 @@ function _acf_settings_slug( $v ) {
|
||||||
return $slug;
|
return $slug;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* acf_strip_protocol
|
||||||
|
*
|
||||||
|
* This function will remove the proticol from a url
|
||||||
|
* Used to allow licences to remain active if a site is switched to https
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 10/01/2017
|
||||||
|
* @since 5.5.4
|
||||||
|
* @author Aaron
|
||||||
|
*
|
||||||
|
* @param $url (string)
|
||||||
|
* @return (string)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function acf_strip_protocol( $url ) {
|
||||||
|
|
||||||
|
// strip the protical
|
||||||
|
return str_replace(array('http://','https://'), '', $url);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* acf_connect_attachment_to_post
|
||||||
|
*
|
||||||
|
* This function will connect an attacment (image etc) to the post
|
||||||
|
* Used to connect attachements uploaded directly to media that have not been attaced to a post
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 11/01/2017
|
||||||
|
* @since 5.5.4
|
||||||
|
*
|
||||||
|
* @param $attachment_id (int)
|
||||||
|
* @param $post_id (int)
|
||||||
|
* @return (boolean)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function acf_connect_attachment_to_post( $attachment_id = 0, $post_id = 0 ) {
|
||||||
|
|
||||||
|
// bail ealry if $attachment_id is not valid
|
||||||
|
if( !$attachment_id || !is_numeric($attachment_id) ) return false;
|
||||||
|
|
||||||
|
|
||||||
|
// bail ealry if $post_id is not valid
|
||||||
|
if( !$post_id || !is_numeric($post_id) ) return false;
|
||||||
|
|
||||||
|
|
||||||
|
// vars
|
||||||
|
$post = get_post( $attachment_id );
|
||||||
|
|
||||||
|
|
||||||
|
// check if valid post
|
||||||
|
if( $post && $post->post_type == 'attachment' && $post->post_parent == 0 ) {
|
||||||
|
|
||||||
|
// update
|
||||||
|
wp_update_post( array('ID' => $post->ID, 'post_parent' => $post_id) );
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* acf_encrypt
|
||||||
|
*
|
||||||
|
* This function will encrypt a string using PHP
|
||||||
|
* https://bhoover.com/using-php-openssl_encrypt-openssl_decrypt-encrypt-decrypt-data/
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 27/2/17
|
||||||
|
* @since 5.5.8
|
||||||
|
*
|
||||||
|
* @param $data (string)
|
||||||
|
* @return (string)
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
function acf_encrypt( $data = '' ) {
|
||||||
|
|
||||||
|
// bail ealry if no encrypt function
|
||||||
|
if( !function_exists('openssl_encrypt') ) return base64_encode($data);
|
||||||
|
|
||||||
|
|
||||||
|
// generate a key
|
||||||
|
$key = wp_hash('acf_encrypt');
|
||||||
|
|
||||||
|
|
||||||
|
// Generate an initialization vector
|
||||||
|
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
|
||||||
|
|
||||||
|
|
||||||
|
// Encrypt the data using AES 256 encryption in CBC mode using our encryption key and initialization vector.
|
||||||
|
$encrypted_data = openssl_encrypt($data, 'aes-256-cbc', $key, 0, $iv);
|
||||||
|
|
||||||
|
|
||||||
|
// The $iv is just as important as the key for decrypting, so save it with our encrypted data using a unique separator (::)
|
||||||
|
return base64_encode($encrypted_data . '::' . $iv);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* acf_decrypt
|
||||||
|
*
|
||||||
|
* This function will decrypt an encrypted string using PHP
|
||||||
|
* https://bhoover.com/using-php-openssl_encrypt-openssl_decrypt-encrypt-decrypt-data/
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 27/2/17
|
||||||
|
* @since 5.5.8
|
||||||
|
*
|
||||||
|
* @param $data (string)
|
||||||
|
* @return (string)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function acf_decrypt( $data = '' ) {
|
||||||
|
|
||||||
|
// bail ealry if no decrypt function
|
||||||
|
if( !function_exists('openssl_decrypt') ) return base64_decode($data);
|
||||||
|
|
||||||
|
|
||||||
|
// generate a key
|
||||||
|
$key = wp_hash('acf_encrypt');
|
||||||
|
|
||||||
|
|
||||||
|
// To decrypt, split the encrypted data from our IV - our unique separator used was "::"
|
||||||
|
list($encrypted_data, $iv) = explode('::', base64_decode($data), 2);
|
||||||
|
|
||||||
|
|
||||||
|
// decrypt
|
||||||
|
return openssl_decrypt($encrypted_data, 'aes-256-cbc', $key, 0, $iv);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
|
|
@ -627,10 +627,11 @@ function get_row_index() {
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
$i = acf_get_loop('active', 'i');
|
$i = acf_get_loop('active', 'i');
|
||||||
|
$offset = acf_get_setting('row_index_offset');
|
||||||
|
|
||||||
|
|
||||||
// return
|
// return
|
||||||
return $i + 1;
|
return $offset + $i;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -946,8 +947,8 @@ function get_row_layout() {
|
||||||
* @return (string)
|
* @return (string)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function acf_shortcode( $atts )
|
function acf_shortcode( $atts ) {
|
||||||
{
|
|
||||||
// extract attributs
|
// extract attributs
|
||||||
extract( shortcode_atts( array(
|
extract( shortcode_atts( array(
|
||||||
'field' => '',
|
'field' => '',
|
||||||
|
|
@ -960,594 +961,20 @@ function acf_shortcode( $atts )
|
||||||
$value = get_field( $field, $post_id, $format_value );
|
$value = get_field( $field, $post_id, $format_value );
|
||||||
|
|
||||||
|
|
||||||
if( is_array($value) )
|
// array
|
||||||
{
|
if( is_array($value) ) {
|
||||||
|
|
||||||
$value = @implode( ', ', $value );
|
$value = @implode( ', ', $value );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
return $value;
|
return $value;
|
||||||
}
|
|
||||||
add_shortcode( 'acf', 'acf_shortcode' );
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* acf_template_form
|
|
||||||
*
|
|
||||||
* This class contains funcitonality for a template form to work
|
|
||||||
*
|
|
||||||
* @type function
|
|
||||||
* @date 7/09/2016
|
|
||||||
* @since 5.4.0
|
|
||||||
*
|
|
||||||
* @param $post_id (int)
|
|
||||||
* @return $post_id (int)
|
|
||||||
*/
|
|
||||||
|
|
||||||
if( ! class_exists('acf_template_form') ) :
|
|
||||||
|
|
||||||
class acf_template_form {
|
|
||||||
|
|
||||||
// vars
|
|
||||||
var $fields;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* __construct
|
|
||||||
*
|
|
||||||
* This function will setup the class functionality
|
|
||||||
*
|
|
||||||
* @type function
|
|
||||||
* @date 5/03/2014
|
|
||||||
* @since 5.0.0
|
|
||||||
*
|
|
||||||
* @param n/a
|
|
||||||
* @return n/a
|
|
||||||
*/
|
|
||||||
|
|
||||||
function __construct() {
|
|
||||||
|
|
||||||
// vars
|
|
||||||
$this->fields = array(
|
|
||||||
|
|
||||||
'_post_title' => array(
|
|
||||||
'prefix' => 'acf',
|
|
||||||
'name' => '_post_title',
|
|
||||||
'key' => '_post_title',
|
|
||||||
'label' => __('Title', 'acf'),
|
|
||||||
'type' => 'text',
|
|
||||||
'required' => true,
|
|
||||||
),
|
|
||||||
|
|
||||||
'_post_content' => array(
|
|
||||||
'prefix' => 'acf',
|
|
||||||
'name' => '_post_content',
|
|
||||||
'key' => '_post_content',
|
|
||||||
'label' => __('Content', 'acf'),
|
|
||||||
'type' => 'wysiwyg',
|
|
||||||
),
|
|
||||||
|
|
||||||
'_validate_email' => array(
|
|
||||||
'prefix' => 'acf',
|
|
||||||
'name' => '_validate_email',
|
|
||||||
'key' => '_validate_email',
|
|
||||||
'label' => __('Validate Email', 'acf'),
|
|
||||||
'type' => 'text',
|
|
||||||
'value' => '',
|
|
||||||
'wrapper' => array('style' => 'display:none !important;')
|
|
||||||
)
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
// actions
|
|
||||||
add_action('acf/validate_save_post', array($this, 'validate_save_post'), 1);
|
|
||||||
|
|
||||||
|
|
||||||
// filters
|
|
||||||
add_filter('acf/pre_save_post', array($this, 'pre_save_post'), 5, 2);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* validate_save_post
|
|
||||||
*
|
|
||||||
* This function will validate fields from the above array
|
|
||||||
*
|
|
||||||
* @type function
|
|
||||||
* @date 7/09/2016
|
|
||||||
* @since 5.4.0
|
|
||||||
*
|
|
||||||
* @param $post_id (int)
|
|
||||||
* @return $post_id (int)
|
|
||||||
*/
|
|
||||||
|
|
||||||
function validate_save_post() {
|
|
||||||
|
|
||||||
// register field if isset in $_POST
|
|
||||||
foreach( $this->fields as $k => $field ) {
|
|
||||||
|
|
||||||
// bail early if no in $_POST
|
|
||||||
if( !isset($_POST['acf'][ $k ]) ) continue;
|
|
||||||
|
|
||||||
|
|
||||||
// register
|
|
||||||
acf_add_local_field($field);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// honeypot
|
|
||||||
if( !empty($_POST['acf']['_validate_email']) ) {
|
|
||||||
|
|
||||||
acf_add_validation_error( '', __('Spam Detected', 'acf') );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* pre_save_post
|
|
||||||
*
|
|
||||||
* description
|
|
||||||
*
|
|
||||||
* @type function
|
|
||||||
* @date 7/09/2016
|
|
||||||
* @since 5.4.0
|
|
||||||
*
|
|
||||||
* @param $post_id (int)
|
|
||||||
* @return $post_id (int)
|
|
||||||
*/
|
|
||||||
|
|
||||||
function pre_save_post( $post_id, $form ) {
|
|
||||||
|
|
||||||
// vars
|
|
||||||
$save = array(
|
|
||||||
'ID' => 0
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
// determine save data
|
|
||||||
if( is_numeric($post_id) ) {
|
|
||||||
|
|
||||||
// update post
|
|
||||||
$save['ID'] = $post_id;
|
|
||||||
|
|
||||||
} elseif( $post_id == 'new_post' ) {
|
|
||||||
|
|
||||||
// new post
|
|
||||||
$form['new_post'] = wp_parse_args( $form['new_post'], array(
|
|
||||||
'post_type' => 'post',
|
|
||||||
'post_status' => 'draft',
|
|
||||||
));
|
|
||||||
|
|
||||||
|
|
||||||
// merge in new post data
|
|
||||||
$save = array_merge($save, $form['new_post']);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// not post
|
|
||||||
return $post_id;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// save post_title
|
|
||||||
if( isset($_POST['acf']['_post_title']) ) {
|
|
||||||
|
|
||||||
$save['post_title'] = acf_extract_var($_POST['acf'], '_post_title');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// save post_content
|
|
||||||
if( isset($_POST['acf']['_post_content']) ) {
|
|
||||||
|
|
||||||
$save['post_content'] = acf_extract_var($_POST['acf'], '_post_content');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// honeypot
|
|
||||||
if( !empty($_POST['acf']['_validate_email']) ) return;
|
|
||||||
|
|
||||||
|
|
||||||
// validate
|
|
||||||
if( count($save) == 1 ) {
|
|
||||||
|
|
||||||
return $post_id;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if( $save['ID'] ) {
|
|
||||||
|
|
||||||
wp_update_post( $save );
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
$post_id = wp_insert_post( $save );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// return
|
|
||||||
return $post_id;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* enqueue
|
|
||||||
*
|
|
||||||
* This function will enqueue a form
|
|
||||||
*
|
|
||||||
* @type function
|
|
||||||
* @date 7/09/2016
|
|
||||||
* @since 5.4.0
|
|
||||||
*
|
|
||||||
* @param $post_id (int)
|
|
||||||
* @return $post_id (int)
|
|
||||||
*/
|
|
||||||
|
|
||||||
function enqueue_form() {
|
|
||||||
|
|
||||||
// verify nonce
|
|
||||||
if( acf_verify_nonce('acf_form') ) {
|
|
||||||
|
|
||||||
// validate data
|
|
||||||
if( acf_validate_save_post(true) ) {
|
|
||||||
|
|
||||||
// form
|
|
||||||
$GLOBALS['acf_form'] = acf_extract_var($_POST, '_acf_form');
|
|
||||||
$GLOBALS['acf_form'] = @json_decode(base64_decode($GLOBALS['acf_form']), true);
|
|
||||||
|
|
||||||
|
|
||||||
// validate
|
|
||||||
if( empty($GLOBALS['acf_form']) ) return;
|
|
||||||
|
|
||||||
|
|
||||||
// vars
|
|
||||||
$post_id = acf_maybe_get( $GLOBALS['acf_form'], 'post_id', 0 );
|
|
||||||
|
|
||||||
|
|
||||||
// allow for custom save
|
|
||||||
$post_id = apply_filters('acf/pre_save_post', $post_id, $GLOBALS['acf_form']);
|
|
||||||
|
|
||||||
|
|
||||||
// save
|
|
||||||
acf_save_post( $post_id );
|
|
||||||
|
|
||||||
|
|
||||||
// vars
|
|
||||||
$return = acf_maybe_get( $GLOBALS['acf_form'], 'return', '' );
|
|
||||||
|
|
||||||
|
|
||||||
// redirect
|
|
||||||
if( $return ) {
|
|
||||||
|
|
||||||
// update %placeholders%
|
|
||||||
$return = str_replace('%post_url%', get_permalink($post_id), $return);
|
|
||||||
|
|
||||||
|
|
||||||
// redirect
|
|
||||||
wp_redirect( $return );
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
// if
|
|
||||||
|
|
||||||
}
|
|
||||||
// if
|
|
||||||
|
|
||||||
|
|
||||||
// load acf scripts
|
|
||||||
acf_enqueue_scripts();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* render
|
|
||||||
*
|
|
||||||
* description
|
|
||||||
*
|
|
||||||
* @type function
|
|
||||||
* @date 7/09/2016
|
|
||||||
* @since 5.4.0
|
|
||||||
*
|
|
||||||
* @param $post_id (int)
|
|
||||||
* @return $post_id (int)
|
|
||||||
*/
|
|
||||||
|
|
||||||
function render_form( $args = array() ) {
|
|
||||||
|
|
||||||
// vars
|
|
||||||
$url = acf_get_current_url();
|
|
||||||
|
|
||||||
|
|
||||||
// defaults
|
|
||||||
$args = wp_parse_args( $args, array(
|
|
||||||
'id' => 'acf-form',
|
|
||||||
'post_id' => false,
|
|
||||||
'new_post' => false,
|
|
||||||
'field_groups' => false,
|
|
||||||
'fields' => false,
|
|
||||||
'post_title' => false,
|
|
||||||
'post_content' => false,
|
|
||||||
'form' => true,
|
|
||||||
'form_attributes' => array(),
|
|
||||||
'return' => add_query_arg( 'updated', 'true', $url ),
|
|
||||||
'html_before_fields' => '',
|
|
||||||
'html_after_fields' => '',
|
|
||||||
'submit_value' => __("Update", 'acf'),
|
|
||||||
'updated_message' => __("Post updated", 'acf'),
|
|
||||||
'label_placement' => 'top',
|
|
||||||
'instruction_placement' => 'label',
|
|
||||||
'field_el' => 'div',
|
|
||||||
'uploader' => 'wp',
|
|
||||||
'honeypot' => true
|
|
||||||
));
|
|
||||||
|
|
||||||
$args['form_attributes'] = wp_parse_args( $args['form_attributes'], array(
|
|
||||||
'id' => $args['id'],
|
|
||||||
'class' => 'acf-form',
|
|
||||||
'action' => '',
|
|
||||||
'method' => 'post',
|
|
||||||
));
|
|
||||||
|
|
||||||
|
|
||||||
// filter post_id
|
|
||||||
$args['post_id'] = acf_get_valid_post_id( $args['post_id'] );
|
|
||||||
|
|
||||||
|
|
||||||
// load values from this post
|
|
||||||
$post_id = $args['post_id'];
|
|
||||||
|
|
||||||
|
|
||||||
// new post?
|
|
||||||
if( $post_id == 'new_post' ) {
|
|
||||||
|
|
||||||
// dont load values
|
|
||||||
$post_id = false;
|
|
||||||
|
|
||||||
|
|
||||||
// new post defaults
|
|
||||||
$args['new_post'] = wp_parse_args( $args['new_post'], array(
|
|
||||||
'post_type' => 'post',
|
|
||||||
'post_status' => 'draft',
|
|
||||||
));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// register local fields
|
|
||||||
foreach( $this->fields as $k => $field ) {
|
|
||||||
|
|
||||||
acf_add_local_field($field);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// vars
|
|
||||||
$field_groups = array();
|
|
||||||
$fields = array();
|
|
||||||
|
|
||||||
|
|
||||||
// post_title
|
|
||||||
if( $args['post_title'] ) {
|
|
||||||
|
|
||||||
// load local field
|
|
||||||
$_post_title = acf_get_field('_post_title');
|
|
||||||
$_post_title['value'] = $post_id ? get_post_field('post_title', $post_id) : '';
|
|
||||||
|
|
||||||
|
|
||||||
// append
|
|
||||||
$fields[] = $_post_title;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// post_content
|
|
||||||
if( $args['post_content'] ) {
|
|
||||||
|
|
||||||
// load local field
|
|
||||||
$_post_content = acf_get_field('_post_content');
|
|
||||||
$_post_content['value'] = $post_id ? get_post_field('post_content', $post_id) : '';
|
|
||||||
|
|
||||||
|
|
||||||
// append
|
|
||||||
$fields[] = $_post_content;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// specific fields
|
|
||||||
if( $args['fields'] ) {
|
|
||||||
|
|
||||||
foreach( $args['fields'] as $selector ) {
|
|
||||||
|
|
||||||
// append field ($strict = false to allow for better compatibility with field names)
|
|
||||||
$fields[] = acf_maybe_get_field( $selector, $post_id, false );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} elseif( $args['field_groups'] ) {
|
|
||||||
|
|
||||||
foreach( $args['field_groups'] as $selector ) {
|
|
||||||
|
|
||||||
$field_groups[] = acf_get_field_group( $selector );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} elseif( $args['post_id'] == 'new_post' ) {
|
|
||||||
|
|
||||||
$field_groups = acf_get_field_groups( $args['new_post'] );
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
$field_groups = acf_get_field_groups(array(
|
|
||||||
'post_id' => $args['post_id']
|
|
||||||
));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//load fields based on field groups
|
|
||||||
if( !empty($field_groups) ) {
|
|
||||||
|
|
||||||
foreach( $field_groups as $field_group ) {
|
|
||||||
|
|
||||||
$field_group_fields = acf_get_fields( $field_group );
|
|
||||||
|
|
||||||
if( !empty($field_group_fields) ) {
|
|
||||||
|
|
||||||
foreach( array_keys($field_group_fields) as $i ) {
|
|
||||||
|
|
||||||
$fields[] = acf_extract_var($field_group_fields, $i);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// honeypot
|
|
||||||
if( $args['honeypot'] ) {
|
|
||||||
|
|
||||||
$fields[] = acf_get_field('_validate_email');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// updated message
|
|
||||||
if( !empty($_GET['updated']) && $args['updated_message'] ) {
|
|
||||||
|
|
||||||
echo '<div id="message" class="updated"><p>' . $args['updated_message'] . '</p></div>';
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// uploader (always set incase of multiple forms on the page)
|
|
||||||
acf_update_setting('uploader', $args['uploader']);
|
|
||||||
|
|
||||||
|
|
||||||
// display form
|
|
||||||
if( $args['form'] ): ?>
|
|
||||||
|
|
||||||
<form <?php acf_esc_attr_e( $args['form_attributes']); ?>>
|
|
||||||
|
|
||||||
<?php endif;
|
|
||||||
|
|
||||||
// render post data
|
|
||||||
acf_form_data(array(
|
|
||||||
'post_id' => $args['post_id'],
|
|
||||||
'nonce' => 'acf_form'
|
|
||||||
));
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
||||||
<div class="acf-hidden">
|
|
||||||
<?php acf_hidden_input(array( 'name' => '_acf_form', 'value' => base64_encode(json_encode($args)) )); ?>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="acf-fields acf-form-fields -<?php echo $args['label_placement']; ?>">
|
|
||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
// html before fields
|
|
||||||
echo $args['html_before_fields'];
|
|
||||||
|
|
||||||
|
|
||||||
// render
|
|
||||||
acf_render_fields( $post_id, $fields, $args['field_el'], $args['instruction_placement'] );
|
|
||||||
|
|
||||||
|
|
||||||
// html after fields
|
|
||||||
echo $args['html_after_fields'];
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
</div><!-- acf-form-fields -->
|
|
||||||
|
|
||||||
<?php if( $args['form'] ): ?>
|
|
||||||
|
|
||||||
<div class="acf-form-submit">
|
|
||||||
|
|
||||||
<input type="submit" class="acf-button button button-primary button-large" value="<?php echo $args['submit_value']; ?>" />
|
|
||||||
<span class="acf-spinner"></span>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</form>
|
|
||||||
<?php endif;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize
|
add_shortcode('acf', 'acf_shortcode');
|
||||||
acf()->template_form = new acf_template_form();
|
|
||||||
|
|
||||||
endif; // class_exists check
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* acf_form_head()
|
|
||||||
*
|
|
||||||
* This function is placed at the very top of a template (before any HTML is rendered) and saves the $_POST data sent by acf_form.
|
|
||||||
*
|
|
||||||
* @type function
|
|
||||||
* @since 1.1.4
|
|
||||||
* @date 29/01/13
|
|
||||||
*
|
|
||||||
* @param n/a
|
|
||||||
* @return n/a
|
|
||||||
*/
|
|
||||||
|
|
||||||
function acf_form_head() {
|
|
||||||
|
|
||||||
acf()->template_form->enqueue_form();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* acf_form()
|
|
||||||
*
|
|
||||||
* This function is used to create an ACF form.
|
|
||||||
*
|
|
||||||
* @type function
|
|
||||||
* @since 1.1.4
|
|
||||||
* @date 29/01/13
|
|
||||||
*
|
|
||||||
* @param array $options: an array containing many options to customize the form
|
|
||||||
* string + post_id: post id to get field groups from and save data to. Default is false
|
|
||||||
* array + field_groups: an array containing field group ID's. If this option is set,
|
|
||||||
* the post_id will not be used to dynamically find the field groups
|
|
||||||
* boolean + form: display the form tag or not. Defaults to true
|
|
||||||
* array + form_attributes: an array containg attributes which will be added into the form tag
|
|
||||||
* string + return: the return URL
|
|
||||||
* string + html_before_fields: html inside form before fields
|
|
||||||
* string + html_after_fields: html inside form after fields
|
|
||||||
* string + submit_value: value of submit button
|
|
||||||
* string + updated_message: default updated message. Can be false
|
|
||||||
*
|
|
||||||
* @return N/A
|
|
||||||
*/
|
|
||||||
|
|
||||||
function acf_form( $args = array() ) {
|
|
||||||
|
|
||||||
acf()->template_form->render_form($args);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -1576,13 +1003,14 @@ function update_field( $selector, $value, $post_id = false ) {
|
||||||
|
|
||||||
|
|
||||||
// create dummy field
|
// create dummy field
|
||||||
if( !$field )
|
if( !$field ) {
|
||||||
{
|
|
||||||
$field = acf_get_valid_field(array(
|
$field = acf_get_valid_field(array(
|
||||||
'name' => $selector,
|
'name' => $selector,
|
||||||
'key' => '',
|
'key' => '',
|
||||||
'type' => '',
|
'type' => '',
|
||||||
));
|
));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1613,17 +1041,15 @@ function update_sub_field( $selector, $value, $post_id = false ) {
|
||||||
$sub_field = false;
|
$sub_field = false;
|
||||||
|
|
||||||
|
|
||||||
// filter post_id
|
|
||||||
$post_id = acf_get_valid_post_id( $post_id );
|
|
||||||
|
|
||||||
|
|
||||||
// get sub field
|
// get sub field
|
||||||
if( is_array($selector) ) {
|
if( is_array($selector) ) {
|
||||||
|
|
||||||
|
$post_id = acf_get_valid_post_id( $post_id );
|
||||||
$sub_field = acf_maybe_get_sub_field( $selector, $post_id, false );
|
$sub_field = acf_maybe_get_sub_field( $selector, $post_id, false );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
$post_id = acf_get_loop('active', 'post_id');
|
||||||
$sub_field = get_row_sub_field( $selector );
|
$sub_field = get_row_sub_field( $selector );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1713,7 +1139,7 @@ function add_row( $selector, $row = false, $post_id = false ) {
|
||||||
|
|
||||||
|
|
||||||
// get field
|
// get field
|
||||||
$field = acf_maybe_get_field( $selector, $post_id );
|
$field = acf_maybe_get_field( $selector, $post_id, false );
|
||||||
|
|
||||||
|
|
||||||
// bail early if no field
|
// bail early if no field
|
||||||
|
|
@ -1733,7 +1159,11 @@ function add_row( $selector, $row = false, $post_id = false ) {
|
||||||
|
|
||||||
|
|
||||||
// update value
|
// update value
|
||||||
return acf_update_value( $value, $post_id, $field );
|
acf_update_value( $value, $post_id, $field );
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return count($value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1759,17 +1189,15 @@ function add_sub_row( $selector, $row = false, $post_id = false ) {
|
||||||
$sub_field = false;
|
$sub_field = false;
|
||||||
|
|
||||||
|
|
||||||
// filter post_id
|
|
||||||
$post_id = acf_get_valid_post_id( $post_id );
|
|
||||||
|
|
||||||
|
|
||||||
// get sub field
|
// get sub field
|
||||||
if( is_array($selector) ) {
|
if( is_array($selector) ) {
|
||||||
|
|
||||||
|
$post_id = acf_get_valid_post_id( $post_id );
|
||||||
$sub_field = acf_maybe_get_sub_field( $selector, $post_id, false );
|
$sub_field = acf_maybe_get_sub_field( $selector, $post_id, false );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
$post_id = acf_get_loop('active', 'post_id');
|
||||||
$sub_field = get_row_sub_field( $selector );
|
$sub_field = get_row_sub_field( $selector );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1792,7 +1220,11 @@ function add_sub_row( $selector, $row = false, $post_id = false ) {
|
||||||
|
|
||||||
|
|
||||||
// update
|
// update
|
||||||
return acf_update_value( $value, $post_id, $sub_field );
|
acf_update_value( $value, $post_id, $sub_field );
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return count($value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1816,7 +1248,8 @@ function add_sub_row( $selector, $row = false, $post_id = false ) {
|
||||||
function update_row( $selector, $i = 1, $row = false, $post_id = false ) {
|
function update_row( $selector, $i = 1, $row = false, $post_id = false ) {
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
$i--;
|
$offset = acf_get_setting('row_index_offset');
|
||||||
|
$i = $i - $offset;
|
||||||
|
|
||||||
|
|
||||||
// filter post_id
|
// filter post_id
|
||||||
|
|
@ -1824,7 +1257,7 @@ function update_row( $selector, $i = 1, $row = false, $post_id = false ) {
|
||||||
|
|
||||||
|
|
||||||
// get field
|
// get field
|
||||||
$field = acf_maybe_get_field( $selector, $post_id );
|
$field = acf_maybe_get_field( $selector, $post_id, false );
|
||||||
|
|
||||||
|
|
||||||
// bail early if no field
|
// bail early if no field
|
||||||
|
|
@ -1872,20 +1305,19 @@ function update_sub_row( $selector, $i = 1, $row = false, $post_id = false ) {
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
$sub_field = false;
|
$sub_field = false;
|
||||||
$i--;
|
$offset = acf_get_setting('row_index_offset');
|
||||||
|
$i = $i - $offset;
|
||||||
|
|
||||||
// filter post_id
|
|
||||||
$post_id = acf_get_valid_post_id( $post_id );
|
|
||||||
|
|
||||||
|
|
||||||
// get sub field
|
// get sub field
|
||||||
if( is_array($selector) ) {
|
if( is_array($selector) ) {
|
||||||
|
|
||||||
|
$post_id = acf_get_valid_post_id( $post_id );
|
||||||
$sub_field = acf_maybe_get_sub_field( $selector, $post_id, false );
|
$sub_field = acf_maybe_get_sub_field( $selector, $post_id, false );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
$post_id = acf_get_loop('active', 'post_id');
|
||||||
$sub_field = get_row_sub_field( $selector );
|
$sub_field = get_row_sub_field( $selector );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1935,7 +1367,8 @@ function update_sub_row( $selector, $i = 1, $row = false, $post_id = false ) {
|
||||||
function delete_row( $selector, $i = 1, $post_id = false ) {
|
function delete_row( $selector, $i = 1, $post_id = false ) {
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
$i--;
|
$offset = acf_get_setting('row_index_offset');
|
||||||
|
$i = $i - $offset;
|
||||||
|
|
||||||
|
|
||||||
// filter post_id
|
// filter post_id
|
||||||
|
|
@ -1957,13 +1390,21 @@ function delete_row( $selector, $i = 1, $post_id = false ) {
|
||||||
// ensure array
|
// ensure array
|
||||||
$value = acf_get_array($value);
|
$value = acf_get_array($value);
|
||||||
|
|
||||||
|
|
||||||
|
// bail early if index doesn't exist
|
||||||
|
if( !isset($value[ $i ]) ) return false;
|
||||||
|
|
||||||
|
|
||||||
// unset
|
// unset
|
||||||
unset( $value[ $i ] );
|
unset( $value[ $i ] );
|
||||||
|
|
||||||
|
|
||||||
// update
|
// update
|
||||||
return acf_update_value( $value, $post_id, $field );
|
acf_update_value( $value, $post_id, $field );
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1987,20 +1428,19 @@ function delete_sub_row( $selector, $i = 1, $post_id = false ) {
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
$sub_field = false;
|
$sub_field = false;
|
||||||
$i--;
|
$offset = acf_get_setting('row_index_offset');
|
||||||
|
$i = $i - $offset;
|
||||||
|
|
||||||
// filter post_id
|
|
||||||
$post_id = acf_get_valid_post_id( $post_id );
|
|
||||||
|
|
||||||
|
|
||||||
// get sub field
|
// get sub field
|
||||||
if( is_array($selector) ) {
|
if( is_array($selector) ) {
|
||||||
|
|
||||||
|
$post_id = acf_get_valid_post_id( $post_id );
|
||||||
$sub_field = acf_maybe_get_sub_field( $selector, $post_id, false );
|
$sub_field = acf_maybe_get_sub_field( $selector, $post_id, false );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
$post_id = acf_get_loop('active', 'post_id');
|
||||||
$sub_field = get_row_sub_field( $selector );
|
$sub_field = get_row_sub_field( $selector );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -2018,12 +1458,20 @@ function delete_sub_row( $selector, $i = 1, $post_id = false ) {
|
||||||
$value = acf_get_array( $value );
|
$value = acf_get_array( $value );
|
||||||
|
|
||||||
|
|
||||||
|
// bail early if index doesn't exist
|
||||||
|
if( !isset($value[ $i ]) ) return false;
|
||||||
|
|
||||||
|
|
||||||
// append
|
// append
|
||||||
unset( $value[ $i ] );
|
unset( $value[ $i ] );
|
||||||
|
|
||||||
|
|
||||||
// update
|
// update
|
||||||
return acf_update_value( $value, $post_id, $sub_field );
|
acf_update_value( $value, $post_id, $sub_field );
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2041,12 +1489,6 @@ function delete_sub_row( $selector, $i = 1, $post_id = false ) {
|
||||||
* @return n/a
|
* @return n/a
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function register_field_group( $field_group ) {
|
|
||||||
|
|
||||||
acf_add_local_field_group( $field_group );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function create_field( $field ) {
|
function create_field( $field ) {
|
||||||
|
|
||||||
acf_render_field( $field );
|
acf_render_field( $field );
|
||||||
|
|
|
||||||
|
|
@ -351,7 +351,15 @@ function acf_update_value( $value = null, $post_id = 0, $field ) {
|
||||||
$value = apply_filters( "acf/update_value/name={$field['name']}", $value, $post_id, $field );
|
$value = apply_filters( "acf/update_value/name={$field['name']}", $value, $post_id, $field );
|
||||||
$value = apply_filters( "acf/update_value/key={$field['key']}", $value, $post_id, $field );
|
$value = apply_filters( "acf/update_value/key={$field['key']}", $value, $post_id, $field );
|
||||||
|
|
||||||
|
|
||||||
|
// allow null to delete
|
||||||
|
if( $value === null ) {
|
||||||
|
|
||||||
|
return acf_delete_value( $post_id, $field );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// update value
|
// update value
|
||||||
$return = acf_update_metadata( $post_id, $field['name'], $value );
|
$return = acf_update_metadata( $post_id, $field['name'], $value );
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,15 @@
|
||||||
* Postbox: Fields
|
* Postbox: Fields
|
||||||
*
|
*
|
||||||
*---------------------------------------------------------------------------------------------*/
|
*---------------------------------------------------------------------------------------------*/
|
||||||
|
.acf-field p.description {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
font-style: normal;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.4em;
|
||||||
|
color: #777777;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
#acf-field-group-fields > .inside,
|
#acf-field-group-fields > .inside,
|
||||||
#acf-field-group-locations > .inside,
|
#acf-field-group-locations > .inside,
|
||||||
#acf-field-group-options > .inside {
|
#acf-field-group-options > .inside {
|
||||||
|
|
|
||||||
|
|
@ -636,48 +636,53 @@ a.acf-icon.-cancel.grey:hover {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
clear: both;
|
clear: both;
|
||||||
|
/* defaults */
|
||||||
|
/* thead */
|
||||||
|
/* tbody */
|
||||||
|
/* -clear */
|
||||||
}
|
}
|
||||||
.acf-table > tbody > tr {
|
.acf-table > tbody > tr > th,
|
||||||
z-index: 1;
|
|
||||||
}
|
|
||||||
.acf-table > thead > tr > th,
|
.acf-table > thead > tr > th,
|
||||||
.acf-table > tbody > tr > td {
|
.acf-table > tbody > tr > td,
|
||||||
|
.acf-table > thead > tr > td {
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
vertical-align: top;
|
vertical-align: top;
|
||||||
background: #fff;
|
background: #fff;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
font-size: 14px;
|
|
||||||
line-height: 1.4em;
|
|
||||||
border-style: solid;
|
border-style: solid;
|
||||||
border-color: #EDEDED;
|
font-weight: normal;
|
||||||
border-width: 1px 0 0 1px;
|
|
||||||
}
|
}
|
||||||
/* th */
|
.acf-table > tbody > tr > th,
|
||||||
.acf-table > thead > tr > th {
|
.acf-table > thead > tr > th {
|
||||||
position: relative;
|
position: relative;
|
||||||
color: #333333;
|
color: #333333;
|
||||||
font-weight: normal;
|
}
|
||||||
|
.acf-table > thead > tr > th {
|
||||||
border-color: #E1E1E1;
|
border-color: #E1E1E1;
|
||||||
border-width: 0 0 1px 1px;
|
border-width: 0 0 1px 1px;
|
||||||
}
|
}
|
||||||
.acf-table > thead > tr > th:first-child {
|
.acf-table > thead > tr > th:first-child {
|
||||||
border-left-width: 0;
|
border-left-width: 0;
|
||||||
}
|
}
|
||||||
/* td */
|
.acf-table > tbody > tr {
|
||||||
.acf-table > tbody > tr > td {
|
z-index: 1;
|
||||||
font-size: 13px;
|
|
||||||
}
|
}
|
||||||
.acf-table > tbody > tr:first-child > td {
|
.acf-table > tbody > tr > td {
|
||||||
border-top-width: 0;
|
border-color: #EDEDED;
|
||||||
|
border-width: 1px 0 0 1px;
|
||||||
}
|
}
|
||||||
.acf-table > tbody > tr > td:first-child {
|
.acf-table > tbody > tr > td:first-child {
|
||||||
border-left-width: 0;
|
border-left-width: 0;
|
||||||
}
|
}
|
||||||
/* clear table */
|
.acf-table > tbody > tr:first-child > td {
|
||||||
|
border-top-width: 0;
|
||||||
|
}
|
||||||
.acf-table.-clear {
|
.acf-table.-clear {
|
||||||
border: 0 none;
|
border: 0 none;
|
||||||
}
|
}
|
||||||
.acf-table.-clear > tbody > tr > td,
|
.acf-table.-clear > tbody > tr > td,
|
||||||
|
.acf-table.-clear > thead > tr > td,
|
||||||
|
.acf-table.-clear > tbody > tr > th,
|
||||||
.acf-table.-clear > thead > tr > th {
|
.acf-table.-clear > thead > tr > th {
|
||||||
border: 0 none;
|
border: 0 none;
|
||||||
padding: 4px;
|
padding: 4px;
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,11 @@
|
||||||
/* input */
|
/* input */
|
||||||
/* error */
|
/* error */
|
||||||
}
|
}
|
||||||
|
.acf-field p.description {
|
||||||
|
display: block;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
.acf-field .acf-label {
|
.acf-field .acf-label {
|
||||||
vertical-align: top;
|
vertical-align: top;
|
||||||
margin: 0 0 10px;
|
margin: 0 0 10px;
|
||||||
|
|
@ -31,22 +36,15 @@
|
||||||
.acf-field .acf-label label {
|
.acf-field .acf-label label {
|
||||||
display: block;
|
display: block;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
font-size: 13px;
|
|
||||||
line-height: 1.4em;
|
|
||||||
margin: 0 0 3px;
|
margin: 0 0 3px;
|
||||||
}
|
padding: 0;
|
||||||
.acf-field .acf-label p {
|
|
||||||
color: #777777;
|
|
||||||
display: block;
|
|
||||||
font-size: 12px;
|
|
||||||
line-height: 1.4em;
|
|
||||||
font-style: normal;
|
|
||||||
margin: 3px 0 0 !important;
|
|
||||||
padding: 0 !important;
|
|
||||||
}
|
}
|
||||||
.acf-field .acf-input {
|
.acf-field .acf-input {
|
||||||
vertical-align: top;
|
vertical-align: top;
|
||||||
}
|
}
|
||||||
|
.acf-field .acf-input > p.description {
|
||||||
|
margin-top: 5px;
|
||||||
|
}
|
||||||
.acf-field .acf-error-message {
|
.acf-field .acf-error-message {
|
||||||
background: #F55E4F;
|
background: #F55E4F;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
|
|
@ -497,9 +495,6 @@ html[dir="rtl"] input.acf-is-prepended.acf-is-appended {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 5px 5px 5px 7px;
|
padding: 5px 5px 5px 7px;
|
||||||
}
|
}
|
||||||
.select2-container.-acf .select2-search-choice-close {
|
|
||||||
margin-top: -1px;
|
|
||||||
}
|
|
||||||
.select2-container.-acf .select2-choice {
|
.select2-container.-acf .select2-choice {
|
||||||
border-color: #BBBBBB;
|
border-color: #BBBBBB;
|
||||||
}
|
}
|
||||||
|
|
@ -520,6 +515,17 @@ html[dir="rtl"] input.acf-is-prepended.acf-is-appended {
|
||||||
background: #fff;
|
background: #fff;
|
||||||
border-color: #5B9DD9;
|
border-color: #5B9DD9;
|
||||||
}
|
}
|
||||||
|
/* rtl */
|
||||||
|
html[dir="rtl"] .select2-container.-acf .select2-search-choice-close {
|
||||||
|
left: 24px;
|
||||||
|
}
|
||||||
|
html[dir="rtl"] .select2-container.-acf .select2-choice > .select2-chosen {
|
||||||
|
margin-left: 42px;
|
||||||
|
}
|
||||||
|
html[dir="rtl"] .select2-container.-acf .select2-choice .select2-arrow {
|
||||||
|
padding-left: 0;
|
||||||
|
padding-right: 1px;
|
||||||
|
}
|
||||||
/* description */
|
/* description */
|
||||||
.select2-drop {
|
.select2-drop {
|
||||||
/* search*/
|
/* search*/
|
||||||
|
|
@ -637,6 +643,7 @@ html[dir="rtl"] ul.acf-checkbox-list input[type="radio"] {
|
||||||
transition: background 0.25s ease;
|
transition: background 0.25s ease;
|
||||||
/* hover */
|
/* hover */
|
||||||
/* active */
|
/* active */
|
||||||
|
/* focus */
|
||||||
/* message */
|
/* message */
|
||||||
}
|
}
|
||||||
.acf-switch span {
|
.acf-switch span {
|
||||||
|
|
@ -681,9 +688,23 @@ html[dir="rtl"] ul.acf-checkbox-list input[type="radio"] {
|
||||||
right: 3px;
|
right: 3px;
|
||||||
border-color: #1f7db1;
|
border-color: #1f7db1;
|
||||||
}
|
}
|
||||||
|
.acf-switch.-focus .acf-switch-slider {
|
||||||
|
border-color: #5b9dd9;
|
||||||
|
box-shadow: 0 0 2px rgba(30, 140, 190, 0.5);
|
||||||
|
}
|
||||||
|
.acf-switch.-focus.-on .acf-switch-slider {
|
||||||
|
border-color: #185e85;
|
||||||
|
box-shadow: 0 0 2px #1f7db1;
|
||||||
|
}
|
||||||
.acf-switch + span {
|
.acf-switch + span {
|
||||||
margin-left: 6px;
|
margin-left: 6px;
|
||||||
}
|
}
|
||||||
|
/* checkbox */
|
||||||
|
.acf-switch-input {
|
||||||
|
opacity: 0;
|
||||||
|
position: absolute;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
.acf-field[data-name="alt"] .acf-switch {
|
.acf-field[data-name="alt"] .acf-switch {
|
||||||
background: #fff;
|
background: #fff;
|
||||||
|
|
@ -1021,6 +1042,10 @@ html[dir="rtl"] .acf-relationship .selection .values .acf-icon {
|
||||||
.acf-editor-wrap.tmce-active .wp-editor-area {
|
.acf-editor-wrap.tmce-active .wp-editor-area {
|
||||||
color: #333 !important;
|
color: #333 !important;
|
||||||
}
|
}
|
||||||
|
/* fix z-index behind media modal */
|
||||||
|
div.mce-toolbar-grp.mce-inline-toolbar-grp {
|
||||||
|
z-index: 170000;
|
||||||
|
}
|
||||||
/*---------------------------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Tab
|
* Tab
|
||||||
|
|
@ -1667,19 +1692,22 @@ html[dir="rtl"] .acf-taxonomy-field[data-type="select"] .acf-icon {
|
||||||
float: left;
|
float: left;
|
||||||
}
|
}
|
||||||
.media-modal .compat-attachment-fields > tbody > .acf-field > .acf-label > label {
|
.media-modal .compat-attachment-fields > tbody > .acf-field > .acf-label > label {
|
||||||
padding-top: 7px;
|
padding-top: 6px;
|
||||||
margin: 5px 0 0;
|
margin: 0;
|
||||||
color: #666666;
|
color: #666666;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
line-height: 16px;
|
line-height: 16px;
|
||||||
}
|
}
|
||||||
.media-modal .compat-attachment-fields > tbody > .acf-field > .acf-input {
|
.media-modal .compat-attachment-fields > tbody > .acf-field > .acf-input {
|
||||||
width: 65%;
|
width: 65%;
|
||||||
margin: 5px 0 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
float: right;
|
float: right;
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
.media-modal .compat-attachment-fields > tbody > .acf-field p.description {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
/* restricted selection (copy of WP .upload-errors)*/
|
/* restricted selection (copy of WP .upload-errors)*/
|
||||||
.acf-selection-error {
|
.acf-selection-error {
|
||||||
background: #ffebe8;
|
background: #ffebe8;
|
||||||
|
|
@ -1718,8 +1746,7 @@ html[dir="rtl"] .acf-taxonomy-field[data-type="select"] .acf-icon {
|
||||||
/* fix % margin which causes .acf-uploadedTo to drop down below select */
|
/* fix % margin which causes .acf-uploadedTo to drop down below select */
|
||||||
/* allow line breaks in upload error */
|
/* allow line breaks in upload error */
|
||||||
/* fix required span */
|
/* fix required span */
|
||||||
/* Sidebar: Collapse */
|
/* sidebar */
|
||||||
/* Create gallery fix */
|
|
||||||
/* mobile md */
|
/* mobile md */
|
||||||
}
|
}
|
||||||
.media-modal .compat-field-acf-form-data,
|
.media-modal .compat-field-acf-form-data,
|
||||||
|
|
@ -1747,28 +1774,8 @@ html[dir="rtl"] .acf-taxonomy-field[data-type="select"] .acf-icon {
|
||||||
float: none !important;
|
float: none !important;
|
||||||
color: #f00 !important;
|
color: #f00 !important;
|
||||||
}
|
}
|
||||||
.media-modal .compat-item .label {
|
.media-modal .media-sidebar .compat-item {
|
||||||
margin: 0;
|
padding-bottom: 20px;
|
||||||
}
|
|
||||||
.media-modal .media-sidebar .setting span,
|
|
||||||
.media-modal .compat-item label span,
|
|
||||||
.media-modal .media-sidebar .setting input,
|
|
||||||
.media-modal .media-sidebar .setting textarea,
|
|
||||||
.media-modal .compat-item .field {
|
|
||||||
min-height: 0;
|
|
||||||
margin: 5px 0 0;
|
|
||||||
}
|
|
||||||
.media-modal .media-sidebar .setting span,
|
|
||||||
.media-modal .compat-item label span {
|
|
||||||
padding-top: 7px;
|
|
||||||
}
|
|
||||||
.media-modal .attachment-display-settings .setting span {
|
|
||||||
margin-top: 0;
|
|
||||||
margin-right: 3%;
|
|
||||||
}
|
|
||||||
.media-modal .media-modal .media-sidebar .collection-settings .setting span {
|
|
||||||
padding-top: 8px;
|
|
||||||
margin: 0 10px 0 0;
|
|
||||||
}
|
}
|
||||||
@media (max-width: 900px) {
|
@media (max-width: 900px) {
|
||||||
.media-modal {
|
.media-modal {
|
||||||
|
|
@ -1844,14 +1851,12 @@ html[dir="rtl"] .acf-taxonomy-field[data-type="select"] .acf-icon {
|
||||||
.media-modal.acf-expanded .acf-expand-details .is-closed {
|
.media-modal.acf-expanded .acf-expand-details .is-closed {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
.media-modal.acf-expanded .attachments-browser .media-toolbar {
|
.media-modal.acf-expanded .media-toolbar,
|
||||||
right: 700px;
|
|
||||||
}
|
|
||||||
.media-modal.acf-expanded .attachments {
|
.media-modal.acf-expanded .attachments {
|
||||||
right: 700px;
|
right: 740px;
|
||||||
}
|
}
|
||||||
.media-modal.acf-expanded .media-sidebar {
|
.media-modal.acf-expanded .media-sidebar {
|
||||||
width: 667px;
|
width: 708px;
|
||||||
}
|
}
|
||||||
.media-modal.acf-expanded .media-sidebar {
|
.media-modal.acf-expanded .media-sidebar {
|
||||||
/* label */
|
/* label */
|
||||||
|
|
@ -1869,6 +1874,9 @@ html[dir="rtl"] .acf-taxonomy-field[data-type="select"] .acf-icon {
|
||||||
.media-modal.acf-expanded .media-sidebar .compat-attachment-fields > tbody > .acf-field > .acf-input {
|
.media-modal.acf-expanded .media-sidebar .compat-attachment-fields > tbody > .acf-field > .acf-input {
|
||||||
min-width: 77%;
|
min-width: 77%;
|
||||||
}
|
}
|
||||||
|
.media-modal.acf-expanded .media-sidebar .setting span {
|
||||||
|
margin-right: 2%;
|
||||||
|
}
|
||||||
.media-modal.acf-expanded .media-sidebar .attachment-info .thumbnail {
|
.media-modal.acf-expanded .media-sidebar .attachment-info .thumbnail {
|
||||||
max-height: none;
|
max-height: none;
|
||||||
}
|
}
|
||||||
|
|
@ -1964,8 +1972,8 @@ body.major-4 .acf-media-modal.-edit .media-frame-content {
|
||||||
}
|
}
|
||||||
.acf-media-modal.-edit .media-sidebar {
|
.acf-media-modal.-edit .media-sidebar {
|
||||||
padding: 0 16px;
|
padding: 0 16px;
|
||||||
/* reposition thumbnail */
|
/* WP details */
|
||||||
/* add missing padding below fields */
|
/* ACF fields */
|
||||||
}
|
}
|
||||||
.acf-media-modal.-edit .media-sidebar .attachment-details {
|
.acf-media-modal.-edit .media-sidebar .attachment-details {
|
||||||
overflow: visible;
|
overflow: visible;
|
||||||
|
|
@ -1986,14 +1994,21 @@ body.major-4 .acf-media-modal.-edit .media-frame-content {
|
||||||
.acf-media-modal.-edit .media-sidebar .attachment-details .thumbnail {
|
.acf-media-modal.-edit .media-sidebar .attachment-details .thumbnail {
|
||||||
margin: 0 16px 0 0;
|
margin: 0 16px 0 0;
|
||||||
}
|
}
|
||||||
.acf-media-modal.-edit .media-sidebar .attachment-details label {
|
.acf-media-modal.-edit .media-sidebar .attachment-details .setting {
|
||||||
display: block;
|
display: block;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
float: none;
|
float: none;
|
||||||
width: auto;
|
width: auto;
|
||||||
|
margin: 0 0 5px;
|
||||||
}
|
}
|
||||||
.acf-media-modal.-edit .media-sidebar .compat-item {
|
.acf-media-modal.-edit .media-sidebar .attachment-details .setting span {
|
||||||
padding-bottom: 16px;
|
margin: 0;
|
||||||
|
}
|
||||||
|
.acf-media-modal.-edit .media-sidebar .compat-attachment-fields > tbody > .acf-field {
|
||||||
|
margin: 0 0 5px;
|
||||||
|
}
|
||||||
|
.acf-media-modal.-edit .media-sidebar .compat-attachment-fields > tbody > .acf-field p.description {
|
||||||
|
margin-top: 3px;
|
||||||
}
|
}
|
||||||
@media (max-width: 900px) {
|
@media (max-width: 900px) {
|
||||||
.acf-media-modal.-edit {
|
.acf-media-modal.-edit {
|
||||||
|
|
@ -2092,11 +2107,19 @@ p.submit .acf-spinner {
|
||||||
* Widget
|
* Widget
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
#widgets-right .widget .acf-field .description {
|
||||||
|
padding-left: 0;
|
||||||
|
padding-right: 0;
|
||||||
|
}
|
||||||
|
.widget .acf-field {
|
||||||
|
margin: 1em 0;
|
||||||
|
}
|
||||||
.widget .acf-field .acf-label {
|
.widget .acf-field .acf-label {
|
||||||
margin: 0;
|
margin-bottom: 5px;
|
||||||
}
|
}
|
||||||
.widget .acf-field .acf-label label {
|
.widget .acf-field .acf-label label {
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
|
margin: 0;
|
||||||
}
|
}
|
||||||
.widget .widget-inside > form > .acf-error-message {
|
.widget .widget-inside > form > .acf-error-message {
|
||||||
margin-top: 15px;
|
margin-top: 15px;
|
||||||
|
|
|
||||||
|
|
@ -1308,7 +1308,7 @@
|
||||||
parent : acf.o.post_id,
|
parent : acf.o.post_id,
|
||||||
field_group : acf.o.post_id,
|
field_group : acf.o.post_id,
|
||||||
prefix : $select.attr('name').replace('[type]', ''),
|
prefix : $select.attr('name').replace('[type]', ''),
|
||||||
type : new_type,
|
type : new_type
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -2315,7 +2315,7 @@
|
||||||
'change_field_type' : '_change_field_type',
|
'change_field_type' : '_change_field_type',
|
||||||
'change_field_label' : '_change_field_label',
|
'change_field_label' : '_change_field_label',
|
||||||
'change_field_name' : '_change_field_name',
|
'change_field_name' : '_change_field_name',
|
||||||
'render_field_settings' : '_render_field_settings',
|
'render_field_settings' : '_render_field_settings'
|
||||||
},
|
},
|
||||||
|
|
||||||
_save_field: function( $el ){
|
_save_field: function( $el ){
|
||||||
|
|
@ -2405,7 +2405,7 @@
|
||||||
acf.field_group.append = acf.model.extend({
|
acf.field_group.append = acf.model.extend({
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
'render_field_settings' : '_render_field_settings',
|
'render_field_settings' : '_render_field_settings'
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function( $el ){
|
render: function( $el ){
|
||||||
|
|
@ -2491,7 +2491,7 @@
|
||||||
type: 'select',
|
type: 'select',
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
'render_settings': 'render',
|
'render_settings': 'render'
|
||||||
},
|
},
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
|
|
@ -2536,7 +2536,7 @@
|
||||||
type: 'radio',
|
type: 'radio',
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
'render_settings': 'render',
|
'render_settings': 'render'
|
||||||
},
|
},
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
|
|
@ -2581,7 +2581,7 @@
|
||||||
type: 'true_false',
|
type: 'true_false',
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
'render_settings': 'render',
|
'render_settings': 'render'
|
||||||
},
|
},
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
|
|
@ -2627,7 +2627,7 @@
|
||||||
type: 'date_picker',
|
type: 'date_picker',
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
'render_settings': 'render',
|
'render_settings': 'render'
|
||||||
},
|
},
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
|
|
@ -2720,7 +2720,7 @@
|
||||||
type: 'tab',
|
type: 'tab',
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
'render_settings': 'render',
|
'render_settings': 'render'
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function( $el ){
|
render: function( $el ){
|
||||||
|
|
@ -2844,8 +2844,244 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* sub fields
|
||||||
|
*
|
||||||
|
* description
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 31/1/17
|
||||||
|
* @since 5.5.6
|
||||||
|
*
|
||||||
|
* @param $post_id (int)
|
||||||
|
* @return $post_id (int)
|
||||||
|
*/
|
||||||
|
|
||||||
|
acf.field_group.sub_fields = acf.model.extend({
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
'open_field': 'update_field_parent',
|
||||||
|
'sortstop': 'update_field_parent',
|
||||||
|
'duplicate_field': 'duplicate_field',
|
||||||
|
'delete_field': 'delete_field',
|
||||||
|
'change_field_type': 'change_field_type'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* fix_conditional_logic
|
||||||
|
*
|
||||||
|
* This function will update sub field conditional logic rules after duplication
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 10/06/2014
|
||||||
|
* @since 5.0.0
|
||||||
|
*
|
||||||
|
* @param $fields (jquery selection)
|
||||||
|
* @return n/a
|
||||||
|
*/
|
||||||
|
|
||||||
|
fix_conditional_logic : function( $fields ){
|
||||||
|
|
||||||
|
// build refernce
|
||||||
|
var ref = {};
|
||||||
|
|
||||||
|
$fields.each(function(){
|
||||||
|
|
||||||
|
ref[ $(this).attr('data-orig') ] = $(this).attr('data-key');
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$fields.find('.conditional-rule-param').each(function(){
|
||||||
|
|
||||||
|
// vars
|
||||||
|
var key = $(this).val();
|
||||||
|
|
||||||
|
|
||||||
|
// bail early if val is not a ref key
|
||||||
|
if( !(key in ref) ) {
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// add option if doesn't yet exist
|
||||||
|
if( ! $(this).find('option[value="' + ref[key] + '"]').exists() ) {
|
||||||
|
|
||||||
|
$(this).append('<option value="' + ref[key] + '">' + ref[key] + '</option>');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// set new val
|
||||||
|
$(this).val( ref[key] );
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* update_field_parent
|
||||||
|
*
|
||||||
|
* This function will update field meta such as parent
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 8/04/2014
|
||||||
|
* @since 5.0.0
|
||||||
|
*
|
||||||
|
* @param $el
|
||||||
|
* @return n/a
|
||||||
|
*/
|
||||||
|
|
||||||
|
update_field_parent: function( $el ){
|
||||||
|
|
||||||
|
// bail early if not div.field (flexible content tr)
|
||||||
|
if( !$el.hasClass('acf-field-object') ) return;
|
||||||
|
|
||||||
|
|
||||||
|
// vars
|
||||||
|
var $parent = $el.parent().closest('.acf-field-object'),
|
||||||
|
val = acf.get('post_id');
|
||||||
|
|
||||||
|
|
||||||
|
// find parent
|
||||||
|
if( $parent.exists() ) {
|
||||||
|
|
||||||
|
// set as parent ID
|
||||||
|
val = acf.field_group.get_field_meta( $parent, 'ID' );
|
||||||
|
|
||||||
|
|
||||||
|
// if parent is new, no ID exists
|
||||||
|
if( !val ) {
|
||||||
|
|
||||||
|
val = acf.field_group.get_field_meta( $parent, 'key' );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// update parent
|
||||||
|
acf.field_group.update_field_meta( $el, 'parent', val );
|
||||||
|
|
||||||
|
|
||||||
|
// action for 3rd party customization
|
||||||
|
acf.do_action('update_field_parent', $el, $parent);
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* duplicate_field
|
||||||
|
*
|
||||||
|
* This function is triggered when duplicating a field
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 8/04/2014
|
||||||
|
* @since 5.0.0
|
||||||
|
*
|
||||||
|
* @param $el
|
||||||
|
* @return n/a
|
||||||
|
*/
|
||||||
|
|
||||||
|
duplicate_field: function( $el ) {
|
||||||
|
|
||||||
|
// vars
|
||||||
|
var $fields = $el.find('.acf-field-object');
|
||||||
|
|
||||||
|
|
||||||
|
// bail early if $fields are empty
|
||||||
|
if( !$fields.exists() ) {
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// loop over sub fields
|
||||||
|
$fields.each(function(){
|
||||||
|
|
||||||
|
// vars
|
||||||
|
var $parent = $(this).parent().closest('.acf-field-object'),
|
||||||
|
key = acf.field_group.get_field_meta( $parent, 'key');
|
||||||
|
|
||||||
|
|
||||||
|
// wipe field
|
||||||
|
acf.field_group.wipe_field( $(this) );
|
||||||
|
|
||||||
|
|
||||||
|
// update parent
|
||||||
|
acf.field_group.update_field_meta( $(this), 'parent', key );
|
||||||
|
|
||||||
|
|
||||||
|
// save field
|
||||||
|
acf.field_group.save_field( $(this) );
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// fix conditional logic rules
|
||||||
|
this.fix_conditional_logic( $fields );
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* delete_field
|
||||||
|
*
|
||||||
|
* This function is triggered when deleting a field
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 8/04/2014
|
||||||
|
* @since 5.0.0
|
||||||
|
*
|
||||||
|
* @param $el
|
||||||
|
* @return n/a
|
||||||
|
*/
|
||||||
|
|
||||||
|
delete_field : function( $el ){
|
||||||
|
|
||||||
|
$el.find('.acf-field-object').each(function(){
|
||||||
|
|
||||||
|
acf.field_group.delete_field( $(this), false );
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* change_field_type
|
||||||
|
*
|
||||||
|
* This function is triggered when changing a field type
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 7/06/2014
|
||||||
|
* @since 5.0.0
|
||||||
|
*
|
||||||
|
* @param $post_id (int)
|
||||||
|
* @return $post_id (int)
|
||||||
|
*/
|
||||||
|
|
||||||
|
change_field_type : function( $el ) {
|
||||||
|
|
||||||
|
$el.find('.acf-field-object').each(function(){
|
||||||
|
|
||||||
|
acf.field_group.delete_field( $(this), false );
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
|
|
|
||||||
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
|
|
@ -6,7 +6,11 @@ if( ! class_exists('acf_cache') ) :
|
||||||
|
|
||||||
class acf_cache {
|
class acf_cache {
|
||||||
|
|
||||||
|
// vars
|
||||||
|
var $cache = array(),
|
||||||
|
$reference = array();
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* __construct
|
* __construct
|
||||||
*
|
*
|
||||||
|
|
@ -22,11 +26,6 @@ class acf_cache {
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
|
|
||||||
// vars
|
|
||||||
$this->cache = array();
|
|
||||||
$this->reference = array();
|
|
||||||
|
|
||||||
|
|
||||||
// prevent ACF from persistent cache
|
// prevent ACF from persistent cache
|
||||||
wp_cache_add_non_persistent_groups('acf');
|
wp_cache_add_non_persistent_groups('acf');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,78 +18,28 @@ class acf_compatibility {
|
||||||
function __construct() {
|
function __construct() {
|
||||||
|
|
||||||
// fields
|
// fields
|
||||||
add_filter('acf/get_valid_field', array($this, 'get_valid_field'), 20, 1);
|
add_filter('acf/validate_field', array($this, 'validate_field'), 20, 1);
|
||||||
add_filter('acf/get_valid_field/type=textarea', array($this, 'get_valid_textarea_field'), 20, 1);
|
add_filter('acf/validate_field/type=textarea', array($this, 'validate_textarea_field'), 20, 1);
|
||||||
add_filter('acf/get_valid_field/type=relationship', array($this, 'get_valid_relationship_field'), 20, 1);
|
add_filter('acf/validate_field/type=relationship', array($this, 'validate_relationship_field'), 20, 1);
|
||||||
add_filter('acf/get_valid_field/type=post_object', array($this, 'get_valid_relationship_field'), 20, 1);
|
add_filter('acf/validate_field/type=post_object', array($this, 'validate_relationship_field'), 20, 1);
|
||||||
add_filter('acf/get_valid_field/type=page_link', array($this, 'get_valid_relationship_field'), 20, 1);
|
add_filter('acf/validate_field/type=page_link', array($this, 'validate_relationship_field'), 20, 1);
|
||||||
add_filter('acf/get_valid_field/type=image', array($this, 'get_valid_image_field'), 20, 1);
|
add_filter('acf/validate_field/type=image', array($this, 'validate_image_field'), 20, 1);
|
||||||
add_filter('acf/get_valid_field/type=file', array($this, 'get_valid_image_field'), 20, 1);
|
add_filter('acf/validate_field/type=file', array($this, 'validate_image_field'), 20, 1);
|
||||||
add_filter('acf/get_valid_field/type=wysiwyg', array($this, 'get_valid_wysiwyg_field'), 20, 1);
|
add_filter('acf/validate_field/type=wysiwyg', array($this, 'validate_wysiwyg_field'), 20, 1);
|
||||||
add_filter('acf/get_valid_field/type=date_picker', array($this, 'get_valid_date_picker_field'), 20, 1);
|
add_filter('acf/validate_field/type=date_picker', array($this, 'validate_date_picker_field'), 20, 1);
|
||||||
add_filter('acf/get_valid_field/type=taxonomy', array($this, 'get_valid_taxonomy_field'), 20, 1);
|
add_filter('acf/validate_field/type=taxonomy', array($this, 'validate_taxonomy_field'), 20, 1);
|
||||||
add_filter('acf/get_valid_field/type=date_time_picker', array($this, 'get_valid_date_time_picker_field'), 20, 1);
|
add_filter('acf/validate_field/type=date_time_picker', array($this, 'validate_date_time_picker_field'), 20, 1);
|
||||||
add_filter('acf/get_valid_field/type=user', array($this, 'get_valid_user_field'), 20, 1);
|
add_filter('acf/validate_field/type=user', array($this, 'validate_user_field'), 20, 1);
|
||||||
|
|
||||||
|
|
||||||
// field groups
|
// field groups
|
||||||
add_filter('acf/get_valid_field_group', array($this, 'get_valid_field_group'), 20, 1);
|
add_filter('acf/validate_field_group', array($this, 'validate_field_group'), 20, 1);
|
||||||
|
|
||||||
|
|
||||||
// settings
|
|
||||||
add_filter('acf/settings/show_admin', array($this, 'settings_acf_lite'), 5, 1);
|
|
||||||
add_filter('acf/settings/l10n_textdomain', array($this, 'settings_export_textdomain'), 5, 1);
|
|
||||||
add_filter('acf/settings/l10n_field', array($this, 'settings_export_translate'), 5, 1);
|
|
||||||
add_filter('acf/settings/l10n_field_group', array($this, 'settings_export_translate'), 5, 1);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* settings
|
* validate_field
|
||||||
*
|
|
||||||
* description
|
|
||||||
*
|
|
||||||
* @type function
|
|
||||||
* @date 19/05/2014
|
|
||||||
* @since 5.0.0
|
|
||||||
*
|
|
||||||
* @param $post_id (int)
|
|
||||||
* @return $post_id (int)
|
|
||||||
*/
|
|
||||||
|
|
||||||
function settings_acf_lite( $setting ) {
|
|
||||||
|
|
||||||
// 5.0.0 - removed ACF_LITE
|
|
||||||
if( defined('ACF_LITE') && ACF_LITE ) {
|
|
||||||
|
|
||||||
$setting = false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// return
|
|
||||||
return $setting;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function settings_export_textdomain( $setting ) {
|
|
||||||
|
|
||||||
// 5.3.3 - changed filter name
|
|
||||||
return acf_get_setting( 'export_textdomain', $setting );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function settings_export_translate( $setting ) {
|
|
||||||
|
|
||||||
// 5.3.3 - changed filter name
|
|
||||||
return acf_get_setting( 'export_translate', $setting );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* get_valid_field
|
|
||||||
*
|
*
|
||||||
* This function will provide compatibility with ACF4 fields
|
* This function will provide compatibility with ACF4 fields
|
||||||
*
|
*
|
||||||
|
|
@ -101,7 +51,7 @@ class acf_compatibility {
|
||||||
* @return $field
|
* @return $field
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function get_valid_field( $field ) {
|
function validate_field( $field ) {
|
||||||
|
|
||||||
// conditional logic has changed
|
// conditional logic has changed
|
||||||
if( isset($field['conditional_logic']['status']) ) {
|
if( isset($field['conditional_logic']['status']) ) {
|
||||||
|
|
@ -163,7 +113,7 @@ class acf_compatibility {
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get_valid_relationship_field
|
* validate_relationship_field
|
||||||
*
|
*
|
||||||
* This function will provide compatibility with ACF4 fields
|
* This function will provide compatibility with ACF4 fields
|
||||||
*
|
*
|
||||||
|
|
@ -175,7 +125,7 @@ class acf_compatibility {
|
||||||
* @return $field
|
* @return $field
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function get_valid_relationship_field( $field ) {
|
function validate_relationship_field( $field ) {
|
||||||
|
|
||||||
// force array
|
// force array
|
||||||
$field['post_type'] = acf_get_array($field['post_type']);
|
$field['post_type'] = acf_get_array($field['post_type']);
|
||||||
|
|
@ -213,7 +163,7 @@ class acf_compatibility {
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get_valid_textarea_field
|
* validate_textarea_field
|
||||||
*
|
*
|
||||||
* This function will provide compatibility with ACF4 fields
|
* This function will provide compatibility with ACF4 fields
|
||||||
*
|
*
|
||||||
|
|
@ -225,7 +175,7 @@ class acf_compatibility {
|
||||||
* @return $field
|
* @return $field
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function get_valid_textarea_field( $field ) {
|
function validate_textarea_field( $field ) {
|
||||||
|
|
||||||
// formatting has been removed
|
// formatting has been removed
|
||||||
$formatting = acf_extract_var( $field, 'formatting' );
|
$formatting = acf_extract_var( $field, 'formatting' );
|
||||||
|
|
@ -243,7 +193,7 @@ class acf_compatibility {
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get_valid_image_field
|
* validate_image_field
|
||||||
*
|
*
|
||||||
* This function will provide compatibility with ACF4 fields
|
* This function will provide compatibility with ACF4 fields
|
||||||
*
|
*
|
||||||
|
|
@ -255,7 +205,7 @@ class acf_compatibility {
|
||||||
* @return $field
|
* @return $field
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function get_valid_image_field( $field ) {
|
function validate_image_field( $field ) {
|
||||||
|
|
||||||
// save_format is now return_format
|
// save_format is now return_format
|
||||||
if( !empty($field['save_format']) ) {
|
if( !empty($field['save_format']) ) {
|
||||||
|
|
@ -279,7 +229,7 @@ class acf_compatibility {
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get_valid_wysiwyg_field
|
* validate_wysiwyg_field
|
||||||
*
|
*
|
||||||
* This function will provide compatibility with ACF4 fields
|
* This function will provide compatibility with ACF4 fields
|
||||||
*
|
*
|
||||||
|
|
@ -291,7 +241,7 @@ class acf_compatibility {
|
||||||
* @return $field
|
* @return $field
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function get_valid_wysiwyg_field( $field ) {
|
function validate_wysiwyg_field( $field ) {
|
||||||
|
|
||||||
// media_upload is now numeric
|
// media_upload is now numeric
|
||||||
if( $field['media_upload'] === 'yes' ) {
|
if( $field['media_upload'] === 'yes' ) {
|
||||||
|
|
@ -311,7 +261,7 @@ class acf_compatibility {
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get_valid_date_picker_field
|
* validate_date_picker_field
|
||||||
*
|
*
|
||||||
* This function will provide compatibility with ACF4 fields
|
* This function will provide compatibility with ACF4 fields
|
||||||
*
|
*
|
||||||
|
|
@ -323,7 +273,7 @@ class acf_compatibility {
|
||||||
* @return $field
|
* @return $field
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function get_valid_date_picker_field( $field ) {
|
function validate_date_picker_field( $field ) {
|
||||||
|
|
||||||
// v4 used date_format
|
// v4 used date_format
|
||||||
if( !empty($field['date_format']) ) {
|
if( !empty($field['date_format']) ) {
|
||||||
|
|
@ -356,7 +306,7 @@ class acf_compatibility {
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get_valid_taxonomy_field
|
* validate_taxonomy_field
|
||||||
*
|
*
|
||||||
* This function will provide compatibility with ACF4 fields
|
* This function will provide compatibility with ACF4 fields
|
||||||
*
|
*
|
||||||
|
|
@ -368,7 +318,7 @@ class acf_compatibility {
|
||||||
* @return $field
|
* @return $field
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function get_valid_taxonomy_field( $field ) {
|
function validate_taxonomy_field( $field ) {
|
||||||
|
|
||||||
// 5.2.7
|
// 5.2.7
|
||||||
if( isset($field['load_save_terms']) ) {
|
if( isset($field['load_save_terms']) ) {
|
||||||
|
|
@ -385,7 +335,7 @@ class acf_compatibility {
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get_valid_date_time_picker_field
|
* validate_date_time_picker_field
|
||||||
*
|
*
|
||||||
* This function will provide compatibility with existing 3rd party fields
|
* This function will provide compatibility with existing 3rd party fields
|
||||||
*
|
*
|
||||||
|
|
@ -397,7 +347,7 @@ class acf_compatibility {
|
||||||
* @return $field
|
* @return $field
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function get_valid_date_time_picker_field( $field ) {
|
function validate_date_time_picker_field( $field ) {
|
||||||
|
|
||||||
// 3rd party date time picker
|
// 3rd party date time picker
|
||||||
// https://github.com/soderlind/acf-field-date-time-picker
|
// https://github.com/soderlind/acf-field-date-time-picker
|
||||||
|
|
@ -436,7 +386,7 @@ class acf_compatibility {
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get_valid_user_field
|
* validate_user_field
|
||||||
*
|
*
|
||||||
* This function will provide compatibility with ACF4 fields
|
* This function will provide compatibility with ACF4 fields
|
||||||
*
|
*
|
||||||
|
|
@ -448,7 +398,7 @@ class acf_compatibility {
|
||||||
* @return $field
|
* @return $field
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function get_valid_user_field( $field ) {
|
function validate_user_field( $field ) {
|
||||||
|
|
||||||
// remove 'all' from roles
|
// remove 'all' from roles
|
||||||
if( acf_in_array('all', $field['role']) ) {
|
if( acf_in_array('all', $field['role']) ) {
|
||||||
|
|
@ -481,7 +431,7 @@ class acf_compatibility {
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get_valid_field_group
|
* validate_field_group
|
||||||
*
|
*
|
||||||
* This function will provide compatibility with ACF4 field groups
|
* This function will provide compatibility with ACF4 field groups
|
||||||
*
|
*
|
||||||
|
|
@ -493,21 +443,17 @@ class acf_compatibility {
|
||||||
* @return $field_group
|
* @return $field_group
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function get_valid_field_group( $field_group ) {
|
function validate_field_group( $field_group ) {
|
||||||
|
|
||||||
// global
|
|
||||||
global $wpdb;
|
|
||||||
|
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
$v = 5;
|
$version = 5;
|
||||||
|
|
||||||
|
|
||||||
// add missing 'key' (v5.0.0)
|
// add missing 'key' (v5.0.0)
|
||||||
if( empty($field_group['key']) ) {
|
if( empty($field_group['key']) ) {
|
||||||
|
|
||||||
// update version
|
// update version
|
||||||
$v = 4;
|
$version = 4;
|
||||||
|
|
||||||
|
|
||||||
// add missing key
|
// add missing key
|
||||||
|
|
@ -547,11 +493,7 @@ class acf_compatibility {
|
||||||
foreach( $location['rules'] as $rule ) {
|
foreach( $location['rules'] as $rule ) {
|
||||||
|
|
||||||
// sperate groups?
|
// sperate groups?
|
||||||
if( $all_or_any == 'any' ) {
|
if( $all_or_any == 'any' ) $group++;
|
||||||
|
|
||||||
$group++;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// add to group
|
// add to group
|
||||||
|
|
@ -572,7 +514,7 @@ class acf_compatibility {
|
||||||
if( !empty($field_group['location']) ) {
|
if( !empty($field_group['location']) ) {
|
||||||
|
|
||||||
// param changes
|
// param changes
|
||||||
$param_replace = array(
|
$replace = array(
|
||||||
'taxonomy' => 'post_taxonomy',
|
'taxonomy' => 'post_taxonomy',
|
||||||
'ef_media' => 'attachment',
|
'ef_media' => 'attachment',
|
||||||
'ef_taxonomy' => 'taxonomy',
|
'ef_taxonomy' => 'taxonomy',
|
||||||
|
|
@ -582,75 +524,43 @@ class acf_compatibility {
|
||||||
|
|
||||||
|
|
||||||
// remove conflicting param
|
// remove conflicting param
|
||||||
if( $v == 5 ) {
|
if( $version == 5 ) {
|
||||||
|
|
||||||
unset($param_replace['taxonomy']);
|
unset($replace['taxonomy']);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// loop over location groups
|
// loop over location groups
|
||||||
foreach( array_keys($field_group['location']) as $i ) {
|
foreach( $field_group['location'] as $i => $group ) {
|
||||||
|
|
||||||
// extract group
|
|
||||||
$group = acf_extract_var( $field_group['location'], $i );
|
|
||||||
|
|
||||||
|
|
||||||
// bail early if group is empty
|
// bail early if group is empty
|
||||||
if( empty($group) ) {
|
if( empty($group) ) continue;
|
||||||
|
|
||||||
continue;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// loop over group rules
|
// loop over group rules
|
||||||
foreach( array_keys($group) as $j ) {
|
foreach( $group as $ii => $rule ) {
|
||||||
|
|
||||||
// extract rule
|
|
||||||
$rule = acf_extract_var( $group, $j );
|
|
||||||
|
|
||||||
|
|
||||||
// migrate param
|
// migrate param
|
||||||
if( isset($param_replace[ $rule['param'] ]) ) {
|
if( isset($replace[ $rule['param'] ]) ) {
|
||||||
|
|
||||||
$rule['param'] = $param_replace[ $rule['param'] ];
|
$rule['param'] = $replace[ $rule['param'] ];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// category / taxonomy terms are saved differently
|
|
||||||
if( $rule['param'] == 'post_category' || $rule['param'] == 'post_taxonomy' ) {
|
|
||||||
|
|
||||||
if( is_numeric($rule['value']) ) {
|
|
||||||
|
|
||||||
$term_id = $rule['value'];
|
|
||||||
$taxonomy = $wpdb->get_var( $wpdb->prepare( "SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d LIMIT 1", $term_id) );
|
|
||||||
$term = get_term( $term_id, $taxonomy );
|
|
||||||
|
|
||||||
// update rule value
|
|
||||||
$rule['value'] = "{$term->taxonomy}:{$term->slug}";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// update
|
||||||
// append rule
|
$group[ $ii ] = $rule;
|
||||||
$group[ $j ] = $rule;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// foreach
|
|
||||||
|
|
||||||
|
|
||||||
// append group
|
// update
|
||||||
$field_group['location'][ $i ] = $group;
|
$field_group['location'][ $i ] = $group;
|
||||||
|
|
||||||
}
|
}
|
||||||
// foreach
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// if
|
|
||||||
|
|
||||||
|
|
||||||
// change layout to style (v5.0.0)
|
// change layout to style (v5.0.0)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,185 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||||
|
|
||||||
|
if( ! class_exists('acf_deprecated') ) :
|
||||||
|
|
||||||
|
class acf_deprecated {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* __construct
|
||||||
|
*
|
||||||
|
* This function will setup the class functionality
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 30/1/17
|
||||||
|
* @since 5.5.6
|
||||||
|
*
|
||||||
|
* @param n/a
|
||||||
|
* @return n/a
|
||||||
|
*/
|
||||||
|
|
||||||
|
function __construct() {
|
||||||
|
|
||||||
|
// settings
|
||||||
|
add_filter('acf/settings/show_admin', array($this, 'acf_settings_show_admin'), 5, 1); // 5.0.0
|
||||||
|
add_filter('acf/settings/l10n_textdomain', array($this, 'acf_settings_l10n_textdomain'), 5, 1); // 5.3.3
|
||||||
|
add_filter('acf/settings/l10n_field', array($this, 'acf_settings_l10n_field'), 5, 1); // 5.3.3
|
||||||
|
add_filter('acf/settings/l10n_field_group', array($this, 'acf_settings_l10n_field'), 5, 1); // 5.3.3
|
||||||
|
|
||||||
|
|
||||||
|
// filters
|
||||||
|
add_filter('acf/validate_field', array($this, 'acf_validate_field'), 10, 1); // 5.5.6
|
||||||
|
add_filter('acf/validate_field_group', array($this, 'acf_validate_field_group'), 10, 1); // 5.5.6
|
||||||
|
add_filter('acf/validate_post_id', array($this, 'acf_validate_post_id'), 10, 2); // 5.5.6
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* acf_settings_show_admin
|
||||||
|
*
|
||||||
|
* This function will add compatibility for previously named hooks
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 19/05/2014
|
||||||
|
* @since 5.0.0
|
||||||
|
*
|
||||||
|
* @param n/a
|
||||||
|
* @return n/a
|
||||||
|
*/
|
||||||
|
|
||||||
|
function acf_settings_show_admin( $setting ) {
|
||||||
|
|
||||||
|
// 5.0.0 - removed ACF_LITE
|
||||||
|
return ( defined('ACF_LITE') && ACF_LITE ) ? false : $setting;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* acf_settings_l10n_textdomain
|
||||||
|
*
|
||||||
|
* This function will add compatibility for previously named hooks
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 19/05/2014
|
||||||
|
* @since 5.0.0
|
||||||
|
*
|
||||||
|
* @param n/a
|
||||||
|
* @return n/a
|
||||||
|
*/
|
||||||
|
|
||||||
|
function acf_settings_l10n_textdomain( $setting ) {
|
||||||
|
|
||||||
|
// 5.3.3 - changed filter name
|
||||||
|
return acf_get_setting( 'export_textdomain', $setting );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* acf_settings_l10n_field
|
||||||
|
*
|
||||||
|
* This function will add compatibility for previously named hooks
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 19/05/2014
|
||||||
|
* @since 5.0.0
|
||||||
|
*
|
||||||
|
* @param n/a
|
||||||
|
* @return n/a
|
||||||
|
*/
|
||||||
|
|
||||||
|
function acf_settings_l10n_field( $setting ) {
|
||||||
|
|
||||||
|
// 5.3.3 - changed filter name
|
||||||
|
return acf_get_setting( 'export_translate', $setting );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* acf_validate_field
|
||||||
|
*
|
||||||
|
* This function will add compatibility for previously named hooks
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 30/1/17
|
||||||
|
* @since 5.5.6
|
||||||
|
*
|
||||||
|
* @param $post_id (int)
|
||||||
|
* @return $post_id (int)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function acf_validate_field( $field ) {
|
||||||
|
|
||||||
|
// 5.5.6 - changed filter name
|
||||||
|
$field = apply_filters( "acf/get_valid_field", $field );
|
||||||
|
$field = apply_filters( "acf/get_valid_field/type={$field['type']}", $field );
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return $field;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* acf_validate_field_group
|
||||||
|
*
|
||||||
|
* This function will add compatibility for previously named hooks
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 30/1/17
|
||||||
|
* @since 5.5.6
|
||||||
|
*
|
||||||
|
* @param $post_id (int)
|
||||||
|
* @return $post_id (int)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function acf_validate_field_group( $field_group ) {
|
||||||
|
|
||||||
|
// 5.5.6 - changed filter name
|
||||||
|
$field_group = apply_filters('acf/get_valid_field_group', $field_group);
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return $field_group;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* acf_validate_post_id
|
||||||
|
*
|
||||||
|
* This function will add compatibility for previously named hooks
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 6/2/17
|
||||||
|
* @since 5.5.6
|
||||||
|
*
|
||||||
|
* @param $post_id (int)
|
||||||
|
* @return $post_id (int)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function acf_validate_post_id( $post_id, $_post_id ) {
|
||||||
|
|
||||||
|
// 5.5.6 - changed filter name
|
||||||
|
$post_id = apply_filters('acf/get_valid_post_id', $post_id, $_post_id);
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return $post_id;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// initialize
|
||||||
|
acf()->deprecated = new acf_deprecated();
|
||||||
|
|
||||||
|
endif; // class_exists check
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
@ -41,7 +41,7 @@ class acf_field {
|
||||||
|
|
||||||
|
|
||||||
// field
|
// field
|
||||||
$this->add_field_filter('acf/get_valid_field', array($this, 'get_valid_field'), 10, 1);
|
$this->add_field_filter('acf/validate_field', array($this, 'validate_field'), 10, 1);
|
||||||
$this->add_field_filter('acf/load_field', array($this, 'load_field'), 10, 1);
|
$this->add_field_filter('acf/load_field', array($this, 'load_field'), 10, 1);
|
||||||
$this->add_field_filter('acf/update_field', array($this, 'update_field'), 10, 1);
|
$this->add_field_filter('acf/update_field', array($this, 'update_field'), 10, 1);
|
||||||
$this->add_field_filter('acf/duplicate_field', array($this, 'duplicate_field'), 10, 1);
|
$this->add_field_filter('acf/duplicate_field', array($this, 'duplicate_field'), 10, 1);
|
||||||
|
|
@ -211,11 +211,11 @@ class acf_field {
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get_valid_field
|
* validate_field
|
||||||
*
|
*
|
||||||
* This function will append default settings to a field
|
* This function will append default settings to a field
|
||||||
*
|
*
|
||||||
* @type filter ("acf/get_valid_field/type={$this->name}")
|
* @type filter ("acf/validate_field/type={$this->name}")
|
||||||
* @since 3.6
|
* @since 3.6
|
||||||
* @date 23/01/13
|
* @date 23/01/13
|
||||||
*
|
*
|
||||||
|
|
@ -223,14 +223,22 @@ class acf_field {
|
||||||
* @return $field (array)
|
* @return $field (array)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function get_valid_field( $field ) {
|
function validate_field( $field ) {
|
||||||
|
|
||||||
// bail early if no defaults
|
// bail early if no defaults
|
||||||
if( !is_array($this->defaults) ) return $field;
|
if( !is_array($this->defaults) ) return $field;
|
||||||
|
|
||||||
|
|
||||||
// merge in defaults
|
// merge in defaults but keep order of $field keys
|
||||||
return array_merge($this->defaults, $field);
|
foreach( $this->defaults as $k => $v ) {
|
||||||
|
|
||||||
|
if( !isset($field[ $k ]) ) $field[ $k ] = $v;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return $field;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,697 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||||
|
|
||||||
|
if( ! class_exists('acf_form') ) :
|
||||||
|
|
||||||
|
class acf_form {
|
||||||
|
|
||||||
|
// vars
|
||||||
|
var $forms = array(),
|
||||||
|
$fields = array();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* __construct
|
||||||
|
*
|
||||||
|
* This function will setup the class functionality
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 5/03/2014
|
||||||
|
* @since 5.0.0
|
||||||
|
*
|
||||||
|
* @param n/a
|
||||||
|
* @return n/a
|
||||||
|
*/
|
||||||
|
|
||||||
|
function __construct() {
|
||||||
|
|
||||||
|
// vars
|
||||||
|
$this->fields = array(
|
||||||
|
|
||||||
|
'_post_title' => array(
|
||||||
|
'prefix' => 'acf',
|
||||||
|
'name' => '_post_title',
|
||||||
|
'key' => '_post_title',
|
||||||
|
'label' => __('Title', 'acf'),
|
||||||
|
'type' => 'text',
|
||||||
|
'required' => true,
|
||||||
|
),
|
||||||
|
|
||||||
|
'_post_content' => array(
|
||||||
|
'prefix' => 'acf',
|
||||||
|
'name' => '_post_content',
|
||||||
|
'key' => '_post_content',
|
||||||
|
'label' => __('Content', 'acf'),
|
||||||
|
'type' => 'wysiwyg',
|
||||||
|
),
|
||||||
|
|
||||||
|
'_validate_email' => array(
|
||||||
|
'prefix' => 'acf',
|
||||||
|
'name' => '_validate_email',
|
||||||
|
'key' => '_validate_email',
|
||||||
|
'label' => __('Validate Email', 'acf'),
|
||||||
|
'type' => 'text',
|
||||||
|
'value' => '',
|
||||||
|
'wrapper' => array('style' => 'display:none !important;')
|
||||||
|
)
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// actions
|
||||||
|
add_action('acf/validate_save_post', array($this, 'validate_save_post'), 1);
|
||||||
|
|
||||||
|
|
||||||
|
// filters
|
||||||
|
add_filter('acf/pre_save_post', array($this, 'pre_save_post'), 5, 2);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* validate_form
|
||||||
|
*
|
||||||
|
* description
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 28/2/17
|
||||||
|
* @since 5.5.8
|
||||||
|
*
|
||||||
|
* @param $post_id (int)
|
||||||
|
* @return $post_id (int)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function validate_form( $args ) {
|
||||||
|
|
||||||
|
// defaults
|
||||||
|
$args = wp_parse_args( $args, array(
|
||||||
|
'id' => 'acf-form',
|
||||||
|
'post_id' => false,
|
||||||
|
'new_post' => false,
|
||||||
|
'field_groups' => false,
|
||||||
|
'fields' => false,
|
||||||
|
'post_title' => false,
|
||||||
|
'post_content' => false,
|
||||||
|
'form' => true,
|
||||||
|
'form_attributes' => array(),
|
||||||
|
'return' => add_query_arg( 'updated', 'true', acf_get_current_url() ),
|
||||||
|
'html_before_fields' => '',
|
||||||
|
'html_after_fields' => '',
|
||||||
|
'submit_value' => __("Update", 'acf'),
|
||||||
|
'updated_message' => __("Post updated", 'acf'),
|
||||||
|
'label_placement' => 'top',
|
||||||
|
'instruction_placement' => 'label',
|
||||||
|
'field_el' => 'div',
|
||||||
|
'uploader' => 'wp',
|
||||||
|
'honeypot' => true,
|
||||||
|
'html_updated_message' => '<div id="message" class="updated"><p>%s</p></div>', // 5.5.10
|
||||||
|
'html_submit_button' => '<input type="submit" class="acf-button button button-primary button-large" value="%s" />', // 5.5.10
|
||||||
|
'html_submit_spinner' => '<span class="acf-spinner"></span>' // 5.5.10
|
||||||
|
));
|
||||||
|
|
||||||
|
$args['form_attributes'] = wp_parse_args( $args['form_attributes'], array(
|
||||||
|
'id' => $args['id'],
|
||||||
|
'class' => 'acf-form',
|
||||||
|
'action' => '',
|
||||||
|
'method' => 'post',
|
||||||
|
));
|
||||||
|
|
||||||
|
|
||||||
|
// filter post_id
|
||||||
|
$args['post_id'] = acf_get_valid_post_id( $args['post_id'] );
|
||||||
|
|
||||||
|
|
||||||
|
// new post?
|
||||||
|
if( $args['post_id'] === 'new_post' ) {
|
||||||
|
|
||||||
|
$args['new_post'] = wp_parse_args( $args['new_post'], array(
|
||||||
|
'post_type' => 'post',
|
||||||
|
'post_status' => 'draft',
|
||||||
|
));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// filter
|
||||||
|
$args = apply_filters('acf/validate_form', $args);
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return $args;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* add_form
|
||||||
|
*
|
||||||
|
* description
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 28/2/17
|
||||||
|
* @since 5.5.8
|
||||||
|
*
|
||||||
|
* @param $post_id (int)
|
||||||
|
* @return $post_id (int)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function add_form( $args = array() ) {
|
||||||
|
|
||||||
|
// validate
|
||||||
|
$args = $this->validate_form( $args );
|
||||||
|
|
||||||
|
|
||||||
|
// append
|
||||||
|
$this->forms[ $args['id'] ] = $args;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get_form
|
||||||
|
*
|
||||||
|
* description
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 28/2/17
|
||||||
|
* @since 5.5.8
|
||||||
|
*
|
||||||
|
* @param $post_id (int)
|
||||||
|
* @return $post_id (int)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function get_form( $id = '' ) {
|
||||||
|
|
||||||
|
// bail early if not set
|
||||||
|
if( !isset($this->forms[ $id ]) ) return false;
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return $this->forms[ $id ];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* validate_save_post
|
||||||
|
*
|
||||||
|
* This function will validate fields from the above array
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 7/09/2016
|
||||||
|
* @since 5.4.0
|
||||||
|
*
|
||||||
|
* @param $post_id (int)
|
||||||
|
* @return $post_id (int)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function validate_save_post() {
|
||||||
|
|
||||||
|
// register field if isset in $_POST
|
||||||
|
foreach( $this->fields as $k => $field ) {
|
||||||
|
|
||||||
|
// bail early if no in $_POST
|
||||||
|
if( !isset($_POST['acf'][ $k ]) ) continue;
|
||||||
|
|
||||||
|
|
||||||
|
// register
|
||||||
|
acf_add_local_field($field);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// honeypot
|
||||||
|
if( !empty($_POST['acf']['_validate_email']) ) {
|
||||||
|
|
||||||
|
acf_add_validation_error( '', __('Spam Detected', 'acf') );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* pre_save_post
|
||||||
|
*
|
||||||
|
* description
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 7/09/2016
|
||||||
|
* @since 5.4.0
|
||||||
|
*
|
||||||
|
* @param $post_id (int)
|
||||||
|
* @return $post_id (int)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function pre_save_post( $post_id, $form ) {
|
||||||
|
|
||||||
|
// vars
|
||||||
|
$save = array(
|
||||||
|
'ID' => 0
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// determine save data
|
||||||
|
if( is_numeric($post_id) ) {
|
||||||
|
|
||||||
|
// update post
|
||||||
|
$save['ID'] = $post_id;
|
||||||
|
|
||||||
|
} elseif( $post_id == 'new_post' ) {
|
||||||
|
|
||||||
|
// merge in new post data
|
||||||
|
$save = array_merge($save, $form['new_post']);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// not post
|
||||||
|
return $post_id;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// save post_title
|
||||||
|
if( isset($_POST['acf']['_post_title']) ) {
|
||||||
|
|
||||||
|
$save['post_title'] = acf_extract_var($_POST['acf'], '_post_title');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// save post_content
|
||||||
|
if( isset($_POST['acf']['_post_content']) ) {
|
||||||
|
|
||||||
|
$save['post_content'] = acf_extract_var($_POST['acf'], '_post_content');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// honeypot
|
||||||
|
if( !empty($_POST['acf']['_validate_email']) ) return false;
|
||||||
|
|
||||||
|
|
||||||
|
// validate
|
||||||
|
if( count($save) == 1 ) {
|
||||||
|
|
||||||
|
return $post_id;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if( $save['ID'] ) {
|
||||||
|
|
||||||
|
wp_update_post( $save );
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$post_id = wp_insert_post( $save );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return $post_id;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* enqueue
|
||||||
|
*
|
||||||
|
* This function will enqueue a form
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 7/09/2016
|
||||||
|
* @since 5.4.0
|
||||||
|
*
|
||||||
|
* @param $post_id (int)
|
||||||
|
* @return $post_id (int)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function enqueue_form() {
|
||||||
|
|
||||||
|
// check
|
||||||
|
$this->check_submit_form();
|
||||||
|
|
||||||
|
|
||||||
|
// load acf scripts
|
||||||
|
acf_enqueue_scripts();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check_submit_form
|
||||||
|
*
|
||||||
|
* This function will maybe submit form data
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 3/3/17
|
||||||
|
* @since 5.5.10
|
||||||
|
*
|
||||||
|
* @param n/a
|
||||||
|
* @return n/a
|
||||||
|
*/
|
||||||
|
|
||||||
|
function check_submit_form() {
|
||||||
|
|
||||||
|
// bail ealry if form not submit
|
||||||
|
if( !isset($_POST['_acfform']) ) return;
|
||||||
|
|
||||||
|
|
||||||
|
// verify nonce
|
||||||
|
if( !acf_verify_nonce('acf_form') ) return;
|
||||||
|
|
||||||
|
|
||||||
|
// validate data
|
||||||
|
acf_validate_save_post(true);
|
||||||
|
|
||||||
|
|
||||||
|
// submit
|
||||||
|
$this->submit_form();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* submit_form
|
||||||
|
*
|
||||||
|
* This function will submit form data
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 3/3/17
|
||||||
|
* @since 5.5.10
|
||||||
|
*
|
||||||
|
* @param n/a
|
||||||
|
* @return n/a
|
||||||
|
*/
|
||||||
|
|
||||||
|
function submit_form() {
|
||||||
|
|
||||||
|
// vars
|
||||||
|
$form = @json_decode(acf_decrypt($_POST['_acfform']), true);
|
||||||
|
|
||||||
|
|
||||||
|
// bail ealry if form is corrupt
|
||||||
|
if( empty($form) ) return;
|
||||||
|
|
||||||
|
|
||||||
|
// filter
|
||||||
|
$form = apply_filters('acf/pre_submit_form', $form);
|
||||||
|
|
||||||
|
|
||||||
|
// vars
|
||||||
|
$post_id = acf_maybe_get($form, 'post_id', 0);
|
||||||
|
|
||||||
|
|
||||||
|
// add global for backwards compatibility
|
||||||
|
$GLOBALS['acf_form'] = $form;
|
||||||
|
|
||||||
|
|
||||||
|
// allow for custom save
|
||||||
|
$post_id = apply_filters('acf/pre_save_post', $post_id, $form);
|
||||||
|
|
||||||
|
|
||||||
|
// save
|
||||||
|
acf_save_post( $post_id );
|
||||||
|
|
||||||
|
|
||||||
|
// restore form (potentially modified)
|
||||||
|
$form = $GLOBALS['acf_form'];
|
||||||
|
|
||||||
|
|
||||||
|
// action
|
||||||
|
do_action('acf/submit_form', $form, $post_id);
|
||||||
|
|
||||||
|
|
||||||
|
// vars
|
||||||
|
$return = acf_maybe_get($form, 'return', '');
|
||||||
|
|
||||||
|
|
||||||
|
// redirect
|
||||||
|
if( $return ) {
|
||||||
|
|
||||||
|
// update %placeholders%
|
||||||
|
$return = str_replace('%post_id%', $post_id, $return);
|
||||||
|
$return = str_replace('%post_url%', get_permalink($post_id), $return);
|
||||||
|
|
||||||
|
|
||||||
|
// redirect
|
||||||
|
wp_redirect( $return );
|
||||||
|
exit;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* render
|
||||||
|
*
|
||||||
|
* description
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 7/09/2016
|
||||||
|
* @since 5.4.0
|
||||||
|
*
|
||||||
|
* @param $post_id (int)
|
||||||
|
* @return $post_id (int)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function render_form( $args = array() ) {
|
||||||
|
|
||||||
|
// array
|
||||||
|
if( is_array($args) ) {
|
||||||
|
|
||||||
|
$args = $this->validate_form( $args );
|
||||||
|
|
||||||
|
// id
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$args = $this->get_form( $args );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// bail early if no args
|
||||||
|
if( !$args ) return false;
|
||||||
|
|
||||||
|
|
||||||
|
// load values from this post
|
||||||
|
$post_id = $args['post_id'];
|
||||||
|
|
||||||
|
|
||||||
|
// dont load values for 'new_post'
|
||||||
|
if( $post_id === 'new_post' ) $post_id = false;
|
||||||
|
|
||||||
|
|
||||||
|
// register local fields
|
||||||
|
foreach( $this->fields as $k => $field ) {
|
||||||
|
|
||||||
|
acf_add_local_field($field);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// vars
|
||||||
|
$field_groups = array();
|
||||||
|
$fields = array();
|
||||||
|
|
||||||
|
|
||||||
|
// post_title
|
||||||
|
if( $args['post_title'] ) {
|
||||||
|
|
||||||
|
// load local field
|
||||||
|
$_post_title = acf_get_field('_post_title');
|
||||||
|
$_post_title['value'] = $post_id ? get_post_field('post_title', $post_id) : '';
|
||||||
|
|
||||||
|
|
||||||
|
// append
|
||||||
|
$fields[] = $_post_title;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// post_content
|
||||||
|
if( $args['post_content'] ) {
|
||||||
|
|
||||||
|
// load local field
|
||||||
|
$_post_content = acf_get_field('_post_content');
|
||||||
|
$_post_content['value'] = $post_id ? get_post_field('post_content', $post_id) : '';
|
||||||
|
|
||||||
|
|
||||||
|
// append
|
||||||
|
$fields[] = $_post_content;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// specific fields
|
||||||
|
if( $args['fields'] ) {
|
||||||
|
|
||||||
|
foreach( $args['fields'] as $selector ) {
|
||||||
|
|
||||||
|
// append field ($strict = false to allow for better compatibility with field names)
|
||||||
|
$fields[] = acf_maybe_get_field( $selector, $post_id, false );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} elseif( $args['field_groups'] ) {
|
||||||
|
|
||||||
|
foreach( $args['field_groups'] as $selector ) {
|
||||||
|
|
||||||
|
$field_groups[] = acf_get_field_group( $selector );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} elseif( $args['post_id'] == 'new_post' ) {
|
||||||
|
|
||||||
|
$field_groups = acf_get_field_groups( $args['new_post'] );
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$field_groups = acf_get_field_groups(array(
|
||||||
|
'post_id' => $args['post_id']
|
||||||
|
));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//load fields based on field groups
|
||||||
|
if( !empty($field_groups) ) {
|
||||||
|
|
||||||
|
foreach( $field_groups as $field_group ) {
|
||||||
|
|
||||||
|
$field_group_fields = acf_get_fields( $field_group );
|
||||||
|
|
||||||
|
if( !empty($field_group_fields) ) {
|
||||||
|
|
||||||
|
foreach( array_keys($field_group_fields) as $i ) {
|
||||||
|
|
||||||
|
$fields[] = acf_extract_var($field_group_fields, $i);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// honeypot
|
||||||
|
if( $args['honeypot'] ) {
|
||||||
|
|
||||||
|
$fields[] = acf_get_field('_validate_email');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// updated message
|
||||||
|
if( !empty($_GET['updated']) && $args['updated_message'] ) {
|
||||||
|
|
||||||
|
printf( $args['html_updated_message'], $args['updated_message'] );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// uploader (always set incase of multiple forms on the page)
|
||||||
|
acf_update_setting('uploader', $args['uploader']);
|
||||||
|
|
||||||
|
|
||||||
|
// display form
|
||||||
|
if( $args['form'] ): ?>
|
||||||
|
|
||||||
|
<form <?php acf_esc_attr_e( $args['form_attributes']); ?>>
|
||||||
|
|
||||||
|
<?php endif;
|
||||||
|
|
||||||
|
// render post data
|
||||||
|
acf_form_data(array(
|
||||||
|
'post_id' => $args['post_id'],
|
||||||
|
'nonce' => 'acf_form',
|
||||||
|
'_acfform' => acf_encrypt(json_encode($args))
|
||||||
|
));
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="acf-fields acf-form-fields -<?php echo $args['label_placement']; ?>">
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
// html before fields
|
||||||
|
echo $args['html_before_fields'];
|
||||||
|
|
||||||
|
|
||||||
|
// render
|
||||||
|
acf_render_fields( $post_id, $fields, $args['field_el'], $args['instruction_placement'] );
|
||||||
|
|
||||||
|
|
||||||
|
// html after fields
|
||||||
|
echo $args['html_after_fields'];
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php if( $args['form'] ): ?>
|
||||||
|
|
||||||
|
<div class="acf-form-submit">
|
||||||
|
|
||||||
|
<?php printf( $args['html_submit_button'], $args['submit_value'] ); ?>
|
||||||
|
<?php echo $args['html_submit_spinner']; ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
<?php endif;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// initialize
|
||||||
|
acf()->form = new acf_form();
|
||||||
|
|
||||||
|
endif; // class_exists check
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Functions
|
||||||
|
*
|
||||||
|
* alias of acf()->form->functions
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 11/06/2014
|
||||||
|
* @since 5.0.0
|
||||||
|
*
|
||||||
|
* @param n/a
|
||||||
|
* @return n/a
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
function acf_form_head() {
|
||||||
|
|
||||||
|
acf()->form->enqueue_form();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function acf_form( $args = array() ) {
|
||||||
|
|
||||||
|
acf()->form->render_form( $args );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function acf_get_form( $id = '' ) {
|
||||||
|
|
||||||
|
acf()->form->get_form( $id );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function acf_register_form( $args ) {
|
||||||
|
|
||||||
|
acf()->form->add_form( $args );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
@ -456,10 +456,26 @@ function acf_form_data( $args = array() ) {
|
||||||
$args = acf_set_form_data( $args );
|
$args = acf_set_form_data( $args );
|
||||||
|
|
||||||
|
|
||||||
|
// hidden inputs
|
||||||
|
$inputs = array(
|
||||||
|
'_acfnonce' => wp_create_nonce($args['nonce']),
|
||||||
|
'_acfchanged' => 0
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// append custom
|
||||||
|
foreach( $args as $k => $v ) {
|
||||||
|
|
||||||
|
if( substr($k, 0, 4) === '_acf' ) $inputs[ $k ] = $v;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<div id="acf-form-data" class="acf-hidden">
|
<div id="acf-form-data" class="acf-hidden">
|
||||||
<input type="hidden" name="_acfnonce" value="<?php echo wp_create_nonce( $args['nonce'] ); ?>" />
|
<?php foreach( $inputs as $k => $v ): ?>
|
||||||
<input type="hidden" name="_acfchanged" value="0" />
|
<input type="hidden" name="<?php echo esc_attr($k); ?>" value="<?php echo esc_attr($v); ?>" />
|
||||||
|
<?php endforeach; ?>
|
||||||
<?php do_action('acf/input/form_data', $args); ?>
|
<?php do_action('acf/input/form_data', $args); ?>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||||
|
|
||||||
|
if( ! class_exists('acf_json') ) :
|
||||||
|
|
||||||
class acf_json {
|
class acf_json {
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
|
|
@ -10,12 +14,12 @@ class acf_json {
|
||||||
|
|
||||||
|
|
||||||
// actions
|
// actions
|
||||||
add_action('acf/update_field_group', array($this, 'update_field_group'), 10, 5);
|
add_action('acf/update_field_group', array($this, 'update_field_group'), 10, 1);
|
||||||
add_action('acf/duplicate_field_group', array($this, 'update_field_group'), 10, 5);
|
add_action('acf/duplicate_field_group', array($this, 'update_field_group'), 10, 1);
|
||||||
add_action('acf/untrash_field_group', array($this, 'update_field_group'), 10, 5);
|
add_action('acf/untrash_field_group', array($this, 'update_field_group'), 10, 1);
|
||||||
add_action('acf/trash_field_group', array($this, 'delete_field_group'), 10, 5);
|
add_action('acf/trash_field_group', array($this, 'delete_field_group'), 10, 1);
|
||||||
add_action('acf/delete_field_group', array($this, 'delete_field_group'), 10, 5);
|
add_action('acf/delete_field_group', array($this, 'delete_field_group'), 10, 1);
|
||||||
add_action('acf/include_fields', array($this, 'include_fields'), 10, 5);
|
add_action('acf/include_fields', array($this, 'include_fields'), 10, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,11 +98,7 @@ class acf_json {
|
||||||
function include_fields() {
|
function include_fields() {
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
if( !acf_get_setting('json') ) {
|
if( !acf_get_setting('json') ) return;
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
|
|
@ -123,13 +123,9 @@ class acf_json {
|
||||||
$dir = opendir( $path );
|
$dir = opendir( $path );
|
||||||
|
|
||||||
while(false !== ( $file = readdir($dir)) ) {
|
while(false !== ( $file = readdir($dir)) ) {
|
||||||
|
|
||||||
// only json files
|
|
||||||
if( strpos($file, '.json') === false ) {
|
|
||||||
|
|
||||||
continue;
|
// validate type
|
||||||
|
if( pathinfo($file, PATHINFO_EXTENSION) !== 'json' ) continue;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// read json
|
// read json
|
||||||
|
|
@ -137,11 +133,7 @@ class acf_json {
|
||||||
|
|
||||||
|
|
||||||
// validate json
|
// validate json
|
||||||
if( empty($json) ) {
|
if( empty($json) ) continue;
|
||||||
|
|
||||||
continue;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// decode
|
// decode
|
||||||
|
|
@ -163,7 +155,11 @@ class acf_json {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
new acf_json();
|
|
||||||
|
// initialize
|
||||||
|
acf()->json = new acf_json();
|
||||||
|
|
||||||
|
endif; // class_exists check
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
263
core/local.php
263
core/local.php
|
|
@ -7,8 +7,10 @@ if( ! class_exists('acf_local') ) :
|
||||||
class acf_local {
|
class acf_local {
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
var $groups = array(),
|
var $temp = array(),
|
||||||
|
$groups = array(),
|
||||||
$fields = array(),
|
$fields = array(),
|
||||||
|
$reference = array(),
|
||||||
$parents = array();
|
$parents = array();
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -32,7 +34,7 @@ class acf_local {
|
||||||
|
|
||||||
|
|
||||||
// actions
|
// actions
|
||||||
add_action('acf/delete_field', array($this, 'acf_delete_field'), 20, 1);
|
add_action('acf/include_fields', array($this, 'acf_include_fields'), 5, 0);
|
||||||
|
|
||||||
|
|
||||||
// filters
|
// filters
|
||||||
|
|
@ -41,6 +43,35 @@ class acf_local {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* reset
|
* reset
|
||||||
*
|
*
|
||||||
|
|
@ -57,8 +88,10 @@ class acf_local {
|
||||||
function reset() {
|
function reset() {
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
|
$this->temp = array();
|
||||||
$this->groups = array();
|
$this->groups = array();
|
||||||
$this->fields = array();
|
$this->fields = array();
|
||||||
|
$this->reference = array();
|
||||||
$this->parents = array();
|
$this->parents = array();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -160,21 +193,28 @@ class acf_local {
|
||||||
|
|
||||||
function add_field( $field ) {
|
function add_field( $field ) {
|
||||||
|
|
||||||
// vars
|
// defaults
|
||||||
$key = acf_maybe_get($field, 'key', '');
|
$field = wp_parse_args($field, array(
|
||||||
$parent = acf_maybe_get($field, 'parent', '');
|
'key' => '',
|
||||||
|
'name' => '',
|
||||||
|
'parent' => 0
|
||||||
|
));
|
||||||
|
|
||||||
|
|
||||||
// add parent reference
|
// add parent reference
|
||||||
$this->add_parent_reference( $parent, $key );
|
$this->add_parent_reference( $field['parent'], $field['key'] );
|
||||||
|
|
||||||
|
|
||||||
// add in menu order
|
// add in menu order
|
||||||
$field['menu_order'] = count( $this->parents[ $parent ] ) - 1;
|
$field['menu_order'] = $this->count_fields( $field['parent'] ) - 1;
|
||||||
|
|
||||||
|
|
||||||
// add field
|
// add field
|
||||||
$this->fields[ $key ] = $field;
|
$this->fields[ $field['key'] ] = $field;
|
||||||
|
|
||||||
|
|
||||||
|
// add reference for field name
|
||||||
|
$this->reference[ $field['name'] ] = $field['key'];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -194,6 +234,10 @@ class acf_local {
|
||||||
|
|
||||||
function is_field( $key = '' ) {
|
function is_field( $key = '' ) {
|
||||||
|
|
||||||
|
// vars
|
||||||
|
$key = $this->get_key($key);
|
||||||
|
|
||||||
|
|
||||||
// bail early if not enabled
|
// bail early if not enabled
|
||||||
if( !$this->is_enabled() ) return false;
|
if( !$this->is_enabled() ) return false;
|
||||||
|
|
||||||
|
|
@ -203,6 +247,28 @@ class acf_local {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function is_field_key( $key ) {
|
||||||
|
|
||||||
|
// bail early if not enabled
|
||||||
|
if( !$this->is_enabled() ) return false;
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return isset( $this->fields[ $key ] );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_field_name( $name ) {
|
||||||
|
|
||||||
|
// bail early if not enabled
|
||||||
|
if( !$this->is_enabled() ) return false;
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return isset( $this->reference[ $name ] );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get_field
|
* get_field
|
||||||
|
|
@ -219,6 +285,10 @@ class acf_local {
|
||||||
|
|
||||||
function get_field( $key = '' ) {
|
function get_field( $key = '' ) {
|
||||||
|
|
||||||
|
// vars
|
||||||
|
$key = $this->get_key($key);
|
||||||
|
|
||||||
|
|
||||||
// bail early if no group
|
// bail early if no group
|
||||||
if( !$this->is_field($key) ) return false;
|
if( !$this->is_field($key) ) return false;
|
||||||
|
|
||||||
|
|
@ -257,19 +327,95 @@ class acf_local {
|
||||||
|
|
||||||
|
|
||||||
// remove field
|
// remove field
|
||||||
unset( $this->fields[ $key ] );
|
unset( $this->fields[ $field['key'] ] );
|
||||||
|
|
||||||
|
|
||||||
|
// remove reference for field name
|
||||||
|
unset( $this->reference[ $field['name'] ] );
|
||||||
|
|
||||||
|
|
||||||
// remove children
|
// remove children
|
||||||
if( acf_have_local_fields( $key) ) {
|
if( $this->have_fields($key) ) {
|
||||||
|
|
||||||
acf_remove_local_fields( $key );
|
$this->remove_fields( $key );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* acf_include_fields
|
||||||
|
*
|
||||||
|
* This function include any $temp field groups during the 'acf/include_fields' action
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 8/2/17
|
||||||
|
* @since 5.5.6
|
||||||
|
*
|
||||||
|
* @param n/a
|
||||||
|
* @return n/a
|
||||||
|
*/
|
||||||
|
|
||||||
|
function acf_include_fields() {
|
||||||
|
|
||||||
|
// bail ealry if no temp
|
||||||
|
if( empty($this->temp) ) return;
|
||||||
|
|
||||||
|
|
||||||
|
// loop
|
||||||
|
foreach( $this->temp as $i => $temp ) {
|
||||||
|
|
||||||
|
// add
|
||||||
|
$this->add_field_group($temp);
|
||||||
|
|
||||||
|
|
||||||
|
// unset
|
||||||
|
unset($this->temp[ $i ]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* maybe_add_field_group
|
||||||
|
*
|
||||||
|
* This function will determine if it is too early to 'add' a field group and if so will add to $temp
|
||||||
|
* Field groups added to $temp will be included during the 'acf/include_fields' action which ensures all field types exist
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 9/2/17
|
||||||
|
* @since 5.5.6
|
||||||
|
*
|
||||||
|
* @param $post_id (int)
|
||||||
|
* @return $post_id (int)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function maybe_add_field_group( $field_group ) {
|
||||||
|
|
||||||
|
// add to temp if too early
|
||||||
|
if( !did_action('acf/include_fields') ) {
|
||||||
|
|
||||||
|
// append
|
||||||
|
$this->temp[] = $field_group;
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// add
|
||||||
|
$this->add_field_group( $field_group );
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* add_field_group
|
* add_field_group
|
||||||
*
|
*
|
||||||
|
|
@ -285,6 +431,10 @@ class acf_local {
|
||||||
|
|
||||||
function add_field_group( $field_group ) {
|
function add_field_group( $field_group ) {
|
||||||
|
|
||||||
|
// vars
|
||||||
|
$fields = acf_extract_var($field_group, 'fields');
|
||||||
|
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
$field_group = acf_get_valid_field_group($field_group);
|
$field_group = acf_get_valid_field_group($field_group);
|
||||||
|
|
||||||
|
|
@ -293,35 +443,27 @@ class acf_local {
|
||||||
if( $this->is_field_group($field_group['key']) ) return;
|
if( $this->is_field_group($field_group['key']) ) return;
|
||||||
|
|
||||||
|
|
||||||
// add local
|
// add local (may be set to json)
|
||||||
if( empty($field_group['local']) ) {
|
if( empty($field_group['local']) ) $field_group['local'] = 'php';
|
||||||
|
|
||||||
$field_group['local'] = 'php';
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// remove fields
|
|
||||||
$fields = acf_extract_var($field_group, 'fields');
|
|
||||||
|
|
||||||
|
|
||||||
// format fields
|
|
||||||
$fields = acf_prepare_fields_for_import( $fields );
|
|
||||||
|
|
||||||
|
|
||||||
// add field group
|
// add field group
|
||||||
$this->groups[ $field_group['key'] ] = $field_group;
|
$this->groups[ $field_group['key'] ] = $field_group;
|
||||||
|
|
||||||
|
|
||||||
|
// bail ealry if no fields
|
||||||
|
if( !$fields ) return;
|
||||||
|
|
||||||
|
|
||||||
|
// format fields
|
||||||
|
$fields = acf_prepare_fields_for_import( $fields );
|
||||||
|
|
||||||
|
|
||||||
// add fields
|
// add fields
|
||||||
foreach( $fields as $field ) {
|
foreach( $fields as $field ) {
|
||||||
|
|
||||||
// add parent
|
// add parent
|
||||||
if( empty($field['parent']) ) {
|
if( empty($field['parent']) ) $field['parent'] = $field_group['key'];
|
||||||
|
|
||||||
$field['parent'] = $field_group['key'];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// add field
|
// add field
|
||||||
|
|
@ -444,7 +586,24 @@ class acf_local {
|
||||||
|
|
||||||
function get_field_groups() {
|
function get_field_groups() {
|
||||||
|
|
||||||
return array_values($this->groups);
|
// bail early if no parent
|
||||||
|
if( !$this->have_field_groups() ) return false;
|
||||||
|
|
||||||
|
|
||||||
|
// vars
|
||||||
|
$field_groups = array();
|
||||||
|
|
||||||
|
|
||||||
|
// append
|
||||||
|
foreach( array_keys($this->groups) as $field_group_key ) {
|
||||||
|
|
||||||
|
$field_groups[] = acf_get_field_group( $field_group_key );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return $field_groups;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -650,26 +809,6 @@ class acf_local {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* acf_delete_field
|
|
||||||
*
|
|
||||||
* description
|
|
||||||
*
|
|
||||||
* @type function
|
|
||||||
* @date 10/12/2014
|
|
||||||
* @since 5.1.5
|
|
||||||
*
|
|
||||||
* @param $post_id (int)
|
|
||||||
* @return $post_id (int)
|
|
||||||
*/
|
|
||||||
|
|
||||||
function acf_delete_field( $field ) {
|
|
||||||
|
|
||||||
$this->remove_field( $field['key'] );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -720,7 +859,7 @@ function acf_reset_local() {
|
||||||
// field group
|
// field group
|
||||||
function acf_add_local_field_group( $field_group ) {
|
function acf_add_local_field_group( $field_group ) {
|
||||||
|
|
||||||
return acf_local()->add_field_group( $field_group );
|
return acf_local()->maybe_add_field_group( $field_group );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -782,6 +921,18 @@ function acf_is_local_field( $key = '' ) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function acf_is_local_field_key( $key = '' ) {
|
||||||
|
|
||||||
|
return acf_local()->is_field_key( $key );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function acf_is_local_field_name( $name = '' ) {
|
||||||
|
|
||||||
|
return acf_local()->is_field_name( $name );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function acf_get_local_field( $key = '' ) {
|
function acf_get_local_field( $key = '' ) {
|
||||||
|
|
||||||
return acf_local()->get_field( $key );
|
return acf_local()->get_field( $key );
|
||||||
|
|
@ -815,4 +966,12 @@ function acf_remove_local_fields( $key = '' ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// deprecated
|
||||||
|
function register_field_group( $field_group ) {
|
||||||
|
|
||||||
|
acf_add_local_field_group( $field_group );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,11 @@ if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||||
if( ! class_exists('acf_revisions') ) :
|
if( ! class_exists('acf_revisions') ) :
|
||||||
|
|
||||||
class acf_revisions {
|
class acf_revisions {
|
||||||
|
|
||||||
|
// vars
|
||||||
|
var $cache = array();
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* __construct
|
* __construct
|
||||||
*
|
*
|
||||||
|
|
@ -28,6 +32,7 @@ class acf_revisions {
|
||||||
add_filter('wp_save_post_revision_check_for_changes', array($this, 'wp_save_post_revision_check_for_changes'), 10, 3);
|
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_preview_post_fields'), 10, 2 );
|
add_filter('_wp_post_revision_fields', array($this, 'wp_preview_post_fields'), 10, 2 );
|
||||||
add_filter('_wp_post_revision_fields', array($this, 'wp_post_revision_fields'), 10, 2 );
|
add_filter('_wp_post_revision_fields', array($this, 'wp_post_revision_fields'), 10, 2 );
|
||||||
|
add_filter('acf/validate_post_id', array($this, 'acf_validate_post_id'), 10, 2 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -333,6 +338,80 @@ class acf_revisions {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* acf_validate_post_id
|
||||||
|
*
|
||||||
|
* This function will modify the $post_id and allow loading values from a revision
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 6/3/17
|
||||||
|
* @since 5.5.10
|
||||||
|
*
|
||||||
|
* @param $post_id (int)
|
||||||
|
* @param $_post_id (int)
|
||||||
|
* @return $post_id (int)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function acf_validate_post_id( $post_id, $_post_id ) {
|
||||||
|
|
||||||
|
// bail early if no preview in URL
|
||||||
|
if( !isset($_GET['preview']) ) return $post_id;
|
||||||
|
|
||||||
|
|
||||||
|
// bail early if $post_id is not numeric
|
||||||
|
if( !is_numeric($post_id) ) return $post_id;
|
||||||
|
|
||||||
|
|
||||||
|
// vars
|
||||||
|
$k = $post_id;
|
||||||
|
$preview_id = 0;
|
||||||
|
|
||||||
|
|
||||||
|
// check cache
|
||||||
|
if( isset($this->cache[$k]) ) return $this->cache[$k];
|
||||||
|
|
||||||
|
|
||||||
|
// validate
|
||||||
|
if( isset($_GET['preview_id']) ) {
|
||||||
|
|
||||||
|
$preview_id = (int) $_GET['preview_id'];
|
||||||
|
|
||||||
|
} elseif( isset($_GET['p']) ) {
|
||||||
|
|
||||||
|
$preview_id = (int) $_GET['p'];
|
||||||
|
|
||||||
|
} elseif( isset($_GET['page_id']) ) {
|
||||||
|
|
||||||
|
$preview_id = (int) $_GET['page_id'];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// bail early id $preview_id does not match $post_id
|
||||||
|
if( $preview_id != $post_id ) return $post_id;
|
||||||
|
|
||||||
|
|
||||||
|
// attempt find revision
|
||||||
|
$revision = acf_get_post_latest_revision( $post_id );
|
||||||
|
|
||||||
|
|
||||||
|
// save
|
||||||
|
if( $revision && $revision->post_parent == $post_id) {
|
||||||
|
|
||||||
|
$post_id = (int) $revision->ID;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// set cache
|
||||||
|
$this->cache[$k] = $post_id;
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return $post_id;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,6 @@ class acf_field_file extends acf_field {
|
||||||
|
|
||||||
// filters
|
// filters
|
||||||
add_filter('get_media_item_args', array($this, 'get_media_item_args'));
|
add_filter('get_media_item_args', array($this, 'get_media_item_args'));
|
||||||
add_filter('wp_prepare_attachment_for_js', array($this, 'wp_prepare_attachment_for_js'), 10, 3);
|
|
||||||
|
|
||||||
|
|
||||||
// do not delete!
|
// do not delete!
|
||||||
|
|
@ -133,9 +132,7 @@ class acf_field_file extends acf_field {
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<div <?php acf_esc_attr_e($div); ?>>
|
<div <?php acf_esc_attr_e($div); ?>>
|
||||||
<div class="acf-hidden">
|
<?php acf_hidden_input(array( 'name' => $field['name'], 'value' => $field['value'], 'data-name' => 'id' )); ?>
|
||||||
<?php acf_hidden_input(array( 'name' => $field['name'], 'value' => $field['value'], 'data-name' => 'id' )); ?>
|
|
||||||
</div>
|
|
||||||
<div class="show-if-value file-wrap acf-soh">
|
<div class="show-if-value file-wrap acf-soh">
|
||||||
<div class="file-icon">
|
<div class="file-icon">
|
||||||
<img data-name="icon" src="<?php echo $o['icon']; ?>" alt=""/>
|
<img data-name="icon" src="<?php echo $o['icon']; ?>" alt=""/>
|
||||||
|
|
@ -364,16 +361,32 @@ class acf_field_file extends acf_field {
|
||||||
|
|
||||||
function update_value( $value, $post_id, $field ) {
|
function update_value( $value, $post_id, $field ) {
|
||||||
|
|
||||||
// numeric
|
// bail early if is empty
|
||||||
if( is_numeric($value) ) return $value;
|
if( empty($value) ) return false;
|
||||||
|
|
||||||
|
|
||||||
// array?
|
// validate
|
||||||
if( is_array($value) && isset($value['ID']) ) return $value['ID'];
|
if( is_array($value) && isset($value['ID']) ) {
|
||||||
|
|
||||||
|
$value = $value['ID'];
|
||||||
|
|
||||||
|
} elseif( is_object($value) && isset($value->ID) ) {
|
||||||
|
|
||||||
|
$value = $value->ID;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// object?
|
// bail early if not attachment ID
|
||||||
if( is_object($value) && isset($value->ID) ) return $value->ID;
|
if( !$value || !is_numeric($value) ) return false;
|
||||||
|
|
||||||
|
|
||||||
|
// confirm type
|
||||||
|
$value = (int) $value;
|
||||||
|
|
||||||
|
|
||||||
|
// maybe connect attacment to post
|
||||||
|
acf_connect_attachment_to_post( $value, $post_id );
|
||||||
|
|
||||||
|
|
||||||
// return
|
// return
|
||||||
|
|
@ -382,38 +395,57 @@ class acf_field_file extends acf_field {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* wp_prepare_attachment_for_js
|
* validate_value
|
||||||
*
|
*
|
||||||
* this filter allows ACF to add in extra data to an attachment JS object
|
* This function will validate a basic file input
|
||||||
*
|
*
|
||||||
* @type function
|
* @type function
|
||||||
* @date 1/06/13
|
* @date 11/02/2014
|
||||||
|
* @since 5.0.0
|
||||||
*
|
*
|
||||||
* @param {int} $post_id
|
* @param $post_id (int)
|
||||||
* @return {int} $post_id
|
* @return $post_id (int)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function wp_prepare_attachment_for_js( $response, $attachment, $meta ) {
|
function validate_value( $valid, $value, $field, $input ){
|
||||||
|
|
||||||
// default
|
// bail early if empty
|
||||||
$fs = '0 kb';
|
if( empty($value) ) return $valid;
|
||||||
|
|
||||||
|
|
||||||
// supress PHP warnings caused by corrupt images
|
// bail ealry if is numeric
|
||||||
if( $i = @filesize( get_attached_file( $attachment->ID ) ) ) {
|
if( is_numeric($value) ) return $valid;
|
||||||
|
|
||||||
$fs = size_format( $i );
|
|
||||||
|
// bail ealry if not basic string
|
||||||
|
if( !is_string($value) ) return $valid;
|
||||||
|
|
||||||
|
|
||||||
|
// decode value
|
||||||
|
$file = null;
|
||||||
|
parse_str($value, $file);
|
||||||
|
|
||||||
|
|
||||||
|
// bail early if no attachment
|
||||||
|
if( empty($file) ) return $valid;
|
||||||
|
|
||||||
|
|
||||||
|
// get errors
|
||||||
|
$errors = acf_validate_attachment( $file, $field, 'basic_upload' );
|
||||||
|
|
||||||
|
|
||||||
|
// append error
|
||||||
|
if( !empty($errors) ) {
|
||||||
|
|
||||||
|
$valid = implode("\n", $errors);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// update JSON
|
// return
|
||||||
$response['filesize'] = $fs;
|
return $valid;
|
||||||
|
|
||||||
|
|
||||||
// return
|
|
||||||
return $response;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -132,9 +132,7 @@ class acf_field_image extends acf_field {
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<div <?php acf_esc_attr_e( $div ); ?>>
|
<div <?php acf_esc_attr_e( $div ); ?>>
|
||||||
<div class="acf-hidden">
|
<?php acf_hidden_input(array( 'name' => $field['name'], 'value' => $field['value'] )); ?>
|
||||||
<?php acf_hidden_input(array( 'name' => $field['name'], 'value' => $field['value'] )); ?>
|
|
||||||
</div>
|
|
||||||
<div class="view show-if-value acf-soh" <?php if( $size['width'] ) echo 'style="max-width: '.$size['width'].'px"'; ?>>
|
<div class="view show-if-value acf-soh" <?php if( $size['width'] ) echo 'style="max-width: '.$size['width'].'px"'; ?>>
|
||||||
<img data-name="image" src="<?php echo $url; ?>" alt="<?php echo $alt; ?>"/>
|
<img data-name="image" src="<?php echo $url; ?>" alt="<?php echo $alt; ?>"/>
|
||||||
<ul class="acf-hl acf-soh-target">
|
<ul class="acf-hl acf-soh-target">
|
||||||
|
|
@ -457,20 +455,27 @@ class acf_field_image extends acf_field {
|
||||||
|
|
||||||
function update_value( $value, $post_id, $field ) {
|
function update_value( $value, $post_id, $field ) {
|
||||||
|
|
||||||
// numeric
|
return acf_get_field_type('file')->update_value( $value, $post_id, $field );
|
||||||
if( is_numeric($value) ) return $value;
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* validate_value
|
||||||
|
*
|
||||||
|
* This function will validate a basic file input
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 11/02/2014
|
||||||
|
* @since 5.0.0
|
||||||
|
*
|
||||||
|
* @param $post_id (int)
|
||||||
|
* @return $post_id (int)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function validate_value( $valid, $value, $field, $input ){
|
||||||
|
|
||||||
// array?
|
return acf_get_field_type('file')->validate_value( $valid, $value, $field, $input );
|
||||||
if( is_array($value) && isset($value['ID']) ) return $value['ID'];
|
|
||||||
|
|
||||||
|
|
||||||
// object?
|
|
||||||
if( is_object($value) && isset($value->ID) ) return $value->ID;
|
|
||||||
|
|
||||||
|
|
||||||
// return
|
|
||||||
return $value;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,15 +39,13 @@ class acf_field_oembed extends acf_field {
|
||||||
'width' => '',
|
'width' => '',
|
||||||
'height' => '',
|
'height' => '',
|
||||||
);
|
);
|
||||||
$this->default_values = array(
|
$this->width = 640;
|
||||||
'width' => 640,
|
$this->height = 390;
|
||||||
'height' => 390
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
// extra
|
// extra
|
||||||
add_action('wp_ajax_acf/fields/oembed/search', array($this, 'ajax_search'));
|
add_action('wp_ajax_acf/fields/oembed/search', array($this, 'ajax_query'));
|
||||||
add_action('wp_ajax_nopriv_acf/fields/oembed/search', array($this, 'ajax_search'));
|
add_action('wp_ajax_nopriv_acf/fields/oembed/search', array($this, 'ajax_query'));
|
||||||
|
|
||||||
|
|
||||||
// do not delete!
|
// do not delete!
|
||||||
|
|
@ -56,6 +54,32 @@ class acf_field_oembed extends acf_field {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* prepare_field
|
||||||
|
*
|
||||||
|
* This function will prepare the field for input
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 14/2/17
|
||||||
|
* @since 5.5.8
|
||||||
|
*
|
||||||
|
* @param $field (array)
|
||||||
|
* @return (int)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function prepare_field( $field ) {
|
||||||
|
|
||||||
|
// defaults
|
||||||
|
if( !$field['width'] ) $field['width'] = $this->width;
|
||||||
|
if( !$field['height'] ) $field['height'] = $this->height;
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return $field;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* wp_oembed_get
|
* wp_oembed_get
|
||||||
*
|
*
|
||||||
|
|
@ -102,7 +126,7 @@ class acf_field_oembed extends acf_field {
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ajax_search
|
* ajax_query
|
||||||
*
|
*
|
||||||
* description
|
* description
|
||||||
*
|
*
|
||||||
|
|
@ -114,40 +138,62 @@ class acf_field_oembed extends acf_field {
|
||||||
* @return $post_id (int)
|
* @return $post_id (int)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function ajax_search() {
|
function ajax_query() {
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
if( !acf_verify_ajax() ) die();
|
if( !acf_verify_ajax() ) die();
|
||||||
|
|
||||||
|
|
||||||
// options
|
// get choices
|
||||||
$args = acf_parse_args( $_POST, array(
|
$response = $this->get_ajax_query( $_POST );
|
||||||
's' => '',
|
|
||||||
'width' => 0,
|
|
||||||
'height' => 0,
|
// return
|
||||||
|
wp_send_json($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( $args = array() ) {
|
||||||
|
|
||||||
|
// defaults
|
||||||
|
$args = acf_parse_args($args, array(
|
||||||
|
's' => '',
|
||||||
|
'field_key' => '',
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
// width and height
|
// load field
|
||||||
if( !$args['width'] ) {
|
$field = acf_get_field( $args['field_key'] );
|
||||||
|
if( !$field ) return false;
|
||||||
$args['width'] = $this->default_values['width'];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if( !$args['height'] ) {
|
|
||||||
|
|
||||||
$args['height'] = $this->default_values['height'];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get oembed
|
// prepare field to correct width and height
|
||||||
echo $this->wp_oembed_get($args['s'], $args['width'], $args['height']);
|
$field = $this->prepare_field($field);
|
||||||
|
|
||||||
|
|
||||||
// die
|
// vars
|
||||||
die();
|
$response = array(
|
||||||
|
'url' => $args['s'],
|
||||||
|
'html' => $this->wp_oembed_get($args['s'], $field['width'], $field['height'])
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return $response;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,30 +212,14 @@ class acf_field_oembed extends acf_field {
|
||||||
|
|
||||||
function render_field( $field ) {
|
function render_field( $field ) {
|
||||||
|
|
||||||
// default options
|
|
||||||
foreach( $this->default_values as $k => $v ) {
|
|
||||||
|
|
||||||
if( empty($field[ $k ]) ) {
|
|
||||||
|
|
||||||
$field[ $k ] = $v;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// atts
|
// atts
|
||||||
$atts = array(
|
$atts = array(
|
||||||
'class' => 'acf-oembed',
|
'class' => 'acf-oembed',
|
||||||
'data-width' => $field['width'],
|
|
||||||
'data-height' => $field['height']
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if( $field['value'] ) {
|
|
||||||
|
|
||||||
$atts['class'] .= ' has-value';
|
// value
|
||||||
|
if( $field['value'] ) $atts['class'] .= ' has-value';
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<div <?php acf_esc_attr_e($atts) ?>>
|
<div <?php acf_esc_attr_e($atts) ?>>
|
||||||
|
|
@ -221,15 +251,12 @@ class acf_field_oembed extends acf_field {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="canvas-media" data-name="value-embed">
|
<div class="canvas-media" data-name="value-embed">
|
||||||
<?php if( !empty( $field['value'] ) ): ?>
|
<?php if( $field['value'] ) echo $this->wp_oembed_get($field['value'], $field['width'], $field['height']); ?>
|
||||||
<?php echo $this->wp_oembed_get($field['value'], $field['width'], $field['height']); ?>
|
|
||||||
<?php endif; ?>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<i class="acf-icon -picture hide-if-value"></i>
|
<i class="acf-icon -picture hide-if-value"></i>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
@ -258,7 +285,7 @@ class acf_field_oembed extends acf_field {
|
||||||
'name' => 'width',
|
'name' => 'width',
|
||||||
'prepend' => __('Width', 'acf'),
|
'prepend' => __('Width', 'acf'),
|
||||||
'append' => 'px',
|
'append' => 'px',
|
||||||
'placeholder' => $this->default_values['width']
|
'placeholder' => $this->width
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -269,7 +296,7 @@ class acf_field_oembed extends acf_field {
|
||||||
'name' => 'height',
|
'name' => 'height',
|
||||||
'prepend' => __('Height', 'acf'),
|
'prepend' => __('Height', 'acf'),
|
||||||
'append' => 'px',
|
'append' => 'px',
|
||||||
'placeholder' => $this->default_values['height'],
|
'placeholder' => $this->height,
|
||||||
'_append' => 'width'
|
'_append' => 'width'
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
@ -295,11 +322,11 @@ class acf_field_oembed extends acf_field {
|
||||||
function format_value( $value, $post_id, $field ) {
|
function format_value( $value, $post_id, $field ) {
|
||||||
|
|
||||||
// bail early if no value
|
// bail early if no value
|
||||||
if( empty($value) ) {
|
if( empty($value) ) return $value;
|
||||||
|
|
||||||
return $value;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
// prepare field to correct width and height
|
||||||
|
$field = $this->prepare_field($field);
|
||||||
|
|
||||||
|
|
||||||
// get oembed
|
// get oembed
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,15 @@ class acf_field_select extends acf_field {
|
||||||
$style = '';
|
$style = '';
|
||||||
|
|
||||||
|
|
||||||
|
// attempt to find 3rd party Select2 version
|
||||||
|
// - avoid including v3 CSS when v4 JS is already enququed
|
||||||
|
if( isset($wp_scripts->registered['select2']) ) {
|
||||||
|
|
||||||
|
$major = (int) $wp_scripts->registered['select2']->ver;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// v4
|
// v4
|
||||||
if( $major == 4 ) {
|
if( $major == 4 ) {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ class acf_field_true_false extends acf_field {
|
||||||
|
|
||||||
// update input
|
// update input
|
||||||
$input['class'] .= ' acf-switch-input';
|
$input['class'] .= ' acf-switch-input';
|
||||||
$input['style'] = 'display:none;';
|
//$input['style'] = 'display:none;';
|
||||||
|
|
||||||
$switch .= '<div class="acf-switch' . ($active ? ' -on' : '') . '">';
|
$switch .= '<div class="acf-switch' . ($active ? ' -on' : '') . '">';
|
||||||
$switch .= '<span class="acf-switch-on">'.$field['ui_on_text'].'</span>';
|
$switch .= '<span class="acf-switch-on">'.$field['ui_on_text'].'</span>';
|
||||||
|
|
|
||||||
|
|
@ -72,8 +72,33 @@ class acf_field_user extends acf_field {
|
||||||
if( !acf_verify_ajax() ) die();
|
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
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 15/10/2014
|
||||||
|
* @since 5.0.9
|
||||||
|
*
|
||||||
|
* @param $options (array)
|
||||||
|
* @return (array)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function get_ajax_query( $options = array() ) {
|
||||||
|
|
||||||
// defaults
|
// defaults
|
||||||
$options = acf_parse_args($_POST, array(
|
$options = acf_parse_args($options, array(
|
||||||
'post_id' => 0,
|
'post_id' => 0,
|
||||||
's' => '',
|
's' => '',
|
||||||
'field_key' => '',
|
'field_key' => '',
|
||||||
|
|
@ -81,6 +106,11 @@ class acf_field_user extends acf_field {
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
|
// load field
|
||||||
|
$field = acf_get_field( $options['field_key'] );
|
||||||
|
if( !$field ) return false;
|
||||||
|
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
$results = array();
|
$results = array();
|
||||||
$args = array();
|
$args = array();
|
||||||
|
|
@ -107,11 +137,6 @@ class acf_field_user extends acf_field {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// load field
|
|
||||||
$field = acf_get_field( $options['field_key'] );
|
|
||||||
if( !$field ) die();
|
|
||||||
|
|
||||||
|
|
||||||
// role
|
// role
|
||||||
if( !empty($field['role']) ) {
|
if( !empty($field['role']) ) {
|
||||||
|
|
||||||
|
|
@ -203,11 +228,15 @@ class acf_field_user extends acf_field {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// return
|
// vars
|
||||||
acf_send_ajax_results(array(
|
$response = array(
|
||||||
'results' => $results,
|
'results' => $results,
|
||||||
'limit' => $args['users_per_page']
|
'limit' => $args['users_per_page']
|
||||||
));
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return $response;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -136,10 +136,7 @@ class acf_form_taxonomy {
|
||||||
function add_term( $taxonomy ) {
|
function add_term( $taxonomy ) {
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
$post_id = "{$taxonomy}_0";
|
$post_id = acf_get_term_post_id( $taxonomy, 0 );
|
||||||
$args = array(
|
|
||||||
'taxonomy' => $taxonomy
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
// update vars
|
// update vars
|
||||||
|
|
@ -147,17 +144,22 @@ class acf_form_taxonomy {
|
||||||
|
|
||||||
|
|
||||||
// get field groups
|
// get field groups
|
||||||
$field_groups = acf_get_field_groups( $args );
|
$field_groups = acf_get_field_groups(array(
|
||||||
|
'taxonomy' => $taxonomy
|
||||||
|
));
|
||||||
|
|
||||||
|
|
||||||
// render
|
// render
|
||||||
if( !empty($field_groups) ) {
|
if( !empty($field_groups) ) {
|
||||||
|
|
||||||
|
// data
|
||||||
acf_form_data(array(
|
acf_form_data(array(
|
||||||
'post_id' => $post_id,
|
'post_id' => $post_id,
|
||||||
'nonce' => 'taxonomy',
|
'nonce' => 'taxonomy',
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
|
// loop
|
||||||
foreach( $field_groups as $field_group ) {
|
foreach( $field_groups as $field_group ) {
|
||||||
|
|
||||||
$fields = acf_get_fields( $field_group );
|
$fields = acf_get_fields( $field_group );
|
||||||
|
|
@ -187,10 +189,7 @@ class acf_form_taxonomy {
|
||||||
function edit_term( $term, $taxonomy ) {
|
function edit_term( $term, $taxonomy ) {
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
$post_id = "{$taxonomy}_{$term->term_id}";
|
$post_id = acf_get_term_post_id( $term->taxonomy, $term->term_id );
|
||||||
$args = array(
|
|
||||||
'taxonomy' => $taxonomy
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
// update vars
|
// update vars
|
||||||
|
|
@ -198,7 +197,9 @@ class acf_form_taxonomy {
|
||||||
|
|
||||||
|
|
||||||
// get field groups
|
// get field groups
|
||||||
$field_groups = acf_get_field_groups( $args );
|
$field_groups = acf_get_field_groups(array(
|
||||||
|
'taxonomy' => $taxonomy
|
||||||
|
));
|
||||||
|
|
||||||
|
|
||||||
// render
|
// render
|
||||||
|
|
@ -386,6 +387,10 @@ class acf_form_taxonomy {
|
||||||
|
|
||||||
function save_term( $term_id, $tt_id, $taxonomy ) {
|
function save_term( $term_id, $tt_id, $taxonomy ) {
|
||||||
|
|
||||||
|
// vars
|
||||||
|
$post_id = acf_get_term_post_id( $taxonomy, $term_id );
|
||||||
|
|
||||||
|
|
||||||
// verify and remove nonce
|
// verify and remove nonce
|
||||||
if( !acf_verify_nonce('taxonomy') ) return $term_id;
|
if( !acf_verify_nonce('taxonomy') ) return $term_id;
|
||||||
|
|
||||||
|
|
@ -395,7 +400,7 @@ class acf_form_taxonomy {
|
||||||
|
|
||||||
|
|
||||||
// save
|
// save
|
||||||
acf_save_post('term_' . $term_id);
|
acf_save_post( $post_id );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -449,4 +454,5 @@ new acf_form_taxonomy();
|
||||||
|
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
|
|
@ -136,11 +136,13 @@ class acf_form_widget {
|
||||||
|
|
||||||
$fields = acf_get_fields( $field_group );
|
$fields = acf_get_fields( $field_group );
|
||||||
|
|
||||||
acf_render_fields( $post_id, $fields, 'div', 'field' );
|
acf_render_fields( $post_id, $fields, 'div', $field_group['instruction_placement'] );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// jQuery selector looks odd, but is necessary due to WP adding an incremental number into the ID
|
||||||
|
// - not possible to find number via PHP parameters
|
||||||
if( $widget->updated ): ?>
|
if( $widget->updated ): ?>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
(function($) {
|
(function($) {
|
||||||
|
|
|
||||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
|
@ -3,7 +3,7 @@ msgstr ""
|
||||||
"Project-Id-Version: Advanced Custom Fields Pro v5.2.9\n"
|
"Project-Id-Version: Advanced Custom Fields Pro v5.2.9\n"
|
||||||
"Report-Msgid-Bugs-To: http://support.advancedcustomfields.com\n"
|
"Report-Msgid-Bugs-To: http://support.advancedcustomfields.com\n"
|
||||||
"POT-Creation-Date: 2016-11-10 22:35+0100\n"
|
"POT-Creation-Date: 2016-11-10 22:35+0100\n"
|
||||||
"PO-Revision-Date: 2016-11-10 22:35+0100\n"
|
"PO-Revision-Date: 2017-01-31 10:39+1000\n"
|
||||||
"Last-Translator: Elliot Condon <e@elliotcondon.com>\n"
|
"Last-Translator: Elliot Condon <e@elliotcondon.com>\n"
|
||||||
"Language-Team: Elliot Condon <e@elliotcondon.com>\n"
|
"Language-Team: Elliot Condon <e@elliotcondon.com>\n"
|
||||||
"Language: it_IT\n"
|
"Language: it_IT\n"
|
||||||
|
|
@ -11,7 +11,7 @@ msgstr ""
|
||||||
"Content-Type: text/plain; charset=UTF-8\n"
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
"Content-Transfer-Encoding: 8bit\n"
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
"X-Generator: Poedit 1.8.11\n"
|
"X-Generator: Poedit 1.8.1\n"
|
||||||
"X-Loco-Target-Locale: it_IT\n"
|
"X-Loco-Target-Locale: it_IT\n"
|
||||||
"X-Poedit-SourceCharset: UTF-8\n"
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
"X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;"
|
"X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;"
|
||||||
|
|
@ -1422,8 +1422,8 @@ msgstr "Dimensione piena"
|
||||||
msgid "(no title)"
|
msgid "(no title)"
|
||||||
msgstr "(nessun titolo)"
|
msgstr "(nessun titolo)"
|
||||||
|
|
||||||
#: api/api-helpers.php:1776 fields/page_link.php:284 fields/post_object.php:283
|
#: api/api-helpers.php:1776 fields/page_link.php:284
|
||||||
#: fields/taxonomy.php:988
|
#: fields/post_object.php:283 fields/taxonomy.php:988
|
||||||
msgid "Parent"
|
msgid "Parent"
|
||||||
msgstr "Genitore"
|
msgstr "Genitore"
|
||||||
|
|
||||||
|
|
@ -1710,8 +1710,8 @@ msgid "The format displayed when editing a post"
|
||||||
msgstr "Il formato visualizzato durante la modifica di un post"
|
msgstr "Il formato visualizzato durante la modifica di un post"
|
||||||
|
|
||||||
#: fields/date_picker.php:212 fields/date_time_picker.php:202
|
#: fields/date_picker.php:212 fields/date_time_picker.php:202
|
||||||
#: fields/post_object.php:447 fields/relationship.php:783 fields/select.php:522
|
#: fields/post_object.php:447 fields/relationship.php:783
|
||||||
#: fields/time_picker.php:140
|
#: fields/select.php:522 fields/time_picker.php:140
|
||||||
msgid "Return Format"
|
msgid "Return Format"
|
||||||
msgstr "Formato di ritorno"
|
msgstr "Formato di ritorno"
|
||||||
|
|
||||||
|
|
@ -2980,7 +2980,7 @@ msgstr "Righe minime raggiunte ({min} righe)"
|
||||||
|
|
||||||
#: pro/fields/repeater.php:48
|
#: pro/fields/repeater.php:48
|
||||||
msgid "Maximum rows reached ({max} rows)"
|
msgid "Maximum rows reached ({max} rows)"
|
||||||
msgstr "Righe massime raggiunte ({min} righe)"
|
msgstr "Righe massime raggiunte ({max} righe)"
|
||||||
|
|
||||||
#: pro/fields/repeater.php:396
|
#: pro/fields/repeater.php:396
|
||||||
msgid "Add row"
|
msgid "Add row"
|
||||||
|
|
|
||||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
238
pro/acf-pro.php
238
pro/acf-pro.php
|
|
@ -50,13 +50,6 @@ class acf_pro {
|
||||||
add_action('acf/include_field_types', array($this, 'include_field_types'), 5);
|
add_action('acf/include_field_types', array($this, 'include_field_types'), 5);
|
||||||
add_action('acf/input/admin_enqueue_scripts', array($this, 'input_admin_enqueue_scripts'));
|
add_action('acf/input/admin_enqueue_scripts', array($this, 'input_admin_enqueue_scripts'));
|
||||||
add_action('acf/field_group/admin_enqueue_scripts', array($this, 'field_group_admin_enqueue_scripts'));
|
add_action('acf/field_group/admin_enqueue_scripts', array($this, 'field_group_admin_enqueue_scripts'));
|
||||||
add_action('acf/field_group/admin_l10n', array($this, 'field_group_admin_l10n'));
|
|
||||||
|
|
||||||
|
|
||||||
// filters
|
|
||||||
add_filter('acf/get_valid_field', array($this, 'get_valid_field'), 11, 1);
|
|
||||||
add_filter('acf/prepare_field_for_export', array($this, 'prepare_field_for_export'));
|
|
||||||
add_filter('acf/prepare_field_for_import', array($this, 'prepare_field_for_import'));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -84,38 +77,6 @@ class acf_pro {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* get_valid_field
|
|
||||||
*
|
|
||||||
* This function will provide compatibility with ACF4 fields
|
|
||||||
*
|
|
||||||
* @type function
|
|
||||||
* @date 23/04/2014
|
|
||||||
* @since 5.0.0
|
|
||||||
*
|
|
||||||
* @param $field (array)
|
|
||||||
* @return $field
|
|
||||||
*/
|
|
||||||
|
|
||||||
function get_valid_field( $field ) {
|
|
||||||
|
|
||||||
// extract old width
|
|
||||||
$width = acf_extract_var( $field, 'column_width' );
|
|
||||||
|
|
||||||
|
|
||||||
// if old width, update the new width
|
|
||||||
if( $width ) {
|
|
||||||
|
|
||||||
$field['wrapper']['width'] = $width;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// return
|
|
||||||
return $field;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* register_assets
|
* register_assets
|
||||||
*
|
*
|
||||||
|
|
@ -172,32 +133,6 @@ class acf_pro {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* field_group_admin_l10n
|
|
||||||
*
|
|
||||||
* description
|
|
||||||
*
|
|
||||||
* @type function
|
|
||||||
* @date 1/05/2014
|
|
||||||
* @since 5.0.0
|
|
||||||
*
|
|
||||||
* @param $post_id (int)
|
|
||||||
* @return $post_id (int)
|
|
||||||
*/
|
|
||||||
|
|
||||||
function field_group_admin_l10n( $l10n ) {
|
|
||||||
|
|
||||||
// append
|
|
||||||
$l10n['flexible_content'] = array(
|
|
||||||
'layout_warning' => __('Flexible Content requires at least 1 layout','acf')
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
// return
|
|
||||||
return $l10n;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* field_group_admin_enqueue_scripts
|
* field_group_admin_enqueue_scripts
|
||||||
*
|
*
|
||||||
|
|
@ -221,179 +156,6 @@ class acf_pro {
|
||||||
wp_enqueue_style('acf-pro-field-group');
|
wp_enqueue_style('acf-pro-field-group');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* prepare_field_for_export
|
|
||||||
*
|
|
||||||
* description
|
|
||||||
*
|
|
||||||
* @type function
|
|
||||||
* @date 11/03/2014
|
|
||||||
* @since 5.0.0
|
|
||||||
*
|
|
||||||
* @param $post_id (int)
|
|
||||||
* @return $post_id (int)
|
|
||||||
*/
|
|
||||||
|
|
||||||
function prepare_field_for_export( $field ) {
|
|
||||||
|
|
||||||
// sub field (parent_layout)
|
|
||||||
acf_extract_var( $field, 'parent_layout');
|
|
||||||
|
|
||||||
|
|
||||||
// repeater
|
|
||||||
if( $field['type'] == 'repeater' ) {
|
|
||||||
|
|
||||||
$field['sub_fields'] = acf_prepare_fields_for_export( $field['sub_fields'] );
|
|
||||||
|
|
||||||
// flexible content
|
|
||||||
} elseif( $field['type'] == 'flexible_content' ) {
|
|
||||||
|
|
||||||
foreach( $field['layouts'] as $l => $layout ) {
|
|
||||||
|
|
||||||
$field['layouts'][ $l ]['sub_fields'] = acf_prepare_fields_for_export( $layout['sub_fields'] );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// return
|
|
||||||
return $field;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* prepare_field_for_import
|
|
||||||
*
|
|
||||||
* description
|
|
||||||
*
|
|
||||||
* @type function
|
|
||||||
* @date 11/03/2014
|
|
||||||
* @since 5.0.0
|
|
||||||
*
|
|
||||||
* @param $post_id (int)
|
|
||||||
* @return $post_id (int)
|
|
||||||
*/
|
|
||||||
|
|
||||||
function prepare_field_for_import( $field ) {
|
|
||||||
|
|
||||||
// var
|
|
||||||
$extra = array();
|
|
||||||
|
|
||||||
|
|
||||||
// sub fields
|
|
||||||
if( $field['type'] == 'repeater' ) {
|
|
||||||
|
|
||||||
// extract sub fields
|
|
||||||
$sub_fields = acf_extract_var( $field, 'sub_fields');
|
|
||||||
|
|
||||||
|
|
||||||
// reset field setting
|
|
||||||
$field['sub_fields'] = array();
|
|
||||||
|
|
||||||
|
|
||||||
if( !empty($sub_fields) ) {
|
|
||||||
|
|
||||||
foreach( array_keys($sub_fields) as $i ) {
|
|
||||||
|
|
||||||
// extract sub field
|
|
||||||
$sub_field = acf_extract_var( $sub_fields, $i );
|
|
||||||
|
|
||||||
|
|
||||||
// attributes
|
|
||||||
$sub_field['parent'] = $field['key'];
|
|
||||||
|
|
||||||
|
|
||||||
// append to extra
|
|
||||||
$extra[] = $sub_field;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} elseif( $field['type'] == 'flexible_content' ) {
|
|
||||||
|
|
||||||
// extract layouts
|
|
||||||
$layouts = acf_extract_var( $field, 'layouts');
|
|
||||||
|
|
||||||
|
|
||||||
// reset field setting
|
|
||||||
$field['layouts'] = array();
|
|
||||||
|
|
||||||
|
|
||||||
// validate layouts
|
|
||||||
if( !empty($layouts) ) {
|
|
||||||
|
|
||||||
// loop over layouts
|
|
||||||
foreach( array_keys($layouts) as $i ) {
|
|
||||||
|
|
||||||
// extract layout
|
|
||||||
$layout = acf_extract_var( $layouts, $i );
|
|
||||||
|
|
||||||
|
|
||||||
// get valid layout (fixes ACF4 export code bug undefined index 'key')
|
|
||||||
if( empty($layout['key']) ) {
|
|
||||||
|
|
||||||
$layout['key'] = uniqid();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// extract sub fields
|
|
||||||
$sub_fields = acf_extract_var( $layout, 'sub_fields');
|
|
||||||
|
|
||||||
|
|
||||||
// validate sub fields
|
|
||||||
if( !empty($sub_fields) ) {
|
|
||||||
|
|
||||||
// loop over sub fields
|
|
||||||
foreach( array_keys($sub_fields) as $j ) {
|
|
||||||
|
|
||||||
// extract sub field
|
|
||||||
$sub_field = acf_extract_var( $sub_fields, $j );
|
|
||||||
|
|
||||||
|
|
||||||
// attributes
|
|
||||||
$sub_field['parent'] = $field['key'];
|
|
||||||
$sub_field['parent_layout'] = $layout['key'];
|
|
||||||
|
|
||||||
|
|
||||||
// append to extra
|
|
||||||
$extra[] = $sub_field;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// append to layout
|
|
||||||
$field['layouts'][] = $layout;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// extra
|
|
||||||
if( !empty($extra) ) {
|
|
||||||
|
|
||||||
array_unshift($extra, $field);
|
|
||||||
|
|
||||||
return $extra;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// return
|
|
||||||
return $field;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ function acf_pro_get_remote_url( $action = '', $args = array() ) {
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
$url = "https://connect.advancedcustomfields.com/index.php?" . build_query($args);
|
$url = "https://connect.advancedcustomfields.com/index.php?" . build_query($args);
|
||||||
|
//$url = "http://connect/index.php?" . build_query($args);
|
||||||
|
|
||||||
|
|
||||||
// return
|
// return
|
||||||
|
|
@ -255,7 +256,7 @@ function acf_pro_get_license() {
|
||||||
|
|
||||||
|
|
||||||
// bail early if corrupt
|
// bail early if corrupt
|
||||||
if( !$license ) return false;
|
if( !acf_is_array( $license )) return false;
|
||||||
|
|
||||||
|
|
||||||
// return
|
// return
|
||||||
|
|
@ -312,7 +313,6 @@ function acf_pro_is_license_active() {
|
||||||
$license = acf_pro_get_license();
|
$license = acf_pro_get_license();
|
||||||
$url = home_url();
|
$url = home_url();
|
||||||
|
|
||||||
|
|
||||||
// bail early if empty
|
// bail early if empty
|
||||||
if( !$license ) return false;
|
if( !$license ) return false;
|
||||||
|
|
||||||
|
|
@ -320,16 +320,21 @@ function acf_pro_is_license_active() {
|
||||||
// bail early if no key
|
// bail early if no key
|
||||||
if( !$license['key'] ) return false;
|
if( !$license['key'] ) return false;
|
||||||
|
|
||||||
|
|
||||||
|
// strip proticol from urls
|
||||||
|
$license['url'] = acf_strip_protocol( $license['url'] );
|
||||||
|
$url = acf_strip_protocol( $url );
|
||||||
|
|
||||||
|
|
||||||
// bail early if url does not match
|
// bail early if url does not match
|
||||||
if( $license['url'] !== $url ) {
|
if( $license['url'] !== $url ) {
|
||||||
|
|
||||||
// add notice (only once)
|
// add notice (only once) - removed due to feedback
|
||||||
if( !acf_has_done('acf_pro_is_license_active_notice') ) {
|
// if( !acf_has_done('acf_pro_is_license_active_notice') ) {
|
||||||
|
//
|
||||||
acf_add_admin_notice( __('Error validating ACF PRO license URL (website does not match). Please re-activate your license','acf'), 'error' );
|
// acf_add_admin_notice( __('Error validating ACF PRO license URL (website does not match). Please re-activate your license','acf'), 'error' );
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
@ -358,18 +363,27 @@ function acf_pro_is_license_active() {
|
||||||
function acf_pro_update_license( $key = '' ) {
|
function acf_pro_update_license( $key = '' ) {
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
$save = array(
|
$value = '';
|
||||||
'key' => $key,
|
|
||||||
'url' => home_url()
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
// encode
|
// key
|
||||||
$save = base64_encode(maybe_serialize($save));
|
if( $key ) {
|
||||||
|
|
||||||
|
// vars
|
||||||
|
$data = array(
|
||||||
|
'key' => $key,
|
||||||
|
'url' => home_url()
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// encode
|
||||||
|
$value = base64_encode(maybe_serialize($data));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// update
|
// update
|
||||||
return update_option('acf_pro_license', $save);
|
return update_option('acf_pro_license', $value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,3 +50,18 @@
|
||||||
.acf-fl-actions a.ui-sortable-handle {
|
.acf-fl-actions a.ui-sortable-handle {
|
||||||
cursor: move;
|
cursor: move;
|
||||||
}
|
}
|
||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Clone
|
||||||
|
*
|
||||||
|
*---------------------------------------------------------------------------------------------*/
|
||||||
|
.acf-field-object-clone {
|
||||||
|
/* group */
|
||||||
|
/* seamless */
|
||||||
|
}
|
||||||
|
.acf-field-object-clone[data-display="seamless"] .acf-field-setting-instructions,
|
||||||
|
.acf-field-object-clone[data-display="seamless"] .acf-field-setting-layout,
|
||||||
|
.acf-field-object-clone[data-display="seamless"] .acf-field-setting-wrapper,
|
||||||
|
.acf-field-object-clone[data-display="seamless"] .acf-field-setting-conditional_logic {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -465,7 +465,7 @@ html[dir="rtl"] .acf-gallery .acf-gallery-attachment {
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
border-top: #DFDFDF solid 1px;
|
border-top: #DFDFDF solid 1px;
|
||||||
background: #fff;
|
background: #fff;
|
||||||
height: 28px;
|
min-height: 28px;
|
||||||
}
|
}
|
||||||
.acf-gallery .acf-gallery-toolbar .acf-hl li {
|
.acf-gallery .acf-gallery-toolbar .acf-hl li {
|
||||||
line-height: 24px;
|
line-height: 24px;
|
||||||
|
|
|
||||||
|
|
@ -1,228 +1,5 @@
|
||||||
(function($){
|
(function($){
|
||||||
|
|
||||||
acf.field_group_pro = acf.model.extend({
|
|
||||||
|
|
||||||
actions: {
|
|
||||||
'open_field': 'update_field_parent',
|
|
||||||
'sortstop': 'update_field_parent',
|
|
||||||
'duplicate_field': 'duplicate_field',
|
|
||||||
'delete_field': 'delete_field',
|
|
||||||
'change_field_type': 'change_field_type'
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* fix_conditional_logic
|
|
||||||
*
|
|
||||||
* This function will update sub field conditional logic rules after duplication
|
|
||||||
*
|
|
||||||
* @type function
|
|
||||||
* @date 10/06/2014
|
|
||||||
* @since 5.0.0
|
|
||||||
*
|
|
||||||
* @param $fields (jquery selection)
|
|
||||||
* @return n/a
|
|
||||||
*/
|
|
||||||
|
|
||||||
fix_conditional_logic : function( $fields ){
|
|
||||||
|
|
||||||
// build refernce
|
|
||||||
var ref = {};
|
|
||||||
|
|
||||||
$fields.each(function(){
|
|
||||||
|
|
||||||
ref[ $(this).attr('data-orig') ] = $(this).attr('data-key');
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
$fields.find('.conditional-rule-param').each(function(){
|
|
||||||
|
|
||||||
// vars
|
|
||||||
var key = $(this).val();
|
|
||||||
|
|
||||||
|
|
||||||
// bail early if val is not a ref key
|
|
||||||
if( !(key in ref) ) {
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// add option if doesn't yet exist
|
|
||||||
if( ! $(this).find('option[value="' + ref[key] + '"]').exists() ) {
|
|
||||||
|
|
||||||
$(this).append('<option value="' + ref[key] + '">' + ref[key] + '</option>');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// set new val
|
|
||||||
$(this).val( ref[key] );
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* update_field_parent
|
|
||||||
*
|
|
||||||
* This function will update field meta such as parent
|
|
||||||
*
|
|
||||||
* @type function
|
|
||||||
* @date 8/04/2014
|
|
||||||
* @since 5.0.0
|
|
||||||
*
|
|
||||||
* @param $el
|
|
||||||
* @return n/a
|
|
||||||
*/
|
|
||||||
|
|
||||||
update_field_parent: function( $el ){
|
|
||||||
|
|
||||||
// bail early if not div.field (flexible content tr)
|
|
||||||
if( !$el.hasClass('acf-field-object') ) return;
|
|
||||||
|
|
||||||
|
|
||||||
// vars
|
|
||||||
var $parent = $el.parent().closest('.acf-field-object'),
|
|
||||||
val = acf.get('post_id');
|
|
||||||
|
|
||||||
|
|
||||||
// find parent
|
|
||||||
if( $parent.exists() ) {
|
|
||||||
|
|
||||||
// set as parent ID
|
|
||||||
val = acf.field_group.get_field_meta( $parent, 'ID' );
|
|
||||||
|
|
||||||
|
|
||||||
// if parent is new, no ID exists
|
|
||||||
if( !val ) {
|
|
||||||
|
|
||||||
val = acf.field_group.get_field_meta( $parent, 'key' );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// update parent
|
|
||||||
acf.field_group.update_field_meta( $el, 'parent', val );
|
|
||||||
|
|
||||||
|
|
||||||
// action for 3rd party customization
|
|
||||||
acf.do_action('update_field_parent', $el, $parent);
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* duplicate_field
|
|
||||||
*
|
|
||||||
* This function is triggered when duplicating a field
|
|
||||||
*
|
|
||||||
* @type function
|
|
||||||
* @date 8/04/2014
|
|
||||||
* @since 5.0.0
|
|
||||||
*
|
|
||||||
* @param $el
|
|
||||||
* @return n/a
|
|
||||||
*/
|
|
||||||
|
|
||||||
duplicate_field: function( $el ) {
|
|
||||||
|
|
||||||
// vars
|
|
||||||
var $fields = $el.find('.acf-field-object');
|
|
||||||
|
|
||||||
|
|
||||||
// bail early if $fields are empty
|
|
||||||
if( !$fields.exists() ) {
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// loop over sub fields
|
|
||||||
$fields.each(function(){
|
|
||||||
|
|
||||||
// vars
|
|
||||||
var $parent = $(this).parent().closest('.acf-field-object'),
|
|
||||||
key = acf.field_group.get_field_meta( $parent, 'key');
|
|
||||||
|
|
||||||
|
|
||||||
// wipe field
|
|
||||||
acf.field_group.wipe_field( $(this) );
|
|
||||||
|
|
||||||
|
|
||||||
// update parent
|
|
||||||
acf.field_group.update_field_meta( $(this), 'parent', key );
|
|
||||||
|
|
||||||
|
|
||||||
// save field
|
|
||||||
acf.field_group.save_field( $(this) );
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// fix conditional logic rules
|
|
||||||
this.fix_conditional_logic( $fields );
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* delete_field
|
|
||||||
*
|
|
||||||
* This function is triggered when deleting a field
|
|
||||||
*
|
|
||||||
* @type function
|
|
||||||
* @date 8/04/2014
|
|
||||||
* @since 5.0.0
|
|
||||||
*
|
|
||||||
* @param $el
|
|
||||||
* @return n/a
|
|
||||||
*/
|
|
||||||
|
|
||||||
delete_field : function( $el ){
|
|
||||||
|
|
||||||
$el.find('.acf-field-object').each(function(){
|
|
||||||
|
|
||||||
acf.field_group.delete_field( $(this), false );
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* change_field_type
|
|
||||||
*
|
|
||||||
* This function is triggered when changing a field type
|
|
||||||
*
|
|
||||||
* @type function
|
|
||||||
* @date 7/06/2014
|
|
||||||
* @since 5.0.0
|
|
||||||
*
|
|
||||||
* @param $post_id (int)
|
|
||||||
* @return $post_id (int)
|
|
||||||
*/
|
|
||||||
|
|
||||||
change_field_type : function( $el ) {
|
|
||||||
|
|
||||||
$el.find('.acf-field-object').each(function(){
|
|
||||||
|
|
||||||
acf.field_group.delete_field( $(this), false );
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Repeater
|
* Repeater
|
||||||
*
|
*
|
||||||
|
|
@ -241,7 +18,7 @@
|
||||||
type: 'repeater',
|
type: 'repeater',
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
'render_settings': 'render',
|
'render_settings': 'render'
|
||||||
},
|
},
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
|
|
@ -344,7 +121,7 @@
|
||||||
type: 'flexible_content',
|
type: 'flexible_content',
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
'render_settings': 'render',
|
'render_settings': 'render'
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function(){
|
render: function(){
|
||||||
|
|
@ -659,13 +436,13 @@
|
||||||
type: 'clone',
|
type: 'clone',
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
'render_settings': 'render',
|
'render_settings': 'render'
|
||||||
},
|
},
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
'change .acf-field-setting-display select': 'render_display',
|
'change .acf-field-setting-display select': 'render_display',
|
||||||
'change .acf-field-setting-prefix_label input': 'render_prefix_label',
|
'change .acf-field-setting-prefix_label input': 'render_prefix_label',
|
||||||
'change .acf-field-setting-prefix_name input': 'render_prefix_name',
|
'change .acf-field-setting-prefix_name input': 'render_prefix_name'
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function(){
|
render: function(){
|
||||||
|
|
@ -679,20 +456,12 @@
|
||||||
|
|
||||||
render_display: function(){
|
render_display: function(){
|
||||||
|
|
||||||
// hide conditional logic
|
// vars
|
||||||
if( this.setting('display select').val() == 'seamless' ) {
|
var display = this.setting('display select').val()
|
||||||
|
|
||||||
this.setting('conditional_logic').hide();
|
|
||||||
this.setting('wrapper').hide();
|
// update data
|
||||||
this.setting('layout').hide();
|
this.$field.attr('data-display', display);
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
this.setting('conditional_logic').show();
|
|
||||||
this.setting('wrapper').show();
|
|
||||||
this.setting('layout').show();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -762,7 +531,7 @@
|
||||||
select2_ajax_data: function( data, args, params ){
|
select2_ajax_data: function( data, args, params ){
|
||||||
|
|
||||||
// bail early if not clone
|
// bail early if not clone
|
||||||
if( args.ajax_action !== 'acf/fields/clone/query' ) return select2_args;
|
if( args.ajax_action !== 'acf/fields/clone/query' ) return data;
|
||||||
|
|
||||||
|
|
||||||
// find current fields
|
// find current fields
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1,178 +1,3 @@
|
||||||
(function($){
|
|
||||||
|
|
||||||
// comon
|
|
||||||
acf.pro = acf.model.extend({
|
|
||||||
|
|
||||||
actions: {
|
|
||||||
'refresh': 'refresh',
|
|
||||||
},
|
|
||||||
|
|
||||||
filters: {
|
|
||||||
'get_fields' : 'get_fields',
|
|
||||||
},
|
|
||||||
|
|
||||||
get_fields: function( $fields ){
|
|
||||||
|
|
||||||
// remove clone fields
|
|
||||||
$fields = $fields.not('.acf-clone .acf-field');
|
|
||||||
|
|
||||||
// return
|
|
||||||
return $fields;
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* refresh
|
|
||||||
*
|
|
||||||
* This function will run when acf detects a refresh is needed on the UI
|
|
||||||
* Most commonly after ready / conditional logic change
|
|
||||||
*
|
|
||||||
* @type function
|
|
||||||
* @date 10/11/2014
|
|
||||||
* @since 5.0.9
|
|
||||||
*
|
|
||||||
* @param n/a
|
|
||||||
* @return n/a
|
|
||||||
*/
|
|
||||||
|
|
||||||
refresh: function( $el ){
|
|
||||||
|
|
||||||
// reference
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
|
|
||||||
// defaults
|
|
||||||
$el = $el || false;
|
|
||||||
|
|
||||||
|
|
||||||
// if is row
|
|
||||||
if( $el && $el.is('tr') ) {
|
|
||||||
|
|
||||||
self.render_table( $el.closest('table') );
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// find and rener all tables
|
|
||||||
$('.acf-table', $el).each(function(){
|
|
||||||
|
|
||||||
self.render_table( $(this) );
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
render_table: function( $table ){
|
|
||||||
|
|
||||||
// vars
|
|
||||||
var $ths = $table.find('> thead th.acf-th'),
|
|
||||||
colspan = 1,
|
|
||||||
available_width = 100;
|
|
||||||
|
|
||||||
|
|
||||||
// bail early if no $ths
|
|
||||||
if( !$ths.exists() ) {
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// render th/td visibility
|
|
||||||
$ths.each(function(){
|
|
||||||
|
|
||||||
// vars
|
|
||||||
var $th = $(this),
|
|
||||||
key = $th.attr('data-key'),
|
|
||||||
$td = $table.find('td[data-key="' + key + '"]');
|
|
||||||
|
|
||||||
|
|
||||||
// clear class
|
|
||||||
$td.removeClass('appear-empty');
|
|
||||||
$th.removeClass('hidden-by-conditional-logic');
|
|
||||||
|
|
||||||
|
|
||||||
// no td
|
|
||||||
if( !$td.exists() ) {
|
|
||||||
|
|
||||||
// do nothing
|
|
||||||
|
|
||||||
// if all td are hidden
|
|
||||||
} else if( $td.not('.hidden-by-conditional-logic').length == 0 ) {
|
|
||||||
|
|
||||||
$th.addClass('hidden-by-conditional-logic');
|
|
||||||
|
|
||||||
// if 1 or more td are visible
|
|
||||||
} else {
|
|
||||||
|
|
||||||
$td.filter('.hidden-by-conditional-logic').addClass('appear-empty');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// clear widths
|
|
||||||
$ths.css('width', 'auto');
|
|
||||||
|
|
||||||
|
|
||||||
// update $ths
|
|
||||||
$ths = $ths.not('.hidden-by-conditional-logic');
|
|
||||||
|
|
||||||
|
|
||||||
// set colspan
|
|
||||||
colspan = $ths.length;
|
|
||||||
|
|
||||||
|
|
||||||
// set custom widths first
|
|
||||||
$ths.filter('[data-width]').each(function(){
|
|
||||||
|
|
||||||
// vars
|
|
||||||
var width = parseInt( $(this).attr('data-width') );
|
|
||||||
|
|
||||||
|
|
||||||
// remove from available
|
|
||||||
available_width -= width;
|
|
||||||
|
|
||||||
|
|
||||||
// set width
|
|
||||||
$(this).css('width', width + '%');
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// update $ths
|
|
||||||
$ths = $ths.not('[data-width]');
|
|
||||||
|
|
||||||
|
|
||||||
// set custom widths first
|
|
||||||
$ths.each(function(){
|
|
||||||
|
|
||||||
// cal width
|
|
||||||
var width = available_width / $ths.length;
|
|
||||||
|
|
||||||
|
|
||||||
// set width
|
|
||||||
$(this).css('width', width + '%');
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// update colspan
|
|
||||||
$table.find('.acf-row .acf-field.-collapsed-target').removeAttr('colspan');
|
|
||||||
$table.find('.acf-row.-collapsed .acf-field.-collapsed-target').attr('colspan', colspan);
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
})(jQuery);
|
|
||||||
|
|
||||||
(function($){
|
(function($){
|
||||||
|
|
||||||
acf.fields.repeater = acf.field.extend({
|
acf.fields.repeater = acf.field.extend({
|
||||||
|
|
@ -644,7 +469,7 @@
|
||||||
action: 'acf/fields/flexible_content/layout_title',
|
action: 'acf/fields/flexible_content/layout_title',
|
||||||
field_key: this.$field.data('key'),
|
field_key: this.$field.data('key'),
|
||||||
i: $layout.index(),
|
i: $layout.index(),
|
||||||
layout: $layout.data('layout'),
|
layout: $layout.data('layout')
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1036,7 +861,7 @@
|
||||||
// vars
|
// vars
|
||||||
$popup.css({
|
$popup.css({
|
||||||
'margin-top' : 0 - $popup.height() - e.$el.outerHeight() - 15,
|
'margin-top' : 0 - $popup.height() - e.$el.outerHeight() - 15,
|
||||||
'margin-left' : ( e.$el.outerWidth() - $popup.width() ) / 2,
|
'margin-left' : ( e.$el.outerWidth() - $popup.width() ) / 2
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1866,6 +1691,10 @@
|
||||||
if( $attachment.hasClass('active') ) return;
|
if( $attachment.hasClass('active') ) return;
|
||||||
|
|
||||||
|
|
||||||
|
// save any changes in sidebar
|
||||||
|
this.$side.find(':focus').trigger('blur');
|
||||||
|
|
||||||
|
|
||||||
// clear selection
|
// clear selection
|
||||||
this.get_attachment('active').removeClass('active');
|
this.get_attachment('active').removeClass('active');
|
||||||
|
|
||||||
|
|
@ -2408,7 +2237,6 @@
|
||||||
|
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
|
|
||||||
// @codekit-prepend "../js/acf-pro.js";
|
|
||||||
// @codekit-prepend "../js/acf-repeater.js";
|
// @codekit-prepend "../js/acf-repeater.js";
|
||||||
// @codekit-prepend "../js/acf-flexible-content.js";
|
// @codekit-prepend "../js/acf-flexible-content.js";
|
||||||
// @codekit-prepend "../js/acf-gallery.js";
|
// @codekit-prepend "../js/acf-gallery.js";
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -849,6 +849,9 @@ class acf_field_clone extends acf_field {
|
||||||
|
|
||||||
function render_field_settings( $field ) {
|
function render_field_settings( $field ) {
|
||||||
|
|
||||||
|
// temp enable 'local' to allow .json fields to be displayed
|
||||||
|
acf_enable_filter('local');
|
||||||
|
|
||||||
// default_value
|
// default_value
|
||||||
acf_render_field_setting( $field, array(
|
acf_render_field_setting( $field, array(
|
||||||
'label' => __('Fields', 'acf'),
|
'label' => __('Fields', 'acf'),
|
||||||
|
|
@ -864,6 +867,8 @@ class acf_field_clone extends acf_field {
|
||||||
'placeholder' => '',
|
'placeholder' => '',
|
||||||
));
|
));
|
||||||
|
|
||||||
|
acf_disable_filter('local');
|
||||||
|
|
||||||
|
|
||||||
// display
|
// display
|
||||||
acf_render_field_setting( $field, array(
|
acf_render_field_setting( $field, array(
|
||||||
|
|
|
||||||
|
|
@ -51,20 +51,25 @@ class acf_field_flexible_content extends acf_field {
|
||||||
'max_layout' => __("Maximum {label} limit reached ({max} {identifier})",'acf'),
|
'max_layout' => __("Maximum {label} limit reached ({max} {identifier})",'acf'),
|
||||||
'available' => __("{available} {label} {identifier} available (max {max})",'acf'),
|
'available' => __("{available} {label} {identifier} available (max {max})",'acf'),
|
||||||
'required' => __("{required} {label} {identifier} required (min {min})",'acf'),
|
'required' => __("{required} {label} {identifier} required (min {min})",'acf'),
|
||||||
|
'layout_warning' => __('Flexible Content requires at least 1 layout','acf')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// ajax
|
// ajax
|
||||||
add_action('wp_ajax_acf/fields/flexible_content/layout_title', array($this, 'ajax_layout_title'));
|
$this->add_action('wp_ajax_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'));
|
$this->add_action('wp_ajax_nopriv_acf/fields/flexible_content/layout_title', array($this, 'ajax_layout_title'));
|
||||||
|
|
||||||
|
|
||||||
// filters
|
// filters
|
||||||
add_filter('acf/clone_field', array($this, 'acf_clone_field'), 10, 2);
|
$this->add_filter('acf/prepare_field_for_export', array($this, 'prepare_any_field_for_export'));
|
||||||
|
$this->add_filter('acf/clone_field', array($this, 'clone_any_field'), 10, 2);
|
||||||
|
$this->add_filter('acf/validate_field', array($this, 'validate_any_field'));
|
||||||
|
|
||||||
|
|
||||||
// field filters
|
// field filters
|
||||||
$this->add_field_filter('acf/get_sub_field', array($this, 'get_sub_field'), 10, 3);
|
$this->add_field_filter('acf/get_sub_field', array($this, 'get_sub_field'), 10, 3);
|
||||||
|
$this->add_field_filter('acf/prepare_field_for_export', array($this, 'prepare_field_for_export'));
|
||||||
|
$this->add_field_filter('acf/prepare_field_for_import', array($this, 'prepare_field_for_import'));
|
||||||
|
|
||||||
|
|
||||||
// do not delete!
|
// do not delete!
|
||||||
|
|
@ -316,7 +321,7 @@ class acf_field_flexible_content extends acf_field {
|
||||||
|
|
||||||
<ul class="acf-actions acf-hl">
|
<ul class="acf-actions acf-hl">
|
||||||
<li>
|
<li>
|
||||||
<a class="acf-button button button-primary" data-event="add-layout"><?php echo $field['button_label']; ?></a>
|
<a class="acf-button button button-primary" href="#" data-event="add-layout"><?php echo $field['button_label']; ?></a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
@ -1058,6 +1063,165 @@ class acf_field_flexible_content extends acf_field {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get_layout
|
||||||
|
*
|
||||||
|
* This function will return a specific layout by name from a field
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 15/2/17
|
||||||
|
* @since 5.5.8
|
||||||
|
*
|
||||||
|
* @param $name (string)
|
||||||
|
* @param $field (array)
|
||||||
|
* @return (array)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function get_layout( $name = '', $field ) {
|
||||||
|
|
||||||
|
// bail early if no layouts
|
||||||
|
if( !isset($field['layouts']) ) return false;
|
||||||
|
|
||||||
|
|
||||||
|
// loop
|
||||||
|
foreach( $field['layouts'] as $layout ) {
|
||||||
|
|
||||||
|
// match
|
||||||
|
if( $layout['name'] === $name ) return $layout;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* delete_row
|
||||||
|
*
|
||||||
|
* This function will delete a value row
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 15/2/17
|
||||||
|
* @since 5.5.8
|
||||||
|
*
|
||||||
|
* @param $i (int)
|
||||||
|
* @param $field (array)
|
||||||
|
* @param $post_id (mixed)
|
||||||
|
* @return (boolean)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function delete_row( $i = 0, $field, $post_id ) {
|
||||||
|
|
||||||
|
// vars
|
||||||
|
$value = acf_get_metadata( $post_id, $field['name'] );
|
||||||
|
|
||||||
|
|
||||||
|
// bail early if no value
|
||||||
|
if( !is_array($value) || !isset($value[ $i ]) ) return false;
|
||||||
|
|
||||||
|
|
||||||
|
// get layout
|
||||||
|
$layout = $this->get_layout($value[ $i ], $field);
|
||||||
|
|
||||||
|
|
||||||
|
// bail early if no layout
|
||||||
|
if( !$layout || empty($layout['sub_fields']) ) return false;
|
||||||
|
|
||||||
|
|
||||||
|
// loop
|
||||||
|
foreach( $layout['sub_fields'] as $sub_field ) {
|
||||||
|
|
||||||
|
// modify name for delete
|
||||||
|
$sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}";
|
||||||
|
|
||||||
|
|
||||||
|
// delete value
|
||||||
|
acf_delete_value( $post_id, $sub_field );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* update_row
|
||||||
|
*
|
||||||
|
* This function will update a value row
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 15/2/17
|
||||||
|
* @since 5.5.8
|
||||||
|
*
|
||||||
|
* @param $i (int)
|
||||||
|
* @param $field (array)
|
||||||
|
* @param $post_id (mixed)
|
||||||
|
* @return (boolean)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function update_row( $row, $i = 0, $field, $post_id ) {
|
||||||
|
|
||||||
|
// bail early if no layout reference
|
||||||
|
if( !is_array($row) || !isset($row['acf_fc_layout']) ) return false;
|
||||||
|
|
||||||
|
|
||||||
|
// get layout
|
||||||
|
$layout = $this->get_layout($row['acf_fc_layout'], $field);
|
||||||
|
|
||||||
|
|
||||||
|
// bail early if no layout
|
||||||
|
if( !$layout || empty($layout['sub_fields']) ) return false;
|
||||||
|
|
||||||
|
|
||||||
|
// loop
|
||||||
|
foreach( $layout['sub_fields'] as $sub_field ) {
|
||||||
|
|
||||||
|
// value
|
||||||
|
$value = null;
|
||||||
|
|
||||||
|
|
||||||
|
// find value (key)
|
||||||
|
if( isset($row[ $sub_field['key'] ]) ) {
|
||||||
|
|
||||||
|
$value = $row[ $sub_field['key'] ];
|
||||||
|
|
||||||
|
// find value (name)
|
||||||
|
} elseif( isset($row[ $sub_field['name'] ]) ) {
|
||||||
|
|
||||||
|
$value = $row[ $sub_field['name'] ];
|
||||||
|
|
||||||
|
// value does not exist
|
||||||
|
} else {
|
||||||
|
|
||||||
|
continue;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// modify name for save
|
||||||
|
$sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}";
|
||||||
|
|
||||||
|
|
||||||
|
// update field
|
||||||
|
acf_update_value( $value, $post_id, $sub_field );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* update_value()
|
* update_value()
|
||||||
*
|
*
|
||||||
|
|
@ -1076,124 +1240,66 @@ class acf_field_flexible_content extends acf_field {
|
||||||
|
|
||||||
function update_value( $value, $post_id, $field ) {
|
function update_value( $value, $post_id, $field ) {
|
||||||
|
|
||||||
// remove acfcloneindex
|
// bail early if no layouts
|
||||||
if( isset($value['acfcloneindex']) ) {
|
if( empty($field['layouts']) ) return $value;
|
||||||
|
|
||||||
unset($value['acfcloneindex']);
|
|
||||||
|
// vars
|
||||||
|
$new_value = array();
|
||||||
|
$old_value = acf_get_metadata( $post_id, $field['name'] );
|
||||||
|
$old_value = is_array($old_value) ? $old_value : array();
|
||||||
|
|
||||||
|
|
||||||
|
// update
|
||||||
|
if( !empty($value) ) { $i = -1;
|
||||||
|
|
||||||
|
// remove acfcloneindex
|
||||||
|
if( isset($value['acfcloneindex']) ) {
|
||||||
|
|
||||||
|
unset($value['acfcloneindex']);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// loop through rows
|
||||||
|
foreach( $value as $row ) { $i++;
|
||||||
|
|
||||||
|
// bail early if no layout reference
|
||||||
|
if( !is_array($row) || !isset($row['acf_fc_layout']) ) continue;
|
||||||
|
|
||||||
|
|
||||||
|
// delete old row if layout has changed
|
||||||
|
if( isset($old_value[ $i ]) && $old_value[ $i ] !== $row['acf_fc_layout'] ) {
|
||||||
|
|
||||||
|
$this->delete_row( $i, $field, $post_id );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// update row
|
||||||
|
$this->update_row( $row, $i, $field, $post_id );
|
||||||
|
|
||||||
|
|
||||||
|
// append to order
|
||||||
|
$new_value[] = $row['acf_fc_layout'];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
$order = array();
|
$old_count = empty($old_value) ? 0 : count($old_value);
|
||||||
$layouts = array();
|
$new_count = empty($new_value) ? 0 : count($new_value);
|
||||||
|
|
||||||
|
|
||||||
// populate $layouts
|
|
||||||
foreach( $field['layouts'] as $layout ) {
|
|
||||||
|
|
||||||
$layouts[ $layout['name'] ] = $layout['sub_fields'];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// update sub fields
|
|
||||||
if( !empty($value) ) {
|
|
||||||
|
|
||||||
// $i
|
|
||||||
$i = -1;
|
|
||||||
|
|
||||||
|
|
||||||
// loop through rows
|
|
||||||
foreach( $value as $row ) {
|
|
||||||
|
|
||||||
// $i
|
|
||||||
$i++;
|
|
||||||
|
|
||||||
|
|
||||||
// get layout
|
|
||||||
$l = $row['acf_fc_layout'];
|
|
||||||
|
|
||||||
|
|
||||||
// append to order
|
|
||||||
$order[] = $l;
|
|
||||||
|
|
||||||
|
|
||||||
// loop through sub fields
|
|
||||||
if( !empty($layouts[ $l ]) ) {
|
|
||||||
|
|
||||||
foreach( $layouts[ $l ] as $sub_field ) {
|
|
||||||
|
|
||||||
// value
|
|
||||||
$v = false;
|
|
||||||
|
|
||||||
|
|
||||||
// key (backend)
|
|
||||||
if( isset($row[ $sub_field['key'] ]) ) {
|
|
||||||
|
|
||||||
$v = $row[ $sub_field['key'] ];
|
|
||||||
|
|
||||||
} elseif( isset($row[ $sub_field['name'] ]) ) {
|
|
||||||
|
|
||||||
$v = $row[ $sub_field['name'] ];
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// input is not set (hidden by conditioanl logic)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// modify name for save
|
|
||||||
$sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}";
|
|
||||||
|
|
||||||
|
|
||||||
// update field
|
|
||||||
acf_update_value( $v, $post_id, $sub_field );
|
|
||||||
|
|
||||||
}
|
|
||||||
// foreach
|
|
||||||
|
|
||||||
}
|
|
||||||
// if
|
|
||||||
|
|
||||||
}
|
|
||||||
// foreach
|
|
||||||
|
|
||||||
}
|
|
||||||
// if
|
|
||||||
|
|
||||||
|
|
||||||
// remove old data
|
|
||||||
$old_order = acf_get_metadata( $post_id, $field['name'] );
|
|
||||||
$old_count = empty($old_order) ? 0 : count($old_order);
|
|
||||||
$new_count = empty($order) ? 0 : count($order);
|
|
||||||
|
|
||||||
|
|
||||||
|
// remove old rows
|
||||||
if( $old_count > $new_count ) {
|
if( $old_count > $new_count ) {
|
||||||
|
|
||||||
|
// loop
|
||||||
for( $i = $new_count; $i < $old_count; $i++ ) {
|
for( $i = $new_count; $i < $old_count; $i++ ) {
|
||||||
|
|
||||||
// get layout
|
$this->delete_row( $i, $field, $post_id );
|
||||||
$l = $old_order[ $i ];
|
|
||||||
|
|
||||||
|
|
||||||
// loop through sub fields
|
|
||||||
if( !empty($layouts[ $l ]) ) {
|
|
||||||
|
|
||||||
foreach( $layouts[ $l ] as $sub_field ) {
|
|
||||||
|
|
||||||
// modify name for delete
|
|
||||||
$sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}";
|
|
||||||
|
|
||||||
|
|
||||||
// delete value
|
|
||||||
acf_delete_value( $post_id, $sub_field );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1201,15 +1307,11 @@ class acf_field_flexible_content extends acf_field {
|
||||||
|
|
||||||
|
|
||||||
// save false for empty value
|
// save false for empty value
|
||||||
if( empty($order) ) {
|
if( empty($new_value) ) $new_value = '';
|
||||||
|
|
||||||
$order = '';
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// return
|
// return
|
||||||
return $order;
|
return $new_value;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1229,44 +1331,19 @@ class acf_field_flexible_content extends acf_field {
|
||||||
|
|
||||||
function delete_value( $post_id, $key, $field ) {
|
function delete_value( $post_id, $key, $field ) {
|
||||||
|
|
||||||
// get old value (db only)
|
// vars
|
||||||
$old_order = acf_get_metadata( $post_id, $field['name'] );
|
$old_value = acf_get_metadata( $post_id, $field['name'] );
|
||||||
|
$old_value = is_array($old_value) ? $old_value : array();
|
||||||
|
|
||||||
|
|
||||||
// bail early if no rows or no sub fields
|
// bail early if no rows or no sub fields
|
||||||
if( empty($old_order) ) return;
|
if( empty($old_value) ) return;
|
||||||
|
|
||||||
|
|
||||||
// vars
|
|
||||||
$layouts = array();
|
|
||||||
|
|
||||||
|
|
||||||
// populate $layouts
|
|
||||||
foreach( $field['layouts'] as $layout ) {
|
|
||||||
|
|
||||||
$layouts[ $layout['name'] ] = $layout['sub_fields'];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// loop
|
// loop
|
||||||
foreach( $old_order as $i => $l ) {
|
foreach( array_keys($old_value) as $i ) {
|
||||||
|
|
||||||
// bail early if no layout
|
$this->delete_row( $i, $field, $post_id );
|
||||||
if( empty($layouts[ $l ]) ) continue;
|
|
||||||
|
|
||||||
|
|
||||||
// loop through sub fields
|
|
||||||
foreach( $layouts[ $l ] as $sub_field ) {
|
|
||||||
|
|
||||||
// modify name for delete
|
|
||||||
$sub_field['name'] = "{$key}_{$i}_{$sub_field['name']}";
|
|
||||||
|
|
||||||
|
|
||||||
// delete value
|
|
||||||
acf_delete_value( $post_id, $sub_field );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1538,7 +1615,8 @@ class acf_field_flexible_content extends acf_field {
|
||||||
|
|
||||||
|
|
||||||
// prepend order
|
// prepend order
|
||||||
$title = '<span class="acf-fc-layout-order">' . ($i+1) . '</span> ' . $title;
|
$order = is_numeric($i) ? $i+1 : 0;
|
||||||
|
$title = '<span class="acf-fc-layout-order">' . $order . '</span> ' . $title;
|
||||||
|
|
||||||
|
|
||||||
// return
|
// return
|
||||||
|
|
@ -1548,7 +1626,7 @@ class acf_field_flexible_content extends acf_field {
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* acf_clone_field
|
* clone_any_field
|
||||||
*
|
*
|
||||||
* This function will update clone field settings based on the origional field
|
* This function will update clone field settings based on the origional field
|
||||||
*
|
*
|
||||||
|
|
@ -1561,7 +1639,7 @@ class acf_field_flexible_content extends acf_field {
|
||||||
* @return $clone
|
* @return $clone
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function acf_clone_field( $field, $clone_field ) {
|
function clone_any_field( $field, $clone_field ) {
|
||||||
|
|
||||||
// remove parent_layout
|
// remove parent_layout
|
||||||
// - allows a sub field to be rendered as a normal field
|
// - allows a sub field to be rendered as a normal field
|
||||||
|
|
@ -1581,6 +1659,162 @@ class acf_field_flexible_content extends acf_field {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* prepare_field_for_export
|
||||||
|
*
|
||||||
|
* description
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 11/03/2014
|
||||||
|
* @since 5.0.0
|
||||||
|
*
|
||||||
|
* @param $post_id (int)
|
||||||
|
* @return $post_id (int)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function prepare_field_for_export( $field ) {
|
||||||
|
|
||||||
|
// bail early if no layouts
|
||||||
|
if( empty($field['layouts']) ) return $field;
|
||||||
|
|
||||||
|
|
||||||
|
// loop
|
||||||
|
foreach( $field['layouts'] as $i => $layout ) {
|
||||||
|
|
||||||
|
$field['layouts'][ $i ]['sub_fields'] = acf_prepare_fields_for_export( $layout['sub_fields'] );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return $field;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function prepare_any_field_for_export( $field ) {
|
||||||
|
|
||||||
|
// remove parent_layout
|
||||||
|
unset( $field['parent_layout'] );
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return $field;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* prepare_field_for_import
|
||||||
|
*
|
||||||
|
* description
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 11/03/2014
|
||||||
|
* @since 5.0.0
|
||||||
|
*
|
||||||
|
* @param $post_id (int)
|
||||||
|
* @return $post_id (int)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function prepare_field_for_import( $field ) {
|
||||||
|
|
||||||
|
// bail early if no layouts
|
||||||
|
if( empty($field['layouts']) ) return $field;
|
||||||
|
|
||||||
|
|
||||||
|
// var
|
||||||
|
$extra = array();
|
||||||
|
|
||||||
|
|
||||||
|
// loop
|
||||||
|
foreach( array_keys($field['layouts']) as $i ) {
|
||||||
|
|
||||||
|
// extract layout
|
||||||
|
$layout = acf_extract_var( $field['layouts'], $i );
|
||||||
|
|
||||||
|
|
||||||
|
// get valid layout (fixes ACF4 export code bug undefined index 'key')
|
||||||
|
if( empty($layout['key']) ) $layout['key'] = uniqid();
|
||||||
|
|
||||||
|
|
||||||
|
// extract sub fields
|
||||||
|
$sub_fields = acf_extract_var( $layout, 'sub_fields');
|
||||||
|
|
||||||
|
|
||||||
|
// validate sub fields
|
||||||
|
if( !empty($sub_fields) ) {
|
||||||
|
|
||||||
|
// loop over sub fields
|
||||||
|
foreach( array_keys($sub_fields) as $j ) {
|
||||||
|
|
||||||
|
// extract sub field
|
||||||
|
$sub_field = acf_extract_var( $sub_fields, $j );
|
||||||
|
|
||||||
|
|
||||||
|
// attributes
|
||||||
|
$sub_field['parent'] = $field['key'];
|
||||||
|
$sub_field['parent_layout'] = $layout['key'];
|
||||||
|
|
||||||
|
|
||||||
|
// append to extra
|
||||||
|
$extra[] = $sub_field;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// append to layout
|
||||||
|
$field['layouts'][ $i ] = $layout;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// extra
|
||||||
|
if( !empty($extra) ) {
|
||||||
|
|
||||||
|
array_unshift($extra, $field);
|
||||||
|
|
||||||
|
return $extra;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return $field;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* validate_any_field
|
||||||
|
*
|
||||||
|
* This function will add compatibility for the 'column_width' setting
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 30/1/17
|
||||||
|
* @since 5.5.6
|
||||||
|
*
|
||||||
|
* @param $field (array)
|
||||||
|
* @return $field
|
||||||
|
*/
|
||||||
|
|
||||||
|
function validate_any_field( $field ) {
|
||||||
|
|
||||||
|
// width has changed
|
||||||
|
if( isset($field['column_width']) ) {
|
||||||
|
|
||||||
|
$field['wrapper']['width'] = acf_extract_var($field, 'column_width');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return $field;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -585,7 +585,7 @@ class acf_field_gallery extends acf_field {
|
||||||
<a href="#" class="acf-button button acf-gallery-close"><?php _e('Close', 'acf'); ?></a>
|
<a href="#" class="acf-button button acf-gallery-close"><?php _e('Close', 'acf'); ?></a>
|
||||||
</li>
|
</li>
|
||||||
<li class="acf-fr">
|
<li class="acf-fr">
|
||||||
<a class="acf-button button button-primary acf-gallery-update"><?php _e('Update', 'acf'); ?></a>
|
<a class="acf-button button button-primary acf-gallery-update" href="#"><?php _e('Update', 'acf'); ?></a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,13 @@ class acf_field_repeater extends acf_field {
|
||||||
|
|
||||||
|
|
||||||
// field filters
|
// field filters
|
||||||
$this->add_field_filter('acf/get_sub_field', array($this, 'get_sub_field'), 10, 3);
|
$this->add_field_filter('acf/get_sub_field', array($this, 'get_sub_field'), 10, 3);
|
||||||
|
$this->add_field_filter('acf/prepare_field_for_export', array($this, 'prepare_field_for_export'));
|
||||||
|
$this->add_field_filter('acf/prepare_field_for_import', array($this, 'prepare_field_for_import'));
|
||||||
|
|
||||||
|
|
||||||
|
// filters
|
||||||
|
$this->add_filter('acf/validate_field', array($this, 'validate_any_field'));
|
||||||
|
|
||||||
|
|
||||||
// do not delete!
|
// do not delete!
|
||||||
|
|
@ -154,7 +160,6 @@ class acf_field_repeater extends acf_field {
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
$sub_fields = $field['sub_fields'];
|
$sub_fields = $field['sub_fields'];
|
||||||
$value = acf_get_array($field['value']);
|
|
||||||
$show_order = true;
|
$show_order = true;
|
||||||
$show_add = true;
|
$show_add = true;
|
||||||
$show_remove = true;
|
$show_remove = true;
|
||||||
|
|
@ -164,6 +169,10 @@ class acf_field_repeater extends acf_field {
|
||||||
if( empty($sub_fields) ) return;
|
if( empty($sub_fields) ) return;
|
||||||
|
|
||||||
|
|
||||||
|
// value
|
||||||
|
$value = is_array($field['value']) ? $field['value'] : array();
|
||||||
|
|
||||||
|
|
||||||
// div
|
// div
|
||||||
$div = array(
|
$div = array(
|
||||||
'class' => 'acf-repeater',
|
'class' => 'acf-repeater',
|
||||||
|
|
@ -406,7 +415,7 @@ class acf_field_repeater extends acf_field {
|
||||||
|
|
||||||
<ul class="acf-actions acf-hl">
|
<ul class="acf-actions acf-hl">
|
||||||
<li>
|
<li>
|
||||||
<a class="acf-button button button-primary" data-event="add-row"><?php echo $field['button_label']; ?></a>
|
<a class="acf-button button button-primary" href="#" data-event="add-row"><?php echo $field['button_label']; ?></a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
@ -546,61 +555,54 @@ class acf_field_repeater extends acf_field {
|
||||||
function load_value( $value, $post_id, $field ) {
|
function load_value( $value, $post_id, $field ) {
|
||||||
|
|
||||||
// bail early if no value
|
// bail early if no value
|
||||||
if( empty($value) || empty($field['sub_fields']) ) {
|
if( empty($value) ) return false;
|
||||||
|
|
||||||
return $value;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// convert to int
|
// bail ealry if not numeric
|
||||||
$value = intval( $value );
|
if( !is_numeric($value) ) return false;
|
||||||
|
|
||||||
|
|
||||||
|
// bail early if no sub fields
|
||||||
|
if( empty($field['sub_fields']) ) return false;
|
||||||
|
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
|
$value = intval($value);
|
||||||
$rows = array();
|
$rows = array();
|
||||||
|
|
||||||
|
|
||||||
// check number of rows
|
// loop
|
||||||
if( $value > 0 ) {
|
for( $i = 0; $i < $value; $i++ ) {
|
||||||
|
|
||||||
// loop through rows
|
// create empty array
|
||||||
for( $i = 0; $i < $value; $i++ ) {
|
$rows[ $i ] = array();
|
||||||
|
|
||||||
|
|
||||||
|
// loop through sub fields
|
||||||
|
foreach( array_keys($field['sub_fields']) as $j ) {
|
||||||
|
|
||||||
// create empty array
|
// get sub field
|
||||||
$rows[ $i ] = array();
|
$sub_field = $field['sub_fields'][ $j ];
|
||||||
|
|
||||||
|
|
||||||
// loop through sub fields
|
// bail ealry if no name (tab)
|
||||||
foreach( array_keys($field['sub_fields']) as $j ) {
|
if( acf_is_empty($sub_field['name']) ) continue;
|
||||||
|
|
||||||
// get sub field
|
|
||||||
$sub_field = $field['sub_fields'][ $j ];
|
|
||||||
|
|
||||||
|
|
||||||
// bail ealry if no name (tab)
|
|
||||||
if( acf_is_empty($sub_field['name']) ) continue;
|
|
||||||
|
|
||||||
|
|
||||||
// update $sub_field name
|
|
||||||
$sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}";
|
|
||||||
|
|
||||||
|
|
||||||
// get value
|
|
||||||
$sub_value = acf_get_value( $post_id, $sub_field );
|
|
||||||
|
|
||||||
|
|
||||||
// add value
|
// update $sub_field name
|
||||||
$rows[ $i ][ $sub_field['key'] ] = $sub_value;
|
$sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}";
|
||||||
|
|
||||||
}
|
|
||||||
// foreach
|
// get value
|
||||||
|
$sub_value = acf_get_value( $post_id, $sub_field );
|
||||||
|
|
||||||
|
|
||||||
|
// add value
|
||||||
|
$rows[ $i ][ $sub_field['key'] ] = $sub_value;
|
||||||
|
|
||||||
}
|
}
|
||||||
// for
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// if
|
|
||||||
|
|
||||||
|
|
||||||
// return
|
// return
|
||||||
|
|
@ -628,11 +630,15 @@ class acf_field_repeater extends acf_field {
|
||||||
function format_value( $value, $post_id, $field ) {
|
function format_value( $value, $post_id, $field ) {
|
||||||
|
|
||||||
// bail early if no value
|
// bail early if no value
|
||||||
if( empty($value) || empty($field['sub_fields']) ) {
|
if( empty($value) ) return false;
|
||||||
|
|
||||||
return false;
|
|
||||||
|
// bail ealry if not array
|
||||||
}
|
if( !is_array($value) ) return false;
|
||||||
|
|
||||||
|
|
||||||
|
// bail early if no sub fields
|
||||||
|
if( empty($field['sub_fields']) ) return false;
|
||||||
|
|
||||||
|
|
||||||
// loop over rows
|
// loop over rows
|
||||||
|
|
@ -740,6 +746,112 @@ class acf_field_repeater extends acf_field {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* update_row
|
||||||
|
*
|
||||||
|
* This function will update a value row
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 15/2/17
|
||||||
|
* @since 5.5.8
|
||||||
|
*
|
||||||
|
* @param $i (int)
|
||||||
|
* @param $field (array)
|
||||||
|
* @param $post_id (mixed)
|
||||||
|
* @return (boolean)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function update_row( $row, $i = 0, $field, $post_id ) {
|
||||||
|
|
||||||
|
// bail early if no layout reference
|
||||||
|
if( !is_array($row) ) return false;
|
||||||
|
|
||||||
|
|
||||||
|
// bail early if no layout
|
||||||
|
if( empty($field['sub_fields']) ) return false;
|
||||||
|
|
||||||
|
|
||||||
|
// loop
|
||||||
|
foreach( $field['sub_fields'] as $sub_field ) {
|
||||||
|
|
||||||
|
// value
|
||||||
|
$value = null;
|
||||||
|
|
||||||
|
|
||||||
|
// find value (key)
|
||||||
|
if( isset($row[ $sub_field['key'] ]) ) {
|
||||||
|
|
||||||
|
$value = $row[ $sub_field['key'] ];
|
||||||
|
|
||||||
|
// find value (name)
|
||||||
|
} elseif( isset($row[ $sub_field['name'] ]) ) {
|
||||||
|
|
||||||
|
$value = $row[ $sub_field['name'] ];
|
||||||
|
|
||||||
|
// value does not exist
|
||||||
|
} else {
|
||||||
|
|
||||||
|
continue;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// modify name for save
|
||||||
|
$sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}";
|
||||||
|
|
||||||
|
|
||||||
|
// update field
|
||||||
|
acf_update_value( $value, $post_id, $sub_field );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* delete_row
|
||||||
|
*
|
||||||
|
* This function will delete a value row
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 15/2/17
|
||||||
|
* @since 5.5.8
|
||||||
|
*
|
||||||
|
* @param $i (int)
|
||||||
|
* @param $field (array)
|
||||||
|
* @param $post_id (mixed)
|
||||||
|
* @return (boolean)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function delete_row( $i = 0, $field, $post_id ) {
|
||||||
|
|
||||||
|
// bail early if no sub fields
|
||||||
|
if( empty($field['sub_fields']) ) return false;
|
||||||
|
|
||||||
|
|
||||||
|
// loop
|
||||||
|
foreach( $field['sub_fields'] as $sub_field ) {
|
||||||
|
|
||||||
|
// modify name for delete
|
||||||
|
$sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}";
|
||||||
|
|
||||||
|
|
||||||
|
// delete value
|
||||||
|
acf_delete_value( $post_id, $sub_field );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* update_value()
|
* update_value()
|
||||||
*
|
*
|
||||||
|
|
@ -758,121 +870,63 @@ class acf_field_repeater extends acf_field {
|
||||||
|
|
||||||
function update_value( $value, $post_id, $field ) {
|
function update_value( $value, $post_id, $field ) {
|
||||||
|
|
||||||
// vars
|
|
||||||
$total = 0;
|
|
||||||
|
|
||||||
|
|
||||||
// bail early if no sub fields
|
// bail early if no sub fields
|
||||||
if( empty($field['sub_fields']) ) return $value;
|
if( empty($field['sub_fields']) ) return $value;
|
||||||
|
|
||||||
|
|
||||||
// remove acfcloneindex
|
// vars
|
||||||
if( isset($value['acfcloneindex']) ) {
|
$new_value = 0;
|
||||||
|
$old_value = (int) acf_get_metadata( $post_id, $field['name'] );
|
||||||
unset($value['acfcloneindex']);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// update sub fields
|
// update sub fields
|
||||||
if( !empty($value) ) {
|
if( !empty($value) ) { $i = -1;
|
||||||
|
|
||||||
// $i
|
// remove acfcloneindex
|
||||||
$i = -1;
|
if( isset($value['acfcloneindex']) ) {
|
||||||
|
|
||||||
|
unset($value['acfcloneindex']);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// loop through rows
|
// loop through rows
|
||||||
foreach( $value as $row ) {
|
foreach( $value as $row ) { $i++;
|
||||||
|
|
||||||
// $i
|
// bail early if no row
|
||||||
$i++;
|
if( !is_array($row) ) continue;
|
||||||
|
|
||||||
|
|
||||||
// increase total
|
// update row
|
||||||
$total++;
|
$this->update_row( $row, $i, $field, $post_id );
|
||||||
|
|
||||||
|
|
||||||
// loop through sub fields
|
// append
|
||||||
foreach( $field['sub_fields'] as $sub_field ) {
|
$new_value++;
|
||||||
|
|
||||||
// value
|
|
||||||
$v = false;
|
|
||||||
|
|
||||||
|
|
||||||
// key (backend)
|
|
||||||
if( isset($row[ $sub_field['key'] ]) ) {
|
|
||||||
|
|
||||||
$v = $row[ $sub_field['key'] ];
|
|
||||||
|
|
||||||
} elseif( isset($row[ $sub_field['name'] ]) ) {
|
|
||||||
|
|
||||||
$v = $row[ $sub_field['name'] ];
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// input is not set (hidden by conditioanl logic)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// modify name for save
|
|
||||||
$sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}";
|
|
||||||
|
|
||||||
|
|
||||||
// update value
|
|
||||||
acf_update_value( $v, $post_id, $sub_field );
|
|
||||||
|
|
||||||
}
|
|
||||||
// foreach
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// foreach
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// if
|
|
||||||
|
|
||||||
|
|
||||||
// get old value (db only)
|
// remove old rows
|
||||||
$old_total = (int) acf_get_metadata( $post_id, $field['name'] );
|
if( $old_value > $new_value ) {
|
||||||
|
|
||||||
if( $old_total > $total ) {
|
|
||||||
|
|
||||||
for( $i = $total; $i < $old_total; $i++ ) {
|
// loop
|
||||||
|
for( $i = $new_value; $i < $old_value; $i++ ) {
|
||||||
|
|
||||||
foreach( $field['sub_fields'] as $sub_field ) {
|
$this->delete_row( $i, $field, $post_id );
|
||||||
|
|
||||||
// modify name for delete
|
|
||||||
$sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}";
|
|
||||||
|
|
||||||
|
|
||||||
// delete value
|
|
||||||
acf_delete_value( $post_id, $sub_field );
|
|
||||||
|
|
||||||
}
|
|
||||||
// foreach
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// for
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// if
|
|
||||||
|
|
||||||
|
|
||||||
// update $value and return to allow for the normal save function to run
|
|
||||||
$value = $total;
|
|
||||||
|
|
||||||
|
|
||||||
// save false for empty value
|
// save false for empty value
|
||||||
if( empty($value) ) {
|
if( empty($new_value) ) $new_value = '';
|
||||||
|
|
||||||
$value = '';
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// return
|
// return
|
||||||
return $value;
|
return $new_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -892,30 +946,17 @@ class acf_field_repeater extends acf_field {
|
||||||
function delete_value( $post_id, $key, $field ) {
|
function delete_value( $post_id, $key, $field ) {
|
||||||
|
|
||||||
// get old value (db only)
|
// get old value (db only)
|
||||||
$old_total = (int) acf_get_metadata( $post_id, $field['name'] );
|
$old_value = (int) acf_get_metadata( $post_id, $field['name'] );
|
||||||
|
|
||||||
|
|
||||||
// bail early if no rows or no sub fields
|
// bail early if no rows or no sub fields
|
||||||
if( !$old_total || empty($field['sub_fields']) ) {
|
if( !$old_value || empty($field['sub_fields']) ) return;
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
for( $i = 0; $i < $old_total; $i++ ) {
|
// loop
|
||||||
|
for( $i = 0; $i < $old_value; $i++ ) {
|
||||||
|
|
||||||
foreach( $field['sub_fields'] as $sub_field ) {
|
$this->delete_row( $i, $field, $post_id );
|
||||||
|
|
||||||
// modify name for delete
|
|
||||||
$sub_field['name'] = "{$key}_{$i}_{$sub_field['name']}";
|
|
||||||
|
|
||||||
|
|
||||||
// delete value
|
|
||||||
acf_delete_value( $post_id, $sub_field );
|
|
||||||
|
|
||||||
}
|
|
||||||
// foreach
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1029,6 +1070,128 @@ class acf_field_repeater extends acf_field {
|
||||||
$field['button_label'] = acf_translate( $field['button_label'] );
|
$field['button_label'] = acf_translate( $field['button_label'] );
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return $field;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* prepare_field_for_export
|
||||||
|
*
|
||||||
|
* description
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 11/03/2014
|
||||||
|
* @since 5.0.0
|
||||||
|
*
|
||||||
|
* @param $post_id (int)
|
||||||
|
* @return $post_id (int)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function prepare_field_for_export( $field ) {
|
||||||
|
|
||||||
|
// bail early if no layouts
|
||||||
|
if( empty($field['sub_fields']) ) return $field;
|
||||||
|
|
||||||
|
|
||||||
|
// prepare
|
||||||
|
$field['sub_fields'] = acf_prepare_fields_for_export( $field['sub_fields'] );
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return $field;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* prepare_field_for_import
|
||||||
|
*
|
||||||
|
* description
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 11/03/2014
|
||||||
|
* @since 5.0.0
|
||||||
|
*
|
||||||
|
* @param $post_id (int)
|
||||||
|
* @return $post_id (int)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function prepare_field_for_import( $field ) {
|
||||||
|
|
||||||
|
// bail early if no layouts
|
||||||
|
if( empty($field['sub_fields']) ) return $field;
|
||||||
|
|
||||||
|
|
||||||
|
// var
|
||||||
|
$extra = array();
|
||||||
|
|
||||||
|
|
||||||
|
// extract sub fields
|
||||||
|
$sub_fields = acf_extract_var( $field, 'sub_fields');
|
||||||
|
|
||||||
|
|
||||||
|
// reset field setting
|
||||||
|
$field['sub_fields'] = array();
|
||||||
|
|
||||||
|
|
||||||
|
// loop
|
||||||
|
foreach( array_keys($sub_fields) as $i ) {
|
||||||
|
|
||||||
|
// extract sub field
|
||||||
|
$sub_field = acf_extract_var( $sub_fields, $i );
|
||||||
|
|
||||||
|
|
||||||
|
// attributes
|
||||||
|
$sub_field['parent'] = $field['key'];
|
||||||
|
|
||||||
|
|
||||||
|
// append to extra
|
||||||
|
$extra[] = $sub_field;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// extra
|
||||||
|
if( !empty($extra) ) {
|
||||||
|
|
||||||
|
array_unshift($extra, $field);
|
||||||
|
|
||||||
|
return $extra;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
return $field;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* validate_any_field
|
||||||
|
*
|
||||||
|
* This function will add compatibility for the 'column_width' setting
|
||||||
|
*
|
||||||
|
* @type function
|
||||||
|
* @date 30/1/17
|
||||||
|
* @since 5.5.6
|
||||||
|
*
|
||||||
|
* @param $field (array)
|
||||||
|
* @return $field
|
||||||
|
*/
|
||||||
|
|
||||||
|
function validate_any_field( $field ) {
|
||||||
|
|
||||||
|
// width has changed
|
||||||
|
if( isset($field['column_width']) ) {
|
||||||
|
|
||||||
|
$field['wrapper']['width'] = acf_extract_var($field, 'column_width');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// return
|
// return
|
||||||
return $field;
|
return $field;
|
||||||
|
|
||||||
|
|
|
||||||
57
readme.txt
57
readme.txt
|
|
@ -106,6 +106,63 @@ http://support.advancedcustomfields.com/
|
||||||
|
|
||||||
== Changelog ==
|
== Changelog ==
|
||||||
|
|
||||||
|
= 5.5.10 =
|
||||||
|
* API: Added new functionality to the `acf_form()` function:
|
||||||
|
* - added new 'html_updated_message' setting
|
||||||
|
* - added new 'html_submit_button' setting
|
||||||
|
* - added new 'html_submit_spinner' setting
|
||||||
|
* - added new 'acf/pre_submit_form' filter run when form is successfully submit (before saving $_POST)
|
||||||
|
* - added new 'acf/submit_form' action run when form is successfully submit (after saving $_POST)
|
||||||
|
* - added new '%post_id%' replace string to the 'return' setting
|
||||||
|
* - added new encryption logic to prevent $_POST exploits
|
||||||
|
* - added new `acf_register_form()` function
|
||||||
|
* Core: Fixed bug preventing values being loaded on a new post/page preview
|
||||||
|
* Core: Fixed missing 'Bulk Actions' dropdown on sync screen when no field groups exist
|
||||||
|
* Core: Fixed bug ignoring PHP field groups if exists in JSON
|
||||||
|
* Core: Minor fixes and improvements
|
||||||
|
|
||||||
|
= 5.5.9 =
|
||||||
|
* Core: Fixed bug causing ACF4 PHP field groups to be ignored if missing ‘key’ setting
|
||||||
|
|
||||||
|
= 5.5.8 =
|
||||||
|
* Flexible Content: Added logic to better 'clean up' data when re-ordering layouts
|
||||||
|
* oEmbed field: Fixed bug causing incorrect width and height settings in embed HTML
|
||||||
|
* Core: Fixed bug causing incorrect Select2 CSS version loading for WooCommerce 2.7
|
||||||
|
* Core: Fixed bug preventing 'min-height' style being applied to floating width fields
|
||||||
|
* Core: Added new JS 'init' actions for wysiwyg, date, datetime, time and select2 fields
|
||||||
|
* Core: Minor fixes and improvements
|
||||||
|
|
||||||
|
= 5.5.7 =
|
||||||
|
* Core: Fixed bug causing `get_field()` to return incorrect data for sub fields registered via PHP code.
|
||||||
|
|
||||||
|
= 5.5.6 =
|
||||||
|
* Core: Fixed bug causing license key to be ignored after changing url from http to https
|
||||||
|
* Core: Fixed Select2 (v4) bug where 'allow null' setting would not correctly save empty value
|
||||||
|
* Core: Added new 'acf/validate_field' filter
|
||||||
|
* Core: Added new 'acf/validate_field_group' filter
|
||||||
|
* Core: Added new 'acf/validate_post_id' filter
|
||||||
|
* Core: Added new 'row_index_offset' setting
|
||||||
|
* Core: Fixed bug causing value loading issues for a taxonomy term in WP < 4.4
|
||||||
|
* Core: Minor fixes and improvements
|
||||||
|
|
||||||
|
= 5.5.5 =
|
||||||
|
* File field: Fixed bug creating draft post when saving an empty value
|
||||||
|
* Image field: Fixed bug mentioned above
|
||||||
|
|
||||||
|
= 5.5.4 =
|
||||||
|
* File field: Added logic to 'connect' selected attachment to post (only if attachment is not 'connected')
|
||||||
|
* File field: Removed `filesize()` call causing performance issues with externally hosted attachments
|
||||||
|
* File field: Added AJAX validation to 'basic' uploader
|
||||||
|
* Image field: Added 'connect' logic mentioned above
|
||||||
|
* Image field: Added AJAX validation mentioned above
|
||||||
|
* True false field: Improved usability by allowing 'tab' key to focus element (use space or arrow keys to toggle)
|
||||||
|
* Gallery field: Fixed bug causing unsaved changes in sidebar to be lost when selecting another attachment
|
||||||
|
* API: Fixed `add_row()` and `add_sub_row()` return values (from true to new row index)
|
||||||
|
* Core: Improved `get_posts()` query speeds by setting 'update_cache' settings to false
|
||||||
|
* Core: Allowed 'instruction_placement' setting on 'widget' forms (previously set always to 'below fields')
|
||||||
|
* Core: Removed 'ACF PRO invalid license nag' and will include fix for 'protocol change' in next release
|
||||||
|
* Language: Updated French translation - thanks to Martial Parfait
|
||||||
|
|
||||||
= 5.5.3 =
|
= 5.5.3 =
|
||||||
* Options page: Fixed bug when using WPML in multiple tabs causing incorrect 'lang' to be used during save.
|
* Options page: Fixed bug when using WPML in multiple tabs causing incorrect 'lang' to be used during save.
|
||||||
* Core: Added support with new `get_user_locale()` setting in WP 4.7
|
* Core: Added support with new `get_user_locale()` setting in WP 4.7
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue