grant_super_admin()
Sets the specified user as a super administrator.
"Super-administrator" is not a separate role like Editor, Administrator, but simply a set of permissions that expand the capabilities of the current role.
If a user had a role lower than "Administrator," for example, "Editor," then after granting them super-admin rights, they will gain the ability to manage everything.
This function adds the user's login to the site_admins option in the wp_sitemeta table:
$super_admins = get_site_option( 'site_admins' );
A super-admin can also be specified in the global variable $super_admins. If it is set, it takes precedence over the site_admins option, and this function becomes non-functional, with all management of super-admins transitioning to the global option $super_admins.
Use the function revoke_super_admin() to undo the action of this function (remove super-admin rights from the specified user).
Also, see WP-CLI commands related to super-admin: wp super-admin.
Hooks from the function
Returns
true|false.
true- Successfully made the user a super-admin.false- Failed to make the user a super-admin.
Or if the specified user is already a super-admin.
Or if the global variable $super_admins is set.
Usage
grant_super_admin( $user_id );
- $user_id(integer) (required)
- User ID to which super-admin rights need to be granted.
Examples
#1 Give super admin rights (caps) to the user with ID 5
It is recommended to call the function only once, not every time the page is generated. Because it changes the value of the option.
grant_super_admin( 5 );
#2 Set super-admin rights (caps) and remove them when activating/deactivating the plugin
register_activation_hook( __FILE__, 'myplugin_activate' );
register_deactivation_hook( __FILE__, 'myplugin_deactivate' );
function myplugin_activate() {
// give caps
grant_super_admin( 5 );
}
function myplugin_deactivate(){
// take away the caps
revoke_super_admin( 5 );
}
Notes
- Global. Array.
$super_admins
Changelog
| Since 3.0.0 | Introduced. |