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