user_has_cap

Dynamically filter a user's capabilities.

Description

apply_filters( 'user_has_cap', (array) $this_allcaps, (array) $caps, (array) $args, (WP_User) $instance ); 

Parameters (4)

0. $this_allcaps (array)
An array of all the user's capabilities.
1. $caps (array)
Actual capabilities for meta capability.
2. $args — Optional. (array)
Parameters passed to has_cap(), typically object ID.
3. $instance (WP_User)
The user object.

Usage

To run the hook, copy the example below.
  1. $this_allcaps = apply_filters( 'user_has_cap', $this_allcaps, $caps, $args, $instance ); 
  2.  
  3. if ( !empty( $this_allcaps ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the user_has_cap callback 
  2. function filter_user_has_cap( $this_allcaps, $caps, $args, $instance ) { 
  3. // make filter magic happen here... 
  4. return $this_allcaps
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( 'user_has_cap', 'filter_user_has_cap', 10, 4 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( 'user_has_cap', 'filter_user_has_cap', 10, 4 ); 

Defined (1)

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

/wp-includes/class-wp-user.php  
  1. $capabilities = apply_filters( 'user_has_cap', $this->allcaps, $caps, $args, $this );