Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
38.46% |
5 / 13 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Classic_Stats | |
38.46% |
5 / 13 |
|
66.67% |
2 / 3 |
14.39 | |
0.00% |
0 / 1 |
| register_feature_flag | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| is_retired | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| page_url | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * The flag that retires the classic Stats page in favor of Stats v2. |
| 4 | * |
| 5 | * @package automattic/jetpack-premium-analytics |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\PremiumAnalytics; |
| 9 | |
| 10 | use Automattic\Jetpack\Feature_Flags\Feature_Flags; |
| 11 | |
| 12 | /** |
| 13 | * Owns the classic Stats retirement flag, so every plugin that bundles Stats v2 reads the same switch. |
| 14 | * |
| 15 | * @since 0.16.0 |
| 16 | */ |
| 17 | final class Classic_Stats { |
| 18 | |
| 19 | const RETIRED_FLAG = 'jetpack-stats-classic-page-retired'; |
| 20 | |
| 21 | /** |
| 22 | * Register the flag, so feature-flag tooling lists it. |
| 23 | * |
| 24 | * @return void |
| 25 | */ |
| 26 | public static function register_feature_flag() { |
| 27 | Feature_Flags::register( |
| 28 | self::RETIRED_FLAG, |
| 29 | array( |
| 30 | 'default' => false, |
| 31 | 'description' => 'Turn Stats v2 on for every site and stop registering the classic Stats page; old admin.php?page=stats links open Stats v2.', |
| 32 | 'owner' => 'jetpack-stats', |
| 33 | ) |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Whether the retirement flag is on; callers still keep the classic page until Stats v2 has booted. |
| 39 | * |
| 40 | * Read on `plugins_loaded`, so a filter forcing it has to be added before that. |
| 41 | * |
| 42 | * @return bool |
| 43 | */ |
| 44 | public static function is_retired() { |
| 45 | return Feature_Flags::is_enabled( self::RETIRED_FLAG ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * The classic Stats page's URL, or null once it is retired or while no plugin registers a `stats` menu page. |
| 50 | * |
| 51 | * Retired wins over the menu, since WordPress.com Simple still registers an older `index.php?page=stats`. Reads |
| 52 | * the menu, not `$admin_page_hooks`, which keys top-level pages only and misses Jetpack's Stats submenu. |
| 53 | * |
| 54 | * @since $$next-version$$ |
| 55 | * |
| 56 | * @return string|null |
| 57 | */ |
| 58 | public static function page_url() { |
| 59 | if ( self::is_retired() ) { |
| 60 | return null; |
| 61 | } |
| 62 | |
| 63 | $url = function_exists( 'menu_page_url' ) ? menu_page_url( 'stats', false ) : ''; |
| 64 | |
| 65 | return '' === $url ? null : $url; |
| 66 | } |
| 67 | } |