WordPress at a glance

is_super_admin() WP 1.0

Determine if user is a site admin.

✈ 1 time = 0.000055s = very fast | 50000 times = 0.18s = very fast | PHP 7.1.2, WP 4.7.5

No Hooks.

Return

true/false. True if the user is a site admin.

Usage

is_super_admin( $user_id );
$user_id(int)
(Optional) The ID of a user.
Default: current user

Changelog

Since 3.0.0 Introduced.

Code of is super admin: wp-includes/capabilities.php WP 5.2.2

<?php
function is_super_admin( $user_id = false ) {
	if ( ! $user_id || $user_id == get_current_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 ) ) {
			return true;
		}
	} else {
		if ( $user->has_cap( 'delete_users' ) ) {
			return true;
		}
	}

	return false;
}

Related Functions

From tag: Roles capabilities

No comments
    Hello, !     Log In . Register