grant_super_admin

Grants Super Admin privileges.

Description

grant_super_admin( (int) $user_id ); 

Parameters (1)

0. $user_id (int)
ID of the user to be granted Super Admin privileges.

Usage

  1. if ( !function_exists( 'grant_super_admin' ) ) { 
  2. require_once ABSPATH . WPINC . '/capabilities.php'; 
  3.  
  4. // ID of the user to be granted Super Admin privileges. 
  5. $user_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = grant_super_admin($user_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/capabilities.php  
  1. function grant_super_admin( $user_id ) { 
  2. // If global super_admins override is defined, there is nothing to do here. 
  3. if ( isset( $GLOBALS['super_admins'] ) || ! is_multisite() ) { 
  4. return false; 
  5.  
  6. /** 
  7. * Fires before the user is granted Super Admin privileges. 
  8. * @since 3.0.0 
  9. * @param int $user_id ID of the user that is about to be granted Super Admin privileges. 
  10. */ 
  11.  
  12. // Directly fetch site_admins instead of using get_super_admins() 
  13. $super_admins = get_site_option( 'site_admins', array( 'admin' ) ); 
  14.  
  15. $user = get_userdata( $user_id ); 
  16. if ( $user && ! in_array( $user->user_login, $super_admins ) ) { 
  17. $super_admins[] = $user->user_login; 
  18. update_site_option( 'site_admins' , $super_admins ); 
  19.  
  20. /** 
  21. * Fires after the user is granted Super Admin privileges. 
  22. * @since 3.0.0 
  23. * @param int $user_id ID of the user that was granted Super Admin privileges. 
  24. */ 
  25. return true; 
  26. return false;