Make WordPress Core

Ticket #22993: 22993.3.diff

File 22993.3.diff, 3.4 KB (added by johnbillion, 9 years ago)
  • src/wp-admin/includes/class-wp-users-list-table.php

     
    8787
    8888                $paged = $this->get_pagenum();
    8989
    90                 $args = array(
    91                         'number' => $users_per_page,
    92                         'offset' => ( $paged-1 ) * $users_per_page,
    93                         'role' => $role,
    94                         'search' => $usersearch,
    95                         'fields' => 'all_with_meta'
    96                 );
     90                if ( 'none' === $role ) {
     91                        $args = array(
     92                                'number' => $users_per_page,
     93                                'offset' => ( $paged-1 ) * $users_per_page,
     94                                'include' => wp_get_norole_users(),
     95                                'search' => $usersearch,
     96                                'fields' => 'all_with_meta'
     97                        );
     98                } else {
     99                        $args = array(
     100                                'number' => $users_per_page,
     101                                'offset' => ( $paged-1 ) * $users_per_page,
     102                                'role' => $role,
     103                                'search' => $usersearch,
     104                                'fields' => 'all_with_meta'
     105                        );
     106                }
    97107
    98108                if ( '' !== $args['search'] )
    99109                        $args['search'] = '*' . $args['search'] . '*';
     
    156166                        $url = 'users.php';
    157167                        $users_of_blog = count_users();
    158168                }
     169
    159170                $total_users = $users_of_blog['total_users'];
    160171                $avail_roles =& $users_of_blog['avail_roles'];
    161172                unset($users_of_blog);
     
    179190                        $role_links[$this_role] = "<a href='" . esc_url( add_query_arg( 'role', $this_role, $url ) ) . "'$class>$name</a>";
    180191                }
    181192
     193                if ( ! empty( $avail_roles['none' ] ) ) {
     194
     195                        $class = '';
     196
     197                        if ( 'none' === $role ) {
     198                                $class = ' class="current"';
     199                        }
     200
     201                        $name = __( 'No role' );
     202                        /* translators: User role name with count */
     203                        $name = sprintf( __('%1$s <span class="count">(%2$s)</span>'), $name, number_format_i18n( $avail_roles['none' ] ) );
     204                        $role_links['none'] = "<a href='" . esc_url( add_query_arg( 'role', 'none', $url ) ) . "'$class>$name</a>";
     205
     206                }
     207
    182208                return $role_links;
    183209        }
    184210
  • src/wp-includes/user-functions.php

     
    775775                // Get the meta_value index from the end of the result set.
    776776                $total_users = (int) $row[$col];
    777777
     778                $role_counts['none'] = ( $total_users - array_sum( $role_counts ) );
     779
    778780                $result['total_users'] = $total_users;
    779781                $result['avail_roles'] =& $role_counts;
    780782        } else {
     
    786788                        $b_roles = maybe_unserialize($caps_meta);
    787789                        if ( ! is_array( $b_roles ) )
    788790                                continue;
     791                        if ( empty( $b_roles ) ) {
     792                                if ( isset( $avail_roles['none'] ) ) {
     793                                        $avail_roles['none']++;
     794                                } else {
     795                                        $avail_roles['none'] = 1;
     796                                }
     797                        }
    789798                        foreach ( $b_roles as $b_role => $val ) {
    790799                                if ( isset($avail_roles[$b_role]) ) {
    791800                                        $avail_roles[$b_role]++;
     
    21432152        $manager = WP_Session_Tokens::get_instance( get_current_user_id() );
    21442153        $manager->destroy_all();
    21452154}
     2155
     2156/**
     2157 * Get the user IDs of all users with no role on this site.
     2158 *
     2159 * @since 4.4.0
     2160 *
     2161 * @return array Array of user IDs.
     2162 */
     2163function wp_get_norole_users() {
     2164        global $wpdb;
     2165        $wp_roles = wp_roles();
     2166        $blog_prefix = $wpdb->get_blog_prefix();
     2167        $norole_regexp = implode( '|', array_keys( $wp_roles->get_names() ) );
     2168        $norole_users = $wpdb->get_col( $wpdb->prepare( "
     2169                SELECT user_id
     2170                FROM $wpdb->usermeta
     2171                WHERE meta_key = '{$blog_prefix}capabilities'
     2172                AND meta_value NOT REGEXP %s
     2173        ", $norole_regexp ) );
     2174        return $norole_users;
     2175}