Merge branch 'release/5.3.5'
This commit is contained in:
commit
98a7bcd711
4
acf.php
4
acf.php
|
|
@ -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.4
|
Version: 5.3.5
|
||||||
Author: elliot condon
|
Author: elliot condon
|
||||||
Author URI: http://www.elliotcondon.com/
|
Author URI: http://www.elliotcondon.com/
|
||||||
Copyright: Elliot Condon
|
Copyright: Elliot Condon
|
||||||
|
|
@ -61,7 +61,7 @@ class acf {
|
||||||
|
|
||||||
// basic
|
// basic
|
||||||
'name' => __('Advanced Custom Fields', 'acf'),
|
'name' => __('Advanced Custom Fields', 'acf'),
|
||||||
'version' => '5.3.4',
|
'version' => '5.3.5',
|
||||||
|
|
||||||
// urls
|
// urls
|
||||||
'basename' => plugin_basename( __FILE__ ),
|
'basename' => plugin_basename( __FILE__ ),
|
||||||
|
|
|
||||||
|
|
@ -1581,11 +1581,7 @@ function acf_get_grouped_posts( $args ) {
|
||||||
|
|
||||||
|
|
||||||
// bail early if no posts for this post type
|
// bail early if no posts for this post type
|
||||||
if( empty($this_posts) ) {
|
if( empty($this_posts) ) continue;
|
||||||
|
|
||||||
continue;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// sort into hierachial order!
|
// sort into hierachial order!
|
||||||
|
|
@ -1632,13 +1628,17 @@ function acf_get_grouped_posts( $args ) {
|
||||||
// append
|
// append
|
||||||
for( $i = $offset; $i < ($offset + $length); $i++ ) {
|
for( $i = $offset; $i < ($offset + $length); $i++ ) {
|
||||||
|
|
||||||
$this_posts[] = acf_extract_var( $all_posts, $i);
|
$this_posts[] = acf_extract_var( $all_posts, $i );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// clean up null values
|
||||||
|
$this_posts = array_filter($this_posts);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// populate $this_posts
|
// populate $this_posts
|
||||||
foreach( array_keys($this_posts) as $key ) {
|
foreach( array_keys($this_posts) as $key ) {
|
||||||
|
|
||||||
|
|
@ -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
|
* acf_json_encode
|
||||||
|
|
@ -2089,37 +2284,42 @@ function acf_get_updates() {
|
||||||
* @return $post_id (int)
|
* @return $post_id (int)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function acf_encode_choices( $array = array() ) {
|
function acf_encode_choices( $array = array(), $show_keys = true ) {
|
||||||
|
|
||||||
// bail early if not array
|
// bail early if not array (maybe a single string)
|
||||||
if( !is_array($array) ) {
|
if( !is_array($array) ) return $array;
|
||||||
|
|
||||||
return $array;
|
|
||||||
|
// bail early if empty array
|
||||||
}
|
if( empty($array) ) return '';
|
||||||
|
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
$string = '';
|
$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 ) {
|
foreach( $array as $k => $v ) {
|
||||||
|
|
||||||
if( $k !== $v ) {
|
// ignore if key and value are the same
|
||||||
|
if( $k === $v ) continue;
|
||||||
$array[ $k ] = $k . ' : ' . $v;
|
|
||||||
|
|
||||||
}
|
// show key in the value
|
||||||
|
$array[ $k ] = $k . ' : ' . $v;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$string = implode("\n", $array);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// implode
|
||||||
|
$string = implode("\n", $array);
|
||||||
|
|
||||||
|
|
||||||
// return
|
// return
|
||||||
return $string;
|
return $string;
|
||||||
|
|
||||||
|
|
@ -2127,20 +2327,25 @@ function acf_encode_choices( $array = array() ) {
|
||||||
|
|
||||||
function acf_decode_choices( $string = '' ) {
|
function acf_decode_choices( $string = '' ) {
|
||||||
|
|
||||||
// validate
|
// bail early if already array
|
||||||
if( $string === '') {
|
if( is_array($string) ) {
|
||||||
|
|
||||||
return array();
|
|
||||||
|
|
||||||
|
return $string;
|
||||||
|
|
||||||
// allow numeric values (same as string)
|
// allow numeric values (same as string)
|
||||||
} elseif( is_numeric($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) ) {
|
} elseif( !is_string($string) ) {
|
||||||
|
|
||||||
return array();
|
return array();
|
||||||
|
|
||||||
|
// bail early if is empty string
|
||||||
|
} elseif( $string === '' ) {
|
||||||
|
|
||||||
|
return array();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2949,32 +2949,38 @@ var acf;
|
||||||
acf.add_action('before_duplicate', function( $orig ){
|
acf.add_action('before_duplicate', function( $orig ){
|
||||||
|
|
||||||
// save select values
|
// save select values
|
||||||
$orig.find('select').each(function(){
|
$orig.find('select option:selected').addClass('selected');
|
||||||
|
|
||||||
$(this).find(':selected').addClass('selected');
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
acf.add_action('after_duplicate', function( $orig, $duplicate ){
|
acf.add_action('after_duplicate', function( $orig, $duplicate ){
|
||||||
|
|
||||||
// restore select values
|
// restore select values
|
||||||
$orig.find('select').each(function(){
|
$orig.find('select option.selected').removeClass('selected');
|
||||||
|
|
||||||
$(this).find('.selected').removeClass('selected');
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// set select values
|
// set select values
|
||||||
$duplicate.find('select').each(function(){
|
$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!
|
// remove the blank option as we have a clear all button!
|
||||||
if( args.allow_null ) {
|
if( args.allow_null ) {
|
||||||
|
|
||||||
|
|
@ -7453,7 +7461,7 @@ var acf;
|
||||||
|
|
||||||
|
|
||||||
// disbale select
|
// 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
|
// show input so that select2 can correctly render visible select2 container
|
||||||
$select.siblings('input').show();
|
$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
|
|
@ -465,7 +465,7 @@ class acf_location {
|
||||||
|
|
||||||
|
|
||||||
// find post format
|
// find post format
|
||||||
if( !$post_format ) {
|
if( !$post_status ) {
|
||||||
|
|
||||||
// bail early if not a post
|
// bail early if not a post
|
||||||
if( !$options['post_id'] ) return false;
|
if( !$options['post_id'] ) return false;
|
||||||
|
|
@ -1196,23 +1196,19 @@ function acf_get_field_group_visibility( $field_group, $args = array() ) {
|
||||||
'attachment' => 0,
|
'attachment' => 0,
|
||||||
'comment' => 0,
|
'comment' => 0,
|
||||||
'widget' => 0,
|
'widget' => 0,
|
||||||
'lang' => 0,
|
'lang' => acf_get_setting('current_language'),
|
||||||
'ajax' => false
|
'ajax' => false
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
|
// filter for 3rd party customization
|
||||||
|
$args = apply_filters('acf/location/screen', $args, $field_group);
|
||||||
|
|
||||||
|
|
||||||
// bail early if not active
|
// bail early if not active
|
||||||
if( !$field_group['active'] ) return false;
|
if( !$field_group['active'] ) return false;
|
||||||
|
|
||||||
|
|
||||||
// WPML
|
|
||||||
if( defined('ICL_LANGUAGE_CODE') ) {
|
|
||||||
|
|
||||||
$args['lang'] = ICL_LANGUAGE_CODE;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
$visibility = false;
|
$visibility = false;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,11 +40,7 @@ class acf_wpml_compatibility {
|
||||||
|
|
||||||
|
|
||||||
// bail early if not transaltable
|
// bail early if not transaltable
|
||||||
if( !$this->is_translatable() ) {
|
if( !$this->is_translatable() ) return;
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// actions
|
// actions
|
||||||
|
|
|
||||||
|
|
@ -200,7 +200,7 @@ class acf_field_checkbox extends acf_field {
|
||||||
|
|
||||||
// encode choices (convert from array)
|
// encode choices (convert from array)
|
||||||
$field['choices'] = acf_encode_choices($field['choices']);
|
$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
|
// choices
|
||||||
|
|
|
||||||
|
|
@ -93,11 +93,9 @@ class acf_field_post_object extends acf_field {
|
||||||
// load field
|
// load field
|
||||||
$field = acf_get_field( $options['field_key'] );
|
$field = acf_get_field( $options['field_key'] );
|
||||||
|
|
||||||
if( !$field ) {
|
|
||||||
|
|
||||||
return false;
|
// bail early if no field
|
||||||
|
if( !$field ) return false;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// update $args
|
// update $args
|
||||||
|
|
|
||||||
|
|
@ -346,7 +346,7 @@ class acf_field_select extends acf_field {
|
||||||
|
|
||||||
// encode choices (convert from array)
|
// encode choices (convert from array)
|
||||||
$field['choices'] = acf_encode_choices($field['choices']);
|
$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
|
// choices
|
||||||
|
|
@ -551,10 +551,15 @@ class acf_field_select extends acf_field {
|
||||||
|
|
||||||
function enqueue_assets() {
|
function enqueue_assets() {
|
||||||
|
|
||||||
|
// globals
|
||||||
|
global $wp_scripts, $wp_styles;
|
||||||
|
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
$version = '3.5.2';
|
$version = '3.5.2';
|
||||||
$lang = get_locale();
|
$lang = get_locale();
|
||||||
$min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
|
$min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
|
||||||
|
//$lang = 'fr';
|
||||||
|
|
||||||
|
|
||||||
// v4
|
// v4
|
||||||
|
|
@ -564,43 +569,62 @@ class acf_field_select extends acf_field {
|
||||||
return;
|
return;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// scripts
|
|
||||||
wp_enqueue_script('select2', acf_get_dir("assets/inc/select2/select2{$min}.js"), array('jquery'), $version, true );
|
// register script
|
||||||
|
if( !isset($wp_scripts->registered['select2']) ) {
|
||||||
|
|
||||||
// styles
|
|
||||||
wp_enqueue_style('select2', acf_get_dir('assets/inc/select2/select2.css'), '', $version );
|
|
||||||
|
|
||||||
|
|
||||||
// bail early if no language
|
|
||||||
if( !$lang ) return;
|
|
||||||
|
|
||||||
|
|
||||||
// vars
|
|
||||||
$lang = str_replace('_', '-', $lang);
|
|
||||||
$lang_code = substr($lang, 0, 2);
|
|
||||||
$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");
|
// scripts
|
||||||
|
wp_register_script('select2', acf_get_dir("assets/inc/select2/select2{$min}.js"), array('jquery'), $version );
|
||||||
|
|
||||||
|
|
||||||
} elseif( file_exists(acf_get_path("assets/inc/select2/select2_locale_{$lang}.js")) ) {
|
// translation
|
||||||
|
if( $lang ) {
|
||||||
$src = acf_get_dir("assets/inc/select2/select2_locale_{$lang}.js");
|
|
||||||
|
// vars
|
||||||
|
$lang = str_replace('_', '-', $lang);
|
||||||
|
$lang_code = substr($lang, 0, 2);
|
||||||
|
$lang_src = '';
|
||||||
|
|
||||||
|
|
||||||
|
// attempt 1
|
||||||
|
if( file_exists(acf_get_path("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")) ) {
|
||||||
|
|
||||||
|
$lang_src = acf_get_dir("assets/inc/select2/select2_locale_{$lang}.js");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// enqueue
|
||||||
|
if( $lang_src ) {
|
||||||
|
|
||||||
|
wp_enqueue_script('select2-l10n', $lang_src, array('select2'), $version );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// end translation
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// bail early if no language
|
// register style
|
||||||
if( !$src ) return;
|
if( !isset($wp_styles->registered['select2']) ) {
|
||||||
|
|
||||||
|
wp_register_style('select2', acf_get_dir('assets/inc/select2/select2.css'), '', $version );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// scripts
|
// enqueue
|
||||||
wp_enqueue_script('select2-l10n', $src, '', $version, true );
|
wp_enqueue_script('select2');
|
||||||
|
wp_enqueue_style('select2');
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
167
fields/user.php
167
fields/user.php
|
|
@ -70,10 +70,10 @@ class acf_field_user extends acf_field {
|
||||||
|
|
||||||
// defaults
|
// defaults
|
||||||
$options = acf_parse_args($options, array(
|
$options = acf_parse_args($options, array(
|
||||||
'post_id' => 0,
|
'post_id' => 0,
|
||||||
's' => '',
|
's' => '',
|
||||||
'field_key' => '',
|
'field_key' => '',
|
||||||
'paged' => 1
|
'paged' => 1,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -83,8 +83,8 @@ class acf_field_user extends acf_field {
|
||||||
|
|
||||||
|
|
||||||
// paged
|
// paged
|
||||||
$args['offset'] = 20 * ($options['paged'] - 1);
|
$args['users_per_page'] = 20;
|
||||||
$args['number'] = 20;
|
$args['paged'] = $options['paged'];
|
||||||
|
|
||||||
|
|
||||||
// load field
|
// load field
|
||||||
|
|
@ -95,24 +95,14 @@ class acf_field_user extends acf_field {
|
||||||
if( !$field ) return false;
|
if( !$field ) return false;
|
||||||
|
|
||||||
|
|
||||||
// editable roles
|
// update $args
|
||||||
$editable_roles = get_editable_roles();
|
|
||||||
|
|
||||||
if( !empty($field['role']) ) {
|
if( !empty($field['role']) ) {
|
||||||
|
|
||||||
foreach( $editable_roles as $role => $role_info ) {
|
$args['role'] = acf_get_array( $field['role'] );
|
||||||
|
|
||||||
if( !in_array($role, $field['role']) ) {
|
|
||||||
|
|
||||||
unset( $editable_roles[ $role ] );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// search
|
// search
|
||||||
if( $options['s'] ) {
|
if( $options['s'] ) {
|
||||||
|
|
||||||
|
|
@ -137,78 +127,62 @@ class acf_field_user extends acf_field {
|
||||||
|
|
||||||
|
|
||||||
// get users
|
// get users
|
||||||
$users = get_users( $args );
|
$groups = acf_get_grouped_users( $args );
|
||||||
|
|
||||||
if( !empty($users) && !empty($editable_roles) ) {
|
|
||||||
|
// bail early if no groups
|
||||||
|
if( empty($groups) ) return false;
|
||||||
|
|
||||||
|
|
||||||
|
// loop
|
||||||
|
foreach( array_keys($groups) as $group_title ) {
|
||||||
|
|
||||||
foreach( $editable_roles as $role => $role_info ) {
|
// vars
|
||||||
|
$users = acf_extract_var( $groups, $group_title );
|
||||||
|
$data = array(
|
||||||
|
'text' => $group_title,
|
||||||
|
'children' => array()
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// append users
|
||||||
|
foreach( array_keys($users) as $user_id ) {
|
||||||
|
|
||||||
// vars
|
$users[ $user_id ] = $this->get_result( $users[ $user_id ], $field, $options['post_id'] );
|
||||||
$this_users = array();
|
|
||||||
$this_json = array();
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// order by search
|
||||||
|
if( !empty($args['s']) ) {
|
||||||
|
|
||||||
// loop over users
|
$users = acf_order_by_search( $users, $args['s'] );
|
||||||
foreach( array_keys($users) as $key ) {
|
|
||||||
|
|
||||||
if( in_array($role, $users[ $key ]->roles) ) {
|
|
||||||
|
|
||||||
// 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'] );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// append to json
|
|
||||||
foreach( array_keys($this_users) as $user_id ) {
|
|
||||||
|
|
||||||
// add to json
|
|
||||||
$this_json[] = array(
|
|
||||||
'id' => $user_id,
|
|
||||||
'text' => $this_users[ $user_id ]
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 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 $data
|
||||||
|
foreach( $users as $id => $title ) {
|
||||||
|
|
||||||
|
$data['children'][] = array(
|
||||||
|
'id' => $id,
|
||||||
|
'text' => $title
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 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() {
|
function ajax_query() {
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
if( !acf_verify_ajax() ) {
|
if( !acf_verify_ajax() ) die();
|
||||||
|
|
||||||
die();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get choices
|
// get choices
|
||||||
|
|
@ -246,11 +216,7 @@ class acf_field_user extends acf_field {
|
||||||
|
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
if( !$choices ) {
|
if( !$choices ) die();
|
||||||
|
|
||||||
die();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// return JSON
|
// return JSON
|
||||||
|
|
@ -426,23 +392,12 @@ class acf_field_user extends acf_field {
|
||||||
|
|
||||||
function render_field_settings( $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(
|
acf_render_field_setting( $field, array(
|
||||||
'label' => __('Filter by role','acf'),
|
'label' => __('Filter by role','acf'),
|
||||||
'instructions' => '',
|
'instructions' => '',
|
||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
'name' => 'role',
|
'name' => 'role',
|
||||||
'choices' => $choices,
|
'choices' => acf_get_pretty_user_roles(),
|
||||||
'multiple' => 1,
|
'multiple' => 1,
|
||||||
'ui' => 1,
|
'ui' => 1,
|
||||||
'allow_null' => 1,
|
'allow_null' => 1,
|
||||||
|
|
|
||||||
|
|
@ -215,11 +215,7 @@ class acf_form_user {
|
||||||
|
|
||||||
|
|
||||||
// show title
|
// show title
|
||||||
if( $user_form == 'register' ) {
|
if( $user_form === 'register' ) $show_title = false;
|
||||||
|
|
||||||
$show_title = false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// args
|
// args
|
||||||
|
|
@ -228,51 +224,53 @@ class acf_form_user {
|
||||||
'user_form' => $user_form
|
'user_form' => $user_form
|
||||||
);
|
);
|
||||||
|
|
||||||
if( $user_id ) {
|
if( $user_id ) $args['user_id'] = $user_id;
|
||||||
|
|
||||||
$args['user_id'] = $user_id;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get field groups
|
// get field groups
|
||||||
$field_groups = acf_get_field_groups( $args );
|
$field_groups = acf_get_field_groups( $args );
|
||||||
|
|
||||||
|
|
||||||
// render
|
// bail early if no field groups
|
||||||
if( !empty($field_groups) ) {
|
if( empty($field_groups) ) return;
|
||||||
|
|
||||||
acf_form_data(array(
|
|
||||||
'post_id' => $post_id,
|
|
||||||
'nonce' => 'user'
|
|
||||||
));
|
|
||||||
|
|
||||||
foreach( $field_groups as $field_group ) {
|
|
||||||
|
|
||||||
$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; ?>
|
|
||||||
|
|
||||||
<?php acf_render_fields( $post_id, $fields, $el, 'field' ); ?>
|
|
||||||
|
|
||||||
<?php if( $el == 'tr' ): ?>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
// 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 );
|
||||||
|
|
||||||
|
|
||||||
|
// title
|
||||||
|
if( $show_title && $field_group['style'] === 'default' ) {
|
||||||
|
|
||||||
|
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
|
|
@ -29,12 +29,8 @@ extract($args);
|
||||||
<!-- Main -->
|
<!-- Main -->
|
||||||
<div id="post-body-content">
|
<div id="post-body-content">
|
||||||
|
|
||||||
<div id="normal-sortables" class="meta-box-sortables ui-sortable">
|
<?php do_meta_boxes('acf_options_page', 'normal', null); ?>
|
||||||
|
|
||||||
<?php do_meta_boxes('acf_options_page', 'normal', null); ?>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Sidebar -->
|
<!-- Sidebar -->
|
||||||
|
|
|
||||||
|
|
@ -371,7 +371,7 @@ class acf_field_gallery extends acf_field {
|
||||||
'name' => 'title',
|
'name' => 'title',
|
||||||
'prefix' => $prefix,
|
'prefix' => $prefix,
|
||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
'label' => 'Title',
|
'label' => __('Title', 'acf'),
|
||||||
'value' => $attachment['title']
|
'value' => $attachment['title']
|
||||||
), 'tr');
|
), 'tr');
|
||||||
|
|
||||||
|
|
@ -380,7 +380,7 @@ class acf_field_gallery extends acf_field {
|
||||||
'name' => 'caption',
|
'name' => 'caption',
|
||||||
'prefix' => $prefix,
|
'prefix' => $prefix,
|
||||||
'type' => 'textarea',
|
'type' => 'textarea',
|
||||||
'label' => 'Caption',
|
'label' => __('Caption', 'acf'),
|
||||||
'value' => $attachment['caption']
|
'value' => $attachment['caption']
|
||||||
), 'tr');
|
), 'tr');
|
||||||
|
|
||||||
|
|
@ -389,7 +389,7 @@ class acf_field_gallery extends acf_field {
|
||||||
'name' => 'alt',
|
'name' => 'alt',
|
||||||
'prefix' => $prefix,
|
'prefix' => $prefix,
|
||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
'label' => 'Alt Text',
|
'label' => __('Alt Text', 'acf'),
|
||||||
'value' => $attachment['alt']
|
'value' => $attachment['alt']
|
||||||
), 'tr');
|
), 'tr');
|
||||||
|
|
||||||
|
|
@ -398,7 +398,7 @@ class acf_field_gallery extends acf_field {
|
||||||
'name' => 'description',
|
'name' => 'description',
|
||||||
'prefix' => $prefix,
|
'prefix' => $prefix,
|
||||||
'type' => 'textarea',
|
'type' => 'textarea',
|
||||||
'label' => 'Description',
|
'label' => __('Description', 'acf'),
|
||||||
'value' => $attachment['description']
|
'value' => $attachment['description']
|
||||||
), 'tr');
|
), 'tr');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,14 @@ http://support.advancedcustomfields.com/
|
||||||
|
|
||||||
== Changelog ==
|
== 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 =
|
= 5.3.4 =
|
||||||
* User field: Added pagination for Select2 results
|
* User field: Added pagination for Select2 results
|
||||||
* Tab field: Fixed issue where no tab was active within a widget
|
* Tab field: Fixed issue where no tab was active within a widget
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue