WordPress.org

Make WordPress Core

Ticket #36196: 36196.2.diff

File 36196.2.diff, 3.3 KB (added by flixos90, 4 years ago)

fix table views to include "None"

  • 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';
     
    354354                        $post_counts = count_many_users_posts( array_keys( $this->items ) );
    355355
    356356                foreach ( $this->items as $userid => $user_object ) {
    357                         if ( is_multisite() && empty( $user_object->allcaps ) )
    358                                 continue;
    359 
    360357                        echo "\n\t" . $this->single_row( $user_object, '', '', isset( $post_counts ) ? $post_counts[ $userid ] : 0 );
    361358                }
    362359        }
  • src/wp-includes/user.php

     
    826826 *
    827827 * @since 3.0.0
    828828 * @since 4.4.0 The number of users with no role is now included in the `none` element.
     829 * @since 4.6.0 The `$site_id` parameter was added to support multisite.
    829830 *
    830831 * @global wpdb $wpdb WordPress database abstraction object.
    831832 *
    832  * @param string $strategy 'time' or 'memory'
     833 * @param string   $strategy 'time' or 'memory'
     834 * @param int|null $site_id  Optional. The site ID to count users for. Defaults to the current site.
     835 *
    833836 * @return array Includes a grand total and an array of counts indexed by role strings.
    834837 */
    835 function count_users($strategy = 'time') {
     838function count_users( $strategy = 'time', $site_id = null ) {
    836839        global $wpdb;
    837840
    838841        // Initialize
    839         $id = get_current_blog_id();
    840         $blog_prefix = $wpdb->get_blog_prefix($id);
     842        if ( ! $site_id ) {
     843                $site_id = get_current_blog_id();
     844        }
     845        $blog_prefix = $wpdb->get_blog_prefix( $site_id );
    841846        $result = array();
    842847
    843848        if ( 'time' == $strategy ) {
     
    898903                $result['avail_roles'] =& $avail_roles;
    899904        }
    900905
    901         if ( is_multisite() ) {
    902                 $result['avail_roles']['none'] = 0;
    903         }
    904 
    905906        return $result;
    906907}
    907908
     
    24062407/**
    24072408 * Get the user IDs of all users with no role on this site.
    24082409 *
    2409  * This function returns an empty array when used on Multisite.
    2410  *
    24112410 * @since 4.4.0
     2411 * @since 4.6.0 The `$site_id` parameter was added to support multisite.
    24122412 *
     2413 * @param int|null $site_id Optional. The site ID to get users with no role for. Defaults to the current site.
     2414 *
    24132415 * @return array Array of user IDs.
    24142416 */
    2415 function wp_get_users_with_no_role() {
     2417function wp_get_users_with_no_role( $site_id = null ) {
    24162418        global $wpdb;
    24172419
    2418         if ( is_multisite() ) {
    2419                 return array();
     2420        if ( ! $site_id ) {
     2421                $site_id = get_current_blog_id();
    24202422        }
    24212423
    2422         $prefix = $wpdb->get_blog_prefix();
     2424        $prefix = $wpdb->get_blog_prefix( $site_id );
    24232425        $regex  = implode( '|', wp_roles()->get_names() );
    24242426        $regex  = preg_replace( '/[^a-zA-Z_\|-]/', '', $regex );
    24252427        $users  = $wpdb->get_col( $wpdb->prepare( "