Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
62.50% |
10 / 16 |
|
50.00% |
2 / 4 |
CRAP | n/a |
0 / 0 |
|
| wpcomsh_activate_reader_module | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
5.07 | |||
| wpcomsh_report_forced_reader_module | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| wpcomsh_hide_reader_feature | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| wpcomsh_rm_reader_module_list | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Add a WordPress.com Reader link to the admin bar. |
| 4 | * We want that feature to always be available on Atomic sites. |
| 5 | * |
| 6 | * @package wpcomsh |
| 7 | */ |
| 8 | |
| 9 | /** |
| 10 | * Force-activate the Reader module, and report it as forced on. |
| 11 | */ |
| 12 | function wpcomsh_activate_reader_module() { |
| 13 | if ( ! defined( 'JETPACK__VERSION' ) || ! class_exists( 'Jetpack' ) ) { |
| 14 | return; |
| 15 | } |
| 16 | |
| 17 | if ( ! Jetpack::is_module_active( 'wpcom-reader' ) ) { |
| 18 | Jetpack::activate_module( 'wpcom-reader', false, false ); |
| 19 | } |
| 20 | |
| 21 | // After activating, for the reason given in wpcomsh_force_activate_blaze_module(). |
| 22 | if ( Jetpack::is_module_active( 'wpcom-reader' ) ) { |
| 23 | add_filter( 'jetpack_active_modules', 'wpcomsh_report_forced_reader_module' ); |
| 24 | add_filter( 'jetpack_my_jetpack_feature_visibility', 'wpcomsh_hide_reader_feature' ); |
| 25 | } |
| 26 | } |
| 27 | add_action( 'init', 'wpcomsh_activate_reader_module', 0, 0 ); |
| 28 | |
| 29 | /** |
| 30 | * Add Reader to the active modules, which Jetpack reads as forced on and locks its switch. |
| 31 | * |
| 32 | * @param array $modules Active module slugs. |
| 33 | * @return array |
| 34 | */ |
| 35 | function wpcomsh_report_forced_reader_module( $modules ) { |
| 36 | return array_merge( (array) $modules, array( 'wpcom-reader' ) ); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Keep Reader off the My Jetpack Features page, where its locked switch has nothing to offer. |
| 41 | * |
| 42 | * @param array $states Map of product or module slug to visibility state. |
| 43 | * @return array |
| 44 | */ |
| 45 | function wpcomsh_hide_reader_feature( $states ) { |
| 46 | $states = (array) $states; |
| 47 | $states['wpcom-reader'] = 'hidden'; |
| 48 | return $states; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Remove Reader from the old Module list. |
| 53 | * Available at wp-admin/admin.php?page=jetpack_modules |
| 54 | * |
| 55 | * @param array $items Array of Jetpack modules. |
| 56 | * @return array |
| 57 | */ |
| 58 | function wpcomsh_rm_reader_module_list( $items ) { |
| 59 | if ( isset( $items['wpcom-reader'] ) ) { |
| 60 | unset( $items['wpcom-reader'] ); |
| 61 | } |
| 62 | return $items; |
| 63 | } |
| 64 | add_filter( 'jetpack_modules_list_table_items', 'wpcomsh_rm_reader_module_list' ); |