mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@34804 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -874,4 +874,26 @@ class Tests_User_Query extends WP_UnitTestCase {
|
||||
|
||||
$this->assertEquals( array( $users[2], $users[1] ), $q->results );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 33449
|
||||
*/
|
||||
public function test_query_vars_should_be_filled_in_after_pre_get_users() {
|
||||
$query_vars = array( 'blog_id', 'role', 'meta_key', 'meta_value', 'meta_compare', 'include', 'exclude', 'search', 'search_columns', 'orderby', 'order', 'offset', 'number', 'paged', 'count_total', 'fields', 'who', 'has_published_posts' );
|
||||
|
||||
add_action( 'pre_get_users', array( $this, 'filter_pre_get_users_args' ) );
|
||||
$q = new WP_User_Query( array_fill_keys( $query_vars, '1' ) );
|
||||
remove_action( 'pre_get_users', array( $this, 'filter_pre_get_users_args' ) );
|
||||
|
||||
foreach ( $query_vars as $query_var ) {
|
||||
$this->assertTrue( array_key_exists( $query_var, $q->query_vars ), "$query_var does not exist." );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function filter_pre_get_users_args( $q ) {
|
||||
foreach ( $q->query_vars as $k => $v ) {
|
||||
unset( $q->query_vars[ $k ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user