diff --git src/wp-admin/includes/class-wp-users-list-table.php src/wp-admin/includes/class-wp-users-list-table.php
index f557c2b459..7637896880 100644
|
|
|
class WP_Users_List_Table extends WP_List_Table { |
| 98 | 98 | $args = array( |
| 99 | 99 | 'number' => $users_per_page, |
| 100 | 100 | 'offset' => ( $paged-1 ) * $users_per_page, |
| 101 | | 'include' => wp_get_users_with_no_role(), |
| | 101 | 'include' => wp_get_users_with_no_role( $this->site_id ), |
| 102 | 102 | 'search' => $usersearch, |
| 103 | 103 | 'fields' => 'all_with_meta' |
| 104 | 104 | ); |
| … |
… |
class WP_Users_List_Table extends WP_List_Table { |
| 177 | 177 | if ( $this->is_site_users ) { |
| 178 | 178 | $url = 'site-users.php?id=' . $this->site_id; |
| 179 | 179 | switch_to_blog( $this->site_id ); |
| 180 | | $users_of_blog = count_users(); |
| | 180 | $users_of_blog = count_users( 'time', $this->site_id ); |
| 181 | 181 | restore_current_blog(); |
| 182 | 182 | } else { |
| 183 | 183 | $url = 'users.php'; |
| … |
… |
class WP_Users_List_Table extends WP_List_Table { |
| 369 | 369 | $post_counts = count_many_users_posts( array_keys( $this->items ) ); |
| 370 | 370 | |
| 371 | 371 | foreach ( $this->items as $userid => $user_object ) { |
| 372 | | if ( is_multisite() && empty( $user_object->allcaps ) ) |
| 373 | | continue; |
| 374 | | |
| 375 | 372 | echo "\n\t" . $this->single_row( $user_object, '', '', isset( $post_counts ) ? $post_counts[ $userid ] : 0 ); |
| 376 | 373 | } |
| 377 | 374 | } |
diff --git src/wp-includes/user.php src/wp-includes/user.php
index 5615650692..a0e699c2c1 100644
|
|
|
function update_user_meta($user_id, $meta_key, $meta_value, $prev_value = '') { |
| 838 | 838 | * |
| 839 | 839 | * @since 3.0.0 |
| 840 | 840 | * @since 4.4.0 The number of users with no role is now included in the `none` element. |
| | 841 | * @since 4.9.0 The `$site_id` parameter was added to support multisite. |
| 841 | 842 | * |
| 842 | 843 | * @global wpdb $wpdb WordPress database abstraction object. |
| 843 | 844 | * |
| 844 | | * @param string $strategy 'time' or 'memory' |
| | 845 | * @param string $strategy Optional. The computational strategy to use when counting the users. |
| | 846 | * Accepts either 'time' or 'memory'. Default 'time'. |
| | 847 | * @param int|null $site_id Optional. The site ID to count users for. Defaults to the current site. |
| 845 | 848 | * @return array Includes a grand total and an array of counts indexed by role strings. |
| 846 | 849 | */ |
| 847 | | function count_users($strategy = 'time') { |
| | 850 | function count_users( $strategy = 'time', $site_id = null ) { |
| 848 | 851 | global $wpdb; |
| 849 | 852 | |
| 850 | 853 | // Initialize |
| 851 | | $id = get_current_blog_id(); |
| 852 | | $blog_prefix = $wpdb->get_blog_prefix($id); |
| | 854 | if ( ! $site_id ) { |
| | 855 | $site_id = get_current_blog_id(); |
| | 856 | } |
| | 857 | $blog_prefix = $wpdb->get_blog_prefix( $site_id ); |
| 853 | 858 | $result = array(); |
| 854 | 859 | |
| 855 | 860 | if ( 'time' == $strategy ) { |
| … |
… |
function count_users($strategy = 'time') { |
| 920 | 925 | $result['avail_roles'] =& $avail_roles; |
| 921 | 926 | } |
| 922 | 927 | |
| 923 | | if ( is_multisite() ) { |
| 924 | | $result['avail_roles']['none'] = 0; |
| 925 | | } |
| 926 | | |
| 927 | 928 | return $result; |
| 928 | 929 | } |
| 929 | 930 | |
| … |
… |
function wp_destroy_all_sessions() { |
| 2483 | 2484 | /** |
| 2484 | 2485 | * Get the user IDs of all users with no role on this site. |
| 2485 | 2486 | * |
| 2486 | | * This function returns an empty array when used on Multisite. |
| 2487 | | * |
| 2488 | 2487 | * @since 4.4.0 |
| | 2488 | * @since 4.9.0 The `$site_id` parameter was added to support multisite. |
| 2489 | 2489 | * |
| | 2490 | * @param int|null $site_id Optional. The site ID to get users with no role for. Defaults to the current site. |
| 2490 | 2491 | * @return array Array of user IDs. |
| 2491 | 2492 | */ |
| 2492 | | function wp_get_users_with_no_role() { |
| | 2493 | function wp_get_users_with_no_role( $site_id = null ) { |
| 2493 | 2494 | global $wpdb; |
| 2494 | 2495 | |
| 2495 | | if ( is_multisite() ) { |
| 2496 | | return array(); |
| | 2496 | if ( ! $site_id ) { |
| | 2497 | $site_id = get_current_blog_id(); |
| 2497 | 2498 | } |
| 2498 | 2499 | |
| 2499 | | $prefix = $wpdb->get_blog_prefix(); |
| | 2500 | $prefix = $wpdb->get_blog_prefix( $site_id ); |
| 2500 | 2501 | $regex = implode( '|', array_keys( wp_roles()->get_names() ) ); |
| 2501 | 2502 | $regex = preg_replace( '/[^a-zA-Z_\|-]/', '', $regex ); |
| 2502 | 2503 | $users = $wpdb->get_col( $wpdb->prepare( " |
diff --git tests/phpunit/tests/user/countUsers.php tests/phpunit/tests/user/countUsers.php
index f5fa6b9356..115b4baa73 100644
|
|
|
class Tests_User_CountUsers extends WP_UnitTestCase { |
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * @ticket 22993 |
| | 55 | * @ticket 36196 |
| 55 | 56 | * @group multisite |
| 56 | 57 | * @group ms-required |
| 57 | 58 | * |
| … |
… |
class Tests_User_CountUsers extends WP_UnitTestCase { |
| 103 | 104 | 'author' => 1, |
| 104 | 105 | 'contributor' => 1, |
| 105 | 106 | 'subscriber' => 1, |
| 106 | | 'none' => 0, |
| | 107 | 'none' => 2, |
| 107 | 108 | ), $count['avail_roles'] ); |
| 108 | 109 | |
| 109 | 110 | // Test users counts on blog 1 |
diff --git tests/phpunit/tests/user/wpGetUsersWithNoRole.php tests/phpunit/tests/user/wpGetUsersWithNoRole.php
index 82c0da73bf..10ecf2a565 100644
|
|
|
class Tests_User_GetUsersWithNoRole extends WP_UnitTestCase { |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * @ticket 22993 |
| | 39 | * @ticket 36196 |
| 39 | 40 | * @group multisite |
| 40 | 41 | * @group ms-required |
| 41 | 42 | */ |
| … |
… |
class Tests_User_GetUsersWithNoRole extends WP_UnitTestCase { |
| 56 | 57 | 'user_id' => $editor, |
| 57 | 58 | ) ); |
| 58 | 59 | |
| 59 | | // Add users to blogs |
| | 60 | // Add editor to blog 1 |
| 60 | 61 | add_user_to_blog( $blog_1, $editor, 'editor' ); |
| 61 | 62 | |
| 62 | 63 | // Test users on root site |
| 63 | 64 | $users = wp_get_users_with_no_role(); |
| 64 | | $this->assertSame( array(), $users ); |
| | 65 | $this->assertSame( array( |
| | 66 | "{$nobody}", |
| | 67 | ), $users ); |
| 65 | 68 | |
| 66 | 69 | // Test users counts on blog 1 |
| 67 | | switch_to_blog( $blog_1 ); |
| 68 | | $users = wp_get_users_with_no_role(); |
| 69 | | restore_current_blog(); |
| 70 | | |
| 71 | | // Test users on root site |
| | 70 | $users = wp_get_users_with_no_role( $blog_1 ); |
| 72 | 71 | $this->assertSame( array(), $users ); |
| 73 | 72 | |
| | 73 | // Add admin to blog 1 with no role |
| | 74 | add_user_to_blog( $blog_1, $admin, '' ); |
| | 75 | |
| | 76 | // Re-test users counts on blog 1 |
| | 77 | $users = wp_get_users_with_no_role( $blog_1 ); |
| | 78 | $this->assertSame( array( |
| | 79 | "{$admin}", |
| | 80 | ), $users ); |
| 74 | 81 | } |
| 75 | 82 | |
| 76 | 83 | /** |