Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
16.67% covered (danger)
16.67%
1 / 6
50.00% covered (danger)
50.00%
1 / 2
CRAP
n/a
0 / 0
wpcomsh_extend_stats_menu_item_access
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
wpcomsh_enable_premium_analytics
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * Jetpack Stats.
4 *
5 * @package wpcomsh
6 */
7
8/**
9 * Extends the default value for which roles can access the Stats menu item.
10 *
11 * This enables the `view_stats` capability to work with all roles that are available on Simple sites.
12 *
13 * @see https://github.com/Automattic/jetpack/pull/33255
14 * @see Automattic\Jetpack\Stats\Options::get_defaults()
15 *
16 * @param array $default_value The default value for stats options.
17 * @return array
18 */
19function wpcomsh_extend_stats_menu_item_access( $default_value ) {
20    if ( is_array( $default_value ) ) {
21        $default_value['roles'] = array( 'administrator', 'editor', 'author', 'contributor' );
22    }
23
24    return $default_value;
25}
26add_filter( 'default_option_stats_options', 'wpcomsh_extend_stats_menu_item_access' );
27
28/**
29 * Turns on the bundled Premium Analytics dashboard for Atomic sites carrying the blog sticker.
30 *
31 * The filter is registered here, at file scope, because Jetpack resolves the flag once per request
32 * from `Jetpack::configure()` on `plugins_loaded` — a callback added on `plugins_loaded` or later
33 * would be too late to be seen.
34 *
35 * @param bool $enabled Whether Premium Analytics is already enabled.
36 * @return bool
37 */
38function wpcomsh_enable_premium_analytics( $enabled ) {
39    return $enabled || wpcomsh_is_site_sticker_active( 'jetpack-premium-analytics' );
40}
41add_filter( 'jetpack_premium_analytics_enabled', 'wpcomsh_enable_premium_analytics' );