When searching for users using the `search` arg in `get_users()`/`WP_User_Query`, also search the user's email, url, and display name.

Adds unit tests.

Props mordauk, wonderboymusic.
Fixes #27304.


git-svn-id: https://develop.svn.wordpress.org/trunk@32980 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2015-06-28 00:35:42 +00:00
parent cc762006c5
commit a796d187b3
2 changed files with 60 additions and 3 deletions

View File

@ -797,7 +797,7 @@ class WP_User_Query {
elseif ( preg_match('|^https?://|', $search) && ! ( is_multisite() && wp_is_large_network( 'users' ) ) )
$search_columns = array('user_url');
else
$search_columns = array('user_login', 'user_nicename');
$search_columns = array('user_login', 'user_url', 'user_email', 'user_nicename', 'display_name');
}
/**

View File

@ -6,6 +6,23 @@
*/
class Tests_User extends WP_UnitTestCase {
protected $user_data;
function setUp() {
parent::setUp();
$this->user_data = array(
'user_login' => 'user1',
'user_nicename' => 'userone',
'user_pass' => 'password',
'first_name' => 'John',
'last_name' => 'Doe',
'display_name' => 'John Doe',
'user_email' => 'blackburn@battlefield3.com',
'user_url' => 'http://tacos.com'
);
}
function test_get_users_of_blog() {
// add one of each user role
$nusers = array();
@ -699,4 +716,44 @@ class Tests_User extends WP_UnitTestCase {
$user = get_userdata( $user->ID );
$this->assertEmpty( $user->user_activation_key );
}
public function test_search_users_login() {
$id = $this->factory->user->create( $this->user_data );
$users = get_users( array( 'search' => 'user1', 'fields' => 'ID' ) );
$this->assertTrue( in_array( $id, $users ) );
}
public function test_search_users_url() {
$id = $this->factory->user->create( $this->user_data );
$users = get_users( array( 'search' => '*tacos*', 'fields' => 'ID' ) );
$this->assertTrue( in_array( $id, $users ) );
}
public function test_search_users_email() {
$id = $this->factory->user->create( $this->user_data );
$users = get_users( array( 'search' => '*battle*', 'fields' => 'ID' ) );
$this->assertTrue( in_array( $id, $users ) );
}
public function test_search_users_nicename() {
$id = $this->factory->user->create( $this->user_data );
$users = get_users( array( 'search' => '*one*', 'fields' => 'ID' ) );
$this->assertTrue( in_array( $id, $users ) );
}
public function test_search_users_display_name() {
$id = $this->factory->user->create( $this->user_data );
$users = get_users( array( 'search' => '*Doe*', 'fields' => 'ID' ) );
$this->assertTrue( in_array( $id, $users ) );
}
}