wp_get_users_with_no_role

Get the user IDs of all users with no role on this site.

Description

(array) wp_get_users_with_no_role(); 

This function returns an empty array when used on Multisite.

Returns (array)

Array of user IDs.


Usage

  1. if ( !function_exists( 'wp_get_users_with_no_role' ) ) { 
  2. require_once ABSPATH . WPINC . '/user.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_get_users_with_no_role(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/user.php  
  1. function wp_get_users_with_no_role() { 
  2. global $wpdb; 
  3.  
  4. if ( is_multisite() ) { 
  5. return array(); 
  6.  
  7. $prefix = $wpdb->get_blog_prefix(); 
  8. $regex = implode( '|', array_keys(wp_roles)->get_names() ) ); 
  9. $regex = preg_replace( '/[^a-zA-Z_\|-]/', '', $regex ); 
  10. $users = $wpdb->get_col( $wpdb->prepare( " 
  11. SELECT user_id 
  12. FROM $wpdb->usermeta 
  13. WHERE meta_key = '{$prefix}capabilities' 
  14. AND meta_value NOT REGEXP %s 
  15. ", $regex ) ); 
  16.  
  17. return $users;