is_super_admin( int $user_id = false )
Determine if user is a site admin.
Description Description
Parameters Parameters
- $user_id
-
(int) (Optional) (Optional) The ID of a user. Defaults to the current user.
Default value: false
Return Return
(bool) True if the user is a site admin.
Source Source
File: wp-includes/capabilities.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;
}
Expand full source code Collapse full source code View on Trac
Changelog Changelog
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Example
<?php // 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'); } ?>Expand full source codeCollapse full source code
<?php // 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 } ?><?php // Display hooks for Super admin only if ( is_super_admin() ) { $debug_tags = array(); add_action( 'all', function ( $tag ) { global $debug_tags; if ( in_array( $tag, $debug_tags ) ) { return; } echo "<pre>" . $tag . "</pre>"; $debug_tags[] = $tag; } ); } ?>