WordPress at a glance

is_super_admin() WP 1.0

Determine if user is a site admin.

Возвращает

true/false. True if the 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.

Usage

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

Список изменений

С версии 3.0.0 Введена.

Code of is_super_admin() WP 5.5.1

wp-includes/capabilities.php
<?php
function is_super_admin( $user_id = false ) {
	if ( ! $user_id || get_current_user_id() == $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;
}

Related Functions

From tag: Roles capabilities

No comments
    Log In . Register