Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
20.00% |
3 / 15 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Jetpack_Protect_Dashboard_Feature_Flags | |
25.00% |
3 / 12 |
|
50.00% |
1 / 2 |
6.80 | |
0.00% |
0 / 1 |
| register | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| filter_available_modules | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Protect dashboard feature flags. |
| 4 | * |
| 5 | * @package automattic/jetpack |
| 6 | */ |
| 7 | |
| 8 | use Automattic\Jetpack\Feature_Flags\Feature_Flags; |
| 9 | |
| 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | exit( 0 ); |
| 12 | } |
| 13 | |
| 14 | /** |
| 15 | * Registers the flag that gates the `protect-dashboard` module. |
| 16 | * |
| 17 | * @since $$next-version$$ |
| 18 | */ |
| 19 | class Jetpack_Protect_Dashboard_Feature_Flags { |
| 20 | |
| 21 | const DASHBOARD = 'jetpack-protect-dashboard'; |
| 22 | |
| 23 | const MODULE = 'protect-dashboard'; |
| 24 | |
| 25 | /** |
| 26 | * Register the flag, and hide the module while it is off. |
| 27 | * |
| 28 | * @return void |
| 29 | */ |
| 30 | public static function register() { |
| 31 | Feature_Flags::register( |
| 32 | self::DASHBOARD, |
| 33 | array( |
| 34 | 'default' => false, |
| 35 | 'description' => 'Make the Protect dashboard module available, which replaces the Protect page, including the Jetpack Protect plugin\'s. Not for sites using that plugin until the new page matches it.', |
| 36 | 'owner' => 'jetpack', |
| 37 | ) |
| 38 | ); |
| 39 | |
| 40 | add_filter( 'jetpack_get_available_modules', array( __CLASS__, 'filter_available_modules' ) ); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Drop the module from the available list while the flag is off, which also keeps it from loading. |
| 45 | * |
| 46 | * @param array $modules Available modules, keyed by slug. |
| 47 | * @return array |
| 48 | */ |
| 49 | public static function filter_available_modules( $modules ) { |
| 50 | if ( ! Feature_Flags::is_enabled( self::DASHBOARD ) ) { |
| 51 | unset( $modules[ self::MODULE ] ); |
| 52 | } |
| 53 | return $modules; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | Jetpack_Protect_Dashboard_Feature_Flags::register(); |