current_user_can

Whether the current user has a specific capability.

Description

current_user_can( (string) $capability ); 

While checking against particular roles in place of a capability is supported in part, this practice is discouraged as it may produce unreliable results.

Note: Will always return true if the current user is a super admin, unless specifically denied.

Parameters (1)

0. $capability (string)
Capability name.

Usage

  1. if ( !function_exists( 'current_user_can' ) ) { 
  2. require_once ABSPATH . WPINC . '/capabilities.php'; 
  3.  
  4. // Capability name. 
  5. $capability = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = current_user_can($capability); 
  9.  

Defined (1)

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

/wp-includes/capabilities.php  
  1. function current_user_can( $capability ) { 
  2. $current_user = wp_get_current_user(); 
  3.  
  4. if ( empty( $current_user ) ) 
  5. return false; 
  6.  
  7. $args = array_slice( func_get_args(), 1 ); 
  8. $args = array_merge( array( $capability ), $args ); 
  9.  
  10. return call_user_func_array( array( $current_user, 'has_cap' ), $args );