Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
55.56% covered (warning)
55.56%
10 / 18
28.57% covered (danger)
28.57%
2 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
Minify_CSS
55.56% covered (warning)
55.56%
10 / 18
28.57% covered (danger)
28.57%
2 / 7
13.62
0.00% covered (danger)
0.00%
0 / 1
 setup
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 register_data_sync
88.89% covered (warning)
88.89%
8 / 9
0.00% covered (danger)
0.00%
0 / 1
1.00
 get_slug
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_change_output_action_names
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 is_available
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 init_minify
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 deactivate
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Automattic\Jetpack_Boost\Modules\Optimizations\Minify;
4
5use Automattic\Jetpack\Schema\Schema;
6use Automattic\Jetpack\WP_JS_Data_Sync\Data_Sync;
7use Automattic\Jetpack_Boost\Contracts\Changes_Output_After_Activation;
8use Automattic\Jetpack_Boost\Contracts\Changes_Output_On_Activation;
9use Automattic\Jetpack_Boost\Contracts\Feature;
10use Automattic\Jetpack_Boost\Contracts\Has_Data_Sync;
11use Automattic\Jetpack_Boost\Contracts\Has_Deactivate;
12use Automattic\Jetpack_Boost\Contracts\Optimization;
13use Automattic\Jetpack_Boost\Data_Sync\Minify_Excludes_State_Entry;
14use Automattic\Jetpack_Boost\Lib\Minify\Concatenate_CSS;
15
16class Minify_CSS implements Feature, Changes_Output_On_Activation, Changes_Output_After_Activation, Optimization, Has_Deactivate, Has_Data_Sync {
17
18    public static $default_excludes = array( 'admin-bar', 'dashicons', 'elementor-app' );
19
20    /**
21     * Setup the module. This runs on every page load.
22     */
23    public function setup() {
24        if ( jetpack_boost_page_optimize_bail() ) {
25            return;
26        }
27
28        add_action( 'init', array( $this, 'init_minify' ) );
29    }
30
31    public function register_data_sync( Data_Sync $instance ) {
32        $parser = Schema::as_array( Schema::as_string() )->fallback( self::$default_excludes );
33
34        $instance->register( 'minify_css_excludes', $parser, new Minify_Excludes_State_Entry( 'minify_css_excludes' ) );
35
36        $instance->register_readonly(
37            'minify_css_excludes_default',
38            Schema::as_unsafe_any(),
39            function () {
40                return Minify_CSS::$default_excludes;
41            }
42        );
43    }
44
45    public static function get_slug() {
46        return 'minify_css';
47    }
48
49    public static function get_change_output_action_names() {
50        return array( 'update_option_' . JETPACK_BOOST_DATASYNC_NAMESPACE . '_minify_css_excludes' );
51    }
52
53    public static function is_available() {
54        return true;
55    }
56
57    public function init_minify() {
58        global $wp_styles;
59
60        // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
61        $wp_styles                         = new Concatenate_CSS( $wp_styles );
62        $wp_styles->allow_gzip_compression = true; // @todo - used constant ALLOW_GZIP_COMPRESSION = true if not defined.
63    }
64
65    /**
66     * This is called only when the module is deactivated.
67     */
68    public static function deactivate() {
69        jetpack_boost_page_optimize_cleanup_cache( 'css' );
70    }
71}