is_super_admin()WP 3.0.0

Determine if user is a site admin.

1 time — 0.000055 sec (very fast) | 50000 times — 0.18 sec (very fast) | PHP 7.1.2, WP 4.7.5

No Hooks.

Return

true|false. Whether the user is a site admin.

Usage

is_super_admin( $user_id );
$user_id(int|false)
The ID of a user.
Default: false, to check the current user

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

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;
		}
	} else {
		if ( $user->has_cap( 'delete_users' ) ) {
			return true;
		}
	}

	return false;
}