Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| Enablement | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
| is_enabled | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * The rule that decides whether Stats v2 boots on a connected site. |
| 4 | * |
| 5 | * @package automattic/jetpack-premium-analytics |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\PremiumAnalytics; |
| 9 | |
| 10 | use Automattic\Jetpack\Modules; |
| 11 | |
| 12 | /** |
| 13 | * Whether Stats v2 should boot on a connected site, where {@see Enablement_Setting} is only the stored opt-in. |
| 14 | * |
| 15 | * WordPress.com Simple decides on its own and only answers the filter below. |
| 16 | * |
| 17 | * @since $$next-version$$ |
| 18 | */ |
| 19 | final class Enablement { |
| 20 | |
| 21 | /** |
| 22 | * Whether Stats v2 should boot. It reads what the Stats module collects, so it stays off while the module is. |
| 23 | * |
| 24 | * @return bool |
| 25 | */ |
| 26 | public static function is_enabled() { |
| 27 | if ( ! ( new Modules() )->is_active( 'stats' ) ) { |
| 28 | return false; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Filters whether the bundled Premium Analytics dashboard is enabled. |
| 33 | * |
| 34 | * Read on `plugins_loaded`, and only while the Stats module is active. Register this from a |
| 35 | * mu-plugin or a plugin's main file: a callback added on `plugins_loaded` or later runs too late. |
| 36 | * |
| 37 | * @since jetpack-16.1 |
| 38 | * |
| 39 | * @param bool $enabled Defaults to the `jetpack_premium_analytics_enabled` option (false), or true once the classic Stats page is retired. |
| 40 | */ |
| 41 | return (bool) apply_filters( |
| 42 | 'jetpack_premium_analytics_enabled', |
| 43 | // A site that once switched Stats v2 off would otherwise be left with no Stats page. |
| 44 | Classic_Stats::is_retired() || (bool) get_option( Enablement_Setting::ENABLED_OPTION ) |
| 45 | ); |
| 46 | } |
| 47 | } |