Multisite: Fix `wp_get_users_with_no_role()` possibly including users with a role on a different site.

Prior to this change, when passing another site than the current one to `wp_get_users_with_no_role()` through its `$site_id` parameter, the function still used the roles available on the current site, which would cause users with other roles that possibly exist on the other site to show up as users without a role. Switching the site before retrieving the available rules fixes the issue.

Fixes #42015.

Built from https://develop.svn.wordpress.org/trunk@41654


git-svn-id: http://core.svn.wordpress.org/trunk@41488 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Felix Arntz 2017-09-30 04:10:45 +00:00
parent 5edfea22b9
commit eedca8f3da
2 changed files with 11 additions and 2 deletions

View File

@ -2520,7 +2520,16 @@ function wp_get_users_with_no_role( $site_id = null ) {
}
$prefix = $wpdb->get_blog_prefix( $site_id );
$regex = implode( '|', array_keys( wp_roles()->get_names() ) );
if ( is_multisite() && $site_id != get_current_blog_id() ) {
switch_to_blog( $site_id );
$role_names = wp_roles()->get_names();
restore_current_blog();
} else {
$role_names = wp_roles()->get_names();
}
$regex = implode( '|', array_keys( $role_names ) );
$regex = preg_replace( '/[^a-zA-Z_\|-]/', '', $regex );
$users = $wpdb->get_col( $wpdb->prepare( "
SELECT user_id

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.9-alpha-41653';
$wp_version = '4.9-alpha-41654';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.