Function and usage of grant_super_admin() in wordpress


Answers ( 1 )


    The grant_super_admin() function in WordPress is a crucial tool for managing user privileges, specifically for granting Super Admin status in a WordPress Multisite network. Here's a detailed explanation and sample usage:


    grant_super_admin( int $user_id ): bool


    The function is used to grant Super Admin privileges to a user in a WordPress Multisite setup. Super Admins have the highest level of access, allowing them to manage all sites within the network, including adding and removing sites, managing network-wide plugins and themes, and other high-level administrative tasks.


    • $user_id (int, required) - This is the ID of the user to whom you want to grant Super Admin privileges. The user ID is a unique identifier for each user in the WordPress database.

    Return Value:

    • bool - The function returns a boolean value. It returns true on successful assignment of Super Admin privileges, and false on failure.

    Failure Conditions:

    • The function will return false if the user already has Super Admin privileges. In a WordPress Multisite, a user with these privileges won't need them granted again.
    • It also returns false if the $super_admins global is defined. This global variable is used in some WordPress configurations to manually define a list of Super Admins, bypassing the standard functions.

    Sample Usage:

    To use the grant_super_admin() function, you first need to know the user ID of the user to whom you want to grant Super Admin privileges. Once you have the user ID, you can use the function like this:

    $user_id = 123; // Replace 123 with the actual user ID
    $result = grant_super_admin($user_id);
    if ($result) {
        echo 'User has been granted Super Admin privileges.';
    } else {
        echo 'Failed to grant Super Admin privileges.';

    In this example, replace 123 with the actual user ID. The $result variable will store the result of the function call. If $result is true, it means the user has successfully been granted Super Admin privileges. If it's false, the operation failed, possibly due to the user already being a Super Admin or due to the $super_admins global being defined.

    Remember, this function is typically used by developers or network administrators who manage a WordPress Multisite network and need to assign or alter user permissions at the highest level.

Leave an answer