Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
47.83% |
11 / 23 |
|
50.00% |
4 / 8 |
CRAP | |
0.00% |
0 / 1 |
| Minify_Common | |
47.83% |
11 / 23 |
|
50.00% |
4 / 8 |
37.00 | |
0.00% |
0 / 1 |
| setup | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| get_slug | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| register_data_sync | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| is_available | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| show_legacy_notice | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
42 | |||
| activate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| deactivate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_parent_features | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Automattic\Jetpack_Boost\Modules\Optimizations\Minify; |
| 3 | |
| 4 | use Automattic\Jetpack\Schema\Schema; |
| 5 | use Automattic\Jetpack\WP_JS_Data_Sync\Data_Sync; |
| 6 | use Automattic\Jetpack_Boost\Contracts\Has_Activate; |
| 7 | use Automattic\Jetpack_Boost\Contracts\Has_Data_Sync; |
| 8 | use Automattic\Jetpack_Boost\Contracts\Has_Deactivate; |
| 9 | use Automattic\Jetpack_Boost\Contracts\Is_Always_On; |
| 10 | use Automattic\Jetpack_Boost\Contracts\Optimization; |
| 11 | use Automattic\Jetpack_Boost\Contracts\Sub_Feature; |
| 12 | |
| 13 | class Minify_Common implements Sub_Feature, Optimization, Is_Always_On, Has_Activate, Has_Deactivate, Has_Data_Sync { |
| 14 | |
| 15 | /** |
| 16 | * Setup the module. This runs on every page load. |
| 17 | */ |
| 18 | public function setup() { |
| 19 | require_once JETPACK_BOOST_DIR_PATH . '/app/lib/minify/functions-helpers.php'; |
| 20 | |
| 21 | jetpack_boost_minify_init(); |
| 22 | } |
| 23 | |
| 24 | public static function get_slug() { |
| 25 | return 'minify_common'; |
| 26 | } |
| 27 | |
| 28 | public function register_data_sync( Data_Sync $instance ) { |
| 29 | $instance->register_readonly( |
| 30 | 'minify_legacy_notice', |
| 31 | Schema::as_unsafe_any(), |
| 32 | array( self::class, 'show_legacy_notice' ) |
| 33 | ); |
| 34 | } |
| 35 | |
| 36 | public static function is_available() { |
| 37 | return true; |
| 38 | } |
| 39 | |
| 40 | public static function show_legacy_notice() { |
| 41 | // If the JETPACK_BOOST_DISABLE_404_TESTER is set and true, we don't need to show the legacy notice. |
| 42 | if ( defined( 'JETPACK_BOOST_DISABLE_404_TESTER' ) && JETPACK_BOOST_DISABLE_404_TESTER ) { |
| 43 | return false; |
| 44 | } |
| 45 | |
| 46 | // If this is a multisite, and the user is not a super admin, don't show the legacy notice, as they won't be able to do anything about it. |
| 47 | if ( is_multisite() && ! current_user_can( 'manage_network_options' ) ) { |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | // If the static minfification has not ran yet, don't show the legacy notice. |
| 52 | $static_minification_enabled = get_site_option( 'jetpack_boost_static_minification', 'na' ); |
| 53 | if ( $static_minification_enabled === 'na' ) { |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | // Otherwise show it if the 404 tester determined it can't be used. |
| 58 | return ! (bool) $static_minification_enabled; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * This is called when either minify module is activated |
| 63 | */ |
| 64 | public static function activate() { |
| 65 | jetpack_boost_minify_activation(); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * This is called when either minify module is deactivated. |
| 70 | */ |
| 71 | public static function deactivate() { |
| 72 | jetpack_boost_minify_clear_scheduled_events(); |
| 73 | } |
| 74 | |
| 75 | public static function get_parent_features(): array { |
| 76 | return array( |
| 77 | Minify_JS::class, |
| 78 | Minify_CSS::class, |
| 79 | ); |
| 80 | } |
| 81 | } |