Completed
Push — master ( 888448...89a848 )
by frank
07:21 queued 03:15
created
classes/autoptimizeToolbar.php 1 patch
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Handles toolbar-related stuff.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -12,32 +12,32 @@  discard block
 block discarded – undo
12 12
     public function __construct()
13 13
     {
14 14
         // If Cache is not available we don't add the toolbar.
15
-        if ( ! autoptimizeCache::cacheavail() ) {
15
+        if (!autoptimizeCache::cacheavail()) {
16 16
             return;
17 17
         }
18 18
 
19 19
         // Load admin toolbar feature once WordPress, all plugins, and the theme are fully loaded and instantiated.
20
-        add_action( 'wp_loaded', array( $this, 'load_toolbar' ) );
20
+        add_action('wp_loaded', array($this, 'load_toolbar'));
21 21
     }
22 22
 
23 23
     public function load_toolbar()
24 24
     {
25 25
         // Check permissions and that toolbar is not hidden via filter.
26
-        if ( current_user_can( 'manage_options' ) && apply_filters( 'autoptimize_filter_toolbar_show', true ) ) {
26
+        if (current_user_can('manage_options') && apply_filters('autoptimize_filter_toolbar_show', true)) {
27 27
 
28 28
             // Create a handler for the AJAX toolbar requests.
29
-            add_action( 'wp_ajax_autoptimize_delete_cache', array( $this, 'delete_cache' ) );
29
+            add_action('wp_ajax_autoptimize_delete_cache', array($this, 'delete_cache'));
30 30
 
31 31
             // Load custom styles, scripts and menu only when needed.
32
-            if ( is_admin_bar_showing() ) {
33
-                if ( is_admin() ) {
34
-                    add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
32
+            if (is_admin_bar_showing()) {
33
+                if (is_admin()) {
34
+                    add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
35 35
                 } else {
36
-                    add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
36
+                    add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
37 37
                 }
38 38
 
39 39
                 // Add the Autoptimize Toolbar to the Admin bar.
40
-                add_action( 'admin_bar_menu', array( $this, 'add_toolbar' ), 100 );
40
+                add_action('admin_bar_menu', array($this, 'add_toolbar'), 100);
41 41
             }
42 42
         }
43 43
     }
@@ -50,17 +50,17 @@  discard block
 block discarded – undo
50 50
         $stats = autoptimizeCache::stats();
51 51
 
52 52
         // Set the Max Size recommended for cache files.
53
-        $max_size = apply_filters( 'autoptimize_filter_cachecheck_maxsize', 512 * 1024 * 1024 );
53
+        $max_size = apply_filters('autoptimize_filter_cachecheck_maxsize', 512*1024*1024);
54 54
 
55 55
         // Retrieve the current Total Files in cache.
56 56
         $files = $stats[0];
57 57
         // Retrieve the current Total Size of the cache.
58 58
         $bytes = $stats[1];
59
-        $size  = $this->format_filesize( $bytes );
59
+        $size  = $this->format_filesize($bytes);
60 60
 
61 61
         // Calculate the percentage of cache used.
62
-        $percentage = ceil( $bytes / $max_size * 100 );
63
-        if ( $percentage > 100 ) {
62
+        $percentage = ceil($bytes/$max_size*100);
63
+        if ($percentage > 100) {
64 64
             $percentage = 100;
65 65
         }
66 66
 
@@ -70,82 +70,82 @@  discard block
 block discarded – undo
70 70
          * - "orange" if over 80%.
71 71
          * - "red" if over 100%.
72 72
          */
73
-        $color = ( 100 == $percentage ) ? 'red' : ( ( $percentage > 80 ) ? 'orange' : 'green' );
73
+        $color = (100 == $percentage) ? 'red' : (($percentage > 80) ? 'orange' : 'green');
74 74
 
75 75
         // Create or add new items into the Admin Toolbar.
76 76
         // Main "Autoptimize" node.
77
-        $wp_admin_bar->add_node( array(
77
+        $wp_admin_bar->add_node(array(
78 78
             'id'    => 'autoptimize',
79
-            'title' => '<span class="ab-icon"></span><span class="ab-label">' . __( 'Autoptimize', 'autoptimize' ) . '</span>',
80
-            'href'  => admin_url( 'options-general.php?page=autoptimize' ),
81
-            'meta'  => array( 'class' => 'bullet-' . $color ),
79
+            'title' => '<span class="ab-icon"></span><span class="ab-label">'.__('Autoptimize', 'autoptimize').'</span>',
80
+            'href'  => admin_url('options-general.php?page=autoptimize'),
81
+            'meta'  => array('class' => 'bullet-'.$color),
82 82
         ));
83 83
 
84 84
         // "Cache Info" node.
85
-        $wp_admin_bar->add_node( array(
85
+        $wp_admin_bar->add_node(array(
86 86
             'id'     => 'autoptimize-cache-info',
87
-            'title'  => '<p>' . __( 'Cache Info', 'autoptimize' ) . '</p>' .
88
-                        '<div class="autoptimize-radial-bar" percentage="' . $percentage . '">' .
89
-                        '<div class="autoptimize-circle">' .
90
-                        '<div class="mask full"><div class="fill bg-' . $color . '"></div></div>' .
91
-                        '<div class="mask half"><div class="fill bg-' . $color . '"></div></div>' .
92
-                        '<div class="shadow"></div>' .
93
-                        '</div>' .
94
-                        '<div class="inset"><div class="percentage"><div class="numbers ' . $color . '">' . $percentage . '%</div></div></div>' .
95
-                        '</div>' .
96
-                        '<table>' .
97
-                        '<tr><td>' . __( 'Size', 'autoptimize' ) . ':</td><td class="size ' . $color . '">' . $size . '</td></tr>' .
98
-                        '<tr><td>' . __( 'Files', 'autoptimize' ) . ':</td><td class="files white">' . $files . '</td></tr>' .
87
+            'title'  => '<p>'.__('Cache Info', 'autoptimize').'</p>'.
88
+                        '<div class="autoptimize-radial-bar" percentage="'.$percentage.'">'.
89
+                        '<div class="autoptimize-circle">'.
90
+                        '<div class="mask full"><div class="fill bg-'.$color.'"></div></div>'.
91
+                        '<div class="mask half"><div class="fill bg-'.$color.'"></div></div>'.
92
+                        '<div class="shadow"></div>'.
93
+                        '</div>'.
94
+                        '<div class="inset"><div class="percentage"><div class="numbers '.$color.'">'.$percentage.'%</div></div></div>'.
95
+                        '</div>'.
96
+                        '<table>'.
97
+                        '<tr><td>'.__('Size', 'autoptimize').':</td><td class="size '.$color.'">'.$size.'</td></tr>'.
98
+                        '<tr><td>'.__('Files', 'autoptimize').':</td><td class="files white">'.$files.'</td></tr>'.
99 99
                         '</table>',
100 100
             'parent' => 'autoptimize',
101 101
         ));
102 102
 
103 103
         // "Delete Cache" node.
104
-        $wp_admin_bar->add_node( array(
104
+        $wp_admin_bar->add_node(array(
105 105
             'id'     => 'autoptimize-delete-cache',
106
-            'title'  => __( 'Delete Cache', 'autoptimize' ),
106
+            'title'  => __('Delete Cache', 'autoptimize'),
107 107
             'parent' => 'autoptimize',
108 108
         ));
109 109
     }
110 110
 
111 111
     public function delete_cache()
112 112
     {
113
-        check_ajax_referer( 'ao_delcache_nonce', 'nonce' );
113
+        check_ajax_referer('ao_delcache_nonce', 'nonce');
114 114
 
115 115
         $result = false;
116
-        if ( current_user_can( 'manage_options' ) ) {
116
+        if (current_user_can('manage_options')) {
117 117
             // We call the function for cleaning the Autoptimize cache.
118 118
             $result = autoptimizeCache::clearall();
119 119
         }
120 120
 
121
-        wp_send_json( $result );
121
+        wp_send_json($result);
122 122
     }
123 123
 
124 124
     public function enqueue_scripts()
125 125
     {
126 126
         // Autoptimize Toolbar Styles.
127
-        wp_enqueue_style( 'autoptimize-toolbar', plugins_url( '/static/toolbar.css', __FILE__ ), array(), AUTOPTIMIZE_PLUGIN_VERSION, 'all' );
127
+        wp_enqueue_style('autoptimize-toolbar', plugins_url('/static/toolbar.css', __FILE__), array(), AUTOPTIMIZE_PLUGIN_VERSION, 'all');
128 128
 
129 129
         // Autoptimize Toolbar Javascript.
130
-        wp_enqueue_script( 'autoptimize-toolbar', plugins_url( '/static/toolbar.js', __FILE__ ), array( 'jquery' ), AUTOPTIMIZE_PLUGIN_VERSION, true );
130
+        wp_enqueue_script('autoptimize-toolbar', plugins_url('/static/toolbar.js', __FILE__), array('jquery'), AUTOPTIMIZE_PLUGIN_VERSION, true);
131 131
 
132 132
         // Localizes a registered script with data for a JavaScript variable.
133 133
         // Needed for the AJAX to work properly on the frontend.
134
-        wp_localize_script( 'autoptimize-toolbar', 'autoptimize_ajax_object', array(
135
-            'ajaxurl'     => admin_url( 'admin-ajax.php' ),
134
+        wp_localize_script('autoptimize-toolbar', 'autoptimize_ajax_object', array(
135
+            'ajaxurl'     => admin_url('admin-ajax.php'),
136 136
             // translators: links to the Autoptimize settings page.
137
-            'error_msg'   => sprintf( __( 'Your Autoptimize cache might not have been purged successfully, please check on the <a href="%s">Autoptimize settings page</a>.', 'autoptimize' ), admin_url( 'options-general.php?page=autoptimize' ) . ' style="white-space:nowrap;"' ),
138
-            'dismiss_msg' => __( 'Dismiss this notice.' ),
139
-            'nonce'       => wp_create_nonce( 'ao_delcache_nonce' ),
140
-        ) );
137
+            'error_msg'   => sprintf(__('Your Autoptimize cache might not have been purged successfully, please check on the <a href="%s">Autoptimize settings page</a>.', 'autoptimize'), admin_url('options-general.php?page=autoptimize').' style="white-space:nowrap;"'),
138
+            'dismiss_msg' => __('Dismiss this notice.'),
139
+            'nonce'       => wp_create_nonce('ao_delcache_nonce'),
140
+        ));
141 141
     }
142 142
 
143
-    public function format_filesize( $bytes, $decimals = 2 )
143
+    public function format_filesize($bytes, $decimals = 2)
144 144
     {
145
-        $units = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' );
145
+        $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
146 146
 
147
-        for ( $i = 0; ( $bytes / 1024) > 0.9; $i++, $bytes /= 1024 ) {} // @codingStandardsIgnoreLine
147
+        for ($i = 0; ($bytes/1024) > 0.9; $i++, $bytes /= 1024) {} // @codingStandardsIgnoreLine
148 148
 
149
-        return sprintf( "%1.{$decimals}f %s", round( $bytes, $decimals ), $units[ $i ] );
149
+        return sprintf("%1.{$decimals}f %s", round($bytes, $decimals), $units[$i]);
150 150
     }
151 151
 }
Please login to merge, or discard this patch.
classes/autoptimizeExtra.php 1 patch
Spacing   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Handles autoptimizeExtra frontend features + admin options page
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -21,9 +21,9 @@  discard block
 block discarded – undo
21 21
      *
22 22
      * @param array $options Optional. Allows overriding options without having to specify them via admin options page.
23 23
      */
24
-    public function __construct( $options = array() )
24
+    public function __construct($options = array())
25 25
     {
26
-        if ( empty( $options ) ) {
26
+        if (empty($options)) {
27 27
             $options = self::fetch_options();
28 28
         }
29 29
 
@@ -32,9 +32,9 @@  discard block
 block discarded – undo
32 32
 
33 33
     public function run()
34 34
     {
35
-        if ( is_admin() ) {
36
-            add_action( 'admin_menu', array( $this, 'admin_menu' ) );
37
-            add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_extra_tab' ) );
35
+        if (is_admin()) {
36
+            add_action('admin_menu', array($this, 'admin_menu'));
37
+            add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_extra_tab'));
38 38
         } else {
39 39
             $this->run_on_frontend();
40 40
         }
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
 
43 43
     public static function fetch_options()
44 44
     {
45
-        $value = get_option( 'autoptimize_extra_settings' );
46
-        if ( empty( $value ) ) {
45
+        $value = get_option('autoptimize_extra_settings');
46
+        if (empty($value)) {
47 47
             // Fallback to returning defaults when no stored option exists yet.
48 48
             $value = autoptimizeConfig::get_ao_extra_default_options();
49 49
         }
@@ -54,55 +54,55 @@  discard block
 block discarded – undo
54 54
     public function disable_emojis()
55 55
     {
56 56
         // Removing all actions related to emojis!
57
-        remove_action( 'admin_print_styles', 'print_emoji_styles' );
58
-        remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
59
-        remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
60
-        remove_action( 'wp_print_styles', 'print_emoji_styles' );
61
-        remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
62
-        remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
63
-        remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
57
+        remove_action('admin_print_styles', 'print_emoji_styles');
58
+        remove_action('wp_head', 'print_emoji_detection_script', 7);
59
+        remove_action('admin_print_scripts', 'print_emoji_detection_script');
60
+        remove_action('wp_print_styles', 'print_emoji_styles');
61
+        remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
62
+        remove_filter('the_content_feed', 'wp_staticize_emoji');
63
+        remove_filter('comment_text_rss', 'wp_staticize_emoji');
64 64
 
65 65
         // Removes TinyMCE emojis.
66
-        add_filter( 'tiny_mce_plugins', array( $this, 'filter_disable_emojis_tinymce' ) );
66
+        add_filter('tiny_mce_plugins', array($this, 'filter_disable_emojis_tinymce'));
67 67
 
68 68
         // Removes emoji dns-preftech.
69
-        add_filter( 'wp_resource_hints', array( $this, 'filter_remove_emoji_dns_prefetch' ), 10, 2 );
69
+        add_filter('wp_resource_hints', array($this, 'filter_remove_emoji_dns_prefetch'), 10, 2);
70 70
     }
71 71
 
72
-    public function filter_disable_emojis_tinymce( $plugins )
72
+    public function filter_disable_emojis_tinymce($plugins)
73 73
     {
74
-        if ( is_array( $plugins ) ) {
75
-            return array_diff( $plugins, array( 'wpemoji' ) );
74
+        if (is_array($plugins)) {
75
+            return array_diff($plugins, array('wpemoji'));
76 76
         } else {
77 77
             return array();
78 78
         }
79 79
     }
80 80
 
81
-    public function filter_remove_qs( $src )
81
+    public function filter_remove_qs($src)
82 82
     {
83
-        if ( strpos( $src, '?ver=' ) ) {
84
-            $src = remove_query_arg( 'ver', $src );
83
+        if (strpos($src, '?ver=')) {
84
+            $src = remove_query_arg('ver', $src);
85 85
         }
86 86
 
87 87
         return $src;
88 88
     }
89 89
 
90
-    public function extra_async_js( $in )
90
+    public function extra_async_js($in)
91 91
     {
92 92
         $exclusions = array();
93
-        if ( ! empty( $in ) ) {
94
-            $exclusions = array_fill_keys( array_filter( array_map( 'trim', explode( ',', $in ) ) ), '' );
93
+        if (!empty($in)) {
94
+            $exclusions = array_fill_keys(array_filter(array_map('trim', explode(',', $in))), '');
95 95
         }
96 96
 
97 97
         $settings = $this->options['autoptimize_extra_text_field_3'];
98
-        $async    = array_fill_keys( array_filter( array_map( 'trim', explode( ',', $settings ) ) ), '' );
99
-        $attr     = apply_filters( 'autoptimize_filter_extra_async', 'async' );
100
-        foreach ( $async as $k => $v ) {
101
-            $async[ $k ] = $attr;
98
+        $async    = array_fill_keys(array_filter(array_map('trim', explode(',', $settings))), '');
99
+        $attr     = apply_filters('autoptimize_filter_extra_async', 'async');
100
+        foreach ($async as $k => $v) {
101
+            $async[$k] = $attr;
102 102
         }
103 103
 
104 104
         // Merge exclusions & asyncs in one array and return to AO API.
105
-        $merged = array_merge( $exclusions, $async );
105
+        $merged = array_merge($exclusions, $async);
106 106
 
107 107
         return $merged;
108 108
     }
@@ -112,54 +112,54 @@  discard block
 block discarded – undo
112 112
         $options = $this->options;
113 113
 
114 114
         // Disable emojis if specified.
115
-        if ( ! empty( $options['autoptimize_extra_checkbox_field_1'] ) ) {
115
+        if (!empty($options['autoptimize_extra_checkbox_field_1'])) {
116 116
             $this->disable_emojis();
117 117
         }
118 118
 
119 119
         // Remove version query parameters.
120
-        if ( ! empty( $options['autoptimize_extra_checkbox_field_0'] ) ) {
121
-            add_filter( 'script_loader_src', array( $this, 'filter_remove_qs' ), 15, 1 );
122
-            add_filter( 'style_loader_src', array( $this, 'filter_remove_qs' ), 15, 1 );
120
+        if (!empty($options['autoptimize_extra_checkbox_field_0'])) {
121
+            add_filter('script_loader_src', array($this, 'filter_remove_qs'), 15, 1);
122
+            add_filter('style_loader_src', array($this, 'filter_remove_qs'), 15, 1);
123 123
         }
124 124
 
125 125
         // Avoiding conflicts of interest when async-javascript plugin is active!
126
-        $async_js_plugin_active = autoptimizeUtils::is_plugin_active( 'async-javascript/async-javascript.php' );
127
-        if ( ! empty( $options['autoptimize_extra_text_field_3'] ) && ! $async_js_plugin_active ) {
128
-            add_filter( 'autoptimize_filter_js_exclude', array( $this, 'extra_async_js' ), 10, 1 );
126
+        $async_js_plugin_active = autoptimizeUtils::is_plugin_active('async-javascript/async-javascript.php');
127
+        if (!empty($options['autoptimize_extra_text_field_3']) && !$async_js_plugin_active) {
128
+            add_filter('autoptimize_filter_js_exclude', array($this, 'extra_async_js'), 10, 1);
129 129
         }
130 130
 
131 131
         // Optimize google fonts!
132
-        if ( ! empty( $options['autoptimize_extra_radio_field_4'] ) && ( '1' !== $options['autoptimize_extra_radio_field_4'] ) ) {
133
-            add_filter( 'wp_resource_hints', array( $this, 'filter_remove_gfonts_dnsprefetch' ), 10, 2 );
134
-            add_filter( 'autoptimize_html_after_minify', array( $this, 'filter_optimize_google_fonts' ), 10, 1 );
135
-            add_filter( 'autoptimize_extra_filter_tobepreconn', array( $this, 'filter_preconnect_google_fonts' ), 10, 1 );
132
+        if (!empty($options['autoptimize_extra_radio_field_4']) && ('1' !== $options['autoptimize_extra_radio_field_4'])) {
133
+            add_filter('wp_resource_hints', array($this, 'filter_remove_gfonts_dnsprefetch'), 10, 2);
134
+            add_filter('autoptimize_html_after_minify', array($this, 'filter_optimize_google_fonts'), 10, 1);
135
+            add_filter('autoptimize_extra_filter_tobepreconn', array($this, 'filter_preconnect_google_fonts'), 10, 1);
136 136
         }
137 137
 
138 138
         // Preconnect!
139
-        if ( ! empty( $options['autoptimize_extra_text_field_2'] ) || has_filter( 'autoptimize_extra_filter_tobepreconn' ) ) {
140
-            add_filter( 'wp_resource_hints', array( $this, 'filter_preconnect' ), 10, 2 );
139
+        if (!empty($options['autoptimize_extra_text_field_2']) || has_filter('autoptimize_extra_filter_tobepreconn')) {
140
+            add_filter('wp_resource_hints', array($this, 'filter_preconnect'), 10, 2);
141 141
         }
142 142
     }
143 143
 
144
-    public function filter_remove_emoji_dns_prefetch( $urls, $relation_type )
144
+    public function filter_remove_emoji_dns_prefetch($urls, $relation_type)
145 145
     {
146
-        $emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/' );
146
+        $emoji_svg_url = apply_filters('emoji_svg_url', 'https://s.w.org/images/core/emoji/');
147 147
 
148
-        return $this->filter_remove_dns_prefetch( $urls, $relation_type, $emoji_svg_url );
148
+        return $this->filter_remove_dns_prefetch($urls, $relation_type, $emoji_svg_url);
149 149
     }
150 150
 
151
-    public function filter_remove_gfonts_dnsprefetch( $urls, $relation_type )
151
+    public function filter_remove_gfonts_dnsprefetch($urls, $relation_type)
152 152
     {
153
-        return $this->filter_remove_dns_prefetch( $urls, $relation_type, 'fonts.googleapis.com' );
153
+        return $this->filter_remove_dns_prefetch($urls, $relation_type, 'fonts.googleapis.com');
154 154
     }
155 155
 
156
-    public function filter_remove_dns_prefetch( $urls, $relation_type, $url_to_remove )
156
+    public function filter_remove_dns_prefetch($urls, $relation_type, $url_to_remove)
157 157
     {
158
-        if ( 'dns-prefetch' === $relation_type ) {
158
+        if ('dns-prefetch' === $relation_type) {
159 159
             $cnt = 0;
160
-            foreach ( $urls as $url ) {
161
-                if ( false !== strpos( $url, $url_to_remove ) ) {
162
-                    unset( $urls[ $cnt ] );
160
+            foreach ($urls as $url) {
161
+                if (false !== strpos($url, $url_to_remove)) {
162
+                    unset($urls[$cnt]);
163 163
                 }
164 164
                 $cnt++;
165 165
             }
@@ -168,131 +168,131 @@  discard block
 block discarded – undo
168 168
         return $urls;
169 169
     }
170 170
 
171
-    public function filter_optimize_google_fonts( $in )
171
+    public function filter_optimize_google_fonts($in)
172 172
     {
173 173
         // Extract fonts, partly based on wp rocket's extraction code.
174
-        $markup = preg_replace( '/<!--(.*)-->/Uis', '', $in );
175
-        preg_match_all( '#<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'"])((?:https?:)?\/\/fonts\.googleapis\.com\/css(?:(?!\1).)+)\1)(?:\s+[^>]*)?>#iU', $markup, $matches );
174
+        $markup = preg_replace('/<!--(.*)-->/Uis', '', $in);
175
+        preg_match_all('#<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'"])((?:https?:)?\/\/fonts\.googleapis\.com\/css(?:(?!\1).)+)\1)(?:\s+[^>]*)?>#iU', $markup, $matches);
176 176
 
177 177
         $fonts_collection = array();
178
-        if ( ! $matches[2] ) {
178
+        if (!$matches[2]) {
179 179
             return $in;
180 180
         }
181 181
 
182 182
         // Store them in $fonts array.
183 183
         $i = 0;
184
-        foreach ( $matches[2] as $font ) {
185
-            if ( ! preg_match( '/rel=["\']dns-prefetch["\']/', $matches[0][ $i ] ) ) {
184
+        foreach ($matches[2] as $font) {
185
+            if (!preg_match('/rel=["\']dns-prefetch["\']/', $matches[0][$i])) {
186 186
                 // Get fonts name.
187
-                $font = str_replace( array( '%7C', '%7c' ), '|', $font );
188
-                $font = explode( 'family=', $font );
189
-                $font = ( isset( $font[1] ) ) ? explode( '&', $font[1] ) : array();
187
+                $font = str_replace(array('%7C', '%7c'), '|', $font);
188
+                $font = explode('family=', $font);
189
+                $font = (isset($font[1])) ? explode('&', $font[1]) : array();
190 190
                 // Add font to $fonts[$i] but make sure not to pollute with an empty family!
191
-                $_thisfont = array_values( array_filter( explode( '|', reset( $font ) ) ) );
192
-                if ( ! empty( $_thisfont ) ) {
193
-                    $fonts_collection[ $i ]['fonts'] = $_thisfont;
191
+                $_thisfont = array_values(array_filter(explode('|', reset($font))));
192
+                if (!empty($_thisfont)) {
193
+                    $fonts_collection[$i]['fonts'] = $_thisfont;
194 194
                     // And add subset if any!
195
-                    $subset = ( is_array( $font ) ) ? end( $font ) : '';
196
-                    if ( false !== strpos( $subset, 'subset=' ) ) {
197
-                        $subset                            = str_replace( array( '%2C', '%2c' ), ',', $subset );
198
-                        $subset                            = explode( 'subset=', $subset );
199
-                        $fonts_collection[ $i ]['subsets'] = explode( ',', $subset[1] );
195
+                    $subset = (is_array($font)) ? end($font) : '';
196
+                    if (false !== strpos($subset, 'subset=')) {
197
+                        $subset                            = str_replace(array('%2C', '%2c'), ',', $subset);
198
+                        $subset                            = explode('subset=', $subset);
199
+                        $fonts_collection[$i]['subsets'] = explode(',', $subset[1]);
200 200
                     }
201 201
                 }
202 202
                 // And remove Google Fonts.
203
-                $in = str_replace( $matches[0][ $i ], '', $in );
203
+                $in = str_replace($matches[0][$i], '', $in);
204 204
             }
205 205
             $i++;
206 206
         }
207 207
 
208 208
         $options      = $this->options;
209 209
         $fonts_markup = '';
210
-        if ( '2' === $options['autoptimize_extra_radio_field_4'] ) {
210
+        if ('2' === $options['autoptimize_extra_radio_field_4']) {
211 211
             // Remove Google Fonts.
212
-            unset( $fonts_collection );
212
+            unset($fonts_collection);
213 213
             return $in;
214
-        } elseif ( '3' === $options['autoptimize_extra_radio_field_4'] || '5' === $options['autoptimize_extra_radio_field_4'] ) {
214
+        } elseif ('3' === $options['autoptimize_extra_radio_field_4'] || '5' === $options['autoptimize_extra_radio_field_4']) {
215 215
             // Aggregate & link!
216 216
             $fonts_string  = '';
217 217
             $subset_string = '';
218
-            foreach ( $fonts_collection as $font ) {
219
-                $fonts_string .= '|' . trim( implode( '|', $font['fonts'] ), '|' );
220
-                if ( ! empty( $font['subsets'] ) ) {
221
-                    $subset_string .= ',' . trim( implode( ',', $font['subsets'] ), ',' );
218
+            foreach ($fonts_collection as $font) {
219
+                $fonts_string .= '|'.trim(implode('|', $font['fonts']), '|');
220
+                if (!empty($font['subsets'])) {
221
+                    $subset_string .= ','.trim(implode(',', $font['subsets']), ',');
222 222
                 }
223 223
             }
224 224
 
225
-            if ( ! empty( $subset_string ) ) {
226
-                $subset_string = str_replace( ',', '%2C', ltrim( $subset_string, ',' ) );
227
-                $fonts_string  = $fonts_string . '&#038;subset=' . $subset_string;
225
+            if (!empty($subset_string)) {
226
+                $subset_string = str_replace(',', '%2C', ltrim($subset_string, ','));
227
+                $fonts_string  = $fonts_string.'&#038;subset='.$subset_string;
228 228
             }
229 229
 
230
-            $fonts_string = str_replace( '|', '%7C', ltrim( $fonts_string, '|' ) );
230
+            $fonts_string = str_replace('|', '%7C', ltrim($fonts_string, '|'));
231 231
 
232
-            if ( ! empty( $fonts_string ) ) {
233
-                if ( '5' === $options['autoptimize_extra_radio_field_4'] ) {
234
-                    $rel_string = 'rel="preload" as="style" onload="' . autoptimizeConfig::get_ao_css_preload_onload() . '"';
232
+            if (!empty($fonts_string)) {
233
+                if ('5' === $options['autoptimize_extra_radio_field_4']) {
234
+                    $rel_string = 'rel="preload" as="style" onload="'.autoptimizeConfig::get_ao_css_preload_onload().'"';
235 235
                 } else {
236 236
                     $rel_string = 'rel="stylesheet"';
237 237
                 }
238
-                $fonts_markup = '<link ' . $rel_string . ' id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family=' . $fonts_string . '" />';
238
+                $fonts_markup = '<link '.$rel_string.' id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family='.$fonts_string.'" />';
239 239
             }
240
-        } elseif ( '4' === $options['autoptimize_extra_radio_field_4'] ) {
240
+        } elseif ('4' === $options['autoptimize_extra_radio_field_4']) {
241 241
             // Aggregate & load async (webfont.js impl.)!
242 242
             $fonts_array = array();
243
-            foreach ( $fonts_collection as $_fonts ) {
244
-                if ( ! empty( $_fonts['subsets'] ) ) {
245
-                    $_subset = implode( ',', $_fonts['subsets'] );
246
-                    foreach ( $_fonts['fonts'] as $key => $_one_font ) {
247
-                        $_one_font               = $_one_font . ':' . $_subset;
248
-                        $_fonts['fonts'][ $key ] = $_one_font;
243
+            foreach ($fonts_collection as $_fonts) {
244
+                if (!empty($_fonts['subsets'])) {
245
+                    $_subset = implode(',', $_fonts['subsets']);
246
+                    foreach ($_fonts['fonts'] as $key => $_one_font) {
247
+                        $_one_font               = $_one_font.':'.$_subset;
248
+                        $_fonts['fonts'][$key] = $_one_font;
249 249
                     }
250 250
                 }
251
-                $fonts_array = array_merge( $fonts_array, $_fonts['fonts'] );
251
+                $fonts_array = array_merge($fonts_array, $_fonts['fonts']);
252 252
             }
253 253
 
254
-            $fonts_array          = array_map( 'urldecode', $fonts_array );
255
-            $fonts_markup         = '<script data-cfasync="false" id="ao_optimized_gfonts_config" type="text/javascript">WebFontConfig={google:{families:' . wp_json_encode( $fonts_array ) . ' },classes:false, events:false, timeout:1500};</script>';
254
+            $fonts_array          = array_map('urldecode', $fonts_array);
255
+            $fonts_markup         = '<script data-cfasync="false" id="ao_optimized_gfonts_config" type="text/javascript">WebFontConfig={google:{families:'.wp_json_encode($fonts_array).' },classes:false, events:false, timeout:1500};</script>';
256 256
             $fonts_library_markup = '<script data-cfasync="false" id="ao_optimized_gfonts_webfontloader" type="text/javascript">(function() {var wf = document.createElement(\'script\');wf.src=\'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js\';wf.type=\'text/javascript\';wf.async=\'true\';var s=document.getElementsByTagName(\'script\')[0];s.parentNode.insertBefore(wf, s);})();</script>';
257
-            $in                   = substr_replace( $in, $fonts_library_markup . '</head>', strpos( $in, '</head>' ), strlen( '</head>' ) );
257
+            $in                   = substr_replace($in, $fonts_library_markup.'</head>', strpos($in, '</head>'), strlen('</head>'));
258 258
         }
259 259
 
260 260
         // Replace back in markup.
261
-        $inject_point = apply_filters( 'autoptimize_filter_extra_gfont_injectpoint', '<link' );
262
-        $out          = substr_replace( $in, $fonts_markup . $inject_point, strpos( $in, $inject_point ), strlen( $inject_point ) );
263
-        unset( $fonts_collection );
261
+        $inject_point = apply_filters('autoptimize_filter_extra_gfont_injectpoint', '<link');
262
+        $out          = substr_replace($in, $fonts_markup.$inject_point, strpos($in, $inject_point), strlen($inject_point));
263
+        unset($fonts_collection);
264 264
 
265 265
         // and insert preload polyfill if "link preload" and if the polyfill isn't there yet (courtesy of inline&defer).
266 266
         $preload_polyfill = autoptimizeConfig::get_ao_css_preload_polyfill();
267
-        if ( '5' === $options['autoptimize_extra_radio_field_4'] && strpos( $out, $preload_polyfill ) === false ) {
268
-            $out = str_replace( '</body>', $preload_polyfill . '</body>', $out );
267
+        if ('5' === $options['autoptimize_extra_radio_field_4'] && strpos($out, $preload_polyfill) === false) {
268
+            $out = str_replace('</body>', $preload_polyfill.'</body>', $out);
269 269
         }
270 270
         return $out;
271 271
     }
272 272
 
273
-    public function filter_preconnect( $hints, $relation_type )
273
+    public function filter_preconnect($hints, $relation_type)
274 274
     {
275 275
         $options = $this->options;
276 276
 
277 277
         // Get settings and store in array.
278
-        $preconns = array_filter( array_map( 'trim', explode( ',', $options['autoptimize_extra_text_field_2'] ) ) );
279
-        $preconns = apply_filters( 'autoptimize_extra_filter_tobepreconn', $preconns );
278
+        $preconns = array_filter(array_map('trim', explode(',', $options['autoptimize_extra_text_field_2'])));
279
+        $preconns = apply_filters('autoptimize_extra_filter_tobepreconn', $preconns);
280 280
 
281 281
         // Walk array, extract domain and add to new array with crossorigin attribute.
282
-        foreach ( $preconns as $preconn ) {
283
-            $parsed = parse_url( $preconn );
284
-            if ( is_array( $parsed ) && empty( $parsed['scheme'] ) ) {
285
-                $domain = '//' . $parsed['host'];
286
-            } elseif ( is_array( $parsed ) ) {
287
-                $domain = $parsed['scheme'] . '://' . $parsed['host'];
282
+        foreach ($preconns as $preconn) {
283
+            $parsed = parse_url($preconn);
284
+            if (is_array($parsed) && empty($parsed['scheme'])) {
285
+                $domain = '//'.$parsed['host'];
286
+            } elseif (is_array($parsed)) {
287
+                $domain = $parsed['scheme'].'://'.$parsed['host'];
288 288
             }
289 289
 
290
-            if ( ! empty( $domain ) ) {
291
-                $hint = array( 'href' => $domain );
290
+            if (!empty($domain)) {
291
+                $hint = array('href' => $domain);
292 292
                 // Fonts don't get preconnected unless crossorigin flag is set, non-fonts don't get preconnected if origin flag is set
293 293
                 // so hardcode fonts.gstatic.com to come with crossorigin and have filter to add other domains if needed.
294
-                $crossorigins = apply_filters( 'autoptimize_extra_filter_preconn_crossorigin', array( 'https://fonts.gstatic.com' ) );
295
-                if ( in_array( $domain, $crossorigins ) ) {
294
+                $crossorigins = apply_filters('autoptimize_extra_filter_preconn_crossorigin', array('https://fonts.gstatic.com'));
295
+                if (in_array($domain, $crossorigins)) {
296 296
                     $hint['crossorigin'] = 'anonymous';
297 297
                 }
298 298
                 $new_hints[] = $hint;
@@ -300,21 +300,21 @@  discard block
 block discarded – undo
300 300
         }
301 301
 
302 302
         // Merge in WP's preconnect hints.
303
-        if ( 'preconnect' === $relation_type && ! empty( $new_hints ) ) {
304
-            $hints = array_merge( $hints, $new_hints );
303
+        if ('preconnect' === $relation_type && !empty($new_hints)) {
304
+            $hints = array_merge($hints, $new_hints);
305 305
         }
306 306
 
307 307
         return $hints;
308 308
     }
309 309
 
310
-    public function filter_preconnect_google_fonts( $in )
310
+    public function filter_preconnect_google_fonts($in)
311 311
     {
312
-        if ( '2' !== $this->options['autoptimize_extra_radio_field_4'] ) {
312
+        if ('2' !== $this->options['autoptimize_extra_radio_field_4']) {
313 313
             // Preconnect to fonts.gstatic.com unless we remove gfonts.
314 314
             $in[] = 'https://fonts.gstatic.com';
315 315
         }
316 316
 
317
-        if ( '4' === $this->options['autoptimize_extra_radio_field_4'] ) {
317
+        if ('4' === $this->options['autoptimize_extra_radio_field_4']) {
318 318
             // Preconnect even more hosts for webfont.js!
319 319
             $in[] = 'https://ajax.googleapis.com';
320 320
             $in[] = 'https://fonts.googleapis.com';
@@ -331,14 +331,14 @@  discard block
 block discarded – undo
331 331
             'autoptimize_extra',
332 332
             'manage_options',
333 333
             'autoptimize_extra',
334
-            array( $this, 'options_page' )
334
+            array($this, 'options_page')
335 335
         );
336
-        register_setting( 'autoptimize_extra_settings', 'autoptimize_extra_settings' );
336
+        register_setting('autoptimize_extra_settings', 'autoptimize_extra_settings');
337 337
     }
338 338
 
339
-    public function add_extra_tab( $in )
339
+    public function add_extra_tab($in)
340 340
     {
341
-        $in = array_merge( $in, array( 'autoptimize_extra' => __( 'Extra', 'autoptimize' ) ) );
341
+        $in = array_merge($in, array('autoptimize_extra' => __('Extra', 'autoptimize')));
342 342
 
343 343
         return $in;
344 344
     }
@@ -358,87 +358,87 @@  discard block
 block discarded – undo
358 358
         #autoptimize_extra_descr{font-size: 120%;}
359 359
     </style>
360 360
     <div class="wrap">
361
-    <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
361
+    <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
362 362
         <?php echo autoptimizeConfig::ao_admin_tabs(); ?>
363
-        <?php if ( 'on' !== get_option( 'autoptimize_js' ) && 'on' !== get_option( 'autoptimize_css' ) && 'on' !== get_option( 'autoptimize_html' ) && ! autoptimizeImages::imgopt_active() ) { ?>
363
+        <?php if ('on' !== get_option('autoptimize_js') && 'on' !== get_option('autoptimize_css') && 'on' !== get_option('autoptimize_html') && !autoptimizeImages::imgopt_active()) { ?>
364 364
             <div class="notice-warning notice"><p>
365
-            <?php _e( 'Most of below Extra optimizations require at least one of HTML, JS, CSS or Image autoptimizations being active.', 'autoptimize' ); ?>
365
+            <?php _e('Most of below Extra optimizations require at least one of HTML, JS, CSS or Image autoptimizations being active.', 'autoptimize'); ?>
366 366
             </p></div>
367 367
         <?php } ?>
368 368
 
369 369
     <form id='ao_settings_form' action='options.php' method='post'>
370
-        <?php settings_fields( 'autoptimize_extra_settings' ); ?>
371
-        <h2><?php _e( 'Extra Auto-Optimizations', 'autoptimize' ); ?></h2>
372
-        <span id='autoptimize_extra_descr'><?php _e( 'The following settings can improve your site\'s performance even more.', 'autoptimize' ); ?></span>
370
+        <?php settings_fields('autoptimize_extra_settings'); ?>
371
+        <h2><?php _e('Extra Auto-Optimizations', 'autoptimize'); ?></h2>
372
+        <span id='autoptimize_extra_descr'><?php _e('The following settings can improve your site\'s performance even more.', 'autoptimize'); ?></span>
373 373
         <table class="form-table">
374 374
             <tr>
375
-                <th scope="row"><?php _e( 'Google Fonts', 'autoptimize' ); ?></th>
375
+                <th scope="row"><?php _e('Google Fonts', 'autoptimize'); ?></th>
376 376
                 <td>
377
-                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="1" <?php if ( ! in_array( $gfonts, array( 2, 3, 4, 5 ) ) ) { echo 'checked'; } ?> ><?php _e( 'Leave as is', 'autoptimize' ); ?><br/>
378
-                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="2" <?php checked( 2, $gfonts, true ); ?> ><?php _e( 'Remove Google Fonts', 'autoptimize' ); ?><br/>
379
-                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="3" <?php checked( 3, $gfonts, true ); ?> ><?php _e( 'Combine and link in head (fonts load fast but are render-blocking)', 'autoptimize' ); ?><br/>
380
-                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="5" <?php checked( 5, $gfonts, true ); ?> ><?php _e( 'Combine and preload in head (fonts load late, but are not render-blocking)', 'autoptimize' ); ?><br/>
381
-                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="4" <?php checked( 4, $gfonts, true ); ?> ><?php _e( 'Combine and load fonts asynchronously with <a href="https://github.com/typekit/webfontloader#readme" target="_blank">webfont.js</a>', 'autoptimize' ); ?><br/>
377
+                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="1" <?php if (!in_array($gfonts, array(2, 3, 4, 5))) { echo 'checked'; } ?> ><?php _e('Leave as is', 'autoptimize'); ?><br/>
378
+                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="2" <?php checked(2, $gfonts, true); ?> ><?php _e('Remove Google Fonts', 'autoptimize'); ?><br/>
379
+                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="3" <?php checked(3, $gfonts, true); ?> ><?php _e('Combine and link in head (fonts load fast but are render-blocking)', 'autoptimize'); ?><br/>
380
+                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="5" <?php checked(5, $gfonts, true); ?> ><?php _e('Combine and preload in head (fonts load late, but are not render-blocking)', 'autoptimize'); ?><br/>
381
+                    <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="4" <?php checked(4, $gfonts, true); ?> ><?php _e('Combine and load fonts asynchronously with <a href="https://github.com/typekit/webfontloader#readme" target="_blank">webfont.js</a>', 'autoptimize'); ?><br/>
382 382
                 </td>
383 383
             </tr>
384 384
             <tr>
385
-                <th scope="row"><?php _e( 'Remove emojis', 'autoptimize' ); ?></th>
385
+                <th scope="row"><?php _e('Remove emojis', 'autoptimize'); ?></th>
386 386
                 <td>
387
-                    <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_1]' <?php if ( ! empty( $options['autoptimize_extra_checkbox_field_1'] ) && '1' === $options['autoptimize_extra_checkbox_field_1'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Removes WordPress\' core emojis\' inline CSS, inline JavaScript, and an otherwise un-autoptimized JavaScript file.', 'autoptimize' ); ?></label>
387
+                    <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_1]' <?php if (!empty($options['autoptimize_extra_checkbox_field_1']) && '1' === $options['autoptimize_extra_checkbox_field_1']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Removes WordPress\' core emojis\' inline CSS, inline JavaScript, and an otherwise un-autoptimized JavaScript file.', 'autoptimize'); ?></label>
388 388
                 </td>
389 389
             </tr>
390 390
             <tr>
391
-                <th scope="row"><?php _e( 'Remove query strings from static resources', 'autoptimize' ); ?></th>
391
+                <th scope="row"><?php _e('Remove query strings from static resources', 'autoptimize'); ?></th>
392 392
                 <td>
393
-                    <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_0]' <?php if ( ! empty( $options['autoptimize_extra_checkbox_field_0'] ) && '1' === $options['autoptimize_extra_checkbox_field_0'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Removing query strings (or more specifically the <code>ver</code> parameter) will not improve load time, but might improve performance scores.', 'autoptimize' ); ?></label>
393
+                    <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_0]' <?php if (!empty($options['autoptimize_extra_checkbox_field_0']) && '1' === $options['autoptimize_extra_checkbox_field_0']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Removing query strings (or more specifically the <code>ver</code> parameter) will not improve load time, but might improve performance scores.', 'autoptimize'); ?></label>
394 394
                 </td>
395 395
             </tr>
396 396
             <tr>
397
-                <th scope="row"><?php _e( 'Preconnect to 3rd party domains <em>(advanced users)</em>', 'autoptimize' ); ?></th>
397
+                <th scope="row"><?php _e('Preconnect to 3rd party domains <em>(advanced users)</em>', 'autoptimize'); ?></th>
398 398
                 <td>
399
-                    <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_2]' value='<?php if ( array_key_exists( 'autoptimize_extra_text_field_2', $options ) ) { echo esc_attr( $options['autoptimize_extra_text_field_2'] ); } ?>'><br /><?php _e( 'Add 3rd party domains you want the browser to <a href="https://www.keycdn.com/support/preconnect/#primary" target="_blank">preconnect</a> to, separated by comma\'s. Make sure to include the correct protocol (HTTP or HTTPS).', 'autoptimize' ); ?></label>
399
+                    <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_2]' value='<?php if (array_key_exists('autoptimize_extra_text_field_2', $options)) { echo esc_attr($options['autoptimize_extra_text_field_2']); } ?>'><br /><?php _e('Add 3rd party domains you want the browser to <a href="https://www.keycdn.com/support/preconnect/#primary" target="_blank">preconnect</a> to, separated by comma\'s. Make sure to include the correct protocol (HTTP or HTTPS).', 'autoptimize'); ?></label>
400 400
                 </td>
401 401
             </tr>
402 402
             <tr>
403
-                <th scope="row"><?php _e( 'Async Javascript-files <em>(advanced users)</em>', 'autoptimize' ); ?></th>
403
+                <th scope="row"><?php _e('Async Javascript-files <em>(advanced users)</em>', 'autoptimize'); ?></th>
404 404
                 <td>
405 405
                     <?php
406
-                    if ( autoptimizeUtils::is_plugin_active( 'async-javascript/async-javascript.php' ) ) {
406
+                    if (autoptimizeUtils::is_plugin_active('async-javascript/async-javascript.php')) {
407 407
                         // translators: link points Async Javascript settings page.
408
-                        printf( __( 'You have "Async JavaScript" installed, %1$sconfiguration of async javascript is best done there%2$s.', 'autoptimize' ), '<a href="' . 'options-general.php?page=async-javascript' . '">', '</a>' );
408
+                        printf(__('You have "Async JavaScript" installed, %1$sconfiguration of async javascript is best done there%2$s.', 'autoptimize'), '<a href="'.'options-general.php?page=async-javascript'.'">', '</a>');
409 409
                     } else {
410 410
                     ?>
411
-                        <input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_3]' value='<?php if ( array_key_exists( 'autoptimize_extra_text_field_3', $options ) ) { echo esc_attr( $options['autoptimize_extra_text_field_3'] ); } ?>'>
411
+                        <input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_3]' value='<?php if (array_key_exists('autoptimize_extra_text_field_3', $options)) { echo esc_attr($options['autoptimize_extra_text_field_3']); } ?>'>
412 412
                         <br />
413 413
                         <?php
414
-                            _e( 'Comma-separated list of local or 3rd party JS-files that should loaded with the <code>async</code> flag. JS-files from your own site will be automatically excluded if added here. ', 'autoptimize' );
414
+                            _e('Comma-separated list of local or 3rd party JS-files that should loaded with the <code>async</code> flag. JS-files from your own site will be automatically excluded if added here. ', 'autoptimize');
415 415
                             // translators: %s will be replaced by a link to the "async javascript" plugin.
416
-                            echo sprintf( __( 'Configuration of async javascript is easier and more flexible using the %s plugin.', 'autoptimize' ), '"<a href="https://wordpress.org/plugins/async-javascript" target="_blank">Async Javascript</a>"' );
417
-                            $asj_install_url = network_admin_url() . 'plugin-install.php?s=async+javascript&tab=search&type=term';
418
-                            echo sprintf( ' <a href="' . $asj_install_url . '">%s</a>', __( 'Click here to install and activate it.', 'autoptimize' ) );
416
+                            echo sprintf(__('Configuration of async javascript is easier and more flexible using the %s plugin.', 'autoptimize'), '"<a href="https://wordpress.org/plugins/async-javascript" target="_blank">Async Javascript</a>"');
417
+                            $asj_install_url = network_admin_url().'plugin-install.php?s=async+javascript&tab=search&type=term';
418
+                            echo sprintf(' <a href="'.$asj_install_url.'">%s</a>', __('Click here to install and activate it.', 'autoptimize'));
419 419
                     }
420 420
                     ?>
421 421
                 </td>
422 422
             </tr>
423 423
             <tr>
424
-                <th scope="row"><?php _e( 'Optimize YouTube videos', 'autoptimize' ); ?></th>
424
+                <th scope="row"><?php _e('Optimize YouTube videos', 'autoptimize'); ?></th>
425 425
                 <td>
426 426
                     <?php
427
-                    if ( autoptimizeUtils::is_plugin_active( 'wp-youtube-lyte/wp-youtube-lyte.php' ) ) {
428
-                        _e( 'Great, you have WP YouTube Lyte installed.', 'autoptimize' );
427
+                    if (autoptimizeUtils::is_plugin_active('wp-youtube-lyte/wp-youtube-lyte.php')) {
428
+                        _e('Great, you have WP YouTube Lyte installed.', 'autoptimize');
429 429
                         $lyte_config_url = 'options-general.php?page=lyte_settings_page';
430
-                        echo sprintf( ' <a href="' . $lyte_config_url . '">%s</a>', __( 'Click here to configure it.', 'autoptimize' ) );
430
+                        echo sprintf(' <a href="'.$lyte_config_url.'">%s</a>', __('Click here to configure it.', 'autoptimize'));
431 431
                     } else {
432 432
                         // translators: %s will be replaced by a link to "wp youtube lyte" plugin.
433
-                        echo sprintf( __( '%s allows you to “lazy load” your videos, by inserting responsive “Lite YouTube Embeds". ', 'autoptimize' ), '<a href="https://wordpress.org/plugins/wp-youtube-lyte" target="_blank">WP YouTube Lyte</a>' );
434
-                        $lyte_install_url = network_admin_url() . 'plugin-install.php?s=lyte&tab=search&type=term';
435
-                        echo sprintf( ' <a href="' . $lyte_install_url . '">%s</a>', __( 'Click here to install and activate it.', 'autoptimize' ) );
433
+                        echo sprintf(__('%s allows you to “lazy load” your videos, by inserting responsive “Lite YouTube Embeds". ', 'autoptimize'), '<a href="https://wordpress.org/plugins/wp-youtube-lyte" target="_blank">WP YouTube Lyte</a>');
434
+                        $lyte_install_url = network_admin_url().'plugin-install.php?s=lyte&tab=search&type=term';
435
+                        echo sprintf(' <a href="'.$lyte_install_url.'">%s</a>', __('Click here to install and activate it.', 'autoptimize'));
436 436
                     }
437 437
                     ?>
438 438
                 </td>
439 439
             </tr>
440 440
         </table>
441
-        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /></p>
441
+        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /></p>
442 442
     </form>
443 443
         <?php
444 444
     }
Please login to merge, or discard this patch.
autoptimize.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -16,66 +16,66 @@  discard block
 block discarded – undo
16 16
  */
17 17
 
18 18
 
19
-if ( ! defined( 'ABSPATH' ) ) {
19
+if (!defined('ABSPATH')) {
20 20
     exit;
21 21
 }
22 22
 
23
-define( 'AUTOPTIMIZE_PLUGIN_VERSION', '2.5.0' );
23
+define('AUTOPTIMIZE_PLUGIN_VERSION', '2.5.0');
24 24
 
25 25
 // plugin_dir_path() returns the trailing slash!
26
-define( 'AUTOPTIMIZE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
27
-define( 'AUTOPTIMIZE_PLUGIN_FILE', __FILE__ );
26
+define('AUTOPTIMIZE_PLUGIN_DIR', plugin_dir_path(__FILE__));
27
+define('AUTOPTIMIZE_PLUGIN_FILE', __FILE__);
28 28
 
29 29
 // Bail early if attempting to run on non-supported php versions.
30
-if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
30
+if (version_compare(PHP_VERSION, '5.3', '<')) {
31 31
     function autoptimize_incompatible_admin_notice() {
32
-        echo '<div class="error"><p>' . __( 'Autoptimize requires PHP 5.3 (or higher) to function properly. Please upgrade PHP. The Plugin has been auto-deactivated.', 'autoptimize' ) . '</p></div>';
33
-        if ( isset( $_GET['activate'] ) ) {
34
-            unset( $_GET['activate'] );
32
+        echo '<div class="error"><p>'.__('Autoptimize requires PHP 5.3 (or higher) to function properly. Please upgrade PHP. The Plugin has been auto-deactivated.', 'autoptimize').'</p></div>';
33
+        if (isset($_GET['activate'])) {
34
+            unset($_GET['activate']);
35 35
         }
36 36
     }
37 37
     function autoptimize_deactivate_self() {
38
-        deactivate_plugins( plugin_basename( AUTOPTIMIZE_PLUGIN_FILE ) );
38
+        deactivate_plugins(plugin_basename(AUTOPTIMIZE_PLUGIN_FILE));
39 39
     }
40
-    add_action( 'admin_notices', 'autoptimize_incompatible_admin_notice' );
41
-    add_action( 'admin_init', 'autoptimize_deactivate_self' );
40
+    add_action('admin_notices', 'autoptimize_incompatible_admin_notice');
41
+    add_action('admin_init', 'autoptimize_deactivate_self');
42 42
     return;
43 43
 }
44 44
 
45
-function autoptimize_autoload( $class_name ) {
46
-    if ( in_array( $class_name, array( 'Minify_HTML', 'JSMin' ) ) ) {
47
-        $file     = strtolower( $class_name );
48
-        $file     = str_replace( '_', '-', $file );
49
-        $path     = dirname( __FILE__ ) . '/classes/external/php/';
50
-        $filepath = $path . $file . '.php';
51
-    } elseif ( false !== strpos( $class_name, 'Autoptimize\\tubalmartin\\CssMin' ) ) {
52
-        $file     = str_replace( 'Autoptimize\\tubalmartin\\CssMin\\', '', $class_name );
53
-        $path     = dirname( __FILE__ ) . '/classes/external/php/yui-php-cssmin-bundled/';
54
-        $filepath = $path . $file . '.php';
55
-    } elseif ( 'autoptimize' === substr( $class_name, 0, 11 ) ) {
45
+function autoptimize_autoload($class_name) {
46
+    if (in_array($class_name, array('Minify_HTML', 'JSMin'))) {
47
+        $file     = strtolower($class_name);
48
+        $file     = str_replace('_', '-', $file);
49
+        $path     = dirname(__FILE__).'/classes/external/php/';
50
+        $filepath = $path.$file.'.php';
51
+    } elseif (false !== strpos($class_name, 'Autoptimize\\tubalmartin\\CssMin')) {
52
+        $file     = str_replace('Autoptimize\\tubalmartin\\CssMin\\', '', $class_name);
53
+        $path     = dirname(__FILE__).'/classes/external/php/yui-php-cssmin-bundled/';
54
+        $filepath = $path.$file.'.php';
55
+    } elseif ('autoptimize' === substr($class_name, 0, 11)) {
56 56
         // One of our "old" classes.
57 57
         $file     = $class_name;
58
-        $path     = dirname( __FILE__ ) . '/classes/';
59
-        $filepath = $path . $file . '.php';
60
-    } elseif ( 'PAnD' === $class_name ) {
58
+        $path     = dirname(__FILE__).'/classes/';
59
+        $filepath = $path.$file.'.php';
60
+    } elseif ('PAnD' === $class_name) {
61 61
         $file     = 'persist-admin-notices-dismissal';
62
-        $path     = dirname( __FILE__ ) . '/classes/external/php/persist-admin-notices-dismissal/';
63
-        $filepath = $path . $file . '.php';
62
+        $path     = dirname(__FILE__).'/classes/external/php/persist-admin-notices-dismissal/';
63
+        $filepath = $path.$file.'.php';
64 64
     }
65 65
 
66 66
     // If we didn't match one of our rules, bail!
67
-    if ( ! isset( $filepath ) ) {
67
+    if (!isset($filepath)) {
68 68
         return;
69 69
     }
70 70
 
71 71
     require $filepath;
72 72
 }
73 73
 
74
-spl_autoload_register( 'autoptimize_autoload' );
74
+spl_autoload_register('autoptimize_autoload');
75 75
 
76 76
 // Load WP CLI command(s) on demand.
77
-if ( defined( 'WP_CLI' ) && WP_CLI ) {
78
-    require AUTOPTIMIZE_PLUGIN_DIR . 'classes/autoptimizeCLI.php';
77
+if (defined('WP_CLI') && WP_CLI) {
78
+    require AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeCLI.php';
79 79
 }
80 80
 
81 81
 /**
@@ -86,8 +86,8 @@  discard block
 block discarded – undo
86 86
 function autoptimize() {
87 87
     static $plugin = null;
88 88
 
89
-    if ( null === $plugin ) {
90
-        $plugin = new autoptimizeMain( AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE );
89
+    if (null === $plugin) {
90
+        $plugin = new autoptimizeMain(AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE);
91 91
     }
92 92
 
93 93
     return $plugin;
Please login to merge, or discard this patch.