Merge branch 'release/5.3.5' into develop

This commit is contained in:
Remco Tolsma 2016-03-01 10:47:05 +01:00
commit 305ba91752
18 changed files with 968 additions and 771 deletions

View File

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

View File

@ -1581,11 +1581,7 @@ function acf_get_grouped_posts( $args ) {
// bail early if no posts for this post type
if( empty($this_posts) ) {
continue;
}
if( empty($this_posts) ) continue;
// sort into hierachial order!
@ -1636,6 +1632,10 @@ function acf_get_grouped_posts( $args ) {
}
// clean up null values
$this_posts = array_filter($this_posts);
}
@ -1801,6 +1801,201 @@ function acf_order_by_search( $array, $search ) {
}
/*
* acf_get_pretty_user_roles
*
* description
*
* @type function
* @date 23/02/2016
* @since 5.3.2
*
* @param $post_id (int)
* @return $post_id (int)
*/
function acf_get_pretty_user_roles( $allowed = false ) {
// vars
$editable_roles = get_editable_roles();
$allowed = acf_get_array($allowed);
$roles = array();
// loop
foreach( $editable_roles as $role_name => $role_details ) {
// bail early if not allowed
if( !empty($allowed) && !in_array($role_name, $allowed) ) continue;
// append
$roles[ $role_name ] = translate_user_role( $role_details['name'] );
}
// return
return $roles;
}
/*
* acf_get_grouped_users
*
* This function will return all users grouped by role
* This is handy for select settings
*
* @type function
* @date 27/02/2014
* @since 5.0.0
*
* @param $args (array)
* @return (array)
*/
function acf_get_grouped_users( $args = array() ) {
// vars
$r = array();
// defaults
$args = acf_parse_args( $args, array(
'users_per_page' => -1,
'paged' => 0,
'role' => '',
'orderby' => 'login',
'order' => 'ASC',
));
// offset
$i = 0;
$min = 0;
$max = 0;
$users_per_page = acf_extract_var($args, 'users_per_page');
$paged = acf_extract_var($args, 'paged');
if( $users_per_page > 0 ) {
// prevent paged from being -1
$paged = max(0, $paged);
// set min / max
$min = (($paged-1) * $users_per_page) + 1; // 1, 11
$max = ($paged * $users_per_page); // 10, 20
}
// find array of post_type
$user_roles = acf_get_pretty_user_roles($args['role']);
// fix role
if( is_array($args['role']) ) {
// global
global $wp_version, $wpdb;
// vars
$roles = acf_extract_var($args, 'role');
// new WP has role__in
if( version_compare($wp_version, '4.4', '>=' ) ) {
$args['role__in'] = $roles;
// old WP doesn't have role__in
} else {
// vars
$blog_id = get_current_blog_id();
$meta_query = array( 'relation' => 'OR' );
// loop
foreach( $roles as $role ) {
$meta_query[] = array(
'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities',
'value' => '"' . $role . '"',
'compare' => 'LIKE',
);
}
// append
$args['meta_query'] = $meta_query;
}
}
// get posts
$users = get_users( $args );
// loop
foreach( $user_roles as $user_role_name => $user_role_label ) {
// vars
$this_users = array();
$this_group = array();
// populate $this_posts
foreach( array_keys($users) as $key ) {
// bail ealry if not correct role
if( !in_array($user_role_name, $users[ $key ]->roles) ) continue;
// extract user
$user = acf_extract_var( $users, $key );
// increase
$i++;
// bail ealry if too low
if( $min && $i < $min ) continue;
// bail early if too high (don't bother looking at any more users)
if( $max && $i > $max ) break;
// group by post type
$this_users[ $user->ID ] = $user;
}
// bail early if no posts for this post type
if( empty($this_users) ) continue;
// append
$r[ $user_role_label ] = $this_users;
}
// return
return $r;
}
/*
* acf_json_encode
@ -2089,35 +2284,40 @@ function acf_get_updates() {
* @return $post_id (int)
*/
function acf_encode_choices( $array = array() ) {
function acf_encode_choices( $array = array(), $show_keys = true ) {
// bail early if not array
if( !is_array($array) ) {
// bail early if not array (maybe a single string)
if( !is_array($array) ) return $array;
return $array;
}
// bail early if empty array
if( empty($array) ) return '';
// vars
$string = '';
if( !empty($array) ) {
// if allowed to show keys (good for choices, not for default values)
if( $show_keys ) {
// loop
foreach( $array as $k => $v ) {
if( $k !== $v ) {
// ignore if key and value are the same
if( $k === $v ) continue;
// show key in the value
$array[ $k ] = $k . ' : ' . $v;
}
}
$string = implode("\n", $array);
}
// implode
$string = implode("\n", $array);
// return
@ -2127,21 +2327,26 @@ function acf_encode_choices( $array = array() ) {
function acf_decode_choices( $string = '' ) {
// validate
if( $string === '') {
// bail early if already array
if( is_array($string) ) {
return array();
return $string;
// allow numeric values (same as string)
} elseif( is_numeric($string) ) {
// allow
// do nothing
// bail early if not a a string
// bail early if not a string
} elseif( !is_string($string) ) {
return array();
// bail early if is empty string
} elseif( $string === '' ) {
return array();
}

View File

@ -2949,32 +2949,38 @@ var acf;
acf.add_action('before_duplicate', function( $orig ){
// save select values
$orig.find('select').each(function(){
$(this).find(':selected').addClass('selected');
});
$orig.find('select option:selected').addClass('selected');
});
acf.add_action('after_duplicate', function( $orig, $duplicate ){
// restore select values
$orig.find('select').each(function(){
$(this).find('.selected').removeClass('selected');
});
$orig.find('select option.selected').removeClass('selected');
// set select values
$duplicate.find('select').each(function(){
var $selected = $(this).find('.selected');
// vars
var val = [];
$(this).val( $selected.attr('value') );
$selected.removeClass('selected');
// loop
$(this).find('option.selected').each(function(){
// append
val.push( $(this).val() );
// remove class
$(this).removeClass('selected');
});
// set val
$(this).val( val );
});
@ -7306,6 +7312,8 @@ var acf;
}
// remove the blank option as we have a clear all button!
if( args.allow_null ) {
@ -7453,7 +7461,7 @@ var acf;
// disbale select
$select.attr('disabled', 'disabled').addClass('acf-disabled acf-hidden');
$select.prop('disabled', true).addClass('acf-disabled acf-hidden');
},
@ -7695,6 +7703,10 @@ var acf;
// show input so that select2 can correctly render visible select2 container
$select.siblings('input').show();
// enable select
$select.prop('disabled', false).removeClass('acf-disabled acf-hidden');
}
});

File diff suppressed because one or more lines are too long

View File

@ -465,7 +465,7 @@ class acf_location {
// find post format
if( !$post_format ) {
if( !$post_status ) {
// bail early if not a post
if( !$options['post_id'] ) return false;
@ -1196,23 +1196,19 @@ function acf_get_field_group_visibility( $field_group, $args = array() ) {
'attachment' => 0,
'comment' => 0,
'widget' => 0,
'lang' => 0,
'lang' => acf_get_setting('current_language'),
'ajax' => false
));
// filter for 3rd party customization
$args = apply_filters('acf/location/screen', $args, $field_group);
// bail early if not active
if( !$field_group['active'] ) return false;
// WPML
if( defined('ICL_LANGUAGE_CODE') ) {
$args['lang'] = ICL_LANGUAGE_CODE;
}
// vars
$visibility = false;

View File

@ -40,11 +40,7 @@ class acf_wpml_compatibility {
// bail early if not transaltable
if( !$this->is_translatable() ) {
return;
}
if( !$this->is_translatable() ) return;
// actions

View File

@ -200,7 +200,7 @@ class acf_field_checkbox extends acf_field {
// encode choices (convert from array)
$field['choices'] = acf_encode_choices($field['choices']);
$field['default_value'] = acf_encode_choices($field['default_value']);
$field['default_value'] = acf_encode_choices($field['default_value'], false);
// choices

View File

@ -93,11 +93,9 @@ class acf_field_post_object extends acf_field {
// load field
$field = acf_get_field( $options['field_key'] );
if( !$field ) {
return false;
}
// bail early if no field
if( !$field ) return false;
// update $args

View File

@ -346,7 +346,7 @@ class acf_field_select extends acf_field {
// encode choices (convert from array)
$field['choices'] = acf_encode_choices($field['choices']);
$field['default_value'] = acf_encode_choices($field['default_value']);
$field['default_value'] = acf_encode_choices($field['default_value'], false);
// choices
@ -551,10 +551,15 @@ class acf_field_select extends acf_field {
function enqueue_assets() {
// globals
global $wp_scripts, $wp_styles;
// vars
$version = '3.5.2';
$lang = get_locale();
$min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
//$lang = 'fr';
// v4
@ -564,42 +569,61 @@ class acf_field_select extends acf_field {
return;
*/
// register script
if( !isset($wp_scripts->registered['select2']) ) {
// scripts
wp_enqueue_script('select2', acf_get_dir("assets/inc/select2/select2{$min}.js"), array('jquery'), $version, true );
wp_register_script('select2', acf_get_dir("assets/inc/select2/select2{$min}.js"), array('jquery'), $version );
// styles
wp_enqueue_style('select2', acf_get_dir('assets/inc/select2/select2.css'), '', $version );
// bail early if no language
if( !$lang ) return;
// translation
if( $lang ) {
// vars
$lang = str_replace('_', '-', $lang);
$lang_code = substr($lang, 0, 2);
$src = '';
$lang_src = '';
// attempt 1
if( file_exists(acf_get_path("assets/inc/select2/select2_locale_{$lang_code}.js")) ) {
$src = acf_get_dir("assets/inc/select2/select2_locale_{$lang_code}.js");
$lang_src = acf_get_dir("assets/inc/select2/select2_locale_{$lang_code}.js");
// attempt 2
} elseif( file_exists(acf_get_path("assets/inc/select2/select2_locale_{$lang}.js")) ) {
$src = acf_get_dir("assets/inc/select2/select2_locale_{$lang}.js");
$lang_src = acf_get_dir("assets/inc/select2/select2_locale_{$lang}.js");
}
// bail early if no language
if( !$src ) return;
// enqueue
if( $lang_src ) {
wp_enqueue_script('select2-l10n', $lang_src, array('select2'), $version );
}
}
// end translation
}
// scripts
wp_enqueue_script('select2-l10n', $src, '', $version, true );
// register style
if( !isset($wp_styles->registered['select2']) ) {
wp_register_style('select2', acf_get_dir('assets/inc/select2/select2.css'), '', $version );
}
// enqueue
wp_enqueue_script('select2');
wp_enqueue_style('select2');
}

View File

@ -73,7 +73,7 @@ class acf_field_user extends acf_field {
'post_id' => 0,
's' => '',
'field_key' => '',
'paged' => 1
'paged' => 1,
));
@ -83,8 +83,8 @@ class acf_field_user extends acf_field {
// paged
$args['offset'] = 20 * ($options['paged'] - 1);
$args['number'] = 20;
$args['users_per_page'] = 20;
$args['paged'] = $options['paged'];
// load field
@ -95,20 +95,10 @@ class acf_field_user extends acf_field {
if( !$field ) return false;
// editable roles
$editable_roles = get_editable_roles();
// update $args
if( !empty($field['role']) ) {
foreach( $editable_roles as $role => $role_info ) {
if( !in_array($role, $field['role']) ) {
unset( $editable_roles[ $role ] );
}
}
$args['role'] = acf_get_array( $field['role'] );
}
@ -137,77 +127,61 @@ class acf_field_user extends acf_field {
// get users
$users = get_users( $args );
$groups = acf_get_grouped_users( $args );
if( !empty($users) && !empty($editable_roles) ) {
foreach( $editable_roles as $role => $role_info ) {
// bail early if no groups
if( empty($groups) ) return false;
// loop
foreach( array_keys($groups) as $group_title ) {
// vars
$this_users = array();
$this_json = array();
$users = acf_extract_var( $groups, $group_title );
$data = array(
'text' => $group_title,
'children' => array()
);
// loop over users
foreach( array_keys($users) as $key ) {
// append users
foreach( array_keys($users) as $user_id ) {
if( in_array($role, $users[ $key ]->roles) ) {
$users[ $user_id ] = $this->get_result( $users[ $user_id ], $field, $options['post_id'] );
// extract user
$user = acf_extract_var( $users, $key );
// append to $this_users
$this_users[ $user->ID ] = $this->get_result( $user, $field, $options['post_id'] );
}
}
// bail early if no users for this role
if( empty($this_users) ) {
continue;
}
};
// order by search
if( !empty($args['s']) ) {
$this_users = acf_order_by_search( $this_users, $args['s'] );
$users = acf_order_by_search( $users, $args['s'] );
}
// append to json
foreach( array_keys($this_users) as $user_id ) {
// append to $data
foreach( $users as $id => $title ) {
// add to json
$this_json[] = array(
'id' => $user_id,
'text' => $this_users[ $user_id ]
$data['children'][] = array(
'id' => $id,
'text' => $title
);
}
// add as optgroup or results
if( count($editable_roles) == 1 ) {
$r = $this_json;
} else {
$r[] = array(
'text' => translate_user_role( $role_info['name'] ),
'children' => $this_json
);
// append to $r
$r[] = $data;
}
}
// optgroup or single
if( !empty($args['role']) && count($args['role']) == 1 ) {
$r = $r[0]['children'];
}
@ -234,11 +208,7 @@ class acf_field_user extends acf_field {
function ajax_query() {
// validate
if( !acf_verify_ajax() ) {
die();
}
if( !acf_verify_ajax() ) die();
// get choices
@ -246,11 +216,7 @@ class acf_field_user extends acf_field {
// validate
if( !$choices ) {
die();
}
if( !$choices ) die();
// return JSON
@ -426,23 +392,12 @@ class acf_field_user extends acf_field {
function render_field_settings( $field ) {
// role
$choices = array();
$editable_roles = get_editable_roles();
foreach( $editable_roles as $role => $details ) {
// only translate the output not the value
$choices[ $role ] = translate_user_role( $details['name'] );
}
acf_render_field_setting( $field, array(
'label' => __('Filter by role','acf'),
'instructions' => '',
'type' => 'select',
'name' => 'role',
'choices' => $choices,
'choices' => acf_get_pretty_user_roles(),
'multiple' => 1,
'ui' => 1,
'allow_null' => 1,

View File

@ -215,11 +215,7 @@ class acf_form_user {
// show title
if( $user_form == 'register' ) {
$show_title = false;
}
if( $user_form === 'register' ) $show_title = false;
// args
@ -228,51 +224,53 @@ class acf_form_user {
'user_form' => $user_form
);
if( $user_id ) {
$args['user_id'] = $user_id;
}
if( $user_id ) $args['user_id'] = $user_id;
// get field groups
$field_groups = acf_get_field_groups( $args );
// render
if( !empty($field_groups) ) {
// bail early if no field groups
if( empty($field_groups) ) return;
// form data
acf_form_data(array(
'post_id' => $post_id,
'nonce' => 'user'
));
// loop
foreach( $field_groups as $field_group ) {
// vars
$fields = acf_get_fields( $field_group );
?>
<?php if( $show_title && $field_group['style'] == 'default' ): ?>
<h3><?php echo $field_group['title']; ?></h3>
<?php endif; ?>
<?php if( $el == 'tr' ): ?>
<table class="form-table">
<tbody>
<?php endif; ?>
// title
if( $show_title && $field_group['style'] === 'default' ) {
<?php acf_render_fields( $post_id, $fields, $el, 'field' ); ?>
<?php if( $el == 'tr' ): ?>
</tbody>
</table>
<?php endif; ?>
<?php
echo '<h3>' . $field_group['title'] . '</h3>';
}
// table start
if( $el == 'tr' ) echo '<table class="form-table"><tbody>';
// render fields
acf_render_fields( $post_id, $fields, $el, $field_group['instruction_placement'] );
// table end
if( $el == 'tr' ) echo '</tbody></table>';
}
}

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -29,14 +29,10 @@ extract($args);
<!-- Main -->
<div id="post-body-content">
<div id="normal-sortables" class="meta-box-sortables ui-sortable">
<?php do_meta_boxes('acf_options_page', 'normal', null); ?>
</div>
</div>
<!-- Sidebar -->
<div id="postbox-container-1" class="postbox-container">

View File

@ -371,7 +371,7 @@ class acf_field_gallery extends acf_field {
'name' => 'title',
'prefix' => $prefix,
'type' => 'text',
'label' => 'Title',
'label' => __('Title', 'acf'),
'value' => $attachment['title']
), 'tr');
@ -380,7 +380,7 @@ class acf_field_gallery extends acf_field {
'name' => 'caption',
'prefix' => $prefix,
'type' => 'textarea',
'label' => 'Caption',
'label' => __('Caption', 'acf'),
'value' => $attachment['caption']
), 'tr');
@ -389,7 +389,7 @@ class acf_field_gallery extends acf_field {
'name' => 'alt',
'prefix' => $prefix,
'type' => 'text',
'label' => 'Alt Text',
'label' => __('Alt Text', 'acf'),
'value' => $attachment['alt']
), 'tr');
@ -398,7 +398,7 @@ class acf_field_gallery extends acf_field {
'name' => 'description',
'prefix' => $prefix,
'type' => 'textarea',
'label' => 'Description',
'label' => __('Description', 'acf'),
'value' => $attachment['description']
), 'tr');

View File

@ -106,6 +106,14 @@ http://support.advancedcustomfields.com/
== Changelog ==
= 5.3.5 =
* User field: Fixed pagination bug causing missing results
* Core: Added new filter 'acf/location/screen' to customize location rules matching args
* Core: Minor fixes and improvements
* Language: Updated Dutch translation - thanks to Derk Oosterveld
* Language: Updated Italian translation - thanks to Davide Pantè
* Language: Added Swiss German translation - thanks to Raphael Hüni
= 5.3.4 =
* User field: Added pagination for Select2 results
* Tab field: Fixed issue where no tab was active within a widget