is_super_admin() WordPress Function

The is_super_admin() function in WordPress checks if the current user is a super administrator. This function is only available for multisite installations. Super administrators have all the capabilities of a normal administrator, plus they can manage networks and perform site-wide actions.

is_super_admin( int|false $user_id = false ) #

Determines whether user is a site admin.


Parameters

$user_id

(int|false)(Optional) The ID of a user. Defaults to false, to check the current user.

Default value: false


Top ↑

Return

(bool) Whether the user is a site admin.


Top ↑

Source

File: wp-includes/capabilities.php

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


Top ↑

Changelog

Changelog
VersionDescription
3.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.