is_super_admin

Determine if user is a site admin.

Description

is_super_admin( (bool) $user_id = false ); 

Parameters (1)

0. $user_id — Optional. (bool) => false
The ID of a user. Defaults to the current user.

Usage

  1. if ( !function_exists( 'is_super_admin' ) ) { 
  2. require_once ABSPATH . WPINC . '/capabilities.php'; 
  3.  
  4. // (Optional) The ID of a user. Defaults to the current user. 
  5. $user_id = false; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = is_super_admin($user_id); 
  9.  

Defined (1)

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

/wp-includes/capabilities.php  
  1. function is_super_admin( $user_id = false ) { 
  2. if ( ! $user_id || $user_id == get_current_user_id() ) 
  3. $user = wp_get_current_user(); 
  4. else 
  5. $user = get_userdata( $user_id ); 
  6.  
  7. if ( ! $user || ! $user->exists() ) 
  8. return false; 
  9.  
  10. if ( is_multisite() ) { 
  11. $super_admins = get_super_admins(); 
  12. if ( is_array( $super_admins ) && in_array( $user->user_login, $super_admins ) ) 
  13. return true; 
  14. } else { 
  15. if ( $user->has_cap('delete_users') ) 
  16. return true; 
  17.  
  18. return false;