awesomemotive /
google-analytics-for-wordpress
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Capabilities class. |
||
| 4 | * |
||
| 5 | * @access public |
||
| 6 | * @since 6.0.0 |
||
| 7 | * |
||
| 8 | * @package MonsterInsights |
||
| 9 | * @subpackage Capabilities |
||
| 10 | * @author Chris Christoff |
||
| 11 | */ |
||
| 12 | |||
| 13 | // Exit if accessed directly |
||
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
||
| 15 | exit; |
||
| 16 | } |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Map MonsterInsights Capabilities. |
||
| 20 | * |
||
| 21 | * Using meta caps, we're creating virtual capabilities that are |
||
| 22 | * for backwards compatibility reasons given to users with manage_options, and to |
||
| 23 | * users who have at least of the roles selected in the options on the permissions |
||
| 24 | * tab of the MonsterInsights settings. |
||
| 25 | * |
||
| 26 | * @access public |
||
| 27 | * |
||
| 28 | * @param array $caps Array of capabilities the user has. |
||
| 29 | * @param string $cap The current cap being filtered. |
||
| 30 | * @param int $user_id User to check permissions for. |
||
| 31 | * @param array $args Extra parameters. Unused. |
||
| 32 | * |
||
| 33 | * @return array Array of caps needed to have this meta cap. If returned array is empty, user has the capability. |
||
| 34 | * @since 6.0.0 |
||
| 35 | * |
||
| 36 | */ |
||
| 37 | function monsterinsights_add_capabilities( $caps, $cap, $user_id, $args ) { |
||
|
0 ignored issues
–
show
|
|||
| 38 | |||
| 39 | switch ( $cap ) { |
||
| 40 | case 'monsterinsights_view_dashboard' : |
||
| 41 | $roles = monsterinsights_get_option( 'view_reports', array() ); |
||
| 42 | |||
| 43 | $user_can_via_settings = false; |
||
| 44 | if ( ! empty( $roles ) && is_array( $roles ) ) { |
||
|
0 ignored issues
–
show
|
|||
| 45 | foreach ( $roles as $role ) { |
||
| 46 | if ( is_string( $role ) ) { |
||
| 47 | if ( user_can( $user_id, $role ) ) { |
||
| 48 | $user_can_via_settings = true; |
||
| 49 | break; |
||
| 50 | } |
||
| 51 | } |
||
| 52 | } |
||
| 53 | } else if ( ! empty( $roles ) && is_string( $roles ) ) { |
||
| 54 | if ( user_can( $user_id, $roles ) ) { |
||
| 55 | $user_can_via_settings = true; |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | if ( user_can( $user_id, 'manage_options' ) || $user_can_via_settings ) { |
||
| 60 | $caps = array(); |
||
| 61 | } |
||
| 62 | |||
| 63 | break; |
||
| 64 | case 'monsterinsights_save_settings' : |
||
| 65 | $roles = monsterinsights_get_option( 'save_settings', array() ); |
||
| 66 | |||
| 67 | $user_can_via_settings = false; |
||
| 68 | if ( ! empty( $roles ) && is_array( $roles ) ) { |
||
|
0 ignored issues
–
show
|
|||
| 69 | foreach ( $roles as $role ) { |
||
| 70 | if ( is_string( $role ) ) { |
||
| 71 | if ( user_can( $user_id, $role ) ) { |
||
| 72 | $user_can_via_settings = true; |
||
| 73 | break; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } |
||
| 77 | } else if ( ! empty( $roles ) && is_string( $roles ) ) { |
||
| 78 | if ( user_can( $user_id, $roles ) ) { |
||
| 79 | $user_can_via_settings = true; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | if ( user_can( $user_id, 'manage_options' ) || $user_can_via_settings ) { |
||
| 84 | $caps = array(); |
||
| 85 | } |
||
| 86 | |||
| 87 | break; |
||
| 88 | } |
||
| 89 | |||
| 90 | return $caps; |
||
| 91 | } |
||
| 92 | |||
| 93 | add_filter( 'map_meta_cap', 'monsterinsights_add_capabilities', 10, 4 ); |
||
| 94 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.