Ensure that `WP_User_Query` vars are filled after 'pre_get_users'.
This prevents notices from being thrown when a 'pre_get_users' callback removes required values from the list of `query_vars`. For backward compatibility with previous uses of 'pre_get_users', default values are parsed both before and after the action is fired. Fixes #33449. Built from https://develop.svn.wordpress.org/trunk@34804 git-svn-id: http://core.svn.wordpress.org/trunk@34769 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
86f8dedf68
commit
198dee542d
|
@ -75,6 +75,40 @@ class WP_User_Query {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fills in missing query variables with default values.
|
||||||
|
*
|
||||||
|
* @since 4.4.0
|
||||||
|
* @access public
|
||||||
|
*
|
||||||
|
* @param array $args Query vars, as passed to `WP_User_Query`.
|
||||||
|
* @return array Complete query variables with undefined ones filled in with defaults.
|
||||||
|
*/
|
||||||
|
public static function fill_query_vars( $args ) {
|
||||||
|
$defaults = array(
|
||||||
|
'blog_id' => $GLOBALS['blog_id'],
|
||||||
|
'role' => '',
|
||||||
|
'meta_key' => '',
|
||||||
|
'meta_value' => '',
|
||||||
|
'meta_compare' => '',
|
||||||
|
'include' => array(),
|
||||||
|
'exclude' => array(),
|
||||||
|
'search' => '',
|
||||||
|
'search_columns' => array(),
|
||||||
|
'orderby' => 'login',
|
||||||
|
'order' => 'ASC',
|
||||||
|
'offset' => '',
|
||||||
|
'number' => '',
|
||||||
|
'paged' => 1,
|
||||||
|
'count_total' => true,
|
||||||
|
'fields' => 'all',
|
||||||
|
'who' => '',
|
||||||
|
'has_published_posts' => null,
|
||||||
|
);
|
||||||
|
|
||||||
|
return wp_parse_args( $args, $defaults );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare the query variables.
|
* Prepare the query variables.
|
||||||
*
|
*
|
||||||
|
@ -146,26 +180,7 @@ class WP_User_Query {
|
||||||
|
|
||||||
if ( empty( $this->query_vars ) || ! empty( $query ) ) {
|
if ( empty( $this->query_vars ) || ! empty( $query ) ) {
|
||||||
$this->query_limit = null;
|
$this->query_limit = null;
|
||||||
$this->query_vars = wp_parse_args( $query, array(
|
$this->query_vars = $this->fill_query_vars( $query );
|
||||||
'blog_id' => $GLOBALS['blog_id'],
|
|
||||||
'role' => '',
|
|
||||||
'meta_key' => '',
|
|
||||||
'meta_value' => '',
|
|
||||||
'meta_compare' => '',
|
|
||||||
'include' => array(),
|
|
||||||
'exclude' => array(),
|
|
||||||
'search' => '',
|
|
||||||
'search_columns' => array(),
|
|
||||||
'orderby' => 'login',
|
|
||||||
'order' => 'ASC',
|
|
||||||
'offset' => '',
|
|
||||||
'number' => '',
|
|
||||||
'paged' => 1,
|
|
||||||
'count_total' => true,
|
|
||||||
'fields' => 'all',
|
|
||||||
'who' => '',
|
|
||||||
'has_published_posts' => null,
|
|
||||||
) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -181,7 +196,9 @@ class WP_User_Query {
|
||||||
*/
|
*/
|
||||||
do_action( 'pre_get_users', $this );
|
do_action( 'pre_get_users', $this );
|
||||||
|
|
||||||
|
// Ensure that query vars are filled after 'pre_get_users'.
|
||||||
$qv =& $this->query_vars;
|
$qv =& $this->query_vars;
|
||||||
|
$qv = $this->fill_query_vars( $qv );
|
||||||
|
|
||||||
if ( is_array( $qv['fields'] ) ) {
|
if ( is_array( $qv['fields'] ) ) {
|
||||||
$qv['fields'] = array_unique( $qv['fields'] );
|
$qv['fields'] = array_unique( $qv['fields'] );
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.4-alpha-34803';
|
$wp_version = '4.4-alpha-34804';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue