monsterinsights_add_capabilities

Map MonsterInsights Capabilities.

Description

(array) monsterinsights_add_capabilities( (array) $caps, (string) $cap, (int) $user_id, (array) $args ); 

Using meta caps, we're creating virtual capabilities that are for backwards compatibility reasons given to users with manage_options, and to users who have at least of the roles selected in the options on the permissions tab of the MonsterInsights settings.

Returns (array)

Array of caps needed to have this meta cap. If returned array is empty, user has the capability.

Parameters (4)

0. $caps (array)
Array of capabilities the user has.
1. $cap (string)
The current cap being filtered.
2. $user_id (int)
User to check permissions for.
3. $args (array)
Extra parameters. Unused.

Usage

  1. if ( !function_exists( 'monsterinsights_add_capabilities' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-analytics-for-wordpress-by-monsterinsights/includes/admin/capabilities.php'; 
  3.  
  4. // Array of capabilities the user has. 
  5. $caps = array(); 
  6.  
  7. // The current cap being filtered. 
  8. $cap = ''; 
  9.  
  10. // User to check permissions for. 
  11. $user_id = -1; 
  12.  
  13. // Extra parameters. Unused. 
  14. $args = array(); 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = monsterinsights_add_capabilities($caps, $cap, $user_id, $args); 
  18.  

Defined (1)

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

/includes/admin/capabilities.php  
  1. function monsterinsights_add_capabilities( $caps, $cap, $user_id, $args ) { 
  2. switch( $cap ) { 
  3. case 'monsterinsights_view_dashboard' : 
  4. $roles = monsterinsights_get_option( 'view_reports', array() ); 
  5.  
  6. $user_can_via_settings = false; 
  7. if ( ! empty( $roles ) && is_array( $roles ) ) { 
  8. foreach ( $roles as $role ) { 
  9. if ( is_string( $role ) ) { 
  10. if ( user_can( $user_id, $role ) ) { 
  11. $user_can_via_settings = true; 
  12. break; 
  13. } else if ( ! empty( $roles ) && is_string( $roles ) ) { 
  14. if ( user_can( $user_id, $roles ) ) { 
  15. $user_can_via_settings = true; 
  16.  
  17. if ( user_can( $user_id, 'manage_options' ) || $user_can_via_settings ) { 
  18. $caps = array(); 
  19.  
  20. break; 
  21. $roles = monsterinsights_get_option( 'save_settings', array() ); 
  22.  
  23. $user_can_via_settings = false; 
  24. if ( ! empty( $roles ) && is_array( $roles ) ) { 
  25. foreach ( $roles as $role ) { 
  26. if ( is_string( $role ) ) { 
  27. if ( user_can( $user_id, $role ) ) { 
  28. $user_can_via_settings = true; 
  29. break; 
  30. } else if ( ! empty( $roles ) && is_string( $roles ) ) { 
  31. if ( user_can( $user_id, $roles ) ) { 
  32. $user_can_via_settings = true; 
  33.  
  34. if ( user_can( $user_id, 'manage_options' ) || $user_can_via_settings ) { 
  35. $caps = array(); 
  36.  
  37. break; 
  38. return $caps;