is_super_admin()WP 3.0.0

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

0

#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!';
}
0

#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');
}
0

#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.

is_super_admin() code WP 6.8.3

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;
}