revoke_super_admin

Revokes Super Admin privileges.

Description

revoke_super_admin( (int) $user_id ); 

Parameters (1)

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

Usage

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

Defined (1)

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

/wp-includes/capabilities.php  
  1. function revoke_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's Super Admin privileges are revoked. 
  8. * @since 3.0.0 
  9. * @param int $user_id ID of the user Super Admin privileges are being revoked from. 
  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 && 0 !== strcasecmp( $user->user_email, get_site_option( 'admin_email' ) ) ) { 
  17. if ( false !== ( $key = array_search( $user->user_login, $super_admins ) ) ) { 
  18. unset( $super_admins[$key] ); 
  19. update_site_option( 'site_admins', $super_admins ); 
  20.  
  21. /** 
  22. * Fires after the user's Super Admin privileges are revoked. 
  23. * @since 3.0.0 
  24. * @param int $user_id ID of the user Super Admin privileges were revoked from. 
  25. */ 
  26. return true; 
  27. return false;