is_super_admin( int|false $user_id = false ): bool

Determines whether user is a site admin.

Parameters

$user_idint|falseoptional
The ID of a user. Defaults to false, to check the current user.

Default:false

Return

bool Whether the user is a site admin.

Source

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

	return false;
}

Changelog

VersionDescription
3.0.0Introduced.

User Contributed Notes

  1. Skip to note 5 content

    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');
    }
    ?>

You must log in before being able to contribute a note or feedback.