wp_get_users_with_no_role( int|null $site_id = null ): string[]
- Since
- 4.4.0, 4.9.0
- Source
wp-includes/user.php:3695
Compatibility
- WordPress
- since 4.9.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$site_idint|nulloptional- The site ID to get users with no role for. Defaults to the current site.Default:
null
Return value
string[]- Array of user IDs as strings.
Performance profile
How much work a call to wp_get_users_with_no_role() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Constant
- Instructions
- 37–50
- Plugin surface
- None
- Called by
- 1
Reaches the database via ->get_col().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 55.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- sqldatabase query
->get_col()called directly - hookthird-party callbacks
do_action()one call below wp_get_users_with_no_role() - cacheobject cache
wp_cache_switch_to_blog()one call below wp_get_users_with_no_role()
What one call costs · 6 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_get_users_with_no_role() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!is_multisite() | 37 | ->get_blog_prefix(), is_multisite(), wp_roles(), ->get_names(), array_keys(), ->prepare(), ->get_col() |
!is_multisite() | 40 | get_current_blog_id(), ->get_blog_prefix(), is_multisite(), wp_roles(), ->get_names(), array_keys(), ->prepare(), ->get_col() |
is_multisite() && $site_id === false | 41 | ->get_blog_prefix(), is_multisite(), get_current_blog_id(), wp_roles(), ->get_names(), array_keys(), ->prepare(), ->get_col() |
is_multisite() && $site_id === false | 44 | get_current_blog_id(), ->get_blog_prefix(), is_multisite(), get_current_blog_id(), wp_roles(), ->get_names(), array_keys(), ->prepare(), ->get_col() |
is_multisite() && $site_id !== false | 47 | ->get_blog_prefix(), is_multisite(), get_current_blog_id(), switch_to_blog(), wp_roles(), ->get_names(), restore_current_blog(), array_keys(), ->prepare(), ->get_col() |
is_multisite() && $site_id !== false | 50 | get_current_blog_id(), ->get_blog_prefix(), is_multisite(), get_current_blog_id(), switch_to_blog(), wp_roles(), ->get_names(), restore_current_blog(), array_keys(), ->prepare(), ->get_col() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 55 | 37–50 | 3 | |
| 8.5 | 55 | 37–50 | 3 | |
| 8.4 | 55 | 37–50 | 3 | 7 fewer instructions than PHP 8.3 |
| 8.3 | 62 | 44–57 | 3 | |
| 8.2 | 62 | 44–57 | 3 | |
| 8.1 | 62 | 44–57 | 3 | |
| 7.4 | 62 | 44–57 | 3 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 6
- get_current_blog_id()Retrieves the current site ID.
- is_multisite()Determines whether Multisite is enabled.
- switch_to_blog()Switches the current blog.
- wp_roles()Retrieves the global WP_Roles instance and instantiates it if necessary.
- restore_current_blog()Restores the current blog, after calling switch_to_blog().
- wp_roles()::get_names()
Used by · 1
- WP_Users_List_Table::prepare_items()Prepares the users list for display.
Source code
function wp_get_users_with_no_role( $site_id = null ) { global $wpdb; if ( ! $site_id ) { $site_id = get_current_blog_id(); } $prefix = $wpdb->get_blog_prefix( $site_id ); if ( is_multisite() && get_current_blog_id() !== $site_id ) { switch_to_blog( $site_id ); $role_names = wp_roles()->get_names(); restore_current_blog(); } else { $role_names = wp_roles()->get_names(); } $regex = implode( '|', array_keys( $role_names ) ); $regex = preg_replace( '/[^a-zA-Z_\|-]/', '', $regex ); $users = $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '{$prefix}capabilities' AND meta_value NOT REGEXP %s", $regex ) ); return $users;}Changelog
Introduced in 4.4.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$site_id parameter was added to support multisite.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-includes/user.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.