stats_map_meta_caps

Maps view_stats cap to read cap as needed.

Description

(array) stats_map_meta_caps( $caps, $cap, $user_id, $args ); 

Returns (array)

Possibly mapped capabilities for meta capability

Parameters (4)

0. $caps
The caps.
1. $cap
The cap.
2. $user_id
The user id.
3. $args
The args.

Usage

  1. if ( !function_exists( 'stats_map_meta_caps' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'jetpack-by-wordpress-com/modules/stats.php'; 
  3.  
  4. // The caps. 
  5. $caps = null; 
  6.  
  7. // The cap. 
  8. $cap = null; 
  9.  
  10. // The user id. 
  11. $user_id = null; 
  12.  
  13. // The args. 
  14. $args = null; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = stats_map_meta_caps($caps, $cap, $user_id, $args); 
  18.  

Defined (1)

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

/modules/stats.php  
  1. function stats_map_meta_caps( $caps, $cap, $user_id, $args ) { 
  2. // Map view_stats to exists 
  3. if ( 'view_stats' == $cap ) { 
  4. $user = new WP_User( $user_id ); 
  5. $user_role = array_shift( $user->roles ); 
  6. $stats_roles = stats_get_option( 'roles' ); 
  7.  
  8. // Is the users role in the available stats roles? 
  9. if ( is_array( $stats_roles ) && in_array( $user_role, $stats_roles ) ) { 
  10. $caps = array( 'read' ); 
  11.  
  12. return $caps;