Don't match partial roles in WP_User_Query
.
Because 'role=ocean90' shouldn't match 'role=bocean901'. Props bocean901, ocean90. Fixes #22212. git-svn-id: https://develop.svn.wordpress.org/trunk@35101 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
d936110f7c
commit
9f551a4630
@ -304,7 +304,7 @@ class WP_User_Query {
|
|||||||
foreach ( $roles as $role ) {
|
foreach ( $roles as $role ) {
|
||||||
$roles_clauses[] = array(
|
$roles_clauses[] = array(
|
||||||
'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities',
|
'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities',
|
||||||
'value' => $role,
|
'value' => '"' . $role . '"',
|
||||||
'compare' => 'LIKE',
|
'compare' => 'LIKE',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -317,7 +317,7 @@ class WP_User_Query {
|
|||||||
foreach ( $role__in as $role ) {
|
foreach ( $role__in as $role ) {
|
||||||
$role__in_clauses[] = array(
|
$role__in_clauses[] = array(
|
||||||
'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities',
|
'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities',
|
||||||
'value' => $role,
|
'value' => '"' . $role . '"',
|
||||||
'compare' => 'LIKE',
|
'compare' => 'LIKE',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -330,7 +330,7 @@ class WP_User_Query {
|
|||||||
foreach ( $role__not_in as $role ) {
|
foreach ( $role__not_in as $role ) {
|
||||||
$role__not_in_clauses[] = array(
|
$role__not_in_clauses[] = array(
|
||||||
'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities',
|
'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities',
|
||||||
'value' => $role,
|
'value' => '"' . $role . '"',
|
||||||
'compare' => 'NOT LIKE',
|
'compare' => 'NOT LIKE',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -955,6 +955,27 @@ class Tests_User_Query extends WP_UnitTestCase {
|
|||||||
$this->assertEquals( 2, count( $users ) );
|
$this->assertEquals( 2, count( $users ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 22212
|
||||||
|
*/
|
||||||
|
public function test_get_single_role_by_string_which_is_similar() {
|
||||||
|
$editors = $this->factory->user->create_many( 2, array(
|
||||||
|
'role' => 'editor',
|
||||||
|
) );
|
||||||
|
|
||||||
|
$another_editor = $this->factory->user->create( array(
|
||||||
|
'role' => 'another-editor',
|
||||||
|
) );
|
||||||
|
|
||||||
|
$users = get_users( array(
|
||||||
|
'role' => 'editor',
|
||||||
|
'fields' => 'ids',
|
||||||
|
) );
|
||||||
|
|
||||||
|
$this->assertEqualSets( $editors, $users );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ticket 22212
|
* @ticket 22212
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user