WordPress.org

Make WordPress Core

Ticket #36196: 36196.3.diff

File 36196.3.diff, 3.3 KB (added by scottlee, 4 years ago)

Refreshed patch.

  • src/wp-admin/includes/class-wp-users-list-table.php

     
    9898                        $args = array(
    9999                                'number' => $users_per_page,
    100100                                '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 ),
    102102                                'search' => $usersearch,
    103103                                'fields' => 'all_with_meta'
    104104                        );
     
    177177                if ( $this->is_site_users ) {
    178178                        $url = 'site-users.php?id=' . $this->site_id;
    179179                        switch_to_blog( $this->site_id );
    180                         $users_of_blog = count_users();
     180                        $users_of_blog = count_users( 'time', $this->site_id );
    181181                        restore_current_blog();
    182182                } else {
    183183                        $url = 'users.php';
     
    357357                        $post_counts = count_many_users_posts( array_keys( $this->items ) );
    358358
    359359                foreach ( $this->items as $userid => $user_object ) {
    360                         if ( is_multisite() && empty( $user_object->allcaps ) )
    361                                 continue;
    362 
    363360                        echo "\n\t" . $this->single_row( $user_object, '', '', isset( $post_counts ) ? $post_counts[ $userid ] : 0 );
    364361                }
    365362        }
  • src/wp-includes/user.php

     
    831831 *
    832832 * @since 3.0.0
    833833 * @since 4.4.0 The number of users with no role is now included in the `none` element.
     834 * @since 4.7.0 The `$site_id` parameter was added to support multisite.
    834835 *
    835836 * @global wpdb $wpdb WordPress database abstraction object.
    836837 *
    837838 * @param string $strategy 'time' or 'memory'
     839 * @param int|null $site_id  Optional. The site ID to count users for. Defaults to the current site.
    838840 * @return array Includes a grand total and an array of counts indexed by role strings.
    839841 */
    840 function count_users($strategy = 'time') {
     842function count_users( $strategy = 'time', $site_id = null ) {
    841843        global $wpdb;
    842844
    843845        // Initialize
    844         $id = get_current_blog_id();
    845         $blog_prefix = $wpdb->get_blog_prefix($id);
     846        if ( ! $site_id ) {
     847                $site_id = get_current_blog_id();
     848        }
     849        $blog_prefix = $wpdb->get_blog_prefix( $site_id );
    846850        $result = array();
    847851
    848852        if ( 'time' == $strategy ) {
     
    903907                $result['avail_roles'] =& $avail_roles;
    904908        }
    905909
    906         if ( is_multisite() ) {
    907                 $result['avail_roles']['none'] = 0;
    908         }
    909 
    910910        return $result;
    911911}
    912912
     
    24262426/**
    24272427 * Get the user IDs of all users with no role on this site.
    24282428 *
    2429  * This function returns an empty array when used on Multisite.
    2430  *
    24312429 * @since 4.4.0
     2430 * @since 4.7.0 The `$site_id` parameter was added to support multisite.
    24322431 *
     2432 * @param int|null $site_id Optional. The site ID to get users with no role for. Defaults to the current site.
    24332433 * @return array Array of user IDs.
    24342434 */
    2435 function wp_get_users_with_no_role() {
     2435function wp_get_users_with_no_role( $site_id = null ) {
    24362436        global $wpdb;
    24372437
    2438         if ( is_multisite() ) {
    2439                 return array();
     2438        if ( ! $site_id ) {
     2439                $site_id = get_current_blog_id();
    24402440        }
    24412441
    2442         $prefix = $wpdb->get_blog_prefix();
     2442        $prefix = $wpdb->get_blog_prefix( $site_id );
    24432443        $regex  = implode( '|', array_keys( wp_roles()->get_names() ) );
    24442444        $regex  = preg_replace( '/[^a-zA-Z_\|-]/', '', $regex );
    24452445        $users  = $wpdb->get_col( $wpdb->prepare( "