is_super_admin()
Determines whether the user is a super administrator (for multisites).
If multisite is not used, the function will still work and will check if the user is an admin (if they have the capability to delete other users delete_users, i.e., check the highest level of access).
1 time — 0.000055 sec (very fast) | 50000 times — 0.18 sec (very fast) | PHP 7.1.2, WP 4.7.5
No Hooks.
Returns
true|false.
Usage
if( is_super_admin( $user_id ) ){
// ...
}
- $user_id(integer) (required)
- ID of the user to check.
Examples
#1 Check the access level of the current user
If user is the super administrator, display it.
global $user_ID;
if( is_super_admin( $user_ID ) ){
echo 'Hello network chief administrator!';
} #2 Removes the "Edit" menu for not Super Admins
// Removes the "Edit" menu for users who are not Super Admins of a multisite network
if ( ! is_super_admin() ) {
add_action( 'admin_init', 'wpdocs_remove_edit_menu' );
}
/**
* Remove the profile editing link for non-super admins.
*/
function wpdocs_remove_edit_menu() {
remove_menu_page('edit.php');
} #3 Since WP 4.8 is_super_admin is discouraged
// As of WordPress 4.8 the use of is_super_admin is discouraged.
// Use the `setup_network` capability check instead.
if ( current_user_can( 'setup_network' ) ) {
// do something
}
Changelog
| Since 3.0.0 | Introduced. |