Changeset 34965 for trunk/src/wp-includes/user-functions.php
- Timestamp:
- 10/08/2015 10:06:46 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.