Changeset 34965
- Timestamp:
- 10/08/2015 10:06:46 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-users-list-table.php
r34963 r34965 88 88 $paged = $this->get_pagenum(); 89 89 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_users_with_no_role(), 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 } 97 107 98 108 if ( '' !== $args['search'] ) … … 167 177 $users_of_blog = count_users(); 168 178 } 179 169 180 $total_users = $users_of_blog['total_users']; 170 181 $avail_roles =& $users_of_blog['avail_roles']; … … 188 199 $name = sprintf( __('%1$s <span class="count">(%2$s)</span>'), $name, number_format_i18n( $avail_roles[$this_role] ) ); 189 200 $role_links[$this_role] = "<a href='" . esc_url( add_query_arg( 'role', $this_role, $url ) ) . "'$class>$name</a>"; 201 } 202 203 if ( ! empty( $avail_roles['none' ] ) ) { 204 205 $class = ''; 206 207 if ( 'none' === $role ) { 208 $class = ' class="current"'; 209 } 210 211 $name = __( 'No role' ); 212 /* translators: User role name with count */ 213 $name = sprintf( __('%1$s <span class="count">(%2$s)</span>'), $name, number_format_i18n( $avail_roles['none' ] ) ); 214 $role_links['none'] = "<a href='" . esc_url( add_query_arg( 'role', 'none', $url ) ) . "'$class>$name</a>"; 215 190 216 } 191 217 -
trunk/src/wp-includes/user-functions.php
r34923 r34965 736 736 * 737 737 * @since 3.0.0 738 * @since 4.4.0 The number of users with no role is now included in the `none` element. 738 739 * 739 740 * @global wpdb $wpdb … … 776 777 $total_users = (int) $row[$col]; 777 778 779 $role_counts['none'] = ( $total_users - array_sum( $role_counts ) ); 780 778 781 $result['total_users'] = $total_users; 779 782 $result['avail_roles'] =& $role_counts; 780 783 } else { 781 $avail_roles = array(); 784 $avail_roles = array( 785 'none' => 0, 786 ); 782 787 783 788 $users_of_blog = $wpdb->get_col( "SELECT meta_value FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities'" ); … … 787 792 if ( ! is_array( $b_roles ) ) 788 793 continue; 794 if ( empty( $b_roles ) ) { 795 $avail_roles['none']++; 796 } 789 797 foreach ( $b_roles as $b_role => $val ) { 790 798 if ( isset($avail_roles[$b_role]) ) { … … 798 806 $result['total_users'] = count( $users_of_blog ); 799 807 $result['avail_roles'] =& $avail_roles; 808 } 809 810 if ( is_multisite() ) { 811 $result['avail_roles']['none'] = 0; 800 812 } 801 813 … … 2232 2244 $manager->destroy_all(); 2233 2245 } 2246 2247 /** 2248 * Get the user IDs of all users with no role on this site. 2249 * 2250 * This function returns an empty array when used on Multisite. 2251 * 2252 * @since 4.4.0 2253 * 2254 * @return array Array of user IDs. 2255 */ 2256 function wp_get_users_with_no_role() { 2257 global $wpdb; 2258 2259 if ( is_multisite() ) { 2260 return array(); 2261 } 2262 2263 $prefix = $wpdb->get_blog_prefix(); 2264 $regex = implode( '|', wp_roles()->get_names() ); 2265 $regex = preg_replace( '/[^a-zA-Z_\|-]/', '', $regex ); 2266 $users = $wpdb->get_col( $wpdb->prepare( " 2267 SELECT user_id 2268 FROM $wpdb->usermeta 2269 WHERE meta_key = '{$prefix}capabilities' 2270 AND meta_value NOT REGEXP %s 2271 ", $regex ) ); 2272 2273 return $users; 2274 }
Note: See TracChangeset
for help on using the changeset viewer.