Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
33.33% |
3 / 9 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Jetpack_Monetize_Feature_Flags | |
50.00% |
3 / 6 |
|
50.00% |
1 / 2 |
10.50 | |
0.00% |
0 / 1 |
| register | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| filter_available_modules | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Monetize dashboard feature flag. |
| 4 | * |
| 5 | * @package automattic/jetpack |
| 6 | */ |
| 7 | |
| 8 | use Automattic\Jetpack\Monetize\Dashboard; |
| 9 | use Automattic\Jetpack\Status\Host; |
| 10 | |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit( 0 ); |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * Registers the flag that gates the `monetize` module. |
| 17 | * |
| 18 | * @since $$next-version$$ |
| 19 | */ |
| 20 | class Jetpack_Monetize_Feature_Flags { |
| 21 | |
| 22 | const MODULE = 'monetize'; |
| 23 | |
| 24 | /** |
| 25 | * Register the flag and the module filter. |
| 26 | * |
| 27 | * @return void |
| 28 | */ |
| 29 | public static function register() { |
| 30 | // Another plugin may have loaded the classes without the Monetize package. |
| 31 | if ( class_exists( Dashboard::class ) ) { |
| 32 | Dashboard::register_feature_flag(); |
| 33 | } |
| 34 | |
| 35 | add_filter( 'jetpack_get_available_modules', array( __CLASS__, 'filter_available_modules' ) ); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Drop the module from the available list while the flag is off, which also keeps it from loading. |
| 40 | * |
| 41 | * It stays off on the wpcom platform too, where the dashboard adds no page: see the package README. |
| 42 | * |
| 43 | * @param array $modules Available modules, keyed by slug. |
| 44 | * @return array |
| 45 | */ |
| 46 | public static function filter_available_modules( $modules ) { |
| 47 | if ( ! class_exists( Dashboard::class ) || ! Dashboard::is_enabled() || ( new Host() )->is_wpcom_platform() ) { |
| 48 | unset( $modules[ self::MODULE ] ); |
| 49 | } |
| 50 | return $modules; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | Jetpack_Monetize_Feature_Flags::register(); |