user_can

Whether a particular user has capability or role.

Description

user_can( (int|object) $user, (string) $capability ); 

Parameters (2)

0. $user (int|object)
User ID or object.
1. $capability (string)
Capability or role name.

Usage

  1. if ( !function_exists( 'user_can' ) ) { 
  2. require_once ABSPATH . WPINC . '/capabilities.php'; 
  3.  
  4. // User ID or object. 
  5. $user = null; 
  6.  
  7. // Capability or role name. 
  8. $capability = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = user_can($user, $capability); 
  12.  

Defined (1)

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

/wp-includes/capabilities.php  
  1. function user_can( $user, $capability ) { 
  2. if ( ! is_object( $user ) ) 
  3. $user = get_userdata( $user ); 
  4.  
  5. if ( ! $user || ! $user->exists() ) 
  6. return false; 
  7.  
  8. $args = array_slice( func_get_args(), 2 ); 
  9. $args = array_merge( array( $capability ), $args ); 
  10.  
  11. return call_user_func_array( array( $user, 'has_cap' ), $args );