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