is_super_admin( int|false $user_id = false ): bool
- Since
- 3.0.0
- Source
wp-includes/capabilities.php:1181
Compatibility
- WordPress
- since 3.0.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
$user_idint|falseoptional- The ID of a user. Defaults to false, to check the current user.Default:
false
Return value
bool- Whether the user is a site admin.
Performance profile
How much work a call to is_super_admin() 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
- 8–23
- Plugin surface
- None
- Called by
- 7
Reaches the database via get_user_by().
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 34.
Nothing here hands control to plugin code.
7 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_user_by()one call below is_super_admin() - optionnetwork option
get_site_option()one call below is_super_admin()
Further down the call graph this can also reach hook, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 8 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost is_super_admin() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 8 | get_userdata() |
| always | 8 | wp_get_current_user() |
!->exists() | 11 | get_userdata(), ->exists() |
!->exists() | 11 | wp_get_current_user(), ->exists() |
->exists() && !is_multisite() | 18 | get_userdata(), ->exists(), is_multisite(), ->has_cap() |
->exists() && !is_multisite() | 18 | wp_get_current_user(), ->exists(), is_multisite(), ->has_cap() |
->exists() && is_multisite() | 19–23 | get_userdata(), ->exists(), is_multisite(), get_super_admins() |
->exists() && is_multisite() | 19–23 | wp_get_current_user(), ->exists(), is_multisite(), get_super_admins() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 34 | 8–23 | 7 | |
| 8.5 | 34 | 8–23 | 7 | |
| 8.4 | 34 | 8–23 | 7 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 37 | 8–26 | 7 | |
| 8.2 | 37 | 8–26 | 7 | |
| 8.1 | 37 | 8–26 | 7 | |
| 7.4 | 37 | 8–26 | 7 |
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 · 4
- wp_get_current_user()Retrieves the current user object.
- get_userdata()Retrieves user info by user ID.
- is_multisite()Determines whether Multisite is enabled.
- get_super_admins()Retrieves a list of super admins.
Used by · 7
- WP_MS_Users_List_Table::column_cb()Handles the checkbox column output.
- WP_User::has_cap()Returns whether the user has the specified capability.
- is_site_admin()Determine if user is a site admin.
- map_meta_cap()Maps a capability to the primitive capabilities required of the given user to satisfy the capability being checked.
- ms_site_check()Checks status of current blog.
- wp_install_defaults()Creates the initial content for a newly-installed site.
- wp_maybe_grant_site_health_caps()Filters the user capabilities to grant the 'view_site_health_checks' capabilities as necessary.
Source code
function is_super_admin( $user_id = false ) { if ( ! $user_id ) { $user = wp_get_current_user(); } else { $user = get_userdata( $user_id ); } if ( ! $user || ! $user->exists() ) { return false; } if ( is_multisite() ) { $super_admins = get_super_admins(); if ( is_array( $super_admins ) && in_array( $user->user_login, $super_admins, true ) ) { return true; } } elseif ( $user->has_cap( 'delete_users' ) ) { return true; } return false;}Changelog
Introduced in 3.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-includes/capabilities.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.