Using revoke_super_admin to revoke super admin privileges in WordPress

The revoke_super_admin function in WordPress is used to remove super admin privileges from a specified user. Super admin privileges are granted to users in a multisite network setup, allowing them to perform site-wide administrative tasks that are not available to regular administrators.

By using the revoke_super_admin function, network administrators can manage which users have the ability to perform these high-level administrative tasks. This function helps in maintaining a controlled and secure environment by ensuring that only authorized users have access to super admin capabilities.

Parameters

  • $user_id (int), required. The ID of the user from whom Super Admin privileges will be revoked.

Return Value

The function returns a boolean value: true if successful, false if it fails. Failure can occur if the user’s email matches the network admin email or if the global variable $super_admins is set.

Examples

How to Revoke Super Admin Privileges from a Specific User

function revoke_super_admin_privileges($user_id) {
 if (revoke_super_admin($user_id)) {
 echo 'Super Admin privileges revoked successfully.';
 } else {
 echo 'Failed to revoke Super Admin privileges.';
 }
}

// Usage
revoke_super_admin_privileges(5);

This snippet defines a function revoke_super_admin_privileges that accepts a user ID as a parameter. It then calls the revoke_super_admin function to revoke Super Admin privileges from the specified user. If the operation is successful, it prints a success message; otherwise, it prints a failure message. The function is then called with a user ID of 5.

How to Revoke Super Admin Privileges for a List of Users

function revoke_super_admin_for_users($user_ids) {
 foreach ($user_ids as $user_id) {
 if (revoke_super_admin($user_id)) {
 echo "Super Admin privileges revoked for user ID: $user_id<br>";
 } else {
 echo "Failed to revoke Super Admin privileges for user ID: $user_id<br>";
 }
 }
}

// Usage
$user_ids = array(3, 7, 12);
revoke_super_admin_for_users($user_ids);

This snippet defines a function revoke_super_admin_for_users that accepts an array of user IDs as a parameter. It iterates over the array and attempts to revoke Super Admin privileges for each user ID. It prints a success or failure message for each user ID. The function is then called with an array of user IDs [3, 7, 12].

Conclusion

The revoke_super_admin function in WordPress is designed to remove super admin privileges from a specified user within a multisite network. This function is particularly useful for managing user roles and permissions, ensuring that only designated individuals retain the highest level of administrative access. By utilizing revoke_super_admin, network administrators can effectively control and maintain the security and integrity of their multisite environment. This function plays a critical role in the broader scope of user management and network administration within WordPress.

Related WordPress Functions