Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
18 / 18 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Feature_Visibility | |
100.00% |
18 / 18 |
|
100.00% |
2 / 2 |
7 | |
100.00% |
1 / 1 |
| get_deprecated_modules | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
| get_hidden | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Resolves which items a host keeps off the My Jetpack Features page. |
| 4 | * |
| 5 | * @package automattic/my-jetpack |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\My_Jetpack; |
| 9 | |
| 10 | use Automattic\Jetpack\Admin_UI\Admin_Menu; |
| 11 | use Automattic\Jetpack\Feature_Policy; |
| 12 | |
| 13 | /** |
| 14 | * The Features page counterpart to the sidebar's `jetpack_admin_menu_visibility`. |
| 15 | * |
| 16 | * Display only: forcing a module on or off is `jetpack_active_modules`, which the page |
| 17 | * already honors by dropping the toggle. `jetpack_feature_policy` feeds that filter, this one, |
| 18 | * and the sidebar's alike, so one policy covers both surfaces. |
| 19 | */ |
| 20 | class Feature_Visibility { |
| 21 | /** |
| 22 | * Modules offered only to sites already running them. |
| 23 | * |
| 24 | * @since 6.11.0 |
| 25 | * @return string[] Module slugs. |
| 26 | */ |
| 27 | public static function get_deprecated_modules() { |
| 28 | return array_merge( |
| 29 | array( 'google-fonts' ), |
| 30 | function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ? array( 'widgets', 'widget-visibility' ) : array() |
| 31 | ); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Slugs a host has hidden from the page. |
| 36 | * |
| 37 | * @return string[] Product card and module slugs, in the order the host named them. |
| 38 | */ |
| 39 | public static function get_hidden() { |
| 40 | if ( method_exists( Feature_Policy::class, 'ensure_hooks' ) ) { |
| 41 | Feature_Policy::ensure_hooks(); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Filters which items appear on the My Jetpack Features page. |
| 46 | * |
| 47 | * Keys are product or module slugs, and a Features grid entry also answers to its own |
| 48 | * slug. 'hidden' keeps the item off the page, search included; anything else lists it. |
| 49 | * The whole map is passed so that two mu-plugins setting different keys merge. |
| 50 | * |
| 51 | * @since 6.6.0 |
| 52 | * |
| 53 | * @param array $states Map of slug to state, empty until a host adds to it. |
| 54 | */ |
| 55 | $states = apply_filters( 'jetpack_my_jetpack_feature_visibility', array() ); |
| 56 | |
| 57 | if ( ! is_array( $states ) ) { |
| 58 | return array(); |
| 59 | } |
| 60 | |
| 61 | $hidden = defined( Admin_Menu::class . '::VISIBILITY_HIDDEN' ) ? Admin_Menu::VISIBILITY_HIDDEN : 'hidden'; |
| 62 | |
| 63 | return array_keys( |
| 64 | array_filter( |
| 65 | $states, |
| 66 | function ( $state ) use ( $hidden ) { |
| 67 | return $hidden === $state; |
| 68 | } |
| 69 | ) |
| 70 | ); |
| 71 | } |
| 72 | } |