Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| Feature_Visibility | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
4 | |
100.00% |
1 / 1 |
| 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 | /** |
| 23 | * Slugs a host has hidden from the page. |
| 24 | * |
| 25 | * @return string[] Product card and module slugs, in the order the host named them. |
| 26 | */ |
| 27 | public static function get_hidden() { |
| 28 | if ( method_exists( Feature_Policy::class, 'ensure_hooks' ) ) { |
| 29 | Feature_Policy::ensure_hooks(); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Filters which items appear on the My Jetpack Features page. |
| 34 | * |
| 35 | * Keys are product or module slugs, and a Features grid entry also answers to its own |
| 36 | * slug. 'hidden' keeps the item off the page, search included; anything else lists it. |
| 37 | * The whole map is passed so that two mu-plugins setting different keys merge. |
| 38 | * |
| 39 | * @since 6.6.0 |
| 40 | * |
| 41 | * @param array $states Map of slug to state, empty until a host adds to it. |
| 42 | */ |
| 43 | $states = apply_filters( 'jetpack_my_jetpack_feature_visibility', array() ); |
| 44 | |
| 45 | if ( ! is_array( $states ) ) { |
| 46 | return array(); |
| 47 | } |
| 48 | |
| 49 | $hidden = defined( Admin_Menu::class . '::VISIBILITY_HIDDEN' ) ? Admin_Menu::VISIBILITY_HIDDEN : 'hidden'; |
| 50 | |
| 51 | return array_keys( |
| 52 | array_filter( |
| 53 | $states, |
| 54 | function ( $state ) use ( $hidden ) { |
| 55 | return $hidden === $state; |
| 56 | } |
| 57 | ) |
| 58 | ); |
| 59 | } |
| 60 | } |