author_can

Whether author of supplied post has capability or role.

Description

author_can( (int|object) $post, (string) $capability ); 

Parameters (2)

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

Usage

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

Defined (1)

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

/wp-includes/capabilities.php  
  1. function author_can( $post, $capability ) { 
  2. if ( !$post = get_post($post) ) 
  3. return false; 
  4.  
  5. $author = get_userdata( $post->post_author ); 
  6.  
  7. if ( ! $author ) 
  8. return false; 
  9.  
  10. $args = array_slice( func_get_args(), 2 ); 
  11. $args = array_merge( array( $capability ), $args ); 
  12.  
  13. return call_user_func_array( array( $author, 'has_cap' ), $args );