Merge branch 'release/5.3.6.1' into develop

This commit is contained in:
Remco Tolsma 2016-03-17 11:48:40 +01:00
commit 4b6f56396e
37 changed files with 2039 additions and 1207 deletions

13
acf.php
View File

@ -3,7 +3,7 @@
Plugin Name: Advanced Custom Fields Pro Plugin Name: Advanced Custom Fields Pro
Plugin URI: http://www.advancedcustomfields.com/ Plugin URI: http://www.advancedcustomfields.com/
Description: Customise WordPress with powerful, professional and intuitive fields Description: Customise WordPress with powerful, professional and intuitive fields
Version: 5.3.5 Version: 5.3.6.1
Author: elliot condon Author: elliot condon
Author URI: http://www.elliotcondon.com/ Author URI: http://www.elliotcondon.com/
Copyright: Elliot Condon Copyright: Elliot Condon
@ -17,9 +17,6 @@ if( ! class_exists('acf') ) :
class acf { class acf {
// vars
var $settings;
/* /*
* __construct * __construct
@ -61,7 +58,7 @@ class acf {
// basic // basic
'name' => __('Advanced Custom Fields', 'acf'), 'name' => __('Advanced Custom Fields', 'acf'),
'version' => '5.3.5', 'version' => '5.3.6.1',
// urls // urls
'basename' => plugin_basename( __FILE__ ), 'basename' => plugin_basename( __FILE__ ),
@ -82,9 +79,7 @@ class acf {
'uploader' => 'wp', 'uploader' => 'wp',
'autoload' => false, 'autoload' => false,
'l10n' => true, 'l10n' => true,
'l10n_textdomain' => '', 'l10n_textdomain' => ''
'l10n_field' => array('label', 'instructions'),
'l10n_field_group' => array('title'),
); );
@ -103,9 +98,11 @@ class acf {
acf_include('core/ajax.php'); acf_include('core/ajax.php');
acf_include('core/field.php'); acf_include('core/field.php');
acf_include('core/input.php'); acf_include('core/input.php');
acf_include('core/validation.php');
acf_include('core/json.php'); acf_include('core/json.php');
acf_include('core/local.php'); acf_include('core/local.php');
acf_include('core/location.php'); acf_include('core/location.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/compatibility.php');

View File

@ -638,14 +638,18 @@ if( typeof acf !== 'undefined' ) {
*/ */
case "post_type" : case "post_type" :
// get post types
$choices = acf_get_pretty_post_types();
// all post types except attachment
$exclude = array('attachment'); // remove attachments
$choices = acf_get_post_types( $exclude ); unset( $choices['attachment'] );
$choices = acf_get_pretty_post_types( $choices );
// end
break; break;
case "post" : case "post" :
@ -802,9 +806,10 @@ if( typeof acf !== 'undefined' ) {
case "page_template" : case "page_template" :
$choices = array( $choices = array(
'default' => __("Default Template",'acf'), 'default' => apply_filters( 'default_page_template_title', __('Default Template', 'acf') ),
); );
$templates = get_page_templates(); $templates = get_page_templates();
foreach( $templates as $k => $v ) { foreach( $templates as $k => $v ) {
@ -900,8 +905,17 @@ if( typeof acf !== 'undefined' ) {
case "comment" : case "comment" :
$choices = array('all' => __('All', 'acf')); // vars
$choices = array(
'all' => __('All', 'acf')
);
// append post types
$choices = array_merge( $choices, acf_get_pretty_post_types() );
// end
break; break;

View File

@ -619,7 +619,7 @@ class acf_admin_field_groups {
<div class="acf-column-2"> <div class="acf-column-2">
<div class="acf-box"> <div class="acf-box">
<div class="inner"> <div class="inner">
<h2><?php echo acf_get_setting('name'); ?> <?php echo acf_get_setting('version'); ?></h2> <h2><?php echo acf_get_setting('name'); ?></h2>
<h3><?php _e("Changelog",'acf'); ?></h3> <h3><?php _e("Changelog",'acf'); ?></h3>
<p><?php _e("See what's new in",'acf'); ?> <a href="<?php echo admin_url('edit.php?post_type=acf-field-group&page=acf-settings-info&tab=changelog'); ?>"><?php _e("version",'acf'); ?> <?php echo acf_get_setting('version'); ?></a> <p><?php _e("See what's new in",'acf'); ?> <a href="<?php echo admin_url('edit.php?post_type=acf-field-group&page=acf-settings-info&tab=changelog'); ?>"><?php _e("version",'acf'); ?> <?php echo acf_get_setting('version'); ?></a>

View File

@ -70,14 +70,53 @@ function acf_get_valid_field_group( $field_group = false ) {
)); ));
// translate
$field_group = acf_translate_keys( $field_group, acf_get_setting('l10n_field_group') );
// filter // filter
$field_group = apply_filters('acf/get_valid_field_group', $field_group); $field_group = apply_filters('acf/get_valid_field_group', $field_group);
// translate
$field_group = acf_translate_field_group( $field_group );
// return
return $field_group;
}
/*
* acf_translate_field_group
*
* This function will translate field group's settings
*
* @type function
* @date 8/03/2016
* @since 5.3.2
*
* @param $field_group (array)
* @return $field_group
*/
function acf_translate_field_group( $field_group ) {
// vars
$l10n = acf_get_setting('l10n');
$l10n_textdomain = acf_get_setting('l10n_textdomain');
// if
if( $l10n && $l10n_textdomain ) {
// translate
$field_group['title'] = acf_translate( $field_group['title'] );
// filters
$field_group = apply_filters( "acf/translate_field_group", $field_group );
}
// return // return
return $field_group; return $field_group;

View File

@ -177,10 +177,6 @@ function acf_get_valid_field( $field = false ) {
$field['_name'] = $field['name']; $field['_name'] = $field['name'];
// translate
$field = acf_translate_keys( $field, acf_get_setting('l10n_field') );
// field specific defaults // field specific defaults
$field = apply_filters( "acf/get_valid_field", $field ); $field = apply_filters( "acf/get_valid_field", $field );
$field = apply_filters( "acf/get_valid_field/type={$field['type']}", $field ); $field = apply_filters( "acf/get_valid_field/type={$field['type']}", $field );
@ -190,11 +186,58 @@ function acf_get_valid_field( $field = false ) {
$field['_valid'] = 1; $field['_valid'] = 1;
// translate
$field = acf_translate_field( $field );
// return // return
return $field; return $field;
} }
/*
* acf_translate_field
*
* This function will translate field's settings
*
* @type function
* @date 8/03/2016
* @since 5.3.2
*
* @param $field (array)
* @return $field
*/
function acf_translate_field( $field ) {
// vars
$l10n = acf_get_setting('l10n');
$l10n_textdomain = acf_get_setting('l10n_textdomain');
// if
if( $l10n && $l10n_textdomain ) {
// translate
$field['label'] = acf_translate( $field['label'] );
$field['instructions'] = acf_translate( $field['instructions'] );
// filters
$field = apply_filters( "acf/translate_field", $field );
$field = apply_filters( "acf/translate_field/type={$field['type']}", $field );
}
// return
return $field;
}
/* /*
* acf_prepare_field * acf_prepare_field
* *
@ -1855,4 +1898,5 @@ function acf_get_sub_field( $selector, $field ) {
} }
?> ?>

View File

@ -574,6 +574,34 @@ function acf_extract_vars( &$array, $keys ) {
} }
/*
* acf_get_sub_array
*
* This function will return a sub array of data
*
* @type function
* @date 15/03/2016
* @since 5.3.2
*
* @param $post_id (int)
* @return $post_id (int)
*/
function acf_get_sub_array( $array, $keys ) {
$r = array();
foreach( $keys as $key ) {
$r[ $key ] = $array[ $key ];
}
return $r;
}
/* /*
* acf_get_post_types * acf_get_post_types
* *
@ -2325,7 +2353,7 @@ function acf_encode_choices( $array = array(), $show_keys = true ) {
} }
function acf_decode_choices( $string = '' ) { function acf_decode_choices( $string = '', $array_keys = false ) {
// bail early if already array // bail early if already array
if( is_array($string) ) { if( is_array($string) ) {
@ -2383,6 +2411,14 @@ function acf_decode_choices( $string = '' ) {
} }
// return only array keys? (good for checkbox default_value)
if( $array_keys ) {
return array_keys($array);
}
// return // return
return $array; return $array;
@ -2649,18 +2685,19 @@ function acf_in_array( $value, $array ) {
function acf_get_valid_post_id( $post_id = 0 ) { function acf_get_valid_post_id( $post_id = 0 ) {
// set post_id to global // if not $post_id, load queried object
if( !$post_id ) { if( !$post_id ) {
// try for global post (needed for setup_postdata)
$post_id = (int) get_the_ID(); $post_id = (int) get_the_ID();
}
// try for current screen
if( !$post_id ) {
// allow for option == options
if( $post_id == 'option' ) { $post_id = get_queried_object();
$post_id = 'options'; }
} }
@ -2668,27 +2705,44 @@ function acf_get_valid_post_id( $post_id = 0 ) {
// $post_id may be an object // $post_id may be an object
if( is_object($post_id) ) { if( is_object($post_id) ) {
// user
if( isset($post_id->roles, $post_id->ID) ) { if( isset($post_id->roles, $post_id->ID) ) {
$post_id = 'user_' . $post_id->ID; $post_id = 'user_' . $post_id->ID;
// term
} elseif( isset($post_id->taxonomy, $post_id->term_id) ) { } elseif( isset($post_id->taxonomy, $post_id->term_id) ) {
$post_id = $post_id->taxonomy . '_' . $post_id->term_id; $post_id = $post_id->taxonomy . '_' . $post_id->term_id;
// comment
} elseif( isset($post_id->comment_ID) ) { } elseif( isset($post_id->comment_ID) ) {
$post_id = 'comment_' . $post_id->comment_ID; $post_id = 'comment_' . $post_id->comment_ID;
// post
} elseif( isset($post_id->ID) ) { } elseif( isset($post_id->ID) ) {
$post_id = $post_id->ID; $post_id = $post_id->ID;
// default
} else {
$post_id = 0;
} }
} }
// allow for option == options
if( $post_id === 'option' ) {
$post_id = 'options';
}
// append language code // append language code
if( $post_id == 'options' ) { if( $post_id == 'options' ) {
@ -3658,6 +3712,7 @@ function _acf_settings_uploader( $uploader ) {
* @return $post_id (int) * @return $post_id (int)
*/ */
/*
function acf_translate_keys( $array, $keys ) { function acf_translate_keys( $array, $keys ) {
// bail early if no keys // bail early if no keys
@ -3681,6 +3736,7 @@ function acf_translate_keys( $array, $keys ) {
return $array; return $array;
} }
*/
/* /*
@ -3767,6 +3823,49 @@ function acf_maybe_add_action( $tag, $function_to_add, $priority = 10, $accepted
} }
/*
* acf_is_row_collapsed
*
* This function will return true if the field's row is collapsed
*
* @type function
* @date 2/03/2016
* @since 5.3.2
*
* @param $post_id (int)
* @return $post_id (int)
*/
function acf_is_row_collapsed( $field_key = '', $row_index = 0 ) {
// collapsed
$collapsed = acf_get_user_setting('collapsed_' . $field_key, '');
// cookie fallback ( version < 5.3.2 )
if( $collapsed === '' ) {
$collapsed = acf_extract_var($_COOKIE, "acf_collapsed_{$field_key}", '');
$collapsed = str_replace('|', ',', $collapsed);
// update
acf_update_user_setting( 'collapsed_' . $field_key, $collapsed );
}
// explode
$collapsed = explode(',', $collapsed);
$collapsed = array_filter($collapsed, 'is_numeric');
// collapsed class
return in_array($row_index, $collapsed);
}
/* /*
* Hacks * Hacks
* *

View File

@ -22,35 +22,6 @@ function acf_get_field_reference( $field_name, $post_id ) {
} }
/*
* the_field()
*
* This function is the same as echo get_field().
*
* @type function
* @since 1.0.3
* @date 29/01/13
*
* @param $selector (string) the field name or key
* @param $post_id (mixed) the post_id of which the value is saved against
* @return n/a
*/
function the_field( $selector, $post_id = false, $format_value = true ) {
$value = get_field($selector, $post_id, $format_value);
if( is_array($value) ) {
$value = @implode( ', ', $value );
}
echo $value;
}
/* /*
* get_field() * get_field()
* *
@ -113,6 +84,35 @@ function get_field( $selector, $post_id = false, $format_value = true ) {
} }
/*
* the_field()
*
* This function is the same as echo get_field().
*
* @type function
* @since 1.0.3
* @date 29/01/13
*
* @param $selector (string) the field name or key
* @param $post_id (mixed) the post_id of which the value is saved against
* @return n/a
*/
function the_field( $selector, $post_id = false, $format_value = true ) {
$value = get_field($selector, $post_id, $format_value);
if( is_array($value) ) {
$value = @implode( ', ', $value );
}
echo $value;
}
/* /*
* get_field_object() * get_field_object()
* *
@ -132,11 +132,7 @@ function get_field( $selector, $post_id = false, $format_value = true ) {
function get_field_object( $selector, $post_id = false, $format_value = true, $load_value = true ) { function get_field_object( $selector, $post_id = false, $format_value = true, $load_value = true ) {
// compatibilty // compatibilty
if( is_array($format_value) ) { if( is_array($format_value) ) extract( $format_value );
extract( $format_value );
}
// get valid post_id // get valid post_id
@ -148,11 +144,7 @@ function get_field_object( $selector, $post_id = false, $format_value = true, $l
// bail early if no field found // bail early if no field found
if( !$field ) { if( !$field ) return false;
return false;
}
// load value // load value
@ -197,23 +189,24 @@ function get_fields( $post_id = false, $format_value = true ) {
// vars // vars
$fields = get_field_objects( $post_id, $format_value ); $fields = get_field_objects( $post_id, $format_value );
$return = array(); $meta = array();
// bail early
if( !$fields ) return false;
// populate // populate
if( is_array($fields) ) { foreach( $fields as $k => $field ) {
foreach( $fields as $k => $field ) { $meta[ $k ] = $field['value'];
$return[ $k ] = $field['value'];
}
} }
// return // return
return $return; return $meta;
} }
@ -287,30 +280,18 @@ function get_field_objects( $post_id = false, $format_value = true, $load_value
// bail early if no meta // bail early if no meta
if( empty($meta) ) { if( empty($meta) ) return false;
return false;
}
// populate vars // populate vars
foreach( $meta as $k => $v ) { foreach( $meta as $k => $v ) {
// Hopefuly improve efficiency: bail early if $k does start with an '_' // Hopefuly improve efficiency: bail early if $k does start with an '_'
if( $k[0] === '_' ) { if( $k[0] === '_' ) continue;
continue;
}
// does a field key exist for this value? // does a field key exist for this value?
if( !array_key_exists("_{$k}", $meta) ) { if( !array_key_exists("_{$k}", $meta) ) continue;
continue;
}
// get field // get field
@ -319,11 +300,7 @@ function get_field_objects( $post_id = false, $format_value = true, $load_value
// bail early if not a parent field // bail early if not a parent field
if( !$field || acf_is_sub_field($field) ) { if( !$field || acf_is_sub_field($field) ) continue;
continue;
}
// load value // load value
@ -350,11 +327,7 @@ function get_field_objects( $post_id = false, $format_value = true, $load_value
// no value // no value
if( empty($fields) ) { if( empty($fields) ) return false;
return false;
}
// return // return
@ -380,11 +353,13 @@ function get_field_objects( $post_id = false, $format_value = true, $load_value
function have_rows( $selector, $post_id = false ) { function have_rows( $selector, $post_id = false ) {
// vars // vars
$row = array(); $active_loop = acf_get_loop('active');
$previous_loop = acf_get_loop('previous');
$new_parent_loop = false; $new_parent_loop = false;
$new_child_loop = false; $new_child_loop = false;
$sub_field = false; $sub_field = false;
$sub_exists = false; $sub_exists = false;
$change = false;
// reference // reference
@ -396,29 +371,19 @@ function have_rows( $selector, $post_id = false ) {
// empty? // empty?
if( empty($GLOBALS['acf_field']) ) { if( !$active_loop ) {
// reset
reset_rows( true );
// create a new loop // create a new loop
$new_parent_loop = true; $new_parent_loop = true;
} else { } else {
// vars
$row = end( $GLOBALS['acf_field'] );
$prev = prev( $GLOBALS['acf_field'] );
$change = false;
// detect change // detect change
if( $post_id != $row['post_id'] ) { if( $post_id != $active_loop['post_id'] ) {
$change = 'post_id'; $change = 'post_id';
} elseif( $selector != $row['selector'] ) { } elseif( $selector != $active_loop['selector'] ) {
$change = 'selector'; $change = 'selector';
@ -428,11 +393,11 @@ function have_rows( $selector, $post_id = false ) {
// attempt to find sub field // attempt to find sub field
if( $change ) { if( $change ) {
$sub_field = acf_get_sub_field($selector, $row['field']); $sub_field = acf_get_sub_field($selector, $active_loop['field']);
if( $sub_field ) { if( $sub_field ) {
$sub_exists = isset($row['value'][ $row['i'] ][ $sub_field['key'] ]); $sub_exists = isset( $active_loop['value'][ $active_loop['i'] ][ $sub_field['key'] ] );
} }
@ -448,11 +413,11 @@ function have_rows( $selector, $post_id = false ) {
// action: move down one level into a new loop // action: move down one level into a new loop
$new_child_loop = true; $new_child_loop = true;
} elseif( $prev && $prev['post_id'] == $post_id ) { } elseif( $previous_loop && $previous_loop['post_id'] == $post_id ) {
// case: Change in $post_id was due to a nested loop ending // case: Change in $post_id was due to a nested loop ending
// action: move up one level through the loops // action: move up one level through the loops
reset_rows(); acf_remove_loop('active');
} else { } else {
@ -464,11 +429,11 @@ function have_rows( $selector, $post_id = false ) {
} elseif( $change == 'selector' ) { } elseif( $change == 'selector' ) {
if( $prev && $prev['selector'] == $selector && $prev['post_id'] == $post_id ) { if( $previous_loop && $previous_loop['selector'] == $selector && $previous_loop['post_id'] == $post_id ) {
// case: Change in $field_name was due to a nested loop ending // case: Change in $field_name was due to a nested loop ending
// action: move up one level through the loops // action: move up one level through the loops
reset_rows(); acf_remove_loop('active');
} elseif( $sub_exists ) { } elseif( $sub_exists ) {
@ -489,6 +454,7 @@ function have_rows( $selector, $post_id = false ) {
} }
// add parent loop
if( $new_parent_loop ) { if( $new_parent_loop ) {
// vars // vars
@ -496,40 +462,42 @@ function have_rows( $selector, $post_id = false ) {
$value = acf_extract_var( $field, 'value' ); $value = acf_extract_var( $field, 'value' );
// add row // add loop
$GLOBALS['acf_field'][] = array( acf_add_loop(array(
'selector' => $selector, 'selector' => $selector,
'name' => $field['name'], // used by update_sub_field 'name' => $field['name'], // used by update_sub_field
'value' => $value, 'value' => $value,
'field' => $field, 'field' => $field,
'i' => -1, 'i' => -1,
'post_id' => $post_id, 'post_id' => $post_id,
); ));
// add child loop
} elseif( $new_child_loop ) { } elseif( $new_child_loop ) {
// vars // vars
$value = $row['value'][ $row['i'] ][ $sub_field['key'] ]; $value = $active_loop['value'][ $active_loop['i'] ][ $sub_field['key'] ];
$GLOBALS['acf_field'][] = array(
// add loop
acf_add_loop(array(
'selector' => $selector, 'selector' => $selector,
'name' => $row['name'] . '_' . $row['i'], // used by update_sub_field 'name' => $active_loop['name'] . '_' . $active_loop['i'], // used by update_sub_field
'value' => $value, 'value' => $value,
'field' => $sub_field, 'field' => $sub_field,
'i' => -1, 'i' => -1,
'post_id' => $post_id, 'post_id' => $post_id,
); ));
} }
// update vars // update vars
$row = end( $GLOBALS['acf_field'] ); $active_loop = acf_get_loop('active');
// return true if next row exists // return true if next row exists
if( is_array($row['value']) && array_key_exists($row['i']+1, $row['value']) ) { if( $active_loop && is_array($active_loop['value']) && isset($active_loop['value'][ $active_loop['i']+1 ]) ) {
return true; return true;
@ -537,7 +505,7 @@ function have_rows( $selector, $post_id = false ) {
// no next row! // no next row!
reset_rows(); acf_remove_loop('active');
// return // return
@ -562,11 +530,15 @@ function have_rows( $selector, $post_id = false ) {
function the_row( $format = false ) { function the_row( $format = false ) {
// vars // vars
$depth = count($GLOBALS['acf_field']) - 1; $i = acf_get_loop('active', 'i');
// increase i of current row
$GLOBALS['acf_field'][ $depth ]['i']++; // increase
$i++;
// update
acf_update_loop('active', 'i', $i);
// return // return
@ -577,19 +549,15 @@ function the_row( $format = false ) {
function get_row( $format = false ) { function get_row( $format = false ) {
// vars // vars
$row = acf_get_row(); $loop = acf_get_loop('active');
// bail early if no row // bail early if no loop
if( !$row ) { if( !$loop ) return false;
return false;
}
// get value // get value
$value = $row['value'][ $row['i'] ]; $value = $loop['value'][ $loop['i'] ];
// format // format
@ -598,8 +566,10 @@ function get_row( $format = false ) {
// temp wrap value in array // temp wrap value in array
$value = array( $value ); $value = array( $value );
// format the value (1 row of data) // format the value (1 row of data)
$value = acf_format_value( $value, $row['post_id'], $row['field'] ); $value = acf_format_value( $value, $loop['post_id'], $loop['field'] );
// extract value from array // extract value from array
$value = $value[0]; $value = $value[0];
@ -612,33 +582,14 @@ function get_row( $format = false ) {
} }
function acf_get_row() {
// check and return row
if( !empty($GLOBALS['acf_field']) ) {
return end( $GLOBALS['acf_field'] );
}
// return
return false;
}
function get_row_index() { function get_row_index() {
// vars // vars
$row = acf_get_row(); $i = acf_get_loop('active', 'i');
// bail early if no row
if( !$row ) return 0;
// return // return
return $row['i'] + 1; return $i + 1;
} }
@ -657,34 +608,15 @@ function get_row_index() {
* @return (boolean) * @return (boolean)
*/ */
function reset_rows( $hard_reset = false ) { function reset_rows() {
// completely destroy? // remove last loop
if( $hard_reset ) { acf_remove_loop('active');
$GLOBALS['acf_field'] = array();
// reset current row
} else {
// vars
$depth = count( $GLOBALS['acf_field'] ) - 1;
// remove
unset( $GLOBALS['acf_field'][$depth] );
// refresh index
$GLOBALS['acf_field'] = array_values($GLOBALS['acf_field']);
}
// return // return
return true; return true;
} }
@ -746,7 +678,7 @@ function has_sub_fields( $field_name, $post_id = false ) {
function get_sub_field( $selector, $format_value = true ) { function get_sub_field( $selector, $format_value = true ) {
// vars // vars
$row = acf_get_row(); $row = acf_get_loop('active');
// bail early if no row // bail early if no row
@ -842,7 +774,7 @@ function the_sub_field( $field_name, $format_value = true ) {
function get_sub_field_object( $selector, $format_value = true, $load_value = true ) { function get_sub_field_object( $selector, $format_value = true, $load_value = true ) {
// vars // vars
$row = acf_get_row(); $row = acf_get_loop('active');
// bail early if no row // bail early if no row
@ -975,6 +907,11 @@ function acf_form_head() {
// verify nonce // verify nonce
if( acf_verify_nonce('acf_form') ) { if( acf_verify_nonce('acf_form') ) {
// add actions
add_action('acf/validate_save_post', '_validate_save_post');
add_filter('acf/pre_save_post', '_acf_pre_save_post', 5, 2);
// validate data // validate data
if( acf_validate_save_post(true) ) { if( acf_validate_save_post(true) ) {
@ -1041,8 +978,6 @@ function acf_form_head() {
* @return $post_id (int) * @return $post_id (int)
*/ */
add_action('acf/validate_save_post', '_validate_save_post');
function _validate_save_post() { function _validate_save_post() {
// save post_title // save post_title
@ -1086,8 +1021,6 @@ function _validate_save_post() {
* @return $post_id (int) * @return $post_id (int)
*/ */
add_filter('acf/pre_save_post', '_acf_pre_save_post', 5, 2);
function _acf_pre_save_post( $post_id, $form ) { function _acf_pre_save_post( $post_id, $form ) {
// vars // vars
@ -1491,7 +1424,7 @@ function update_sub_field( $selector, $value, $post_id = false ) {
if( is_string($selector) ) { if( is_string($selector) ) {
// get current row // get current row
$row = acf_get_row(); $row = acf_get_loop('active');
// override $post_id // override $post_id
@ -1828,139 +1761,6 @@ function delete_row( $selector, $row = 1, $post_id = false ) {
} }
/*
* create_field()
*
* This function will creat the HTML for a field
*
* @type function
* @since 4.0.0
* @date 17/03/13
*
* @param array $field - an array containing all the field attributes
*
* @return N/A
*/
function create_field( $field ) {
acf_render_field( $field );
}
function render_field( $field ) {
acf_render_field( $field );
}
/*
* acf_convert_field_names_to_keys()
*
* Helper for the update_field function
*
* @type function
* @since 4.0.0
* @date 17/03/13
*
* @param array $value: the value returned via get_field
* @param array $field: the field or layout to find sub fields from
*
* @return N/A
*/
function acf_convert_field_names_to_keys( $value, $field ) {
// only if $field has sub fields
if( !isset($field['sub_fields']) ) {
return $value;
}
// define sub field keys
$sub_fields = array();
if( $field['sub_fields'] ) {
foreach( $field['sub_fields'] as $sub_field ) {
$sub_fields[ $sub_field['name'] ] = $sub_field;
}
}
// loop through the values and format the array to use sub field keys
if( is_array($value) ) {
foreach( $value as $row_i => $row) {
if( $row ) {
foreach( $row as $sub_field_name => $sub_field_value ) {
// sub field must exist!
if( !isset($sub_fields[ $sub_field_name ]) ) {
continue;
}
// vars
$sub_field = $sub_fields[ $sub_field_name ];
$sub_field_value = acf_convert_field_names_to_keys( $sub_field_value, $sub_field );
// set new value
$value[$row_i][ $sub_field['key'] ] = $sub_field_value;
// unset old value
unset( $value[$row_i][$sub_field_name] );
}
// foreach( $row as $sub_field_name => $sub_field_value )
}
// if( $row )
}
// foreach( $value as $row_i => $row)
}
// if( $value )
// return
return $value;
}
/*
* register_field_group
*
* description
*
* @type function
* @date 11/03/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function register_field_group( $field_group ) {
// add local
acf_add_local_field_group( $field_group );
}
/* /*
* Depreceated Functions * Depreceated Functions
* *
@ -1974,6 +1774,24 @@ function register_field_group( $field_group ) {
* @return n/a * @return n/a
*/ */
function register_field_group( $field_group ) {
acf_add_local_field_group( $field_group );
}
function create_field( $field ) {
acf_render_field( $field );
}
function render_field( $field ) {
acf_render_field( $field );
}
function reset_the_repeater_field() { function reset_the_repeater_field() {
return reset_rows(); return reset_rows();

View File

@ -575,32 +575,44 @@ a.acf-icon.-cancel.grey:hover {
position: relative; position: relative;
display: block; display: block;
background: #F55E4F; background: #F55E4F;
border-radius: 3px;
margin: 5px 0 15px; margin: 5px 0 15px;
padding: 1px 10px; padding: 1px 12px;
min-height: 0px; min-height: 0px;
border-left: #dd4232 solid 4px;
} }
.acf-error-message p { .acf-error-message p {
font-size: 13px !important; font-size: 13px !important;
line-height: 1.4; line-height: 1.5;
margin: 8px 0; margin: 0.5em 0;
padding: 0; padding: 2px;
text-shadow: none; text-shadow: none;
color: #fff; color: #fff;
text-shadow: 0 1px 0 #DD4232;
} }
.acf-error-message .acf-icon { .acf-error-message .acf-icon {
position: absolute; position: absolute;
top: 8px; top: 9px;
right: 10px; right: 12px;
background-color: #dd4232; background-color: #dd4232;
border-color: transparent; border-color: transparent;
color: #fff; color: #fff;
} }
.acf-error-message .acf-icon:hover { /* important to include .-cancel to override .acf-icon.-cancel class */
background-color: #F1F1F1; .acf-error-message .acf-icon.-cancel:hover {
background-color: #191e23;
color: #F55E4F; color: #F55E4F;
} }
/* success */
.acf-error-message.-success {
background-color: #46b450;
border-color: #32973b;
}
.acf-error-message.-success .acf-icon {
background-color: #32973b;
}
.acf-error-message.-success .acf-icon.-cancel:hover {
background-color: #191e23;
color: #46b450;
}
/*-------------------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------------------
* *
* acf-table * acf-table

View File

@ -47,6 +47,8 @@
color: #fff; color: #fff;
margin: 0 0 10px; margin: 0 0 10px;
display: inline-block; display: inline-block;
border-radius: 3px;
border-left: none;
} }
.acf-field .acf-error-message:after { .acf-field .acf-error-message:after {
content: ""; content: "";
@ -1347,6 +1349,7 @@ html[dir="rtl"] .acf-image-uploader .view {
display: block; display: block;
padding: 0; padding: 0;
margin: 0; margin: 0;
max-width: 48px;
} }
.acf-file-uploader .file-info { .acf-file-uploader .file-info {
padding: 10px; padding: 10px;
@ -1361,21 +1364,19 @@ html[dir="rtl"] .acf-image-uploader .view {
.acf-file-uploader .file-info a { .acf-file-uploader .file-info a {
text-decoration: none; text-decoration: none;
} }
/* .acf-file-uploader .file-info ul {
* Hover
*/
.acf-file-uploader .acf-soh-target {
position: absolute; position: absolute;
top: 5px; top: 5px;
right: 5px; right: 5px;
/* rtl */
} }
html[dir="rtl"] .acf-file-uploader .acf-soh-target { .acf-file-uploader .file-info ul li {
margin: 0 0 0 4px;
}
html[dir="rtl"] .acf-file-uploader .file-info ul {
right: auto; right: auto;
left: 5px; left: 5px;
} }
.acf-file-uploader .acf-soh-target li {
margin: 0 0 0 4px;
}
/*--------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------
* *
* Date Picker * Date Picker

View File

@ -15,7 +15,8 @@
addFilter : addFilter, addFilter : addFilter,
removeAction : removeAction, removeAction : removeAction,
doAction : doAction, doAction : doAction,
addAction : addAction addAction : addAction,
storage : getStorage
}; };
/** /**
@ -26,7 +27,13 @@
actions : {}, actions : {},
filters : {} filters : {}
}; };
function getStorage() {
return STORAGE;
};
/** /**
* Adds an action to the event manager. * Adds an action to the event manager.
* *
@ -397,17 +404,38 @@ var acf;
add_action: function() { add_action: function() {
// allow multiple action parameters such as 'ready append' // vars
var actions = arguments[0].split(' '); var a = arguments[0].split(' '),
l = a.length;
for( k in actions ) {
// prefix action // loop
arguments[0] = 'acf.' + actions[ k ]; for( var i = 0; i < l; i++) {
/*
// allow for special actions
if( a[i].indexOf('initialize') !== -1 ) {
a.push( a[i].replace('initialize', 'ready') );
a.push( a[i].replace('initialize', 'append') );
l = a.length;
continue;
}
*/
// prefix action
arguments[0] = 'acf/' + a[i];
// add
wp.hooks.addAction.apply(this, arguments); wp.hooks.addAction.apply(this, arguments);
} }
// return
return this; return this;
}, },
@ -429,7 +457,7 @@ var acf;
remove_action: function() { remove_action: function() {
// prefix action // prefix action
arguments[0] = 'acf.' + arguments[0]; arguments[0] = 'acf/' + arguments[0];
wp.hooks.removeAction.apply(this, arguments); wp.hooks.removeAction.apply(this, arguments);
@ -451,10 +479,10 @@ var acf;
* @return * @return
*/ */
do_action: function() { do_action: function() { //console.log('acf.do_action(%o)', arguments);
// prefix action // prefix action
arguments[0] = 'acf.' + arguments[0]; arguments[0] = 'acf/' + arguments[0];
wp.hooks.doAction.apply(this, arguments); wp.hooks.doAction.apply(this, arguments);
@ -479,7 +507,7 @@ var acf;
add_filter: function() { add_filter: function() {
// prefix action // prefix action
arguments[0] = 'acf.' + arguments[0]; arguments[0] = 'acf/' + arguments[0];
wp.hooks.addFilter.apply(this, arguments); wp.hooks.addFilter.apply(this, arguments);
@ -504,7 +532,7 @@ var acf;
remove_filter: function() { remove_filter: function() {
// prefix action // prefix action
arguments[0] = 'acf.' + arguments[0]; arguments[0] = 'acf/' + arguments[0];
wp.hooks.removeFilter.apply(this, arguments); wp.hooks.removeFilter.apply(this, arguments);
@ -526,10 +554,10 @@ var acf;
* @return * @return
*/ */
apply_filters: function() { apply_filters: function() { //console.log('acf.apply_filters(%o)', arguments);
// prefix action // prefix action
arguments[0] = 'acf.' + arguments[0]; arguments[0] = 'acf/' + arguments[0];
return wp.hooks.applyFilters.apply(this, arguments); return wp.hooks.applyFilters.apply(this, arguments);
@ -770,7 +798,7 @@ var acf;
get_field_key: function( $field ){ get_field_key: function( $field ){
return this.get_data( $field, 'key' ); return $field.data('key');
}, },
@ -790,7 +818,7 @@ var acf;
get_field_type: function( $field ){ get_field_type: function( $field ){
return this.get_data( $field, 'type' ); return $field.data('type');
}, },
@ -902,22 +930,14 @@ var acf;
* @since 5.0.0 * @since 5.0.0
* *
* @param $el (jQuery selection) * @param $el (jQuery selection)
* @param prefix (string)
* @return $post_id (int) * @return $post_id (int)
*/ */
serialize_form : function( $el, prefix ){ serialize_form : function( $el ){
// defaults
prefix = prefix || '';
// vars // vars
var data = {}, var data = {},
names = {}, names = {};
prelen = prefix.length,
_prefix = '_' + prefix,
_prelen = _prefix.length;
// selector // selector
@ -927,14 +947,6 @@ var acf;
// populate data // populate data
$.each( $selector.serializeArray(), function( i, pair ) { $.each( $selector.serializeArray(), function( i, pair ) {
// bail early if name does not start with acf or _acf
if( prefix && pair.name.substring(0, prelen) != prefix && pair.name.substring(0, _prelen) != _prefix ) {
return;
}
// initiate name // initiate name
if( pair.name.slice(-2) === '[]' ) { if( pair.name.slice(-2) === '[]' ) {
@ -966,6 +978,13 @@ var acf;
// return // return
return data; return data;
},
serialize: function( $el ){
return this.serialize_form( $el );
}, },
@ -1510,40 +1529,6 @@ var acf;
}, },
update_cookie : function( name, value, days ) {
// defaults
days = days || 31;
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
},
get_cookie : function( name ) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
},
delete_cookie : function( name ) {
this.update_cookie(name,"",-1);
},
/* /*
* is_in_view * is_in_view
@ -2243,8 +2228,8 @@ var acf;
}, },
_prepare_field: function( $el ){ _prepare_field: function( $el ){
acf.do_action('prepare_field/type=' + acf.get_field_type($el), $el); acf.do_action('prepare_field/type=' + $el.data('type'), $el);
}, },
@ -2260,8 +2245,8 @@ var acf;
}, },
_ready_field: function( $el ){ _ready_field: function( $el ){
acf.do_action('ready_field/type=' + acf.get_field_type($el), $el); acf.do_action('ready_field/type=' + $el.data('type'), $el);
}, },
@ -2278,7 +2263,7 @@ var acf;
_append_field: function( $el ){ _append_field: function( $el ){
acf.do_action('append_field/type=' + acf.get_field_type($el), $el); acf.do_action('append_field/type=' + $el.data('type'), $el);
}, },
@ -2295,7 +2280,7 @@ var acf;
_load_field: function( $el ){ _load_field: function( $el ){
acf.do_action('load_field/type=' + acf.get_field_type($el), $el); acf.do_action('load_field/type=' + $el.data('type'), $el);
}, },
@ -2312,7 +2297,7 @@ var acf;
_remove_field: function( $el ){ _remove_field: function( $el ){
acf.do_action('remove_field/type=' + acf.get_field_type($el), $el); acf.do_action('remove_field/type=' + $el.data('type'), $el);
}, },
@ -2329,7 +2314,7 @@ var acf;
_sortstart_field: function( $el, $placeholder ){ _sortstart_field: function( $el, $placeholder ){
acf.do_action('sortstart_field/type=' + acf.get_field_type($el), $el, $placeholder); acf.do_action('sortstart_field/type=' + $el.data('type'), $el, $placeholder);
}, },
@ -2346,7 +2331,7 @@ var acf;
_sortstop_field: function( $el, $placeholder ){ _sortstop_field: function( $el, $placeholder ){
acf.do_action('sortstop_field/type=' + acf.get_field_type($el), $el, $placeholder); acf.do_action('sortstop_field/type=' + $el.data('type'), $el, $placeholder);
}, },
@ -2364,7 +2349,7 @@ var acf;
_hide_field: function( $el, context ){ _hide_field: function( $el, context ){
acf.do_action('hide_field/type=' + acf.get_field_type($el), $el, context); acf.do_action('hide_field/type=' + $el.data('type'), $el, context);
}, },
@ -2381,7 +2366,7 @@ var acf;
_show_field: function( $el, context ){ _show_field: function( $el, context ){
acf.do_action('show_field/type=' + acf.get_field_type($el), $el, context); acf.do_action('show_field/type=' + $el.data('type'), $el, context);
} }
@ -2986,25 +2971,25 @@ var acf;
}); });
/*
/*
//console.time("acf_test_ready"); console.time("acf_test_ready");
//console.time("acf_test_load"); console.time("acf_test_load");
acf.add_action('ready', function(){ acf.add_action('ready', function(){
//console.timeEnd("acf_test_ready"); console.timeEnd("acf_test_ready");
}, 999); }, 999);
acf.add_action('load', function(){ acf.add_action('load', function(){
//console.timeEnd("acf_test_load"); console.timeEnd("acf_test_load");
}, 999); }, 999);
*/ */
})(jQuery); })(jQuery);
(function($){ (function($){
@ -3429,7 +3414,8 @@ var acf;
acf.fields.color_picker = acf.field.extend({ acf.fields.color_picker = acf.field.extend({
type: 'color_picker', type: 'color_picker',
timeout: null, $input: null,
$hidden: null,
actions: { actions: {
'ready': 'initialize', 'ready': 'initialize',
@ -3439,59 +3425,53 @@ var acf;
focus: function(){ focus: function(){
this.$input = this.$field.find('input[type="text"]'); this.$input = this.$field.find('input[type="text"]');
this.$hidden = this.$field.find('input[type="hidden"]');
}, },
initialize: function(){ initialize: function(){
// reference // reference
var self = this; var $input = this.$input,
$hidden = this.$hidden;
// vars // trigger change function
var $hidden = this.$input.clone(); var change_hidden = function(){
// timeout is required to ensure the $input val is correct
setTimeout(function(){
acf.val( $hidden, $input.val() );
}, 1);
}
// modify hidden // args
$hidden.attr({ var args = {
'type' : 'hidden',
'class' : '', defaultColor: false,
'id' : '', palettes: true,
'value' : '' hide: true,
}); change: change_hidden,
clear: change_hidden
// append hidden }
this.$input.before( $hidden );
// filter
var args = acf.apply_filters('color_picker_args', args, this.$field);
// iris // iris
this.$input.wpColorPicker({ this.$input.wpColorPicker(args);
change: function( event, ui ){
if( self.timeout ) {
clearTimeout( self.timeout );
}
self.timeout = setTimeout(function(){
$hidden.trigger('change');
}, 1000);
}
});
} }
}); });
})(jQuery); })(jQuery);
(function($){ (function($){
@ -4198,7 +4178,7 @@ var acf;
title: acf._e('file', 'select'), title: acf._e('file', 'select'),
mode: 'select', mode: 'select',
type: '', type: '',
field: acf.get_field_key($field), field: $field.data('key'),
multiple: $repeater.exists(), multiple: $repeater.exists(),
library: this.o.library, library: this.o.library,
mime_types: this.o.mime_types, mime_types: this.o.mime_types,
@ -4210,7 +4190,7 @@ var acf;
if( i > 0 ) { if( i > 0 ) {
// vars // vars
var key = acf.get_field_key( $field ), var key = $field.data('key'),
$tr = $field.closest('.acf-row'); $tr = $field.closest('.acf-row');
@ -5198,7 +5178,7 @@ var acf;
title: acf._e('image', 'select'), title: acf._e('image', 'select'),
mode: 'select', mode: 'select',
type: 'image', type: 'image',
field: acf.get_field_key($field), field: $field.data('key'),
multiple: $repeater.exists(), multiple: $repeater.exists(),
library: this.o.library, library: this.o.library,
mime_types: this.o.mime_types, mime_types: this.o.mime_types,
@ -5209,7 +5189,7 @@ var acf;
if( i > 0 ) { if( i > 0 ) {
// vars // vars
var key = acf.get_field_key( $field ), var key = $field.data('key'),
$tr = $field.closest('.acf-row'); $tr = $field.closest('.acf-row');
@ -5580,7 +5560,9 @@ var acf;
// populate above vars making sure to allow for failure // populate above vars making sure to allow for failure
try { try {
var filters = frame.content.get().toolbar.get('filters'); var toolbar = frame.content.get().toolbar,
filters = toolbar.get('filters'),
search = toolbar.get('search');
} catch(e) { } catch(e) {
@ -5692,6 +5674,10 @@ var acf;
}); });
// add _acfuplaoder to search
search.model.attributes._acfuploader = args.field;
// render // render
if( typeof filters.refresh === 'function' ) { if( typeof filters.refresh === 'function' ) {
@ -8763,7 +8749,7 @@ var acf;
events: { events: {
'click #save-post': 'click_ignore', 'click #save-post': 'click_ignore',
'click input[type="submit"]': 'click_publish', 'click [type="submit"]': 'click_publish',
'submit form': 'submit_form', 'submit form': 'submit_form',
'click .acf-error-message a': 'click_message' 'click .acf-error-message a': 'click_message'
}, },
@ -9093,11 +9079,7 @@ var acf;
fetch: function( $form ){ fetch: function( $form ){
// bail aelry if already busy // bail aelry if already busy
if( this.busy ) { if( this.busy ) return false;
return false;
}
// reference // reference
@ -9105,7 +9087,7 @@ var acf;
// vars // vars
var data = acf.serialize_form( $form, 'acf' ); var data = acf.serialize_form($form);
// append AJAX action // append AJAX action
@ -9189,7 +9171,7 @@ var acf;
if( $message.exists() ) { if( $message.exists() ) {
$message.removeClass('error'); $message.addClass('-success');
$message.children('p').html( acf._e('validation_successful') ); $message.children('p').html( acf._e('validation_successful') );
} }
@ -9650,7 +9632,7 @@ var acf;
toolbars: {}, toolbars: {},
actions: { actions: {
'ready': 'initialize', 'load': 'initialize',
'append': 'initialize', 'append': 'initialize',
'remove': 'disable', 'remove': 'disable',
'sortstart': 'disable', 'sortstart': 'disable',

File diff suppressed because one or more lines are too long

View File

@ -45,6 +45,7 @@ class acf_field {
$this->add_action("acf/render_field/type={$this->name}", array($this, 'render_field'), 10, 1); $this->add_action("acf/render_field/type={$this->name}", array($this, 'render_field'), 10, 1);
$this->add_action("acf/render_field_settings/type={$this->name}", array($this, 'render_field_settings'), 10, 1); $this->add_action("acf/render_field_settings/type={$this->name}", array($this, 'render_field_settings'), 10, 1);
$this->add_action("acf/prepare_field/type={$this->name}", array($this, 'prepare_field'), 10, 1); $this->add_action("acf/prepare_field/type={$this->name}", array($this, 'prepare_field'), 10, 1);
$this->add_action("acf/translate_field/type={$this->name}", array($this, 'translate_field'), 10, 1);
// input actions // input actions

View File

@ -1,30 +1,23 @@
<?php <?php
/* if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
* ACF Input Class
*
* All the logic run on input pages (edit post)
*
* @class acf_input
* @package ACF
* @subpackage Core
*/
if( ! class_exists('acf_input') ) : if( ! class_exists('acf_input') ) :
class acf_input { class acf_input {
/* /*
* __construct * __construct
* *
* Initialize filters, action, variables and includes * This function will setup the class functionality
* *
* @type function * @type function
* @date 23/06/12 * @date 5/03/2014
* @since 5.0.0 * @since 5.0.0
* *
* @param N/A * @param n/a
* @return N/A * @return n/a
*/ */
function __construct() { function __construct() {
@ -33,23 +26,93 @@ class acf_input {
$this->admin_enqueue_scripts = 'admin_enqueue_scripts'; $this->admin_enqueue_scripts = 'admin_enqueue_scripts';
$this->admin_head = 'admin_head'; $this->admin_head = 'admin_head';
$this->admin_footer = 'admin_footer'; $this->admin_footer = 'admin_footer';
$this->enqueued = false;
$this->data = array();
// actions // actions
add_action('acf/save_post', array($this, 'save_post'), 10, 1); add_action('acf/save_post', array($this, 'save_post'), 10, 1);
add_action('acf/input/admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'), 10, 0);
add_action('acf/input/admin_footer', array($this, 'admin_footer'), 10, 0);
// ajax
add_action( 'wp_ajax_acf/validate_save_post', array($this, 'ajax_validate_save_post') );
add_action( 'wp_ajax_nopriv_acf/validate_save_post', array($this, 'ajax_validate_save_post') );
} }
/* /*
* init * get_data
*
* This function will return form data
*
* @type function
* @date 4/03/2016
* @since 5.3.2
*
* @param $key (mixed)
* @return (mixed)
*/
function get_data( $key = false ) {
// vars
$data = $this->data;
// key
if( $key && isset($data[ $key ]) ) {
$data = $data[ $key ];
}
// return
return $data;
}
/*
* set_data
*
* This function will se the form data
*
* @type function
* @date 4/03/2016
* @since 5.3.2
*
* @param $data (array)
* @return (array)
*/
function set_data( $data ) {
// defaults
$data = acf_parse_args($data, array(
'post_id' => 0, // ID of current post
'nonce' => 'post', // nonce used for $_POST validation
'validation' => 1, // runs AJAX validation
'ajax' => 0, // fetches new field groups via AJAX
));
// update
$this->data = $data;
// enqueue uploader if page allows AJAX fields to appear
if( $data['ajax'] ) {
add_action($this->admin_footer, 'acf_enqueue_uploader', 1);
}
// return
return $data;
}
/*
* enqueue
* *
* This function will determin the actions to use for different pages * This function will determin the actions to use for different pages
* *
@ -61,7 +124,15 @@ class acf_input {
* @return n/a * @return n/a
*/ */
function init() { function enqueue() {
// bail ealry if already enqueued
if( $this->enqueued ) return;
// update setting
$this->enqueued = true;
// global // global
global $pagenow; global $pagenow;
@ -89,84 +160,28 @@ class acf_input {
// actions // actions
acf_maybe_add_action($this->admin_enqueue_scripts, array($this, 'do_admin_enqueue_scripts'), 20 ); acf_maybe_add_action($this->admin_enqueue_scripts, array($this, 'admin_enqueue_scripts'), 20 );
acf_maybe_add_action($this->admin_head, array($this, 'do_admin_head'), 20 ); acf_maybe_add_action($this->admin_head, array($this, 'admin_head'), 20 );
acf_maybe_add_action($this->admin_footer, array($this, 'do_admin_footer'), 20 ); acf_maybe_add_action($this->admin_footer, array($this, 'admin_footer'), 20 );
} }
function do_admin_enqueue_scripts() {
do_action('acf/input/admin_enqueue_scripts');
}
function do_admin_head() {
do_action('acf/input/admin_head');
}
function do_admin_footer() {
do_action('acf/input/admin_footer');
}
/*
* save_post
*
* This function will save the $_POST data
*
* @type function
* @date 24/10/2014
* @since 5.0.9
*
* @param $post_id (int)
* @return $post_id (int)
*/
function save_post( $post_id = 0 ) {
// bai learly if empty
if( empty($_POST['acf']) ) return;
// save $_POST data
foreach( $_POST['acf'] as $k => $v ) {
// get field
$field = acf_get_field( $k );
// continue if no field
if( !$field ) continue;
// update
acf_update_value( $v, $post_id, $field );
}
}
/* /*
* admin_enqueue_scripts * admin_enqueue_scripts
* *
* This function will enqueue all the required scripts / styles for ACF * The acf input screen admin_enqueue_scripts
* *
* @type action (acf/input/admin_enqueue_scripts) * @type function
* @date 6/10/13 * @date 4/03/2016
* @since 5.0.0 * @since 5.3.2
* *
* @param n/a * @param n/a
* @return n/a * @return n/a
*/ */
function admin_enqueue_scripts() { function admin_enqueue_scripts() {
// scripts // scripts
wp_enqueue_script('acf-input'); wp_enqueue_script('acf-input');
@ -174,41 +189,63 @@ class acf_input {
// styles // styles
wp_enqueue_style('acf-input'); wp_enqueue_style('acf-input');
// do action
do_action('acf/input/admin_enqueue_scripts');
} }
/*
* admin_head
*
* The acf input screen admin_head
*
* @type function
* @date 4/03/2016
* @since 5.3.2
*
* @param n/a
* @return n/a
*/
function admin_head() {
// do action
do_action('acf/input/admin_head');
}
/* /*
* admin_footer * admin_footer
* *
* description * The acf input screen admin_footer
* *
* @type function * @type function
* @date 7/10/13 * @date 4/03/2016
* @since 5.0.0 * @since 5.3.2
* *
* @param $post_id (int) * @param n/a
* @return $post_id (int) * @return n/a
*/ */
function admin_footer() { function admin_footer() {
// vars
$args = acf_get_setting('form_data');
// global // global
global $wp_version; global $wp_version;
// options // options
$o = array( $o = array(
'post_id' => $args['post_id'], 'post_id' => acf_get_form_data('post_id'),
'nonce' => wp_create_nonce( 'acf_nonce' ), 'nonce' => wp_create_nonce( 'acf_nonce' ),
'admin_url' => admin_url(), 'admin_url' => admin_url(),
'ajaxurl' => admin_url( 'admin-ajax.php' ), 'ajaxurl' => admin_url( 'admin-ajax.php' ),
'ajax' => $args['ajax'], 'ajax' => acf_get_form_data('ajax'),
'validation' => $args['validation'], 'validation' => acf_get_form_data('validation'),
'wp_version' => $wp_version 'wp_version' => $wp_version,
'acf_version' => acf_get_setting('version')
); );
@ -240,77 +277,64 @@ class acf_input {
/* ]]> */ /* ]]> */
</script> </script>
<?php <?php
// do action
do_action('acf/input/admin_footer');
} }
/* /*
* ajax_validate_save_post * save_post
* *
* This function will validate the $_POST data via AJAX * This function will save the $_POST data
* *
* @type function * @type function
* @date 27/10/2014 * @date 24/10/2014
* @since 5.0.9 * @since 5.0.9
* *
* @param n/a * @param $post_id (int)
* @return n/a * @return n/a
*/ */
function ajax_validate_save_post() { function save_post( $post_id ) {
// bail early if _acfnonce is missing // bail early if empty
if( !isset($_POST['_acfnonce']) ) { if( empty($_POST['acf']) ) return;
// save $_POST data
foreach( $_POST['acf'] as $k => $v ) {
wp_send_json_error(); // get field
$field = acf_get_field( $k );
// continue if no field
if( !$field ) continue;
// update
acf_update_value( $v, $post_id, $field );
} }
// vars
$json = array(
'valid' => 1,
'errors' => 0
);
// success
if( acf_validate_save_post() ) {
wp_send_json_success($json);
}
// update vars
$json['valid'] = 0;
$json['errors'] = acf_get_validation_errors();
// return
wp_send_json_success($json);
} }
} }
// global
global $acf_input;
// initialize // initialize
$acf_input = new acf_input(); acf()->input = new acf_input();
endif; // class_exists check
// class_exists check
endif;
/* /*
* acf_enqueue_scripts * acf_enqueue_scripts
* *
* This function is used to setup all actions / functionality for an admin page which will contain ACF inputs * alias of acf()->form->enqueue()
* *
* @type function * @type function
* @date 6/10/13 * @date 6/10/13
@ -322,13 +346,48 @@ endif;
function acf_enqueue_scripts() { function acf_enqueue_scripts() {
// globals return acf()->input->enqueue();
global $acf_input;
}
/*
* acf_get_form_data
*
* alias of acf()->form->get_data()
*
* @type function
* @date 6/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_get_form_data( $key = false ) {
// init return acf()->input->get_data( $key );
$acf_input->init();
}
/*
* acf_set_form_data
*
* alias of acf()->form->set_data()
*
* @type function
* @date 6/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_set_form_data( $data = array() ) {
return acf()->input->set_data( $data );
} }
@ -389,26 +448,10 @@ function acf_form_data( $args = array() ) {
acf_enqueue_scripts(); acf_enqueue_scripts();
// defaults // set form data
$args = acf_parse_args($args, array( $args = acf_set_form_data( $args );
'post_id' => 0, // ID of current post
'nonce' => 'post', // nonce used for $_POST validation
'validation' => 1, // runs AJAX validation
'ajax' => 0, // fetches new field groups via AJAX
));
// save form_data for later actions
acf_update_setting('form_data', $args);
// enqueue uploader if page allows AJAX fields to appear
if( $args['ajax'] ) {
add_action('admin_footer', 'acf_enqueue_uploader', 1);
}
?> ?>
<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'] ); ?>" /> <input type="hidden" name="_acfnonce" value="<?php echo wp_create_nonce( $args['nonce'] ); ?>" />
@ -439,6 +482,12 @@ function acf_save_post( $post_id = 0 ) {
if( empty($_POST['acf']) ) return false; if( empty($_POST['acf']) ) return false;
// set form data
acf_set_form_data(array(
'post_id' => $post_id
));
// hook for 3rd party customization // hook for 3rd party customization
do_action('acf/save_post', $post_id); do_action('acf/save_post', $post_id);
@ -447,198 +496,3 @@ function acf_save_post( $post_id = 0 ) {
return true; return true;
} }
/*
* acf_validate_save_post
*
* This function is run to validate post data
*
* @type function
* @date 25/11/2013
* @since 5.0.0
*
* @param $show_errors (boolean) if true, errors will be shown via a wo_die screen
* @return (boolean)
*/
function acf_validate_save_post( $show_errors = false ) {
// validate required fields
if( !empty($_POST['acf']) ) {
$keys = array_keys($_POST['acf']);
// loop through and save $_POST data
foreach( $keys as $key ) {
// get field
$field = acf_get_field( $key );
// validate
acf_validate_value( $_POST['acf'][ $key ], $field, "acf[{$key}]" );
}
// foreach($fields as $key => $value)
}
// if($fields)
// hook for 3rd party customization
do_action('acf/validate_save_post');
// check errors
if( $errors = acf_get_validation_errors() ) {
if( $show_errors ) {
$message = '<h2>Validation failed</h2><ul>';
foreach( $errors as $error ) {
$message .= '<li>' . $error['message'] . '</li>';
}
$message .= '</ul>';
wp_die( $message, 'Validation failed' );
}
return false;
}
// return
return true;
}
/*
* acf_validate_value
*
* This function will validate a value for a field
*
* @type function
* @date 27/10/2014
* @since 5.0.9
*
* @param $value (mixed)
* @param $field (array)
* @param $input (string) name attribute of DOM elmenet
* @return (boolean)
*/
function acf_validate_value( $value, $field, $input ) {
// vars
$valid = true;
$message = sprintf( __( '%s value is required', 'acf' ), $field['label'] );
// valid
if( $field['required'] ) {
// valid is set to false if the value is empty, but allow 0 as a valid value
if( empty($value) && !is_numeric($value) ) {
$valid = false;
}
}
// filter for 3rd party customization
$valid = apply_filters( "acf/validate_value", $valid, $value, $field, $input );
$valid = apply_filters( "acf/validate_value/type={$field['type']}", $valid, $value, $field, $input );
$valid = apply_filters( "acf/validate_value/name={$field['name']}", $valid, $value, $field, $input );
$valid = apply_filters( "acf/validate_value/key={$field['key']}", $valid, $value, $field, $input );
// allow $valid to be a custom error message
if( !empty($valid) && is_string($valid) ) {
$message = $valid;
$valid = false;
}
if( !$valid ) {
acf_add_validation_error( $input, $message );
return false;
}
// return
return true;
}
/*
* acf_add_validation_error
*
* This function will add an error message for a field
*
* @type function
* @date 25/11/2013
* @since 5.0.0
*
* @param $input (string) name attribute of DOM elmenet
* @param $message (string) error message
* @return $post_id (int)
*/
function acf_add_validation_error( $input, $message = '' ) {
// instantiate array if empty
if( empty($GLOBALS['acf_validation_errors']) ) {
$GLOBALS['acf_validation_errors'] = array();
}
// add to array
$GLOBALS['acf_validation_errors'][] = array(
'input' => $input,
'message' => $message
);
}
/*
* acf_add_validation_error
*
* This function will return any validation errors
*
* @type function
* @date 25/11/2013
* @since 5.0.0
*
* @param n/a
* @return (array|boolean)
*/
function acf_get_validation_errors() {
// bail early if no errors
if( empty($GLOBALS['acf_validation_errors']) ) return false;
// return
return $GLOBALS['acf_validation_errors'];
}
?>

View File

@ -1060,39 +1060,25 @@ class acf_location {
// validate // validate
if( ! $comment ) { if( !$comment ) return false;
return false;
}
// compare // match
if( $rule['operator'] == "==" ) { $match = ( $comment === $rule['value'] );
$match = ( $comment == $rule['value'] );
// override for "all"
// override for "all" if( $rule['value'] == "all" ) $match = true;
if( $rule['value'] == "all" ) {
$match = true; // reverse if 'not equal to'
if( $rule['operator'] === '!=' ) {
}
$match = !$match;
} elseif( $rule['operator'] == "!=" ) {
$match = ( $comment != $rule['value'] );
// override for "all"
if( $rule['value'] == "all" ) {
$match = false;
}
} }
// return // return
return $match; return $match;

333
core/loop.php Normal file
View File

@ -0,0 +1,333 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_loop') ) :
class acf_loop {
/*
* __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->loops = array();
}
/*
* is_empty
*
* This function will return true if no loops exist
*
* @type function
* @date 3/03/2016
* @since 5.3.2
*
* @param n/a
* @return (boolean)
*/
function is_empty() {
return empty( $this->loops );
}
/*
* is_loop
*
* This function will return true if a loop exists for the given array index
*
* @type function
* @date 3/03/2016
* @since 5.3.2
*
* @param $i (int)
* @return (boolean)
*/
function is_loop( $i = 0 ) {
return isset( $this->loops[ $i ] );
}
/*
* get_i
*
* This function will return a valid array index for the given $i
*
* @type function
* @date 3/03/2016
* @since 5.3.2
*
* @param $i (mixed)
* @return (int)
*/
function get_i( $i = 0 ) {
// 'active'
if( $i === 'active' ) $i = -1;
// 'previous'
if( $i === 'previous' ) $i = -2;
// allow negative to look at end of loops
if( $i < 0 ) {
$i = count($this->loops) + $i;
}
// return
return $i;
}
/*
* add_loop
*
* This function will add a new loop
*
* @type function
* @date 3/03/2016
* @since 5.3.2
*
* @param $loop (array)
* @return n/a
*/
function add_loop( $loop = array() ) {
// defaults
$loop = wp_parse_args( $loop, array(
'selector' => '',
'name' => '',
'value' => false,
'field' => false,
'i' => -1,
'post_id' => 0,
));
// append
$this->loops[] = $loop;
}
/*
* update_loop
*
* This function will update a loop's setting
*
* @type function
* @date 3/03/2016
* @since 5.3.2
*
* @param $i (mixed)
* @param $key (string) the loop setting name
* @param $value (mixed) the loop setting value
* @return (boolean) true on success
*/
function update_loop( $i = 'active', $key = null, $value = null ) {
// i
$i = $this->get_i( $i );
// bail early if no set
if( !$this->is_loop($i) ) return false;
// set
$this->loops[ $i ][ $key ] = $value;
// return
return true;
}
/*
* get_loop
*
* This function will return a loop, or loop's setting for a given index & key
*
* @type function
* @date 3/03/2016
* @since 5.3.2
*
* @param $i (mixed)
* @param $key (string) the loop setting name
* @return (mixed) false on failure
*/
function get_loop( $i = 'active', $key = null ) {
// i
$i = $this->get_i( $i );
// bail early if no set
if( !$this->is_loop($i) ) return false;
// check for key
if( $key !== null ) {
return $this->loops[ $i ][ $key ];
}
// return
return $this->loops[ $i ];
}
/*
* remove_loop
*
* This function will remove a loop
*
* @type function
* @date 3/03/2016
* @since 5.3.2
*
* @param $i (mixed)
* @return (boolean) true on success
*/
function remove_loop( $i = 'active' ) {
// i
$i = $this->get_i( $i );
// bail early if no set
if( !$this->is_loop($i) ) return false;
// remove
unset($this->loops[ $i ]);
// reset keys
$this->loops = array_values( $this->loops );
}
}
// initialize
acf()->loop = new acf_loop();
endif; // class_exists check
/*
* acf_add_loop
*
* alias of acf()->loop->add_loop()
*
* @type function
* @date 6/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_add_loop( $loop = array() ) {
return acf()->loop->add_loop( $loop );
}
/*
* acf_update_loop
*
* alias of acf()->loop->update_loop()
*
* @type function
* @date 6/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_update_loop( $i = 'active', $key = null, $value = null ) {
return acf()->loop->update_loop( $i, $key, $value );
}
/*
* acf_get_loop
*
* alias of acf()->loop->get_loop()
*
* @type function
* @date 6/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_get_loop( $i = 'active', $key = null ) {
return acf()->loop->get_loop( $i, $key );
}
/*
* acf_remove_loop
*
* alias of acf()->loop->remove_loop()
*
* @type function
* @date 6/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_remove_loop( $i = 'active' ) {
return acf()->loop->remove_loop( $i );
}
?>

434
core/validation.php Normal file
View File

@ -0,0 +1,434 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_validation') ) :
class acf_validation {
/*
* __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->errors = array();
// ajax
add_action('wp_ajax_acf/validate_save_post', array($this, 'ajax_validate_save_post'));
add_action('wp_ajax_nopriv_acf/validate_save_post', array($this, 'ajax_validate_save_post'));
}
/*
* add_error
*
* This function will add an error message for a field
*
* @type function
* @date 25/11/2013
* @since 5.0.0
*
* @param $input (string) name attribute of DOM elmenet
* @param $message (string) error message
* @return $post_id (int)
*/
function add_error( $input, $message ) {
// add to array
$this->errors[] = array(
'input' => $input,
'message' => $message
);
}
/*
* get_error
*
* This function will return an error for a given input
*
* @type function
* @date 5/03/2016
* @since 5.3.2
*
* @param $input (string) name attribute of DOM elmenet
* @return (mixed)
*/
function get_error( $input ) {
// bail early if no errors
if( empty($this->errors) ) return false;
// loop
foreach( $this->errors as $error ) {
if( $error['input'] === $input ) return $error;
}
// return
return false;
}
/*
* get_errors
*
* This function will return validation errors
*
* @type function
* @date 25/11/2013
* @since 5.0.0
*
* @param n/a
* @return (array|boolean)
*/
function get_errors() {
// bail early if no errors
if( empty($this->errors) ) return false;
// return
return $this->errors;
}
/*
* reset_errors
*
* This function will remove all errors
*
* @type function
* @date 4/03/2016
* @since 5.3.2
*
* @param n/a
* @return n/a
*/
function reset_errors() {
$this->errors = array();
}
/*
* ajax_validate_save_post
*
* This function will validate the $_POST data via AJAX
*
* @type function
* @date 27/10/2014
* @since 5.0.9
*
* @param n/a
* @return n/a
*/
function ajax_validate_save_post() {
// bail early if _acfnonce is missing
if( !isset($_POST['_acfnonce']) ) {
wp_send_json_error();
}
// vars
$json = array(
'valid' => 1,
'errors' => 0
);
// success
if( acf_validate_save_post() ) {
wp_send_json_success($json);
}
// update vars
$json['valid'] = 0;
$json['errors'] = acf_get_validation_errors();
// return
wp_send_json_success($json);
}
/*
* validate_value
*
* This function will validate a field's value
*
* @type function
* @date 27/10/2014
* @since 5.0.9
*
* @param $value (mixed)
* @param $field (array)
* @param $input (string) name attribute of DOM elmenet
* @return (boolean)
*/
function validate_value( $value, $field, $input ) {
// vars
$valid = true;
$message = sprintf( __( '%s value is required', 'acf' ), $field['label'] );
// valid
if( $field['required'] ) {
// valid is set to false if the value is empty, but allow 0 as a valid value
if( empty($value) && !is_numeric($value) ) {
$valid = false;
}
}
// filter for 3rd party customization
$valid = apply_filters( "acf/validate_value", $valid, $value, $field, $input );
$valid = apply_filters( "acf/validate_value/type={$field['type']}", $valid, $value, $field, $input );
$valid = apply_filters( "acf/validate_value/name={$field['name']}", $valid, $value, $field, $input );
$valid = apply_filters( "acf/validate_value/key={$field['key']}", $valid, $value, $field, $input );
// allow $valid to be a custom error message
if( !empty($valid) && is_string($valid) ) {
$message = $valid;
$valid = false;
}
if( !$valid ) {
acf_add_validation_error( $input, $message );
return false;
}
// return
return true;
}
/*
* validate_save_post
*
* This function will validate $_POST data and add errors
*
* @type function
* @date 25/11/2013
* @since 5.0.0
*
* @param $show_errors (boolean) if true, errors will be shown via a wp_die screen
* @return (boolean)
*/
function validate_save_post( $show_errors = false ) {
// validate fields
if( !empty($_POST['acf']) ) {
// loop
foreach( $_POST['acf'] as $field_key => $value ) {
// get field
$field = acf_get_field( $field_key );
$input = 'acf[' . $field_key . ']';
// bail early if not found
if( !$field ) continue;
// validate
acf_validate_value( $value, $field, $input );
}
}
// action for 3rd party customization
do_action('acf/validate_save_post');
// vars
$errors = acf_get_validation_errors();
// bail ealry if no errors
if( !$errors ) return true;
// show errors
if( $show_errors ) {
$message = '<h2>Validation failed</h2>';
$message .= '<ul>';
foreach( $errors as $error ) {
$message .= '<li>' . $error['message'] . '</li>';
}
$message .= '</ul>';
// die
wp_die( $message, 'Validation failed' );
}
// return
return false;
}
}
// initialize
acf()->validation = new acf_validation();
endif; // class_exists check
/*
* acf_add_validation_error
*
* alias of acf()->validation->add_error()
*
* @type function
* @date 6/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_add_validation_error( $input, $message = '' ) {
return acf()->validation->add_error( $input, $message );
}
/*
* acf_get_validation_errors
*
* alias of acf()->validation->get_errors()
*
* @type function
* @date 6/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_get_validation_errors() {
return acf()->validation->get_errors();
}
/*
* acf_reset_validation_errors
*
* alias of acf()->validation->reset_errors()
*
* @type function
* @date 6/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_reset_validation_errors() {
return acf()->validation->reset_errors();
}
/*
* acf_validate_save_post
*
* alias of acf()->validation->validate_save_post()
*
* @type function
* @date 6/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_validate_save_post( $show_errors = false ) {
return acf()->validation->validate_save_post( $show_errors );
}
/*
* acf_validate_value
*
* alias of acf()->validation->validate_value()
*
* @type function
* @date 6/10/13
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function acf_validate_value( $value, $field, $input ) {
return acf()->validation->validate_value( $value, $field, $input );
}

View File

@ -271,11 +271,7 @@ class acf_field_checkbox extends acf_field {
// decode choices (convert to array) // decode choices (convert to array)
$field['choices'] = acf_decode_choices($field['choices']); $field['choices'] = acf_decode_choices($field['choices']);
$field['default_value'] = acf_decode_choices($field['default_value']); $field['default_value'] = acf_decode_choices($field['default_value'], true);
// use only keys for default value
$field['default_value'] = array_keys($field['default_value']);
// return // return
@ -322,6 +318,31 @@ class acf_field_checkbox extends acf_field {
return $value; return $value;
} }
/*
* translate_field
*
* This function will translate field settings
*
* @type function
* @date 8/03/2016
* @since 5.3.2
*
* @param $field (array)
* @return $field
*/
function translate_field( $field ) {
// translate
$field['choices'] = acf_translate( $field['choices'] );
// return
return $field;
}
} }
new acf_field_checkbox(); new acf_field_checkbox();

View File

@ -112,26 +112,18 @@ class acf_field_color_picker extends acf_field {
function render_field( $field ) { function render_field( $field ) {
// vars // vars
$atts = array(); $text = acf_get_sub_array( $field, array('id', 'class', 'name', 'value') );
$hidden = acf_get_sub_array( $field, array('name', 'value') );
$e = ''; $e = '';
// populate atts
foreach( array( 'id', 'class', 'name', 'value' ) as $k ) {
$atts[ $k ] = $field[ $k ];
}
// render // render
$e .= '<div class="acf-color_picker">'; ?>
$e .= '<input type="text" ' . acf_esc_attr($atts) . ' />'; <div class="acf-color_picker">
$e .= '</div>'; <?php acf_hidden_input($hidden); ?>
<input type="text" <?php echo acf_esc_attr($text); ?> />
</div>
// return <?php
echo $e;
} }

View File

@ -149,6 +149,31 @@ class acf_field_message extends acf_field {
} }
/*
* translate_field
*
* This function will translate field settings
*
* @type function
* @date 8/03/2016
* @since 5.3.2
*
* @param $field (array)
* @return $field
*/
function translate_field( $field ) {
// translate
$field['message'] = acf_translate( $field['message'] );
// return
return $field;
}
} }
new acf_field_message(); new acf_field_message();

View File

@ -323,21 +323,7 @@ class acf_field_page_link extends acf_field {
function get_post_title( $post, $field, $post_id = 0 ) { function get_post_title( $post, $field, $post_id = 0 ) {
// get post_id // get post_id
if( !$post_id ) { if( !$post_id ) $post_id = acf_get_form_data('post_id');
$form_data = acf_get_setting('form_data');
if( !empty($form_data['post_id']) ) {
$post_id = $form_data['post_id'];
} else {
$post_id = get_the_ID();
}
}
// vars // vars

View File

@ -277,21 +277,7 @@ class acf_field_post_object extends acf_field {
function get_post_title( $post, $field, $post_id = 0 ) { function get_post_title( $post, $field, $post_id = 0 ) {
// get post_id // get post_id
if( !$post_id ) { if( !$post_id ) $post_id = acf_get_form_data('post_id');
$form_data = acf_get_setting('form_data');
if( !empty($form_data['post_id']) ) {
$post_id = $form_data['post_id'];
} else {
$post_id = get_the_ID();
}
}
// vars // vars

View File

@ -358,6 +358,31 @@ class acf_field_radio extends acf_field {
} }
/*
* translate_field
*
* This function will translate field settings
*
* @type function
* @date 8/03/2016
* @since 5.3.2
*
* @param $field (array)
* @return $field
*/
function translate_field( $field ) {
// translate
$field['choices'] = acf_translate( $field['choices'] );
// return
return $field;
}
} }
new acf_field_radio(); new acf_field_radio();

View File

@ -470,11 +470,7 @@ class acf_field_select extends acf_field {
// decode choices (convert to array) // decode choices (convert to array)
$field['choices'] = acf_decode_choices($field['choices']); $field['choices'] = acf_decode_choices($field['choices']);
$field['default_value'] = acf_decode_choices($field['default_value']); $field['default_value'] = acf_decode_choices($field['default_value'], true);
// use only keys for default value
$field['default_value'] = array_keys($field['default_value']);
// return // return
@ -522,6 +518,31 @@ class acf_field_select extends acf_field {
} }
/*
* translate_field
*
* This function will translate field settings
*
* @type function
* @date 8/03/2016
* @since 5.3.2
*
* @param $field (array)
* @return $field
*/
function translate_field( $field ) {
// translate
$field['choices'] = acf_translate( $field['choices'] );
// return
return $field;
}
/* /*
* enqueue_assets * enqueue_assets
* *

View File

@ -47,37 +47,6 @@ class acf_field_tab extends acf_field {
} }
/*
* prepare_field
*
* description
*
* @type function
* @date 9/07/2015
* @since 5.2.3
*
* @param $post_id (int)
* @return $post_id (int)
*/
/*
function prepare_field( $field ) {
// append class
if( $field['endpoint'] ) {
$field['wrapper']['class'] .= ' acf-field-tab-endpoint';
}
// return
return $field;
}
*/
/* /*
* render_field() * render_field()
* *

View File

@ -231,20 +231,7 @@ class acf_field_taxonomy extends acf_field {
function get_term_title( $term, $field, $post_id = 0 ) { function get_term_title( $term, $field, $post_id = 0 ) {
// get post_id // get post_id
if( !$post_id ) { if( !$post_id ) $post_id = acf_get_form_data('post_id');
$form_data = acf_get_setting('form_data');
if( !empty($form_data['post_id']) ) {
$post_id = $form_data['post_id'];
} else {
$post_id = get_the_ID();
}
}
// vars // vars

View File

@ -180,6 +180,31 @@ class acf_field_true_false extends acf_field {
} }
/*
* translate_field
*
* This function will translate field settings
*
* @type function
* @date 8/03/2016
* @since 5.3.2
*
* @param $field (array)
* @return $field
*/
function translate_field( $field ) {
// translate
$field['message'] = acf_translate( $field['message'] );
// return
return $field;
}
} }
new acf_field_true_false(); new acf_field_true_false();

View File

@ -131,10 +131,10 @@ class acf_form_comment {
// vars // vars
$post_id = "comment_{$comment->comment_ID}"; $post_id = "comment_{$comment->comment_ID}";
// get field groups // get field groups
$field_groups = acf_get_field_groups(array( $field_groups = acf_get_field_groups(array(
'comment' => $comment->comment_ID 'comment' => get_post_type( $comment->comment_post_ID )
)); ));
@ -199,13 +199,17 @@ class acf_form_comment {
function add_comment() { function add_comment() {
// global
global $post;
// vars // vars
$post_id = "comment_0"; $post_id = "comment_0";
// get field groups // get field groups
$field_groups = acf_get_field_groups(array( $field_groups = acf_get_field_groups(array(
'comment' => 'new' 'comment' => $post->post_type
)); ));

View File

@ -67,7 +67,7 @@ class acf_form_taxonomy {
// validate page // validate page
if( $pagenow == 'edit-tags.php' ) { if( $pagenow === 'edit-tags.php' || $pagenow === 'term.php' ) {
return true; return true;

Binary file not shown.

View File

@ -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: 2015-08-11 23:35+0200\n" "POT-Creation-Date: 2015-08-11 23:35+0200\n"
"PO-Revision-Date: 2015-12-01 13:20+0100\n" "PO-Revision-Date: 2016-03-09 12:48+0100\n"
"Last-Translator: Ralf Koller <r.koller@gmail.com>\n" "Last-Translator: Ralf Koller <r.koller@gmail.com>\n"
"Language-Team: Digital Factory <info@digitalfactory.pl>\n" "Language-Team: Digital Factory <info@digitalfactory.pl>\n"
"Language: pl_PL\n" "Language: pl_PL\n"
@ -2578,7 +2578,7 @@ msgstr "Minimalna liczba rzędów"
#: pro/fields/repeater.php:382 #: pro/fields/repeater.php:382
msgid "Maximum Rows" msgid "Maximum Rows"
msgstr "Minimalna liczba rzędów" msgstr "Maksymalna liczba rzędów"
#. Plugin Name of the plugin/theme #. Plugin Name of the plugin/theme
msgid "Advanced Custom Fields Pro" msgid "Advanced Custom Fields Pro"

View File

@ -3,7 +3,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Advanced Custom Fields\n" "Project-Id-Version: Advanced Custom Fields\n"
"Report-Msgid-Bugs-To: http://support.advancedcustomfields.com\n" "Report-Msgid-Bugs-To: http://support.advancedcustomfields.com\n"
"POT-Creation-Date: 2016-02-05 11:05+1000\n" "POT-Creation-Date: 2016-03-15 10:53+1000\n"
"PO-Revision-Date: 2015-06-11 13:00+1000\n" "PO-Revision-Date: 2015-06-11 13:00+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"
@ -22,95 +22,95 @@ msgstr ""
"X-Poedit-SearchPath-0: .\n" "X-Poedit-SearchPath-0: .\n"
"X-Poedit-SearchPathExcluded-0: *.js\n" "X-Poedit-SearchPathExcluded-0: *.js\n"
#: acf.php:63 #: acf.php:60
msgid "Advanced Custom Fields" msgid "Advanced Custom Fields"
msgstr "" msgstr ""
#: acf.php:266 admin/admin.php:61 #: acf.php:263 admin/admin.php:61
msgid "Field Groups" msgid "Field Groups"
msgstr "" msgstr ""
#: acf.php:267 #: acf.php:264
msgid "Field Group" msgid "Field Group"
msgstr "" msgstr ""
#: acf.php:268 acf.php:300 admin/admin.php:62 #: acf.php:265 acf.php:297 admin/admin.php:62
#: pro/fields/flexible-content.php:506 #: pro/fields/flexible-content.php:496
msgid "Add New" msgid "Add New"
msgstr "" msgstr ""
#: acf.php:269 #: acf.php:266
msgid "Add New Field Group" msgid "Add New Field Group"
msgstr "" msgstr ""
#: acf.php:270 #: acf.php:267
msgid "Edit Field Group" msgid "Edit Field Group"
msgstr "" msgstr ""
#: acf.php:271 #: acf.php:268
msgid "New Field Group" msgid "New Field Group"
msgstr "" msgstr ""
#: acf.php:272 #: acf.php:269
msgid "View Field Group" msgid "View Field Group"
msgstr "" msgstr ""
#: acf.php:273 #: acf.php:270
msgid "Search Field Groups" msgid "Search Field Groups"
msgstr "" msgstr ""
#: acf.php:274 #: acf.php:271
msgid "No Field Groups found" msgid "No Field Groups found"
msgstr "" msgstr ""
#: acf.php:275 #: acf.php:272
msgid "No Field Groups found in Trash" msgid "No Field Groups found in Trash"
msgstr "" msgstr ""
#: acf.php:298 admin/field-group.php:176 admin/field-group.php:223 #: acf.php:295 admin/field-group.php:176 admin/field-group.php:223
#: admin/field-groups.php:528 #: admin/field-groups.php:528
msgid "Fields" msgid "Fields"
msgstr "" msgstr ""
#: acf.php:299 #: acf.php:296
msgid "Field" msgid "Field"
msgstr "" msgstr ""
#: acf.php:301 #: acf.php:298
msgid "Add New Field" msgid "Add New Field"
msgstr "" msgstr ""
#: acf.php:302 #: acf.php:299
msgid "Edit Field" msgid "Edit Field"
msgstr "" msgstr ""
#: acf.php:303 admin/views/field-group-fields.php:18 #: acf.php:300 admin/views/field-group-fields.php:18
#: admin/views/settings-info.php:111 #: admin/views/settings-info.php:111
msgid "New Field" msgid "New Field"
msgstr "" msgstr ""
#: acf.php:304 #: acf.php:301
msgid "View Field" msgid "View Field"
msgstr "" msgstr ""
#: acf.php:305 #: acf.php:302
msgid "Search Fields" msgid "Search Fields"
msgstr "" msgstr ""
#: acf.php:306 #: acf.php:303
msgid "No Fields found" msgid "No Fields found"
msgstr "" msgstr ""
#: acf.php:307 #: acf.php:304
msgid "No Fields found in Trash" msgid "No Fields found in Trash"
msgstr "" msgstr ""
#: acf.php:346 admin/field-group.php:316 admin/field-groups.php:586 #: acf.php:343 admin/field-group.php:316 admin/field-groups.php:586
#: admin/views/field-group-options.php:13 #: admin/views/field-group-options.php:13
msgid "Disabled" msgid "Disabled"
msgstr "" msgstr ""
#: acf.php:351 #: acf.php:348
#, php-format #, php-format
msgid "Disabled <span class=\"count\">(%s)</span>" msgid "Disabled <span class=\"count\">(%s)</span>"
msgid_plural "Disabled <span class=\"count\">(%s)</span>" msgid_plural "Disabled <span class=\"count\">(%s)</span>"
@ -173,7 +173,7 @@ msgstr ""
msgid "Field group title is required" msgid "Field group title is required"
msgstr "" msgstr ""
#: admin/field-group.php:221 api/api-field-group.php:581 #: admin/field-group.php:221 api/api-field-group.php:620
msgid "copy" msgid "copy"
msgstr "" msgstr ""
@ -181,7 +181,7 @@ msgstr ""
#: admin/views/field-group-field-conditional-logic.php:62 #: admin/views/field-group-field-conditional-logic.php:62
#: admin/views/field-group-field-conditional-logic.php:162 #: admin/views/field-group-field-conditional-logic.php:162
#: admin/views/field-group-locations.php:59 #: admin/views/field-group-locations.php:59
#: admin/views/field-group-locations.php:135 api/api-helpers.php:3401 #: admin/views/field-group-locations.php:135 api/api-helpers.php:3639
msgid "or" msgid "or"
msgstr "" msgstr ""
@ -205,7 +205,7 @@ msgstr ""
msgid "Null" msgid "Null"
msgstr "" msgstr ""
#: admin/field-group.php:229 core/input.php:217 #: admin/field-group.php:229 core/input.php:254
msgid "The changes you made will be lost if you navigate away from this page" msgid "The changes you made will be lost if you navigate away from this page"
msgstr "" msgstr ""
@ -221,79 +221,79 @@ msgstr ""
msgid "Active" msgid "Active"
msgstr "" msgstr ""
#: admin/field-group.php:785 #: admin/field-group.php:789
msgid "Front Page" msgid "Front Page"
msgstr "" msgstr ""
#: admin/field-group.php:786 #: admin/field-group.php:790
msgid "Posts Page" msgid "Posts Page"
msgstr "" msgstr ""
#: admin/field-group.php:787 #: admin/field-group.php:791
msgid "Top Level Page (no parent)" msgid "Top Level Page (no parent)"
msgstr "" msgstr ""
#: admin/field-group.php:788 #: admin/field-group.php:792
msgid "Parent Page (has children)" msgid "Parent Page (has children)"
msgstr "" msgstr ""
#: admin/field-group.php:789 #: admin/field-group.php:793
msgid "Child Page (has parent)" msgid "Child Page (has parent)"
msgstr "" msgstr ""
#: admin/field-group.php:805 #: admin/field-group.php:809
msgid "Default Template" msgid "Default Template"
msgstr "" msgstr ""
#: admin/field-group.php:827 #: admin/field-group.php:832
msgid "Logged in" msgid "Logged in"
msgstr "" msgstr ""
#: admin/field-group.php:828 #: admin/field-group.php:833
msgid "Viewing front end" msgid "Viewing front end"
msgstr "" msgstr ""
#: admin/field-group.php:829 #: admin/field-group.php:834
msgid "Viewing back end" msgid "Viewing back end"
msgstr "" msgstr ""
#: admin/field-group.php:848 #: admin/field-group.php:853
msgid "Super Admin" msgid "Super Admin"
msgstr "" msgstr ""
#: admin/field-group.php:859 admin/field-group.php:867 #: admin/field-group.php:864 admin/field-group.php:872
#: admin/field-group.php:881 admin/field-group.php:888 #: admin/field-group.php:886 admin/field-group.php:893
#: admin/field-group.php:903 admin/field-group.php:913 fields/file.php:235 #: admin/field-group.php:910 admin/field-group.php:927 fields/file.php:235
#: fields/image.php:231 pro/fields/gallery.php:661 #: fields/image.php:231 pro/fields/gallery.php:661
msgid "All" msgid "All"
msgstr "" msgstr ""
#: admin/field-group.php:868 #: admin/field-group.php:873
msgid "Add / Edit" msgid "Add / Edit"
msgstr "" msgstr ""
#: admin/field-group.php:869 #: admin/field-group.php:874
msgid "Register" msgid "Register"
msgstr "" msgstr ""
#: admin/field-group.php:1100 #: admin/field-group.php:1114
msgid "Move Complete." msgid "Move Complete."
msgstr "" msgstr ""
#: admin/field-group.php:1101 #: admin/field-group.php:1115
#, php-format #, php-format
msgid "The %s field can now be found in the %s field group" msgid "The %s field can now be found in the %s field group"
msgstr "" msgstr ""
#: admin/field-group.php:1103 #: admin/field-group.php:1117
msgid "Close Window" msgid "Close Window"
msgstr "" msgstr ""
#: admin/field-group.php:1138 #: admin/field-group.php:1152
msgid "Please select the destination for this field" msgid "Please select the destination for this field"
msgstr "" msgstr ""
#: admin/field-group.php:1145 #: admin/field-group.php:1159
msgid "Move Field" msgid "Move Field"
msgstr "" msgstr ""
@ -332,12 +332,13 @@ msgstr[1] ""
msgid "Sync available" msgid "Sync available"
msgstr "" msgstr ""
#: admin/field-groups.php:525 #: admin/field-groups.php:525 pro/fields/gallery.php:374
msgid "Title" msgid "Title"
msgstr "" msgstr ""
#: admin/field-groups.php:526 admin/views/field-group-options.php:93 #: admin/field-groups.php:526 admin/views/field-group-options.php:93
#: admin/views/update-network.php:20 admin/views/update-network.php:28 #: admin/views/update-network.php:20 admin/views/update-network.php:28
#: pro/fields/gallery.php:401
msgid "Description" msgid "Description"
msgstr "" msgstr ""
@ -404,7 +405,7 @@ msgid "Duplicate this item"
msgstr "" msgstr ""
#: admin/field-groups.php:684 admin/field-groups.php:700 #: admin/field-groups.php:684 admin/field-groups.php:700
#: admin/views/field-group-field.php:58 pro/fields/flexible-content.php:505 #: admin/views/field-group-field.php:58 pro/fields/flexible-content.php:495
msgid "Duplicate" msgid "Duplicate"
msgstr "" msgstr ""
@ -496,24 +497,24 @@ msgstr ""
#: admin/views/field-group-field-conditional-logic.php:40 #: admin/views/field-group-field-conditional-logic.php:40
#: admin/views/field-group-field.php:140 fields/checkbox.php:246 #: admin/views/field-group-field.php:140 fields/checkbox.php:246
#: fields/message.php:144 fields/page_link.php:553 fields/page_link.php:567 #: fields/message.php:144 fields/page_link.php:539 fields/page_link.php:553
#: fields/post_object.php:419 fields/post_object.php:433 fields/select.php:377 #: fields/post_object.php:403 fields/post_object.php:417 fields/select.php:377
#: fields/select.php:391 fields/select.php:405 fields/select.php:419 #: fields/select.php:391 fields/select.php:405 fields/select.php:419
#: fields/tab.php:161 fields/taxonomy.php:808 fields/taxonomy.php:822 #: fields/tab.php:130 fields/taxonomy.php:784 fields/taxonomy.php:798
#: fields/taxonomy.php:836 fields/taxonomy.php:850 fields/user.php:461 #: fields/taxonomy.php:812 fields/taxonomy.php:826 fields/user.php:416
#: fields/user.php:475 fields/wysiwyg.php:415 #: fields/user.php:430 fields/wysiwyg.php:415
#: pro/admin/views/settings-updates.php:93 #: pro/admin/views/settings-updates.php:93
msgid "Yes" msgid "Yes"
msgstr "" msgstr ""
#: admin/views/field-group-field-conditional-logic.php:41 #: admin/views/field-group-field-conditional-logic.php:41
#: admin/views/field-group-field.php:141 fields/checkbox.php:247 #: admin/views/field-group-field.php:141 fields/checkbox.php:247
#: fields/message.php:145 fields/page_link.php:554 fields/page_link.php:568 #: fields/message.php:145 fields/page_link.php:540 fields/page_link.php:554
#: fields/post_object.php:420 fields/post_object.php:434 fields/select.php:378 #: fields/post_object.php:404 fields/post_object.php:418 fields/select.php:378
#: fields/select.php:392 fields/select.php:406 fields/select.php:420 #: fields/select.php:392 fields/select.php:406 fields/select.php:420
#: fields/tab.php:162 fields/taxonomy.php:723 fields/taxonomy.php:809 #: fields/tab.php:131 fields/taxonomy.php:699 fields/taxonomy.php:785
#: fields/taxonomy.php:823 fields/taxonomy.php:837 fields/taxonomy.php:851 #: fields/taxonomy.php:799 fields/taxonomy.php:813 fields/taxonomy.php:827
#: fields/user.php:462 fields/user.php:476 fields/wysiwyg.php:416 #: fields/user.php:417 fields/user.php:431 fields/wysiwyg.php:416
#: pro/admin/views/settings-updates.php:103 #: pro/admin/views/settings-updates.php:103
msgid "No" msgid "No"
msgstr "" msgstr ""
@ -566,12 +567,12 @@ msgstr ""
msgid "Delete field" msgid "Delete field"
msgstr "" msgstr ""
#: admin/views/field-group-field.php:60 pro/fields/flexible-content.php:504 #: admin/views/field-group-field.php:60 pro/fields/flexible-content.php:494
msgid "Delete" msgid "Delete"
msgstr "" msgstr ""
#: admin/views/field-group-field.php:68 fields/oembed.php:225 #: admin/views/field-group-field.php:68 fields/oembed.php:225
#: fields/taxonomy.php:924 #: fields/taxonomy.php:900
msgid "Error" msgid "Error"
msgstr "" msgstr ""
@ -599,7 +600,7 @@ msgstr ""
msgid "Field Type" msgid "Field Type"
msgstr "" msgstr ""
#: admin/views/field-group-field.php:121 fields/tab.php:134 #: admin/views/field-group-field.php:121 fields/tab.php:103
msgid "Instructions" msgid "Instructions"
msgstr "" msgstr ""
@ -635,11 +636,11 @@ msgstr ""
msgid "Order" msgid "Order"
msgstr "" msgstr ""
#: admin/views/field-group-fields.php:30 pro/fields/flexible-content.php:531 #: admin/views/field-group-fields.php:30 pro/fields/flexible-content.php:521
msgid "Label" msgid "Label"
msgstr "" msgstr ""
#: admin/views/field-group-fields.php:31 pro/fields/flexible-content.php:544 #: admin/views/field-group-fields.php:31 pro/fields/flexible-content.php:534
msgid "Name" msgid "Name"
msgstr "" msgstr ""
@ -785,11 +786,11 @@ msgstr ""
msgid "Label placement" msgid "Label placement"
msgstr "" msgstr ""
#: admin/views/field-group-options.php:59 fields/tab.php:148 #: admin/views/field-group-options.php:59 fields/tab.php:117
msgid "Top aligned" msgid "Top aligned"
msgstr "" msgstr ""
#: admin/views/field-group-options.php:60 fields/tab.php:149 #: admin/views/field-group-options.php:60 fields/tab.php:118
msgid "Left Aligned" msgid "Left Aligned"
msgstr "" msgstr ""
@ -1265,134 +1266,134 @@ msgstr ""
msgid "No updates available" msgid "No updates available"
msgstr "" msgstr ""
#: api/api-helpers.php:909 #: api/api-helpers.php:937
msgid "Thumbnail" msgid "Thumbnail"
msgstr "" msgstr ""
#: api/api-helpers.php:910 #: api/api-helpers.php:938
msgid "Medium" msgid "Medium"
msgstr "" msgstr ""
#: api/api-helpers.php:911 #: api/api-helpers.php:939
msgid "Large" msgid "Large"
msgstr "" msgstr ""
#: api/api-helpers.php:959 #: api/api-helpers.php:987
msgid "Full Size" msgid "Full Size"
msgstr "" msgstr ""
#: api/api-helpers.php:1149 api/api-helpers.php:1711 #: api/api-helpers.php:1177 api/api-helpers.php:1739
msgid "(no title)" msgid "(no title)"
msgstr "" msgstr ""
#: api/api-helpers.php:3322 #: api/api-helpers.php:3560
#, php-format #, php-format
msgid "Image width must be at least %dpx." msgid "Image width must be at least %dpx."
msgstr "" msgstr ""
#: api/api-helpers.php:3327 #: api/api-helpers.php:3565
#, php-format #, php-format
msgid "Image width must not exceed %dpx." msgid "Image width must not exceed %dpx."
msgstr "" msgstr ""
#: api/api-helpers.php:3343 #: api/api-helpers.php:3581
#, php-format #, php-format
msgid "Image height must be at least %dpx." msgid "Image height must be at least %dpx."
msgstr "" msgstr ""
#: api/api-helpers.php:3348 #: api/api-helpers.php:3586
#, php-format #, php-format
msgid "Image height must not exceed %dpx." msgid "Image height must not exceed %dpx."
msgstr "" msgstr ""
#: api/api-helpers.php:3366 #: api/api-helpers.php:3604
#, php-format #, php-format
msgid "File size must be at least %s." msgid "File size must be at least %s."
msgstr "" msgstr ""
#: api/api-helpers.php:3371 #: api/api-helpers.php:3609
#, php-format #, php-format
msgid "File size must must not exceed %s." msgid "File size must must not exceed %s."
msgstr "" msgstr ""
#: api/api-helpers.php:3405 #: api/api-helpers.php:3643
#, php-format #, php-format
msgid "File type must be %s." msgid "File type must be %s."
msgstr "" msgstr ""
#: api/api-template.php:1069 #: api/api-template.php:1004
msgid "Spam Detected" msgid "Spam Detected"
msgstr "" msgstr ""
#: api/api-template.php:1214 pro/fields/gallery.php:572 #: api/api-template.php:1147 pro/fields/gallery.php:572
msgid "Update" msgid "Update"
msgstr "" msgstr ""
#: api/api-template.php:1215 #: api/api-template.php:1148
msgid "Post updated" msgid "Post updated"
msgstr "" msgstr ""
#: core/field.php:131 #: core/field.php:132
msgid "Basic" msgid "Basic"
msgstr "" msgstr ""
#: core/field.php:132 #: core/field.php:133
msgid "Content" msgid "Content"
msgstr "" msgstr ""
#: core/field.php:133 #: core/field.php:134
msgid "Choice" msgid "Choice"
msgstr "" msgstr ""
#: core/field.php:134 #: core/field.php:135
msgid "Relational" msgid "Relational"
msgstr "" msgstr ""
#: core/field.php:135 #: core/field.php:136
msgid "jQuery" msgid "jQuery"
msgstr "" msgstr ""
#: core/field.php:136 fields/checkbox.php:226 fields/radio.php:231 #: core/field.php:137 fields/checkbox.php:226 fields/radio.php:231
#: pro/fields/flexible-content.php:501 pro/fields/flexible-content.php:550 #: pro/fields/flexible-content.php:491 pro/fields/flexible-content.php:540
#: pro/fields/repeater.php:467 #: pro/fields/repeater.php:459
msgid "Layout" msgid "Layout"
msgstr "" msgstr ""
#: core/input.php:218 #: core/input.php:255
msgid "Expand Details" msgid "Expand Details"
msgstr "" msgstr ""
#: core/input.php:219 #: core/input.php:256
msgid "Collapse Details" msgid "Collapse Details"
msgstr "" msgstr ""
#: core/input.php:220 #: core/input.php:257
msgid "Validation successful" msgid "Validation successful"
msgstr "" msgstr ""
#: core/input.php:221 #: core/input.php:258
msgid "Validation failed" msgid "Validation failed"
msgstr "" msgstr ""
#: core/input.php:222 #: core/input.php:259
msgid "1 field requires attention" msgid "1 field requires attention"
msgstr "" msgstr ""
#: core/input.php:223 #: core/input.php:260
#, php-format #, php-format
msgid "%d fields require attention" msgid "%d fields require attention"
msgstr "" msgstr ""
#: core/input.php:224 #: core/input.php:261
msgid "Restricted" msgid "Restricted"
msgstr "" msgstr ""
#: core/input.php:541 #: core/validation.php:207
#, php-format #, php-format
msgid "%s value is required" msgid "%s value is required"
msgstr "" msgstr ""
#: fields/checkbox.php:36 fields/taxonomy.php:790 #: fields/checkbox.php:36 fields/taxonomy.php:766
msgid "Checkbox" msgid "Checkbox"
msgstr "" msgstr ""
@ -1416,7 +1417,7 @@ msgstr ""
msgid "red : Red" msgid "red : Red"
msgstr "" msgstr ""
#: fields/checkbox.php:217 fields/color_picker.php:155 fields/email.php:124 #: fields/checkbox.php:217 fields/color_picker.php:147 fields/email.php:124
#: fields/number.php:150 fields/radio.php:222 fields/select.php:363 #: fields/number.php:150 fields/radio.php:222 fields/select.php:363
#: fields/text.php:148 fields/textarea.php:145 fields/true_false.php:115 #: fields/text.php:148 fields/textarea.php:145 fields/true_false.php:115
#: fields/url.php:117 fields/wysiwyg.php:376 #: fields/url.php:117 fields/wysiwyg.php:376
@ -1571,7 +1572,7 @@ msgstr ""
msgid "Add File" msgid "Add File"
msgstr "" msgstr ""
#: fields/file.php:214 fields/image.php:200 fields/taxonomy.php:859 #: fields/file.php:214 fields/image.php:200 fields/taxonomy.php:835
msgid "Return Value" msgid "Return Value"
msgstr "" msgstr ""
@ -1825,33 +1826,33 @@ msgstr ""
msgid "Archives" msgid "Archives"
msgstr "" msgstr ""
#: fields/page_link.php:520 fields/post_object.php:386 #: fields/page_link.php:506 fields/post_object.php:370
#: fields/relationship.php:689 #: fields/relationship.php:689
msgid "Filter by Post Type" msgid "Filter by Post Type"
msgstr "" msgstr ""
#: fields/page_link.php:528 fields/post_object.php:394 #: fields/page_link.php:514 fields/post_object.php:378
#: fields/relationship.php:697 #: fields/relationship.php:697
msgid "All post types" msgid "All post types"
msgstr "" msgstr ""
#: fields/page_link.php:534 fields/post_object.php:400 #: fields/page_link.php:520 fields/post_object.php:384
#: fields/relationship.php:703 #: fields/relationship.php:703
msgid "Filter by Taxonomy" msgid "Filter by Taxonomy"
msgstr "" msgstr ""
#: fields/page_link.php:542 fields/post_object.php:408 #: fields/page_link.php:528 fields/post_object.php:392
#: fields/relationship.php:711 #: fields/relationship.php:711
msgid "All taxonomies" msgid "All taxonomies"
msgstr "" msgstr ""
#: fields/page_link.php:548 fields/post_object.php:414 fields/select.php:372 #: fields/page_link.php:534 fields/post_object.php:398 fields/select.php:372
#: fields/taxonomy.php:803 fields/user.php:456 #: fields/taxonomy.php:779 fields/user.php:411
msgid "Allow Null?" msgid "Allow Null?"
msgstr "" msgstr ""
#: fields/page_link.php:562 fields/post_object.php:428 fields/select.php:386 #: fields/page_link.php:548 fields/post_object.php:412 fields/select.php:386
#: fields/user.php:470 #: fields/user.php:425
msgid "Select multiple values?" msgid "Select multiple values?"
msgstr "" msgstr ""
@ -1859,16 +1860,16 @@ msgstr ""
msgid "Password" msgid "Password"
msgstr "" msgstr ""
#: fields/post_object.php:36 fields/post_object.php:447 #: fields/post_object.php:36 fields/post_object.php:431
#: fields/relationship.php:768 #: fields/relationship.php:768
msgid "Post Object" msgid "Post Object"
msgstr "" msgstr ""
#: fields/post_object.php:442 fields/relationship.php:763 #: fields/post_object.php:426 fields/relationship.php:763
msgid "Return Format" msgid "Return Format"
msgstr "" msgstr ""
#: fields/post_object.php:448 fields/relationship.php:769 #: fields/post_object.php:432 fields/relationship.php:769
msgid "Post ID" msgid "Post ID"
msgstr "" msgstr ""
@ -1924,7 +1925,7 @@ msgstr ""
msgid "Select taxonomy" msgid "Select taxonomy"
msgstr "" msgstr ""
#: fields/relationship.php:724 fields/taxonomy.php:36 fields/taxonomy.php:773 #: fields/relationship.php:724 fields/taxonomy.php:36 fields/taxonomy.php:749
msgid "Taxonomy" msgid "Taxonomy"
msgstr "" msgstr ""
@ -1951,7 +1952,7 @@ msgid_plural "%s requires at least %s selections"
msgstr[0] "" msgstr[0] ""
msgstr[1] "" msgstr[1] ""
#: fields/select.php:36 fields/select.php:167 fields/taxonomy.php:795 #: fields/select.php:36 fields/select.php:167 fields/taxonomy.php:771
msgid "Select" msgid "Select"
msgstr "" msgstr ""
@ -1967,117 +1968,117 @@ msgstr ""
msgid "Tab" msgid "Tab"
msgstr "" msgstr ""
#: fields/tab.php:128 #: fields/tab.php:97
msgid "" msgid ""
"The tab field will display incorrectly when added to a Table style repeater " "The tab field will display incorrectly when added to a Table style repeater "
"field or flexible content field layout" "field or flexible content field layout"
msgstr "" msgstr ""
#: fields/tab.php:129 #: fields/tab.php:98
msgid "" msgid ""
"Use \"Tab Fields\" to better organize your edit screen by grouping fields " "Use \"Tab Fields\" to better organize your edit screen by grouping fields "
"together." "together."
msgstr "" msgstr ""
#: fields/tab.php:130 #: fields/tab.php:99
msgid "" msgid ""
"All fields following this \"tab field\" (or until another \"tab field\" is " "All fields following this \"tab field\" (or until another \"tab field\" is "
"defined) will be grouped together using this field's label as the tab " "defined) will be grouped together using this field's label as the tab "
"heading." "heading."
msgstr "" msgstr ""
#: fields/tab.php:144 #: fields/tab.php:113
msgid "Placement" msgid "Placement"
msgstr "" msgstr ""
#: fields/tab.php:156 #: fields/tab.php:125
msgid "End-point" msgid "End-point"
msgstr "" msgstr ""
#: fields/tab.php:157 #: fields/tab.php:126
msgid "Use this field as an end-point and start a new group of tabs" msgid "Use this field as an end-point and start a new group of tabs"
msgstr "" msgstr ""
#: fields/taxonomy.php:742 #: fields/taxonomy.php:718
msgid "None" msgid "None"
msgstr "" msgstr ""
#: fields/taxonomy.php:774 #: fields/taxonomy.php:750
msgid "Select the taxonomy to be displayed" msgid "Select the taxonomy to be displayed"
msgstr "" msgstr ""
#: fields/taxonomy.php:783 #: fields/taxonomy.php:759
msgid "Appearance" msgid "Appearance"
msgstr "" msgstr ""
#: fields/taxonomy.php:784 #: fields/taxonomy.php:760
msgid "Select the appearance of this field" msgid "Select the appearance of this field"
msgstr "" msgstr ""
#: fields/taxonomy.php:789 #: fields/taxonomy.php:765
msgid "Multiple Values" msgid "Multiple Values"
msgstr "" msgstr ""
#: fields/taxonomy.php:791 #: fields/taxonomy.php:767
msgid "Multi Select" msgid "Multi Select"
msgstr "" msgstr ""
#: fields/taxonomy.php:793 #: fields/taxonomy.php:769
msgid "Single Value" msgid "Single Value"
msgstr "" msgstr ""
#: fields/taxonomy.php:794 #: fields/taxonomy.php:770
msgid "Radio Buttons" msgid "Radio Buttons"
msgstr "" msgstr ""
#: fields/taxonomy.php:817 #: fields/taxonomy.php:793
msgid "Create Terms" msgid "Create Terms"
msgstr "" msgstr ""
#: fields/taxonomy.php:818 #: fields/taxonomy.php:794
msgid "Allow new terms to be created whilst editing" msgid "Allow new terms to be created whilst editing"
msgstr "" msgstr ""
#: fields/taxonomy.php:831 #: fields/taxonomy.php:807
msgid "Save Terms" msgid "Save Terms"
msgstr "" msgstr ""
#: fields/taxonomy.php:832 #: fields/taxonomy.php:808
msgid "Connect selected terms to the post" msgid "Connect selected terms to the post"
msgstr "" msgstr ""
#: fields/taxonomy.php:845 #: fields/taxonomy.php:821
msgid "Load Terms" msgid "Load Terms"
msgstr "" msgstr ""
#: fields/taxonomy.php:846 #: fields/taxonomy.php:822
msgid "Load value from posts terms" msgid "Load value from posts terms"
msgstr "" msgstr ""
#: fields/taxonomy.php:864 #: fields/taxonomy.php:840
msgid "Term Object" msgid "Term Object"
msgstr "" msgstr ""
#: fields/taxonomy.php:865 #: fields/taxonomy.php:841
msgid "Term ID" msgid "Term ID"
msgstr "" msgstr ""
#: fields/taxonomy.php:924 #: fields/taxonomy.php:900
#, php-format #, php-format
msgid "User unable to add new %s" msgid "User unable to add new %s"
msgstr "" msgstr ""
#: fields/taxonomy.php:937 #: fields/taxonomy.php:913
#, php-format #, php-format
msgid "%s already exists" msgid "%s already exists"
msgstr "" msgstr ""
#: fields/taxonomy.php:978 #: fields/taxonomy.php:954
#, php-format #, php-format
msgid "%s added" msgid "%s added"
msgstr "" msgstr ""
#: fields/taxonomy.php:1023 #: fields/taxonomy.php:999
msgid "Add" msgid "Add"
msgstr "" msgstr ""
@ -2121,11 +2122,11 @@ msgstr ""
msgid "Value must be a valid URL" msgid "Value must be a valid URL"
msgstr "" msgstr ""
#: fields/user.php:441 #: fields/user.php:396
msgid "Filter by role" msgid "Filter by role"
msgstr "" msgstr ""
#: fields/user.php:449 #: fields/user.php:404
msgid "All user roles" msgid "All user roles"
msgstr "" msgstr ""
@ -2206,11 +2207,11 @@ msgstr ""
msgid "<b>Connection Error</b>. Sorry, please try again" msgid "<b>Connection Error</b>. Sorry, please try again"
msgstr "" msgstr ""
#: pro/admin/views/options-page.php:48 #: pro/admin/views/options-page.php:44
msgid "Publish" msgid "Publish"
msgstr "" msgstr ""
#: pro/admin/views/options-page.php:54 #: pro/admin/views/options-page.php:50
msgid "Save Options" msgid "Save Options"
msgstr "" msgstr ""
@ -2328,72 +2329,72 @@ msgstr ""
msgid "{required} {label} {identifier} required (min {min})" msgid "{required} {label} {identifier} required (min {min})"
msgstr "" msgstr ""
#: pro/fields/flexible-content.php:211 #: pro/fields/flexible-content.php:216
#, php-format #, php-format
msgid "Click the \"%s\" button below to start creating your layout" msgid "Click the \"%s\" button below to start creating your layout"
msgstr "" msgstr ""
#: pro/fields/flexible-content.php:357 #: pro/fields/flexible-content.php:346
msgid "Add layout" msgid "Add layout"
msgstr "" msgstr ""
#: pro/fields/flexible-content.php:360 #: pro/fields/flexible-content.php:349
msgid "Remove layout" msgid "Remove layout"
msgstr "" msgstr ""
#: pro/fields/flexible-content.php:363 pro/fields/repeater.php:312 #: pro/fields/flexible-content.php:352 pro/fields/repeater.php:304
msgid "Click to toggle" msgid "Click to toggle"
msgstr "" msgstr ""
#: pro/fields/flexible-content.php:503 #: pro/fields/flexible-content.php:493
msgid "Reorder Layout" msgid "Reorder Layout"
msgstr "" msgstr ""
#: pro/fields/flexible-content.php:503 #: pro/fields/flexible-content.php:493
msgid "Reorder" msgid "Reorder"
msgstr "" msgstr ""
#: pro/fields/flexible-content.php:504 #: pro/fields/flexible-content.php:494
msgid "Delete Layout" msgid "Delete Layout"
msgstr "" msgstr ""
#: pro/fields/flexible-content.php:505 #: pro/fields/flexible-content.php:495
msgid "Duplicate Layout" msgid "Duplicate Layout"
msgstr "" msgstr ""
#: pro/fields/flexible-content.php:506 #: pro/fields/flexible-content.php:496
msgid "Add New Layout" msgid "Add New Layout"
msgstr "" msgstr ""
#: pro/fields/flexible-content.php:560 pro/fields/repeater.php:474 #: pro/fields/flexible-content.php:550 pro/fields/repeater.php:466
msgid "Table" msgid "Table"
msgstr "" msgstr ""
#: pro/fields/flexible-content.php:561 pro/fields/repeater.php:475 #: pro/fields/flexible-content.php:551 pro/fields/repeater.php:467
msgid "Block" msgid "Block"
msgstr "" msgstr ""
#: pro/fields/flexible-content.php:562 pro/fields/repeater.php:476 #: pro/fields/flexible-content.php:552 pro/fields/repeater.php:468
msgid "Row" msgid "Row"
msgstr "" msgstr ""
#: pro/fields/flexible-content.php:577 #: pro/fields/flexible-content.php:567
msgid "Min" msgid "Min"
msgstr "" msgstr ""
#: pro/fields/flexible-content.php:590 #: pro/fields/flexible-content.php:580
msgid "Max" msgid "Max"
msgstr "" msgstr ""
#: pro/fields/flexible-content.php:618 pro/fields/repeater.php:483 #: pro/fields/flexible-content.php:608 pro/fields/repeater.php:475
msgid "Button Label" msgid "Button Label"
msgstr "" msgstr ""
#: pro/fields/flexible-content.php:627 #: pro/fields/flexible-content.php:617
msgid "Minimum Layouts" msgid "Minimum Layouts"
msgstr "" msgstr ""
#: pro/fields/flexible-content.php:636 #: pro/fields/flexible-content.php:626
msgid "Maximum Layouts" msgid "Maximum Layouts"
msgstr "" msgstr ""
@ -2417,6 +2418,14 @@ msgstr ""
msgid "Remove" msgid "Remove"
msgstr "" msgstr ""
#: pro/fields/gallery.php:383
msgid "Caption"
msgstr ""
#: pro/fields/gallery.php:392
msgid "Alt Text"
msgstr ""
#: pro/fields/gallery.php:543 #: pro/fields/gallery.php:543
msgid "Add to gallery" msgid "Add to gallery"
msgstr "" msgstr ""
@ -2465,35 +2474,35 @@ msgstr ""
msgid "Maximum rows reached ({max} rows)" msgid "Maximum rows reached ({max} rows)"
msgstr "" msgstr ""
#: pro/fields/repeater.php:310 #: pro/fields/repeater.php:302
msgid "Drag to reorder" msgid "Drag to reorder"
msgstr "" msgstr ""
#: pro/fields/repeater.php:357 #: pro/fields/repeater.php:349
msgid "Add row" msgid "Add row"
msgstr "" msgstr ""
#: pro/fields/repeater.php:358 #: pro/fields/repeater.php:350
msgid "Remove row" msgid "Remove row"
msgstr "" msgstr ""
#: pro/fields/repeater.php:406 #: pro/fields/repeater.php:398
msgid "Sub Fields" msgid "Sub Fields"
msgstr "" msgstr ""
#: pro/fields/repeater.php:436 #: pro/fields/repeater.php:428
msgid "Collapsed" msgid "Collapsed"
msgstr "" msgstr ""
#: pro/fields/repeater.php:437 #: pro/fields/repeater.php:429
msgid "Select a sub field to show when row is collapsed" msgid "Select a sub field to show when row is collapsed"
msgstr "" msgstr ""
#: pro/fields/repeater.php:447 #: pro/fields/repeater.php:439
msgid "Minimum Rows" msgid "Minimum Rows"
msgstr "" msgstr ""
#: pro/fields/repeater.php:457 #: pro/fields/repeater.php:449
msgid "Maximum Rows" msgid "Maximum Rows"
msgstr "" msgstr ""

View File

@ -146,16 +146,16 @@ th.acf-row-handle span {
font-size: 14px; font-size: 14px;
line-height: 1.4em; line-height: 1.4em;
} }
.acf-flexible-content .layout .fc-layout-order { .acf-flexible-content .layout .acf-fc-layout-order {
display: block; display: block;
width: 20px; width: 20px;
height: 20px; height: 20px;
border-radius: 10px; border-radius: 10px;
display: inline-block;
text-align: center; text-align: center;
line-height: 20px; line-height: 20px;
margin: 0 5px 0 0; margin: 0 2px 0 0;
background: #F1F1F1; background: #F1F1F1;
float: left;
font-size: 12px; font-size: 12px;
color: #666; color: #666;
} }
@ -186,7 +186,7 @@ th.acf-row-handle span {
} }
.acf-flexible-content > .values > .ui-sortable-placeholder { .acf-flexible-content > .values > .ui-sortable-placeholder {
visibility: visible !important; visibility: visible !important;
border: #ccc dashed 2px; border: 1px dashed #b4b9be;
box-shadow: none; box-shadow: none;
background: transparent; background: transparent;
} }
@ -311,7 +311,7 @@ th.acf-row-handle span {
opacity: 0; opacity: 0;
} }
/* rtl */ /* rtl */
html[dir="rtl"] .acf-flexible-content .layout .fc-layout-order { html[dir="rtl"] .acf-flexible-content .layout .acf-fc-layout-order {
float: right; float: right;
margin-right: 0; margin-right: 0;
margin-left: 5px; margin-left: 5px;
@ -422,7 +422,6 @@ html[dir="rtl"] .acf-flexible-content .layout .acf-fc-layout-controlls {
right: 0; right: 0;
bottom: 0; bottom: 0;
left: 0; left: 0;
height: 28px;
padding: 10px; padding: 10px;
border-top: #DFDFDF solid 1px; border-top: #DFDFDF solid 1px;
} }

View File

@ -592,10 +592,14 @@
render: function(){ render: function(){
// vars
var self = this;
// update order numbers // update order numbers
this.$values.children('.layout').each(function( i ){ this.$values.children('.layout').each(function( i ){
$(this).find('> .acf-fc-layout-handle .fc-layout-order').html( i+1 ); $(this).find('> .acf-fc-layout-handle .acf-fc-layout-order').html( i+1 );
}); });
@ -624,6 +628,21 @@
} }
}, },
render_layout: function( $layout ){
// update order number
// update text
/*
var data = acf.serialize_form($layout);
console.log( data );
*/
},
validate_add: function( layout ){ validate_add: function( layout ){
@ -1118,6 +1137,40 @@
// sync collapsed order // sync collapsed order
this.sync(); this.sync();
// vars
var data = acf.serialize( $layout );
// append
$.extend(data, {
action: 'acf/fields/flexible_content/layout_title',
field_key: this.$field.data('key'),
post_id: acf.get('post_id'),
i: $layout.index(),
layout: $layout.data('layout'),
});
// ajax get title HTML
$.ajax({
url : acf.get('ajaxurl'),
dataType : 'html',
type : 'post',
data : data,
success: function( html ){
// bail early if no html
if( !html ) return;
// update html
$layout.find('> .acf-fc-layout-handle').html( html );
}
});
} }
}); });
@ -1300,7 +1353,7 @@
// vars // vars
var data = acf.prepare_for_ajax({ var data = acf.prepare_for_ajax({
action : 'acf/fields/gallery/get_sort_order', action : 'acf/fields/gallery/get_sort_order',
field_key : acf.get_field_key(this.$field), field_key : this.$field.data('key'),
post_id : acf.get('post_id'), post_id : acf.get('post_id'),
ids : [], ids : [],
sort : sort sort : sort
@ -1458,7 +1511,7 @@
// vars // vars
var data = acf.prepare_for_ajax({ var data = acf.prepare_for_ajax({
action : 'acf/fields/gallery/get_attachment', action : 'acf/fields/gallery/get_attachment',
field_key : acf.get_field_key(this.$field), field_key : this.$field.data('key'),
nonce : acf.get('nonce'), nonce : acf.get('nonce'),
post_id : acf.get('post_id'), post_id : acf.get('post_id'),
id : id id : id
@ -1775,7 +1828,7 @@
title: acf._e('gallery', 'select'), title: acf._e('gallery', 'select'),
mode: 'select', mode: 'select',
type: '', type: '',
field: acf.get_field_key(this.$field), field: this.$field.data('key'),
multiple: 'add', multiple: 'add',
library: this.o.library, library: this.o.library,
mime_types: this.o.mime_types, mime_types: this.o.mime_types,

File diff suppressed because one or more lines are too long

View File

@ -54,6 +54,11 @@ class acf_field_flexible_content extends acf_field {
); );
// ajax
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'));
// do not delete! // do not delete!
parent::__construct(); parent::__construct();
@ -195,7 +200,7 @@ class acf_field_flexible_content extends acf_field {
foreach( $field['layouts'] as $k => $layout ) { foreach( $field['layouts'] as $k => $layout ) {
$layouts[ $layout['name'] ] = acf_extract_var( $field['layouts'], $k ); $layouts[ $layout['name'] ] = $layout;
} }
@ -300,29 +305,9 @@ class acf_field_flexible_content extends acf_field {
'data-layout' => $layout['name'] 'data-layout' => $layout['name']
); );
// collapsed
$collapsed = acf_get_user_setting('collapsed_' . $field['key'], '');
// cookie fallback ( version < 5.3.2 )
if( $collapsed === '' ) {
$collapsed = acf_extract_var($_COOKIE, "acf_collapsed_{$field['key']}", '');
$collapsed = str_replace('|', ',', $collapsed);
acf_update_user_setting( 'collapsed_' . $field['key'], $collapsed );
}
// explode
$collapsed = explode(',', $collapsed);
$collapsed = array_filter($collapsed, 'is_numeric');
// collapsed class // collapsed class
if( in_array($i, $collapsed) ) { if( acf_is_row_collapsed($field['key'], $i) ) {
$div['class'] .= ' -collapsed'; $div['class'] .= ' -collapsed';
@ -341,6 +326,12 @@ class acf_field_flexible_content extends acf_field {
} }
// title
$title = $this->get_layout_title( $field, $layout, $i, $value );
// remove row
reset_rows();
?> ?>
<div <?php acf_esc_attr_e($div); ?>> <div <?php acf_esc_attr_e($div); ?>>
@ -348,9 +339,7 @@ class acf_field_flexible_content extends acf_field {
<?php acf_hidden_input(array( 'name' => "{$field['name']}[{$i}][acf_fc_layout]", 'value' => $layout['name'] )); ?> <?php acf_hidden_input(array( 'name' => "{$field['name']}[{$i}][acf_fc_layout]", 'value' => $layout['name'] )); ?>
</div> </div>
<div class="acf-fc-layout-handle"> <div class="acf-fc-layout-handle"><?php echo $title; ?></div>
<span class="fc-layout-order"><?php echo $order; ?></span> <?php echo $layout['label']; ?>
</div>
<ul class="acf-fc-layout-controlls acf-hl"> <ul class="acf-fc-layout-controlls acf-hl">
<li class="acf-fc-show-on-hover"> <li class="acf-fc-show-on-hover">
@ -479,8 +468,9 @@ class acf_field_flexible_content extends acf_field {
// load default layout // load default layout
if( empty($field['layouts']) ) { if( empty($field['layouts']) ) {
$field['layouts'] = array(); $field['layouts'] = array(
$field['layouts'][] = $this->get_valid_layout(); array()
);
} }
@ -1223,6 +1213,121 @@ class acf_field_flexible_content extends acf_field {
} }
/*
* ajax_layout_title
*
* description
*
* @type function
* @date 2/03/2016
* @since 5.3.2
*
* @param $post_id (int)
* @return $post_id (int)
*/
function ajax_layout_title() {
// options
$options = acf_parse_args( $_POST, array(
'post_id' => 0,
'i' => 0,
'field_key' => '',
'nonce' => '',
'layout' => '',
'acf' => array()
));
// load field
$field = acf_get_field( $options['field_key'] );
if( !$field ) die();
// vars
$layout = false;
foreach( $field['layouts'] as $k => $layout ) {
if( $layout['name'] === $options['layout'] ) break;
}
// bail ealry if no layout
if( !$layout ) die();
// value
// this flexible content field may be a sub field so it is important to
// loop though all $_POST data to find thi's field's row value
$value = $options['acf'];
while( is_array($value) ) {
// get first key
$k = key($value);
// update value
$value = array_pop( $value[ $k ] );
// stop looking if we have found the correct field's value
if( $k === $options['field_key'] ) break;
}
// title
$title = $this->get_layout_title( $field, $layout, $options['i'], $value );
// echo
echo $title;
die;
}
function get_layout_title( $field, $layout, $i, $value ) {
// add loop
acf_add_loop(array(
'selector' => $field['name'],
'name' => $field['name'],
'value' => array( $value ),
'field' => $field,
'i' => 0,
'post_id' => 0,
));
// vars
$title = $layout['label'];
// filters
$title = apply_filters('acf/fields/flexible_content/layout_title', $title, $field, $layout, $i);
$title = apply_filters('acf/fields/flexible_content/layout_title/name='.$field['_name'], $title, $field, $layout, $i);
$title = apply_filters('acf/fields/flexible_content/layout_title/key='.$field['key'], $title, $field, $layout, $i);
// remove loop
acf_remove_loop();
// prepend order
$title = '<span class="acf-fc-layout-order">' . ($i+1) . '</span> ' . $title;
// return
return $title;
}
} }
new acf_field_flexible_content(); new acf_field_flexible_content();

View File

@ -218,16 +218,8 @@ class acf_field_repeater extends acf_field {
// collapsed // collapsed
$collapsed = array();
if( $field['collapsed'] ) { if( $field['collapsed'] ) {
// get user setting
$collapsed = acf_get_user_setting('collapsed_' . $field['key'], '');
$collapsed = explode(',', $collapsed);
$collapsed = array_filter($collapsed, 'is_numeric');
// add target class // add target class
foreach( array_keys($field['sub_fields']) as $i ) { foreach( array_keys($field['sub_fields']) as $i ) {
@ -297,7 +289,7 @@ class acf_field_repeater extends acf_field {
$row_class .= ' acf-clone'; $row_class .= ' acf-clone';
} elseif( in_array($i, $collapsed) ) { } elseif( acf_is_row_collapsed($field['key'], $i) ) {
$row_class .= ' -collapsed'; $row_class .= ' -collapsed';

View File

@ -106,6 +106,25 @@ http://support.advancedcustomfields.com/
== Changelog == == Changelog ==
= 5.3.6.1 =
* Flexible Content field: Fixed PHP error in 'acf/fields/flexible_content/layout_title' filter (when used as a sub field)
* Core: Fixed bug causing `get_field()` to load from the incorrect post (when within a custom WP_Query loop)
= 5.3.6 =
* Flexible Content field: Added new 'acf/fields/flexible_content/layout_title' filter to customize layout title
* Image field: Fixed bug where searching within media library would ignore restriction settings
* File field: Same as above
* Field group: Added post types to comment form location rules
* Color Picker field: Added 'color_picker_args' JS filter to modify wpColorPicker args
* API: Improved `get_` functions to load value from the current queried object (post, user, term)
* Core: Added new 'acf/translate_field' filter to translate field settings text
* Core: Added new 'acf/translate_field_group' filter to translate field group settings text
* Core: Removed 'l10n_field' and 'l10n_field_group' settings
* Core: Fixed bug causing 'acf/input/admin_head' action to run twice
* Core: Added support for new WP 4.5 term edit page
* Core: Moved google map and wysiwyg JS initialisation later in the page load to help speed up edit screens
* Core: Minor fixes and improvements
= 5.3.5 = = 5.3.5 =
* User field: Fixed pagination bug causing missing results * User field: Fixed pagination bug causing missing results
* Core: Added new filter 'acf/location/screen' to customize location rules matching args * Core: Added new filter 'acf/location/screen' to customize location rules matching args