Completed
Push — master ( 8cd4be...fd6893 )
by frank
02:38
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/autoptimizeBase.php 1 patch
Spacing   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Base class other (more-specific) classes inherit from.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
      */
31 31
     public $cdn_url = '';
32 32
 
33
-    public function __construct( $content )
33
+    public function __construct($content)
34 34
     {
35 35
         $this->content = $content;
36 36
     }
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      *
43 43
      * @return bool
44 44
      */
45
-    abstract public function read( $options );
45
+    abstract public function read($options);
46 46
 
47 47
     /**
48 48
      * Joins and optimizes collected things.
@@ -73,40 +73,40 @@  discard block
 block discarded – undo
73 73
      *
74 74
      * @return bool|string
75 75
      */
76
-    public function getpath( $url )
76
+    public function getpath($url)
77 77
     {
78
-        $url = apply_filters( 'autoptimize_filter_cssjs_alter_url', $url );
78
+        $url = apply_filters('autoptimize_filter_cssjs_alter_url', $url);
79 79
 
80
-        if ( false !== strpos( $url, '%' ) ) {
81
-            $url = urldecode( $url );
80
+        if (false !== strpos($url, '%')) {
81
+            $url = urldecode($url);
82 82
         }
83 83
 
84
-        $site_host    = parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST );
85
-        $content_host = parse_url( AUTOPTIMIZE_WP_ROOT_URL, PHP_URL_HOST );
84
+        $site_host    = parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST);
85
+        $content_host = parse_url(AUTOPTIMIZE_WP_ROOT_URL, PHP_URL_HOST);
86 86
 
87 87
         // Normalizing attempts...
88
-        $double_slash_position = strpos( $url, '//' );
89
-        if ( 0 === $double_slash_position ) {
90
-            if ( is_ssl() ) {
91
-                $url = 'https:' . $url;
88
+        $double_slash_position = strpos($url, '//');
89
+        if (0 === $double_slash_position) {
90
+            if (is_ssl()) {
91
+                $url = 'https:'.$url;
92 92
             } else {
93
-                $url = 'http:' . $url;
93
+                $url = 'http:'.$url;
94 94
             }
95
-        } elseif ( ( false === $double_slash_position ) && ( false === strpos( $url, $site_host ) ) ) {
96
-            if ( AUTOPTIMIZE_WP_SITE_URL === $site_host ) {
97
-                $url = AUTOPTIMIZE_WP_SITE_URL . $url;
95
+        } elseif ((false === $double_slash_position) && (false === strpos($url, $site_host))) {
96
+            if (AUTOPTIMIZE_WP_SITE_URL === $site_host) {
97
+                $url = AUTOPTIMIZE_WP_SITE_URL.$url;
98 98
             } else {
99
-                $url = AUTOPTIMIZE_WP_SITE_URL . autoptimizeUtils::path_canonicalize( $url );
99
+                $url = AUTOPTIMIZE_WP_SITE_URL.autoptimizeUtils::path_canonicalize($url);
100 100
             }
101 101
         }
102 102
 
103
-        if ( $site_host !== $content_host ) {
104
-            $url = str_replace( AUTOPTIMIZE_WP_CONTENT_URL, AUTOPTIMIZE_WP_SITE_URL . AUTOPTIMIZE_WP_CONTENT_NAME, $url );
103
+        if ($site_host !== $content_host) {
104
+            $url = str_replace(AUTOPTIMIZE_WP_CONTENT_URL, AUTOPTIMIZE_WP_SITE_URL.AUTOPTIMIZE_WP_CONTENT_NAME, $url);
105 105
         }
106 106
 
107 107
         // First check; hostname wp site should be hostname of url!
108
-        $url_host = @parse_url( $url, PHP_URL_HOST ); // @codingStandardsIgnoreLine
109
-        if ( $url_host !== $site_host ) {
108
+        $url_host = @parse_url($url, PHP_URL_HOST); // @codingStandardsIgnoreLine
109
+        if ($url_host !== $site_host) {
110 110
             /**
111 111
              * First try to get all domains from WPML (if available)
112 112
              * then explicitely declare $this->cdn_url as OK as well
@@ -115,20 +115,20 @@  discard block
 block discarded – undo
115 115
              */
116 116
             $multidomains = array();
117 117
 
118
-            $multidomains_wpml = apply_filters( 'wpml_setting', array(), 'language_domains' );
119
-            if ( ! empty( $multidomains_wpml ) ) {
120
-                $multidomains = array_map( array( $this, 'get_url_hostname' ), $multidomains_wpml );
118
+            $multidomains_wpml = apply_filters('wpml_setting', array(), 'language_domains');
119
+            if (!empty($multidomains_wpml)) {
120
+                $multidomains = array_map(array($this, 'get_url_hostname'), $multidomains_wpml);
121 121
             }
122 122
 
123
-            if ( ! empty( $this->cdn_url ) ) {
124
-                $multidomains[] = parse_url( $this->cdn_url, PHP_URL_HOST );
123
+            if (!empty($this->cdn_url)) {
124
+                $multidomains[] = parse_url($this->cdn_url, PHP_URL_HOST);
125 125
             }
126 126
 
127
-            $multidomains = apply_filters( 'autoptimize_filter_cssjs_multidomain', $multidomains );
127
+            $multidomains = apply_filters('autoptimize_filter_cssjs_multidomain', $multidomains);
128 128
 
129
-            if ( ! empty( $multidomains ) ) {
130
-                if ( in_array( $url_host, $multidomains ) ) {
131
-                    $url = str_replace( $url_host, $site_host, $url );
129
+            if (!empty($multidomains)) {
130
+                if (in_array($url_host, $multidomains)) {
131
+                    $url = str_replace($url_host, $site_host, $url);
132 132
                 } else {
133 133
                     return false;
134 134
                 }
@@ -138,28 +138,28 @@  discard block
 block discarded – undo
138 138
         }
139 139
 
140 140
         // Try to remove "wp root url" from url while not minding http<>https.
141
-        $tmp_ao_root = preg_replace( '/https?:/', '', AUTOPTIMIZE_WP_ROOT_URL );
141
+        $tmp_ao_root = preg_replace('/https?:/', '', AUTOPTIMIZE_WP_ROOT_URL);
142 142
 
143
-        if ( $site_host !== $content_host ) {
143
+        if ($site_host !== $content_host) {
144 144
             // As we replaced the content-domain with the site-domain, we should match against that.
145
-            $tmp_ao_root = preg_replace( '/https?:/', '', AUTOPTIMIZE_WP_SITE_URL );
145
+            $tmp_ao_root = preg_replace('/https?:/', '', AUTOPTIMIZE_WP_SITE_URL);
146 146
         }
147 147
 
148
-        $tmp_url = preg_replace( '/https?:/', '', $url );
149
-        $path    = str_replace( $tmp_ao_root, '', $tmp_url );
148
+        $tmp_url = preg_replace('/https?:/', '', $url);
149
+        $path    = str_replace($tmp_ao_root, '', $tmp_url);
150 150
 
151 151
         // If path starts with :// or //, this is not a URL in the WP context and
152 152
         // we have to assume we can't aggregate.
153
-        if ( preg_match( '#^:?//#', $path ) ) {
153
+        if (preg_match('#^:?//#', $path)) {
154 154
             // External script/css (adsense, etc).
155 155
             return false;
156 156
         }
157 157
 
158 158
         // Prepend with WP_ROOT_DIR to have full path to file.
159
-        $path = str_replace( '//', '/', WP_ROOT_DIR . $path );
159
+        $path = str_replace('//', '/', WP_ROOT_DIR.$path);
160 160
 
161 161
         // Final check: does file exist and is it readable?
162
-        if ( file_exists( $path ) && is_file( $path ) && is_readable( $path ) ) {
162
+        if (file_exists($path) && is_file($path) && is_readable($path)) {
163 163
             return $path;
164 164
         } else {
165 165
             return false;
@@ -176,18 +176,18 @@  discard block
 block discarded – undo
176 176
      *
177 177
      * @return string
178 178
      */
179
-    protected function get_url_hostname( $url )
179
+    protected function get_url_hostname($url)
180 180
     {
181 181
         // Checking that the url starts with something vaguely resembling a protocol.
182
-        if ( ( 0 !== strpos( $url, 'http' ) ) && ( 0 !== strpos( $url, '//' ) ) ) {
183
-            $url = 'http://' . $url;
182
+        if ((0 !== strpos($url, 'http')) && (0 !== strpos($url, '//'))) {
183
+            $url = 'http://'.$url;
184 184
         }
185 185
 
186 186
         // Grab the hostname.
187
-        $hostname = parse_url( $url, PHP_URL_HOST );
187
+        $hostname = parse_url($url, PHP_URL_HOST);
188 188
 
189 189
         // Fallback when parse_url() fails.
190
-        if ( empty( $hostname ) ) {
190
+        if (empty($hostname)) {
191 191
             $hostname = $url;
192 192
         }
193 193
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
      *
202 202
      * @return string
203 203
      */
204
-    protected function hide_noptimize( $markup )
204
+    protected function hide_noptimize($markup)
205 205
     {
206 206
         return $this->replace_contents_with_marker_if_exists(
207 207
             'NOPTIMIZE',
@@ -218,9 +218,9 @@  discard block
 block discarded – undo
218 218
      *
219 219
      * @return string
220 220
      */
221
-    protected function restore_noptimize( $markup )
221
+    protected function restore_noptimize($markup)
222 222
     {
223
-        return $this->restore_marked_content( 'NOPTIMIZE', $markup );
223
+        return $this->restore_marked_content('NOPTIMIZE', $markup);
224 224
     }
225 225
 
226 226
     /**
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
      *
231 231
      * @return string
232 232
      */
233
-    protected function hide_iehacks( $markup )
233
+    protected function hide_iehacks($markup)
234 234
     {
235 235
         return $this->replace_contents_with_marker_if_exists(
236 236
             'IEHACK', // Marker name...
@@ -247,9 +247,9 @@  discard block
 block discarded – undo
247 247
      *
248 248
      * @return string
249 249
      */
250
-    protected function restore_iehacks( $markup )
250
+    protected function restore_iehacks($markup)
251 251
     {
252
-        return $this->restore_marked_content( 'IEHACK', $markup );
252
+        return $this->restore_marked_content('IEHACK', $markup);
253 253
     }
254 254
 
255 255
     /**
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
      *
262 262
      * @return string
263 263
      */
264
-    protected function hide_comments( $markup )
264
+    protected function hide_comments($markup)
265 265
     {
266 266
         return $this->replace_contents_with_marker_if_exists(
267 267
             'COMMENTS',
@@ -279,9 +279,9 @@  discard block
 block discarded – undo
279 279
      *
280 280
      * @return string
281 281
      */
282
-    protected function restore_comments( $markup )
282
+    protected function restore_comments($markup)
283 283
     {
284
-        return $this->restore_marked_content( 'COMMENTS', $markup );
284
+        return $this->restore_marked_content('COMMENTS', $markup);
285 285
     }
286 286
 
287 287
     /**
@@ -292,44 +292,44 @@  discard block
 block discarded – undo
292 292
      *
293 293
      * @return string
294 294
      */
295
-    public function url_replace_cdn( $url )
295
+    public function url_replace_cdn($url)
296 296
     {
297 297
         // For 2.3 back-compat in which cdn-ing appeared to be automatically
298 298
         // including WP subfolder/subdirectory into account as part of cdn-ing,
299 299
         // even though it might've caused serious troubles in certain edge-cases.
300
-        $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed( $this->cdn_url );
300
+        $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed($this->cdn_url);
301 301
 
302 302
         // Allows API/filter to further tweak the cdn url...
303
-        $cdn_url = apply_filters( 'autoptimize_filter_base_cdnurl', $cdn_url );
304
-        if ( ! empty( $cdn_url ) ) {
305
-            $this->debug_log( 'before=' . $url );
303
+        $cdn_url = apply_filters('autoptimize_filter_base_cdnurl', $cdn_url);
304
+        if (!empty($cdn_url)) {
305
+            $this->debug_log('before='.$url);
306 306
 
307 307
             // Simple str_replace-based approach fails when $url is protocol-or-host-relative.
308
-            $is_protocol_relative = autoptimizeUtils::is_protocol_relative( $url );
309
-            $is_host_relative     = ( ! $is_protocol_relative && ( '/' === $url[0] ) );
310
-            $cdn_url              = rtrim( $cdn_url, '/' );
308
+            $is_protocol_relative = autoptimizeUtils::is_protocol_relative($url);
309
+            $is_host_relative     = (!$is_protocol_relative && ('/' === $url[0]));
310
+            $cdn_url              = rtrim($cdn_url, '/');
311 311
 
312
-            if ( $is_host_relative ) {
312
+            if ($is_host_relative) {
313 313
                 // Prepending host-relative urls with the cdn url.
314
-                $url = $cdn_url . $url;
314
+                $url = $cdn_url.$url;
315 315
             } else {
316 316
                 // Either a protocol-relative or "regular" url, replacing it either way.
317
-                if ( $is_protocol_relative ) {
317
+                if ($is_protocol_relative) {
318 318
                     // Massage $site_url so that simple str_replace() still "works" by
319 319
                     // searching for the protocol-relative version of AUTOPTIMIZE_WP_SITE_URL.
320
-                    $site_url = str_replace( array( 'http:', 'https:' ), '', AUTOPTIMIZE_WP_SITE_URL );
320
+                    $site_url = str_replace(array('http:', 'https:'), '', AUTOPTIMIZE_WP_SITE_URL);
321 321
                 } else {
322 322
                     $site_url = AUTOPTIMIZE_WP_SITE_URL;
323 323
                 }
324
-                $this->debug_log( '`' . $site_url . '` -> `' . $cdn_url . '` in `' . $url . '`' );
325
-                $url = str_replace( $site_url, $cdn_url, $url );
324
+                $this->debug_log('`'.$site_url.'` -> `'.$cdn_url.'` in `'.$url.'`');
325
+                $url = str_replace($site_url, $cdn_url, $url);
326 326
             }
327 327
 
328
-            $this->debug_log( 'after=' . $url );
328
+            $this->debug_log('after='.$url);
329 329
         }
330 330
 
331 331
         // Allow API filter to take further care of CDN replacement.
332
-        $url = apply_filters( 'autoptimize_filter_base_replace_cdn', $url );
332
+        $url = apply_filters('autoptimize_filter_base_replace_cdn', $url);
333 333
 
334 334
         return $url;
335 335
     }
@@ -347,18 +347,18 @@  discard block
 block discarded – undo
347 347
      *
348 348
      * @return void
349 349
      */
350
-    protected function inject_in_html( $payload, $where )
350
+    protected function inject_in_html($payload, $where)
351 351
     {
352 352
         $warned   = false;
353
-        $position = autoptimizeUtils::strpos( $this->content, $where[0] );
354
-        if ( false !== $position ) {
353
+        $position = autoptimizeUtils::strpos($this->content, $where[0]);
354
+        if (false !== $position) {
355 355
             // Found the tag, setup content/injection as specified.
356
-            if ( 'after' === $where[1] ) {
357
-                $content = $where[0] . $payload;
358
-            } elseif ( 'replace' === $where[1] ) {
356
+            if ('after' === $where[1]) {
357
+                $content = $where[0].$payload;
358
+            } elseif ('replace' === $where[1]) {
359 359
                 $content = $payload;
360 360
             } else {
361
-                $content = $payload . $where[0];
361
+                $content = $payload.$where[0];
362 362
             }
363 363
             // Place where specified.
364 364
             $this->content = autoptimizeUtils::substr_replace(
@@ -367,14 +367,14 @@  discard block
 block discarded – undo
367 367
                 $position,
368 368
                 // Using plain strlen() should be safe here for now, since
369 369
                 // we're not searching for multibyte chars here still...
370
-                strlen( $where[0] )
370
+                strlen($where[0])
371 371
             );
372 372
         } else {
373 373
             // Couldn't find what was specified, just append and add a warning.
374 374
             $this->content .= $payload;
375
-            if ( ! $warned ) {
376
-                $tag_display    = str_replace( array( '<', '>' ), '', $where[0] );
377
-                $this->content .= '<!--noptimize--><!-- Autoptimize found a problem with the HTML in your Theme, tag `' . $tag_display . '` missing --><!--/noptimize-->';
375
+            if (!$warned) {
376
+                $tag_display    = str_replace(array('<', '>'), '', $where[0]);
377
+                $this->content .= '<!--noptimize--><!-- Autoptimize found a problem with the HTML in your Theme, tag `'.$tag_display.'` missing --><!--/noptimize-->';
378 378
                 $warned         = true;
379 379
             }
380 380
         }
@@ -388,10 +388,10 @@  discard block
 block discarded – undo
388 388
      *
389 389
      * @return bool
390 390
      */
391
-    protected function isremovable( $tag, $removables )
391
+    protected function isremovable($tag, $removables)
392 392
     {
393
-        foreach ( $removables as $match ) {
394
-            if ( false !== strpos( $tag, $match ) ) {
393
+        foreach ($removables as $match) {
394
+            if (false !== strpos($tag, $match)) {
395 395
                 return true;
396 396
             }
397 397
         }
@@ -406,10 +406,10 @@  discard block
 block discarded – undo
406 406
      *
407 407
      * @return string
408 408
      */
409
-    public function inject_minified_callback( $matches )
409
+    public function inject_minified_callback($matches)
410 410
     {
411 411
         static $conf = null;
412
-        if ( null === $conf ) {
412
+        if (null === $conf) {
413 413
             $conf = autoptimizeConfig::instance();
414 414
         }
415 415
 
@@ -424,62 +424,62 @@  discard block
 block discarded – undo
424 424
         $filehash = null;
425 425
 
426 426
         // Grab the parts we need.
427
-        $parts = explode( '|', $matches[1] );
428
-        if ( ! empty( $parts ) ) {
429
-            $filepath = isset( $parts[0] ) ? base64_decode( $parts[0] ) : null;
430
-            $filehash = isset( $parts[1] ) ? $parts[1] : null;
427
+        $parts = explode('|', $matches[1]);
428
+        if (!empty($parts)) {
429
+            $filepath = isset($parts[0]) ? base64_decode($parts[0]) : null;
430
+            $filehash = isset($parts[1]) ? $parts[1] : null;
431 431
         }
432 432
 
433 433
         // Bail early if something's not right...
434
-        if ( ! $filepath || ! $filehash ) {
434
+        if (!$filepath || !$filehash) {
435 435
             return "\n";
436 436
         }
437 437
 
438
-        $filecontent = file_get_contents( $filepath );
438
+        $filecontent = file_get_contents($filepath);
439 439
 
440 440
         // Some things are differently handled for css/js...
441
-        $is_js_file = ( '.js' === substr( $filepath, -3, 3 ) );
441
+        $is_js_file = ('.js' === substr($filepath, -3, 3));
442 442
 
443 443
         $is_css_file = false;
444
-        if ( ! $is_js_file ) {
445
-            $is_css_file = ( '.css' === substr( $filepath, -4, 4 ) );
444
+        if (!$is_js_file) {
445
+            $is_css_file = ('.css' === substr($filepath, -4, 4));
446 446
         }
447 447
 
448 448
         // BOMs being nuked here unconditionally (regardless of where they are)!
449
-        $filecontent = preg_replace( "#\x{EF}\x{BB}\x{BF}#", '', $filecontent );
449
+        $filecontent = preg_replace("#\x{EF}\x{BB}\x{BF}#", '', $filecontent);
450 450
 
451 451
         // Remove comments and blank lines.
452
-        if ( $is_js_file ) {
453
-            $filecontent = preg_replace( '#^\s*\/\/.*$#Um', '', $filecontent );
452
+        if ($is_js_file) {
453
+            $filecontent = preg_replace('#^\s*\/\/.*$#Um', '', $filecontent);
454 454
         }
455 455
 
456 456
         // Nuke un-important comments.
457
-        $filecontent = preg_replace( '#^\s*\/\*[^!].*\*\/\s?#Um', '', $filecontent );
457
+        $filecontent = preg_replace('#^\s*\/\*[^!].*\*\/\s?#Um', '', $filecontent);
458 458
 
459 459
         // Normalize newlines.
460
-        $filecontent = preg_replace( '#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#', "\n", $filecontent );
460
+        $filecontent = preg_replace('#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#', "\n", $filecontent);
461 461
 
462 462
         // JS specifics.
463
-        if ( $is_js_file ) {
463
+        if ($is_js_file) {
464 464
             // Append a semicolon at the end of js files if it's missing.
465
-            $last_char = substr( $filecontent, -1, 1 );
466
-            if ( ';' !== $last_char && '}' !== $last_char ) {
465
+            $last_char = substr($filecontent, -1, 1);
466
+            if (';' !== $last_char && '}' !== $last_char) {
467 467
                 $filecontent .= ';';
468 468
             }
469 469
             // Check if try/catch should be used.
470
-            $opt_js_try_catch = $conf->get( 'autoptimize_js_trycatch' );
471
-            if ( 'on' === $opt_js_try_catch ) {
470
+            $opt_js_try_catch = $conf->get('autoptimize_js_trycatch');
471
+            if ('on' === $opt_js_try_catch) {
472 472
                 // It should, wrap in try/catch.
473
-                $filecontent = 'try{' . $filecontent . '}catch(e){}';
473
+                $filecontent = 'try{'.$filecontent.'}catch(e){}';
474 474
             }
475
-        } elseif ( $is_css_file ) {
476
-            $filecontent = autoptimizeStyles::fixurls( $filepath, $filecontent );
475
+        } elseif ($is_css_file) {
476
+            $filecontent = autoptimizeStyles::fixurls($filepath, $filecontent);
477 477
         } else {
478 478
             $filecontent = '';
479 479
         }
480 480
 
481 481
         // Return modified (or empty!) code/content.
482
-        return "\n" . $filecontent;
482
+        return "\n".$filecontent;
483 483
     }
484 484
 
485 485
     /**
@@ -489,13 +489,13 @@  discard block
 block discarded – undo
489 489
      *
490 490
      * @return string
491 491
      */
492
-    protected function inject_minified( $in )
492
+    protected function inject_minified($in)
493 493
     {
494 494
         $out = $in;
495
-        if ( false !== strpos( $in, '%%INJECTLATER%%' ) ) {
495
+        if (false !== strpos($in, '%%INJECTLATER%%')) {
496 496
             $out = preg_replace_callback(
497
-                '#\/\*\!%%INJECTLATER' . AUTOPTIMIZE_HASH . '%%(.*?)%%INJECTLATER%%\*\/#is',
498
-                array( $this, 'inject_minified_callback' ),
497
+                '#\/\*\!%%INJECTLATER'.AUTOPTIMIZE_HASH.'%%(.*?)%%INJECTLATER%%\*\/#is',
498
+                array($this, 'inject_minified_callback'),
499 499
                 $in
500 500
             );
501 501
         }
@@ -515,9 +515,9 @@  discard block
 block discarded – undo
515 515
      *
516 516
      * @return string
517 517
      */
518
-    public static function build_injectlater_marker( $filepath, $hash )
518
+    public static function build_injectlater_marker($filepath, $hash)
519 519
     {
520
-        $contents = '/*!' . self::build_marker( 'INJECTLATER', $filepath, $hash ) . '*/';
520
+        $contents = '/*!'.self::build_marker('INJECTLATER', $filepath, $hash).'*/';
521 521
 
522 522
         return $contents;
523 523
     }
@@ -535,18 +535,18 @@  discard block
 block discarded – undo
535 535
      *
536 536
      * @return string
537 537
      */
538
-    public static function build_marker( $name, $data, $hash = null )
538
+    public static function build_marker($name, $data, $hash = null)
539 539
     {
540 540
         // Start the marker, add the data.
541
-        $marker = '%%' . $name . AUTOPTIMIZE_HASH . '%%' . base64_encode( $data );
541
+        $marker = '%%'.$name.AUTOPTIMIZE_HASH.'%%'.base64_encode($data);
542 542
 
543 543
         // Add the hash if provided.
544
-        if ( null !== $hash ) {
545
-            $marker .= '|' . $hash;
544
+        if (null !== $hash) {
545
+            $marker .= '|'.$hash;
546 546
         }
547 547
 
548 548
         // Close the marker.
549
-        $marker .= '%%' . $name . '%%';
549
+        $marker .= '%%'.$name.'%%';
550 550
 
551 551
         return $marker;
552 552
     }
@@ -566,22 +566,22 @@  discard block
 block discarded – undo
566 566
      *
567 567
      * @return string
568 568
      */
569
-    public static function replace_contents_with_marker_if_exists( $marker, $search, $re_replace_pattern, $content )
569
+    public static function replace_contents_with_marker_if_exists($marker, $search, $re_replace_pattern, $content)
570 570
     {
571 571
         $found = false;
572 572
 
573
-        $is_regex = autoptimizeUtils::str_is_valid_regex( $search );
574
-        if ( $is_regex ) {
575
-            $found = preg_match( $search, $content );
573
+        $is_regex = autoptimizeUtils::str_is_valid_regex($search);
574
+        if ($is_regex) {
575
+            $found = preg_match($search, $content);
576 576
         } else {
577
-            $found = ( false !== strpos( $content, $search ) );
577
+            $found = (false !== strpos($content, $search));
578 578
         }
579 579
 
580
-        if ( $found ) {
580
+        if ($found) {
581 581
             $content = preg_replace_callback(
582 582
                 $re_replace_pattern,
583
-                function( $matches ) use ( $marker ) {
584
-                    return autoptimizeBase::build_marker( $marker, $matches[0] );
583
+                function($matches) use ($marker) {
584
+                    return autoptimizeBase::build_marker($marker, $matches[0]);
585 585
                 },
586 586
                 $content
587 587
             );
@@ -598,13 +598,13 @@  discard block
 block discarded – undo
598 598
      *
599 599
      * @return string
600 600
      */
601
-    public static function restore_marked_content( $marker, $content )
601
+    public static function restore_marked_content($marker, $content)
602 602
     {
603
-        if ( false !== strpos( $content, $marker ) ) {
603
+        if (false !== strpos($content, $marker)) {
604 604
             $content = preg_replace_callback(
605
-                '#%%' . $marker . AUTOPTIMIZE_HASH . '%%(.*?)%%' . $marker . '%%#is',
606
-                function ( $matches ) {
607
-                    return base64_decode( $matches[1] );
605
+                '#%%'.$marker.AUTOPTIMIZE_HASH.'%%(.*?)%%'.$marker.'%%#is',
606
+                function($matches) {
607
+                    return base64_decode($matches[1]);
608 608
                 },
609 609
                 $content
610 610
             );
@@ -620,17 +620,17 @@  discard block
 block discarded – undo
620 620
      *
621 621
      * @return void
622 622
      */
623
-    protected function debug_log( $data )
623
+    protected function debug_log($data)
624 624
     {
625
-        if ( ! isset( $this->debug_log ) || ! $this->debug_log ) {
625
+        if (!isset($this->debug_log) || !$this->debug_log) {
626 626
             return;
627 627
         }
628 628
 
629
-        if ( ! is_string( $data ) && ! is_resource( $data ) ) {
630
-            $data = var_export( $data, true );
629
+        if (!is_string($data) && !is_resource($data)) {
630
+            $data = var_export($data, true);
631 631
         }
632 632
 
633
-        error_log( $data );
633
+        error_log($data);
634 634
     }
635 635
 
636 636
     /**
@@ -640,12 +640,12 @@  discard block
 block discarded – undo
640 640
      *
641 641
      * @return bool|string to be minified code or false.
642 642
      */
643
-    protected function prepare_minify_single( $filepath )
643
+    protected function prepare_minify_single($filepath)
644 644
     {
645 645
         // Decide what we're dealing with, return false if we don't know.
646
-        if ( autoptimizeUtils::str_ends_in( $filepath, '.js' ) ) {
646
+        if (autoptimizeUtils::str_ends_in($filepath, '.js')) {
647 647
             $type = 'js';
648
-        } elseif ( autoptimizeUtils::str_ends_in( $filepath, '.css' ) ) {
648
+        } elseif (autoptimizeUtils::str_ends_in($filepath, '.css')) {
649 649
             $type = 'css';
650 650
         } else {
651 651
             return false;
@@ -654,18 +654,18 @@  discard block
 block discarded – undo
654 654
         // Bail if it looks like its already minifed (by having -min or .min
655 655
         // in filename) or if it looks like WP jquery.js (which is minified).
656 656
         $minified_variants = array(
657
-            '-min.' . $type,
658
-            '.min.' . $type,
657
+            '-min.'.$type,
658
+            '.min.'.$type,
659 659
             'js/jquery/jquery.js',
660 660
         );
661
-        foreach ( $minified_variants as $ending ) {
662
-            if ( autoptimizeUtils::str_ends_in( $filepath, $ending ) ) {
661
+        foreach ($minified_variants as $ending) {
662
+            if (autoptimizeUtils::str_ends_in($filepath, $ending)) {
663 663
                 return false;
664 664
             }
665 665
         }
666 666
 
667 667
         // Get file contents, bail if empty.
668
-        $contents = file_get_contents( $filepath );
668
+        $contents = file_get_contents($filepath);
669 669
 
670 670
         return $contents;
671 671
     }
@@ -678,12 +678,12 @@  discard block
 block discarded – undo
678 678
      *
679 679
      * @return string
680 680
      */
681
-    protected function build_minify_single_url( autoptimizeCache $cache )
681
+    protected function build_minify_single_url(autoptimizeCache $cache)
682 682
     {
683
-        $url = AUTOPTIMIZE_CACHE_URL . $cache->getname();
683
+        $url = AUTOPTIMIZE_CACHE_URL.$cache->getname();
684 684
 
685 685
         // CDN-replace the resulting URL if needed...
686
-        $url = $this->url_replace_cdn( $url );
686
+        $url = $this->url_replace_cdn($url);
687 687
 
688 688
         return $url;
689 689
     }
Please login to merge, or discard this patch.
classes/autoptimizeCacheChecker.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * Checks if cachesize is > 0.5GB (size is filterable), if so, an option is set which controls showing an admin notice.
7 7
  */
8 8
 
9
-if ( ! defined( 'ABSPATH' ) ) {
9
+if (!defined('ABSPATH')) {
10 10
     exit;
11 11
 }
12 12
 
@@ -25,51 +25,51 @@  discard block
 block discarded – undo
25 25
 
26 26
     public function add_hooks()
27 27
     {
28
-        if ( is_admin() ) {
29
-            add_action( 'plugins_loaded', array( $this, 'setup' ) );
28
+        if (is_admin()) {
29
+            add_action('plugins_loaded', array($this, 'setup'));
30 30
         }
31
-        add_action( self::SCHEDULE_HOOK, array( $this, 'cronjob' ) );
32
-        add_action( 'admin_notices', array( $this, 'show_admin_notice' ) );
31
+        add_action(self::SCHEDULE_HOOK, array($this, 'cronjob'));
32
+        add_action('admin_notices', array($this, 'show_admin_notice'));
33 33
     }
34 34
 
35 35
     public function setup()
36 36
     {
37
-        $do_cache_check = (bool) apply_filters( 'autoptimize_filter_cachecheck_do', true );
38
-        $schedule       = wp_get_schedule( self::SCHEDULE_HOOK );
39
-        $frequency      = apply_filters( 'autoptimize_filter_cachecheck_frequency', 'twicedaily' );
40
-        if ( ! in_array( $frequency, array( 'hourly', 'twicedaily', 'daily', 'weekly', 'monthly' ) ) ) {
37
+        $do_cache_check = (bool) apply_filters('autoptimize_filter_cachecheck_do', true);
38
+        $schedule       = wp_get_schedule(self::SCHEDULE_HOOK);
39
+        $frequency      = apply_filters('autoptimize_filter_cachecheck_frequency', 'twicedaily');
40
+        if (!in_array($frequency, array('hourly', 'twicedaily', 'daily', 'weekly', 'monthly'))) {
41 41
             $frequency = 'twicedaily';
42 42
         }
43
-        if ( $do_cache_check && ( ! $schedule || $schedule !== $frequency ) ) {
44
-            if ( $schedule ) {
45
-                wp_clear_scheduled_hook( self::SCHEDULE_HOOK );
43
+        if ($do_cache_check && (!$schedule || $schedule !== $frequency)) {
44
+            if ($schedule) {
45
+                wp_clear_scheduled_hook(self::SCHEDULE_HOOK);
46 46
             }
47
-            wp_schedule_event( time(), $frequency, self::SCHEDULE_HOOK );
48
-        } elseif ( $schedule && ! $do_cache_check ) {
49
-            wp_clear_scheduled_hook( self::SCHEDULE_HOOK );
47
+            wp_schedule_event(time(), $frequency, self::SCHEDULE_HOOK);
48
+        } elseif ($schedule && !$do_cache_check) {
49
+            wp_clear_scheduled_hook(self::SCHEDULE_HOOK);
50 50
         }
51 51
     }
52 52
 
53 53
     public function cronjob()
54 54
     {
55 55
         // Check cachesize and act accordingly.
56
-        $max_size       = (int) apply_filters( 'autoptimize_filter_cachecheck_maxsize', 536870912 );
57
-        $do_cache_check = (bool) apply_filters( 'autoptimize_filter_cachecheck_do', true );
56
+        $max_size       = (int) apply_filters('autoptimize_filter_cachecheck_maxsize', 536870912);
57
+        $do_cache_check = (bool) apply_filters('autoptimize_filter_cachecheck_do', true);
58 58
         $stat_array     = autoptimizeCache::stats();
59
-        $cache_size     = round( $stat_array[1] );
60
-        if ( ( $cache_size > $max_size ) && ( $do_cache_check ) ) {
61
-            autoptimizeOptionWrapper::update_option( 'autoptimize_cachesize_notice', true );
62
-            if ( apply_filters( 'autoptimize_filter_cachecheck_sendmail', true ) ) {
63
-                $home_url  = esc_url( home_url() );
64
-                $ao_mailto = apply_filters( 'autoptimize_filter_cachecheck_mailto', autoptimizeOptionWrapper::get_option( 'admin_email', '' ) );
65
-
66
-                $ao_mailsubject = __( 'Autoptimize cache size warning', 'autoptimize' ) . ' (' . $home_url . ')';
67
-                $ao_mailbody    = __( 'Autoptimize\'s cache size is getting big, consider purging the cache. Have a look at https://wordpress.org/plugins/autoptimize/faq/ to see how you can keep the cache size under control.', 'autoptimize' ) . ' (site: ' . $home_url . ')';
68
-
69
-                if ( ! empty( $ao_mailto ) ) {
70
-                    $ao_mailresult = wp_mail( $ao_mailto, $ao_mailsubject, $ao_mailbody );
71
-                    if ( ! $ao_mailresult ) {
72
-                        error_log( 'Autoptimize could not send cache size warning mail.' );
59
+        $cache_size     = round($stat_array[1]);
60
+        if (($cache_size > $max_size) && ($do_cache_check)) {
61
+            autoptimizeOptionWrapper::update_option('autoptimize_cachesize_notice', true);
62
+            if (apply_filters('autoptimize_filter_cachecheck_sendmail', true)) {
63
+                $home_url  = esc_url(home_url());
64
+                $ao_mailto = apply_filters('autoptimize_filter_cachecheck_mailto', autoptimizeOptionWrapper::get_option('admin_email', ''));
65
+
66
+                $ao_mailsubject = __('Autoptimize cache size warning', 'autoptimize').' ('.$home_url.')';
67
+                $ao_mailbody    = __('Autoptimize\'s cache size is getting big, consider purging the cache. Have a look at https://wordpress.org/plugins/autoptimize/faq/ to see how you can keep the cache size under control.', 'autoptimize').' (site: '.$home_url.')';
68
+
69
+                if (!empty($ao_mailto)) {
70
+                    $ao_mailresult = wp_mail($ao_mailto, $ao_mailsubject, $ao_mailbody);
71
+                    if (!$ao_mailresult) {
72
+                        error_log('Autoptimize could not send cache size warning mail.');
73 73
                     }
74 74
                 }
75 75
             }
@@ -87,16 +87,16 @@  discard block
 block discarded – undo
87 87
 
88 88
     public function show_admin_notice()
89 89
     {
90
-        if ( (bool) autoptimizeOptionWrapper::get_option( 'autoptimize_cachesize_notice', false ) && current_user_can( 'manage_options' ) ) {
90
+        if ((bool) autoptimizeOptionWrapper::get_option('autoptimize_cachesize_notice', false) && current_user_can('manage_options')) {
91 91
             echo '<div class="notice notice-warning"><p>';
92
-            _e( '<strong>Autoptimize\'s cache size is getting big</strong>, consider purging the cache. Have a look at <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank" rel="noopener noreferrer">the Autoptimize FAQ</a> to see how you can keep the cache size under control.', 'autoptimize' );
92
+            _e('<strong>Autoptimize\'s cache size is getting big</strong>, consider purging the cache. Have a look at <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank" rel="noopener noreferrer">the Autoptimize FAQ</a> to see how you can keep the cache size under control.', 'autoptimize');
93 93
             echo '</p></div>';
94
-            autoptimizeOptionWrapper::update_option( 'autoptimize_cachesize_notice', false );
94
+            autoptimizeOptionWrapper::update_option('autoptimize_cachesize_notice', false);
95 95
         }
96 96
 
97 97
         // Notice for image proxy usage.
98 98
         $_imgopt_notice = autoptimizeImages::instance()->get_imgopt_status_notice_wrapper();
99
-        if ( current_user_can( 'manage_options' ) && is_array( $_imgopt_notice ) && array_key_exists( 'status', $_imgopt_notice ) && in_array( $_imgopt_notice['status'], array( 1, -1, -2, -3 ) ) ) {
99
+        if (current_user_can('manage_options') && is_array($_imgopt_notice) && array_key_exists('status', $_imgopt_notice) && in_array($_imgopt_notice['status'], array(1, -1, -2, -3))) {
100 100
             $_dismissible = 'ao-img-opt-notice-';
101 101
             $_hide_notice = '7';
102 102
 
@@ -104,10 +104,10 @@  discard block
 block discarded – undo
104 104
                 $_hide_notice = '1';
105 105
             }
106 106
 
107
-            $_imgopt_notice_dismissible = apply_filters( 'autoptimize_filter_imgopt_notice_dismissable', $_dismissible . $_hide_notice );
107
+            $_imgopt_notice_dismissible = apply_filters('autoptimize_filter_imgopt_notice_dismissable', $_dismissible.$_hide_notice);
108 108
 
109
-            if ( $_imgopt_notice && PAnD::is_admin_notice_active( $_imgopt_notice_dismissible ) ) {
110
-                echo '<div class="notice notice-warning is-dismissible" data-dismissible="' . $_imgopt_notice_dismissible . '"><p><strong>' . __( 'Autoptimize', 'autoptimize' ) . '</strong>: ' . $_imgopt_notice['notice'] . '</p></div>';
109
+            if ($_imgopt_notice && PAnD::is_admin_notice_active($_imgopt_notice_dismissible)) {
110
+                echo '<div class="notice notice-warning is-dismissible" data-dismissible="'.$_imgopt_notice_dismissible.'"><p><strong>'.__('Autoptimize', 'autoptimize').'</strong>: '.$_imgopt_notice['notice'].'</p></div>';
111 111
             }
112 112
         }
113 113
     }
Please login to merge, or discard this patch.
classes/autoptimizePartners.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * addons and/or affiliate services.
5 5
  */
6 6
 
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
     exit;
9 9
 }
10 10
 
@@ -17,68 +17,68 @@  discard block
 block discarded – undo
17 17
 
18 18
     public function run()
19 19
     {
20
-        if ( $this->enabled() ) {
21
-            add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_partner_tabs' ), 10, 1 );
20
+        if ($this->enabled()) {
21
+            add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_partner_tabs'), 10, 1);
22 22
         }
23
-        if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
24
-            add_action( 'network_admin_menu', array( $this, 'add_admin_menu' ) );
23
+        if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
24
+            add_action('network_admin_menu', array($this, 'add_admin_menu'));
25 25
         } else {
26
-            add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
26
+            add_action('admin_menu', array($this, 'add_admin_menu'));
27 27
         }
28 28
     }
29 29
 
30 30
     protected function enabled()
31 31
     {
32
-        return apply_filters( 'autoptimize_filter_show_partner_tabs', true );
32
+        return apply_filters('autoptimize_filter_show_partner_tabs', true);
33 33
     }
34 34
 
35
-    public function add_partner_tabs( $in )
35
+    public function add_partner_tabs($in)
36 36
     {
37
-        $in = array_merge( $in, array(
38
-            'ao_partners' => __( 'Optimize More!', 'autoptimize' ),
39
-        ) );
37
+        $in = array_merge($in, array(
38
+            'ao_partners' => __('Optimize More!', 'autoptimize'),
39
+        ));
40 40
 
41 41
         return $in;
42 42
     }
43 43
 
44 44
     public function add_admin_menu()
45 45
     {
46
-        if ( $this->enabled() ) {
47
-            add_submenu_page( null, 'AO partner', 'AO partner', 'manage_options', 'ao_partners', array( $this, 'ao_partners_page' ) );
46
+        if ($this->enabled()) {
47
+            add_submenu_page(null, 'AO partner', 'AO partner', 'manage_options', 'ao_partners', array($this, 'ao_partners_page'));
48 48
         }
49 49
     }
50 50
 
51 51
     protected function get_ao_partner_feed_markup()
52 52
     {
53
-        $no_feed_text = __( 'Have a look at <a href="http://optimizingmatters.com/">optimizingmatters.com</a> for Autoptimize power-ups!', 'autoptimize' );
53
+        $no_feed_text = __('Have a look at <a href="http://optimizingmatters.com/">optimizingmatters.com</a> for Autoptimize power-ups!', 'autoptimize');
54 54
         $output       = '';
55
-        if ( apply_filters( 'autoptimize_settingsscreen_remotehttp', true ) ) {
56
-            $rss      = fetch_feed( 'http://feeds.feedburner.com/OptimizingMattersDownloads' );
55
+        if (apply_filters('autoptimize_settingsscreen_remotehttp', true)) {
56
+            $rss      = fetch_feed('http://feeds.feedburner.com/OptimizingMattersDownloads');
57 57
             $maxitems = 0;
58 58
 
59
-            if ( ! is_wp_error( $rss ) ) {
60
-                $maxitems  = $rss->get_item_quantity( 20 );
61
-                $rss_items = $rss->get_items( 0, $maxitems );
59
+            if (!is_wp_error($rss)) {
60
+                $maxitems  = $rss->get_item_quantity(20);
61
+                $rss_items = $rss->get_items(0, $maxitems);
62 62
             }
63 63
 
64
-            if ( 0 == $maxitems ) {
64
+            if (0 == $maxitems) {
65 65
                 $output .= $no_feed_text;
66 66
             } else {
67 67
                 $output .= '<ul>';
68
-                foreach ( $rss_items as $item ) {
69
-                    $item_url  = esc_url( $item->get_permalink() );
68
+                foreach ($rss_items as $item) {
69
+                    $item_url  = esc_url($item->get_permalink());
70 70
                     $enclosure = $item->get_enclosure();
71 71
 
72 72
                     $output .= '<li class="itemDetail">';
73
-                    $output .= '<h3 class="itemTitle"><a href="' . $item_url . '" target="_blank">' . esc_html( $item->get_title() ) . '</a></h3>';
73
+                    $output .= '<h3 class="itemTitle"><a href="'.$item_url.'" target="_blank">'.esc_html($item->get_title()).'</a></h3>';
74 74
 
75
-                    if ( $enclosure && ( false !== strpos( $enclosure->get_type(), 'image' ) ) ) {
76
-                        $img_url = esc_url( $enclosure->get_link() );
77
-                        $output .= '<div class="itemImage"><a href="' . $item_url . '" target="_blank"><img src="' . $img_url . '"></a></div>';
75
+                    if ($enclosure && (false !== strpos($enclosure->get_type(), 'image'))) {
76
+                        $img_url = esc_url($enclosure->get_link());
77
+                        $output .= '<div class="itemImage"><a href="'.$item_url.'" target="_blank"><img src="'.$img_url.'"></a></div>';
78 78
                     }
79 79
 
80
-                    $output .= '<div class="itemDescription">' . wp_kses_post( $item->get_description() ) . '</div>';
81
-                    $output .= '<div class="itemButtonRow"><div class="itemButton button-secondary"><a href="' . $item_url . '" target="_blank">' . __( 'More info', 'autoptimize' ) . '</a></div></div>';
80
+                    $output .= '<div class="itemDescription">'.wp_kses_post($item->get_description()).'</div>';
81
+                    $output .= '<div class="itemButtonRow"><div class="itemButton button-secondary"><a href="'.$item_url.'" target="_blank">'.__('More info', 'autoptimize').'</a></div></div>';
82 82
                     $output .= '</li>';
83 83
                 }
84 84
                 $output .= '</ul>';
@@ -136,11 +136,11 @@  discard block
 block discarded – undo
136 136
         color: #23282d;
137 137
     }
138 138
     </style>
139
-    <script>document.title = "Autoptimize: <?php _e( 'Optimize More!', 'autoptimize' ); ?> " + document.title;</script>
139
+    <script>document.title = "Autoptimize: <?php _e('Optimize More!', 'autoptimize'); ?> " + document.title;</script>
140 140
     <div class="wrap">
141
-        <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
141
+        <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
142 142
         <?php echo autoptimizeConfig::ao_admin_tabs(); ?>
143
-        <?php echo '<h2>' . __( "These Autoptimize power-ups and related services will improve your site's performance even more!", 'autoptimize' ) . '</h2>'; ?>
143
+        <?php echo '<h2>'.__("These Autoptimize power-ups and related services will improve your site's performance even more!", 'autoptimize').'</h2>'; ?>
144 144
         <div>
145 145
             <?php echo $this->get_ao_partner_feed_markup(); ?>
146 146
         </div>
Please login to merge, or discard this patch.
classes/autoptimizeOptionWrapper.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Autoptimize options handler.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
      * Ensure that is_plugin_active_for_network function is declared.
22 22
      */
23 23
     public static function maybe_include_plugin_functions() {
24
-        if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
25
-            include_once ABSPATH . 'wp-admin/includes/plugin.php';
24
+        if (!function_exists('is_plugin_active_for_network')) {
25
+            include_once ABSPATH.'wp-admin/includes/plugin.php';
26 26
         }
27 27
     }
28 28
 
@@ -33,19 +33,19 @@  discard block
 block discarded – undo
33 33
      * @param mixed  $default Optional. Default value to return if the option does not exist.
34 34
      * @return mixed Value set for the option.
35 35
      */
36
-    public static function get_option( $option, $default = false ) {
36
+    public static function get_option($option, $default = false) {
37 37
         // This is always a network setting, it is on by default to ensure settings are available at site level unless explicitly turned off.
38
-        if ( 'autoptimize_enable_site_config' === $option ) {
39
-            return get_network_option( get_main_network_id(), $option, 'on' );
38
+        if ('autoptimize_enable_site_config' === $option) {
39
+            return get_network_option(get_main_network_id(), $option, 'on');
40 40
         }
41 41
 
42 42
         // If the plugin is network activated and our per site setting is not on, use the network configuration.
43
-        $configuration_per_site = get_network_option( get_main_network_id(), 'autoptimize_enable_site_config', 'on' );
44
-        if ( self::is_ao_active_for_network() && ( 'on' !== $configuration_per_site || is_network_admin() ) ) {
45
-            return get_network_option( get_main_network_id(), $option, $default );
43
+        $configuration_per_site = get_network_option(get_main_network_id(), 'autoptimize_enable_site_config', 'on');
44
+        if (self::is_ao_active_for_network() && ('on' !== $configuration_per_site || is_network_admin())) {
45
+            return get_network_option(get_main_network_id(), $option, $default);
46 46
         }
47 47
 
48
-        return get_option( $option, $default );
48
+        return get_option($option, $default);
49 49
     }
50 50
 
51 51
     /**
@@ -59,11 +59,11 @@  discard block
 block discarded – undo
59 59
      *                              the default value is 'yes'. Default null.
60 60
      * @return bool False if value was not updated and true if value was updated.
61 61
      */
62
-    public static function update_option( $option, $value, $autoload = null ) {
63
-        if ( self::is_ao_active_for_network() && is_network_admin() ) {
64
-            return update_network_option( get_main_network_id(), $option, $value );
65
-        } elseif ( 'autoptimize_enable_site_config' !== $option ) {
66
-            return update_option( $option, $value, $autoload );
62
+    public static function update_option($option, $value, $autoload = null) {
63
+        if (self::is_ao_active_for_network() && is_network_admin()) {
64
+            return update_network_option(get_main_network_id(), $option, $value);
65
+        } elseif ('autoptimize_enable_site_config' !== $option) {
66
+            return update_option($option, $value, $autoload);
67 67
         }
68 68
     }
69 69
 
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
      * in that case, take care of multisite case.
73 73
      */
74 74
     public static function check_multisite_on_saving_options() {
75
-        if ( self::is_ao_active_for_network() ) {
76
-            add_filter( 'pre_update_option', 'autoptimizeOptionWrapper::update_autoptimize_option_on_network', 10, 3 );
75
+        if (self::is_ao_active_for_network()) {
76
+            add_filter('pre_update_option', 'autoptimizeOptionWrapper::update_autoptimize_option_on_network', 10, 3);
77 77
         }
78 78
     }
79 79
 
@@ -84,16 +84,16 @@  discard block
 block discarded – undo
84 84
      * @param string $option    Option name.
85 85
      * @param string $old_value Old value.
86 86
      */
87
-    public static function update_autoptimize_option_on_network( $value, $option, $old_value ) {
88
-        if ( strpos( $option, 'autoptimize_' ) === 0 && self::is_options_from_network_admin() ) {
89
-            if ( self::is_ao_active_for_network() ) {
90
-                update_network_option( get_main_network_id(), $option, $value );
87
+    public static function update_autoptimize_option_on_network($value, $option, $old_value) {
88
+        if (strpos($option, 'autoptimize_') === 0 && self::is_options_from_network_admin()) {
89
+            if (self::is_ao_active_for_network()) {
90
+                update_network_option(get_main_network_id(), $option, $value);
91 91
                 // Return old value, to stop update_option logic.
92 92
                 return $old_value;
93 93
             }
94
-            if ( apply_filters( 'autoptimize_filter_optionwrapper_wp_cache_delete', false ) ) {
94
+            if (apply_filters('autoptimize_filter_optionwrapper_wp_cache_delete', false)) {
95 95
                 // in some (rare) cases options seem to get stuck in WP's Object cache, this should clear it there.
96
-                wp_cache_delete( $option );
96
+                wp_cache_delete($option);
97 97
             }
98 98
         }
99 99
         return $value;
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
     public static function is_options_from_network_admin() {
108 108
         static $_really_is_network_admin = null;
109 109
 
110
-        if ( null === $_really_is_network_admin ) {
111
-            if ( array_key_exists( '_wp_http_referer', $_POST ) && strpos( network_admin_url( 'settings.php' ), strtok( $_POST['_wp_http_referer'], '?' ) ) !== false ) {
110
+        if (null === $_really_is_network_admin) {
111
+            if (array_key_exists('_wp_http_referer', $_POST) && strpos(network_admin_url('settings.php'), strtok($_POST['_wp_http_referer'], '?')) !== false) {
112 112
                 $_really_is_network_admin = true;
113 113
             } else {
114 114
                 $_really_is_network_admin = false;
@@ -123,9 +123,9 @@  discard block
 block discarded – undo
123 123
      */
124 124
     public static function is_ao_active_for_network() {
125 125
         static $_is_ao_active_for_network = null;
126
-        if ( null === $_is_ao_active_for_network || defined( 'TEST_MULTISITE_FORCE_AO_ON_NETWORK' ) ) {
126
+        if (null === $_is_ao_active_for_network || defined('TEST_MULTISITE_FORCE_AO_ON_NETWORK')) {
127 127
             self::maybe_include_plugin_functions();
128
-            if ( is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) || is_plugin_active_for_network( 'autoptimize-beta/autoptimize.php' ) || defined( 'TEST_MULTISITE_FORCE_AO_ON_NETWORK' ) ) {
128
+            if (is_plugin_active_for_network('autoptimize/autoptimize.php') || is_plugin_active_for_network('autoptimize-beta/autoptimize.php') || defined('TEST_MULTISITE_FORCE_AO_ON_NETWORK')) {
129 129
                 $_is_ao_active_for_network = true;
130 130
             } else {
131 131
                 $_is_ao_active_for_network = false;
Please login to merge, or discard this patch.
classes/critcss-inc/admin_settings_impexp.js.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -9,15 +9,15 @@  discard block
 block discarded – undo
9 9
     console.log('Exporting...');
10 10
     var data = {
11 11
         'action': 'ao_ccss_export',
12
-        'ao_ccss_export_nonce': '<?php echo wp_create_nonce( 'ao_ccss_export_nonce' ); ?>',
12
+        'ao_ccss_export_nonce': '<?php echo wp_create_nonce('ao_ccss_export_nonce'); ?>',
13 13
     };
14 14
 
15 15
     jQuery.post(ajaxurl, data, function(response) {
16 16
         response_array=JSON.parse(response);
17 17
         if (response_array['code'] == 200) {
18 18
             <?php
19
-            if ( is_multisite() ) {
20
-                $blog_id = '/' . get_current_blog_id() . '/';
19
+            if (is_multisite()) {
20
+                $blog_id = '/'.get_current_blog_id().'/';
21 21
             } else {
22 22
                 $blog_id = '/';
23 23
             }
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
             autoOpen: true,
33 33
             height: 210,
34 34
             width: 700,
35
-            title: "<?php _e( 'Export settings result', 'autoptimize' ); ?>",
35
+            title: "<?php _e('Export settings result', 'autoptimize'); ?>",
36 36
             modal: true,
37 37
             buttons: {
38 38
                 OK: function() {
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
     var settings_file = file[0].files[0];
51 51
     fd.append('file', settings_file);
52 52
     fd.append('action', 'ao_ccss_import');
53
-    fd.append('ao_ccss_import_nonce', '<?php echo wp_create_nonce( 'ao_ccss_import_nonce' ); ?>');
53
+    fd.append('ao_ccss_import_nonce', '<?php echo wp_create_nonce('ao_ccss_import_nonce'); ?>');
54 54
 
55 55
     jQuery.ajax({
56 56
         url: ajaxurl,
Please login to merge, or discard this patch.
classes/critcss-inc/admin_settings_rules.php 1 patch
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -13,12 +13,12 @@  discard block
 block discarded – undo
13 13
 ?>
14 14
     <ul id="rules-panel">
15 15
         <li class="itemDetail">
16
-            <h2 class="itemTitle"><?php _e( 'Rules', 'autoptimize' ); ?></h2>
16
+            <h2 class="itemTitle"><?php _e('Rules', 'autoptimize'); ?></h2>
17 17
 
18 18
             <!-- BEGIN Rule dialogs -->
19 19
             <!-- Unsaved dialog -->
20 20
             <div id="unSavedWarning" class="hidden updated settings-error notice notice-warning is-dismissible">
21
-                <p><?php _e( "<strong>Rules or Queue changed!</strong> Don't forget to save your changes!", 'autoptimize' ); ?></p>
21
+                <p><?php _e("<strong>Rules or Queue changed!</strong> Don't forget to save your changes!", 'autoptimize'); ?></p>
22 22
             </div>
23 23
 
24 24
             <!-- Create/edit rule dialog -->
@@ -26,97 +26,97 @@  discard block
 block discarded – undo
26 26
                 <table class="form-table rules">
27 27
                     <tr id="critcss_addedit_type_wrapper">
28 28
                         <th scope="row">
29
-                            <?php _e( 'Rule Type', 'autoptimize' ); ?>
29
+                            <?php _e('Rule Type', 'autoptimize'); ?>
30 30
                         </th>
31 31
                         <td>
32 32
                             <select id="critcss_addedit_type" style="width:100%;">
33
-                                <option value="paths"><?php _e( 'Path', 'autoptimize' ); ?></option>
34
-                                <option value="types"><?php _e( 'Conditional Tag', 'autoptimize' ); ?></option>
33
+                                <option value="paths"><?php _e('Path', 'autoptimize'); ?></option>
34
+                                <option value="types"><?php _e('Conditional Tag', 'autoptimize'); ?></option>
35 35
                             </select>
36 36
                         </td>
37 37
                     </tr>
38 38
                     <tr id="critcss_addedit_path_wrapper">
39 39
                         <th scope="row">
40
-                            <?php _e( 'String in Path', 'autoptimize' ); ?>
40
+                            <?php _e('String in Path', 'autoptimize'); ?>
41 41
                         </th>
42 42
                         <td>
43
-                            <input type="text" id="critcss_addedit_path" placeholder="<?php _e( "Enter a part of the URL that identifies the page(s) you're targetting.", 'autoptimize' ); ?>" style="width:100%;" value="">
43
+                            <input type="text" id="critcss_addedit_path" placeholder="<?php _e("Enter a part of the URL that identifies the page(s) you're targetting.", 'autoptimize'); ?>" style="width:100%;" value="">
44 44
                         </td>
45 45
                     </tr>
46 46
                     <tr id="critcss_addedit_pagetype_wrapper">
47 47
                         <th scope="row">
48
-                            <?php _e( 'Conditional Tag, Custom Post Type or Page Template', 'autoptimize' ); ?>
48
+                            <?php _e('Conditional Tag, Custom Post Type or Page Template', 'autoptimize'); ?>
49 49
                         </th>
50 50
                         <td>
51 51
                             <select id="critcss_addedit_pagetype" style="width:100%;">
52
-                                <option value="" disabled selected><?php _e( 'Select from the list below...', 'autoptimize' ); ?></option>
53
-                                <optgroup label="<?php _e( 'Standard Conditional Tags', 'autoptimize' ); ?>">
52
+                                <option value="" disabled selected><?php _e('Select from the list below...', 'autoptimize'); ?></option>
53
+                                <optgroup label="<?php _e('Standard Conditional Tags', 'autoptimize'); ?>">
54 54
                                     <?php
55 55
                                     // Render grouped simple conditional tags.
56
-                                    foreach ( $ao_ccss_types as $ctag ) {
57
-                                        $optgrp = substr( $ctag, 0, 3 );
58
-                                        if ( substr( $ctag, 0, 3 ) === 'is_' ) {
59
-                                            echo '<option value="' . $ctag . '">' . $ctag . '</option>';
56
+                                    foreach ($ao_ccss_types as $ctag) {
57
+                                        $optgrp = substr($ctag, 0, 3);
58
+                                        if (substr($ctag, 0, 3) === 'is_') {
59
+                                            echo '<option value="'.$ctag.'">'.$ctag.'</option>';
60 60
                                         }
61
-                                        $prevgrp = substr( $ctag, 0, 3 );
61
+                                        $prevgrp = substr($ctag, 0, 3);
62 62
                                     }
63 63
 
64 64
                                     // Render grouped custom post types, templates and specific conditional tags.
65
-                                    foreach ( $ao_ccss_types as $type ) {
66
-                                        $optgrp = substr( $type, 0, 3 );
65
+                                    foreach ($ao_ccss_types as $type) {
66
+                                        $optgrp = substr($type, 0, 3);
67 67
 
68 68
                                         // Option groups labels.
69
-                                        if ( $optgrp !== $prevgrp && 'is_' !== $optgrp ) {
69
+                                        if ($optgrp !== $prevgrp && 'is_' !== $optgrp) {
70 70
                                             ?>
71 71
                                             </optgroup>
72 72
                                             <?php
73
-                                            if ( substr( $type, 0, 12 ) === 'custom_post_' ) {
73
+                                            if (substr($type, 0, 12) === 'custom_post_') {
74 74
                                                 ?>
75
-                                                <optgroup label="<?php _e( 'Custom Post Types', 'autoptimize' ); ?>">
75
+                                                <optgroup label="<?php _e('Custom Post Types', 'autoptimize'); ?>">
76 76
                                                 <?php
77
-                                            } elseif ( substr( $type, 0, 9 ) === 'template_' ) {
77
+                                            } elseif (substr($type, 0, 9) === 'template_') {
78 78
                                                 ?>
79
-                                                <optgroup label="<?php _e( 'Page Templates', 'autoptimize' ); ?>">
79
+                                                <optgroup label="<?php _e('Page Templates', 'autoptimize'); ?>">
80 80
                                                 <?php
81
-                                            } elseif ( substr( $type, 0, 4 ) === 'bbp_' ) {
81
+                                            } elseif (substr($type, 0, 4) === 'bbp_') {
82 82
                                                 ?>
83
-                                                <optgroup label="<?php _e( 'BBPress Conditional Tags', 'autoptimize' ); ?>">
83
+                                                <optgroup label="<?php _e('BBPress Conditional Tags', 'autoptimize'); ?>">
84 84
                                                 <?php
85
-                                            } elseif ( substr( $type, 0, 3 ) === 'bp_' ) {
85
+                                            } elseif (substr($type, 0, 3) === 'bp_') {
86 86
                                                 ?>
87
-                                                <optgroup label="<?php _e( 'BuddyPress Conditional Tags', 'autoptimize' ); ?>">
87
+                                                <optgroup label="<?php _e('BuddyPress Conditional Tags', 'autoptimize'); ?>">
88 88
                                                 <?php
89
-                                            } elseif ( substr( $type, 0, 4 ) === 'edd_' ) {
89
+                                            } elseif (substr($type, 0, 4) === 'edd_') {
90 90
                                                 ?>
91
-                                                <optgroup label="<?php _e( 'Easy Digital Downloads Conditional Tags', 'autoptimize' ); ?>">
91
+                                                <optgroup label="<?php _e('Easy Digital Downloads Conditional Tags', 'autoptimize'); ?>">
92 92
                                                 <?php
93
-                                            } elseif ( substr( $type, 0, 4 ) === 'woo_' ) {
93
+                                            } elseif (substr($type, 0, 4) === 'woo_') {
94 94
                                                 ?>
95
-                                                <optgroup label="<?php _e( 'WooCommerce Conditional Tags', 'autoptimize' ); ?>">
95
+                                                <optgroup label="<?php _e('WooCommerce Conditional Tags', 'autoptimize'); ?>">
96 96
                                                 <?php
97 97
                                             }
98 98
                                         }
99 99
 
100 100
                                         // Options.
101
-                                        if ( 'is_' !== $optgrp ) {
101
+                                        if ('is_' !== $optgrp) {
102 102
                                             // Remove prefix from custom post types, templates and some specific conditional tags.
103
-                                            if ( substr( $type, 0, 12 ) === 'custom_post_' ) {
104
-                                                $_type = str_replace( 'custom_post_', '', $type );
105
-                                            } elseif ( substr( $type, 0, 9 ) === 'template_' ) {
106
-                                                $_type = str_replace( 'template_', '', $type );
107
-                                            } elseif ( 'bbp_is_bbpress' == $type ) {
108
-                                                $_type = str_replace( 'bbp_', '', $type );
109
-                                            } elseif ( 'bp_is_buddypress' == $type ) {
110
-                                                $_type = str_replace( 'bp_', '', $type );
111
-                                            } elseif ( substr( $type, 0, 4 ) === 'woo_' ) {
112
-                                                $_type = str_replace( 'woo_', '', $type );
113
-                                            } elseif ( substr( $type, 0, 4 ) === 'edd_' ) {
114
-                                                $_type = str_replace( 'edd_', '', $type );
103
+                                            if (substr($type, 0, 12) === 'custom_post_') {
104
+                                                $_type = str_replace('custom_post_', '', $type);
105
+                                            } elseif (substr($type, 0, 9) === 'template_') {
106
+                                                $_type = str_replace('template_', '', $type);
107
+                                            } elseif ('bbp_is_bbpress' == $type) {
108
+                                                $_type = str_replace('bbp_', '', $type);
109
+                                            } elseif ('bp_is_buddypress' == $type) {
110
+                                                $_type = str_replace('bp_', '', $type);
111
+                                            } elseif (substr($type, 0, 4) === 'woo_') {
112
+                                                $_type = str_replace('woo_', '', $type);
113
+                                            } elseif (substr($type, 0, 4) === 'edd_') {
114
+                                                $_type = str_replace('edd_', '', $type);
115 115
                                             } else {
116 116
                                                 $_type = $type;
117 117
                                             }
118 118
 
119
-                                            echo '<option value="' . $type . '">' . $_type . '</option>';
119
+                                            echo '<option value="'.$type.'">'.$_type.'</option>';
120 120
                                             $prevgrp = $optgrp;
121 121
                                         }
122 122
                                     }
@@ -127,10 +127,10 @@  discard block
 block discarded – undo
127 127
                     </tr>
128 128
                     <tr>
129 129
                         <th scope="row">
130
-                            <?php _e( 'Custom Critical CSS', 'autoptimize' ); ?>
130
+                            <?php _e('Custom Critical CSS', 'autoptimize'); ?>
131 131
                         </th>
132 132
                         <td>
133
-                            <textarea id="critcss_addedit_css" rows="13" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste your specific critical CSS here and hit submit to save.', 'autoptimize' ); ?>"></textarea>
133
+                            <textarea id="critcss_addedit_css" rows="13" cols="10" style="width:100%;" placeholder="<?php _e('Paste your specific critical CSS here and hit submit to save.', 'autoptimize'); ?>"></textarea>
134 134
                             <input type="hidden" id="critcss_addedit_file">
135 135
                             <input type="hidden" id="critcss_addedit_id">
136 136
                         </td>
@@ -139,23 +139,23 @@  discard block
 block discarded – undo
139 139
             </div>
140 140
 
141 141
             <!-- Remove dialog -->
142
-            <div id="confirm-rm" title="<?php _e( 'Delete Rule', 'autoptimize' ); ?>" class="hidden">
143
-                <p><?php _e( 'This Critical CSS rule will be deleted immediately and cannot be recovered.<br /><br /><strong>Are you sure?</strong>', 'autoptimize' ); ?></p>
142
+            <div id="confirm-rm" title="<?php _e('Delete Rule', 'autoptimize'); ?>" class="hidden">
143
+                <p><?php _e('This Critical CSS rule will be deleted immediately and cannot be recovered.<br /><br /><strong>Are you sure?</strong>', 'autoptimize'); ?></p>
144 144
             </div>
145 145
 
146 146
             <!-- Remove All dialog -->
147
-            <div id="confirm-rm-all" title="<?php _e( 'Delete all Rules and Jobs', 'autoptimize' ); ?>" class="hidden">
148
-                <p><?php _e( 'All Critical CSS rules will be deleted immediately and cannot be recovered.<br /><br /><strong>Are you sure?</strong>', 'autoptimize' ); ?></p>
147
+            <div id="confirm-rm-all" title="<?php _e('Delete all Rules and Jobs', 'autoptimize'); ?>" class="hidden">
148
+                <p><?php _e('All Critical CSS rules will be deleted immediately and cannot be recovered.<br /><br /><strong>Are you sure?</strong>', 'autoptimize'); ?></p>
149 149
             </div>
150 150
 
151 151
             <!-- Add/edit default critical CSS dialog -->
152 152
             <div id="default_critcss_wrapper" class="hidden">
153
-                <textarea id="dummyDefault" rows="19" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste your MINIFIED default critical CSS here and hit submit to save. This is the critical CSS to be used for every page NOT MATCHING any rule.', 'autoptimize' ); ?>"></textarea>
153
+                <textarea id="dummyDefault" rows="19" cols="10" style="width:100%;" placeholder="<?php _e('Paste your MINIFIED default critical CSS here and hit submit to save. This is the critical CSS to be used for every page NOT MATCHING any rule.', 'autoptimize'); ?>"></textarea>
154 154
             </div>
155 155
 
156 156
             <!-- Add/edit additional critical CSS dialog -->
157 157
             <div id="additional_critcss_wrapper" class="hidden">
158
-                <textarea id="dummyAdditional" rows="19" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste your MINIFIED additional critical CSS here and hit submit to save. This is the CSS to be added AT THE END of every critical CSS provided by a matching rule, or the default one.', 'autoptimize' ); ?>"></textarea>
158
+                <textarea id="dummyAdditional" rows="19" cols="10" style="width:100%;" placeholder="<?php _e('Paste your MINIFIED additional critical CSS here and hit submit to save. This is the CSS to be added AT THE END of every critical CSS provided by a matching rule, or the default one.', 'autoptimize'); ?>"></textarea>
159 159
             </div>
160 160
 
161 161
             <!-- Wrapper for in screen notices -->
@@ -165,38 +165,38 @@  discard block
 block discarded – undo
165 165
             <!-- BEGIN Rules UI -->
166 166
             <div class="howto">
167 167
                 <div class="title-wrap">
168
-                    <h4 class="title"><?php _e( 'How To Use Autoptimize CriticalCSS Power-Up Rules', 'autoptimize' ); ?></h4>
169
-                    <p class="subtitle"><?php _e( 'Click the side arrow to toggle instructions', 'autoptimize' ); ?></p>
168
+                    <h4 class="title"><?php _e('How To Use Autoptimize CriticalCSS Power-Up Rules', 'autoptimize'); ?></h4>
169
+                    <p class="subtitle"><?php _e('Click the side arrow to toggle instructions', 'autoptimize'); ?></p>
170 170
                 </div>
171 171
                 <button type="button" class="toggle-btn">
172 172
                     <span class="toggle-indicator dashicons dashicons-arrow-up dashicons-arrow-down"></span>
173 173
                 </button>
174 174
                 <div class="howto-wrap hidden">
175
-                <p><?php _e( "TL;DR:<br />Critical CSS files from <span class='badge auto'>AUTO</span> <strong>rules are updated automatically</strong> while from <span class='badge manual'>MANUAL</span> <strong>rules are not.</strong>", 'autoptimize' ); ?></p>
175
+                <p><?php _e("TL;DR:<br />Critical CSS files from <span class='badge auto'>AUTO</span> <strong>rules are updated automatically</strong> while from <span class='badge manual'>MANUAL</span> <strong>rules are not.</strong>", 'autoptimize'); ?></p>
176 176
                     <ol>
177
-                        <li><?php _e( 'When a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> API key is in place, Autoptimize CriticalCSS Power-Up starts to operate <strong>automatically</strong>.', 'autoptimize' ); ?></li>
178
-                        <li><?php _e( 'Upon a request to any of the frontend pages made by a <strong>not logged in user</strong>, it will <strong>asynchronously</strong> fetch and update the critical CSS from <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for conditional tags you have on your site (e.g. is_page, is_single, is_archive etc.)', 'autoptimize' ); ?></li>
179
-                        <li><?php _e( 'These requests also creates an <span class="badge auto">AUTO</span> rule for you. The critical CSS files from <span class="badge auto">AUTO</span> <strong>rules are updated automatically</strong> when a CSS file in your theme or frontend plugins changes.', 'autoptimize' ); ?></li>
180
-                        <li><?php _e( 'If you want to make any fine tunning in the critical CSS file of an <span class="badge auto">AUTO</span> rule, click on "Edit" button of that rule, change what you need, submit and save it. The rule you\'ve just edited becomes a <span class="badge manual">MANUAL</span> rule then.', 'autoptimize' ); ?></li>
181
-                        <li><?php _e( 'You can create <span class="badge manual">MANUAL</span> rules for specific page paths (URL). Longer, more specific paths have higher priority over shorter ones, which in turn have higher priority over <span class="badge auto">AUTO</span> rules. Also, critical CSS files from <span class="badge manual">MANUAL</span> <strong>rules are NEVER updated automatically.</strong>', 'autoptimize' ); ?></li>
182
-                        <li><?php _e( 'You can also create an <span class="badge auto">AUTO</span> rule for a path by leaving its critical CSS content empty. The critical CSS for that path will be automatically fetched from <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for you and updated whenever it changes.', 'autoptimize' ); ?></li>
183
-                        <li><?php _e( "If you see an <span class='badge auto'>AUTO</span> rule with a <span class='badge review'>R</span> besides it (R is after REVIEW), it means that the fetched critical CSS for that rule is not 100% garanteed to work according to <a href='https://criticalcss.com/?aff=1' target='_blank'>criticalcss.com</a> analysis. It's advised that you edit and review that rule to make any required adjustments.", 'autoptimize' ); ?></li>
184
-                        <li><?php _e( 'At any time you can delete an <span class="badge auto">AUTO</span> or <span class="badge manual">MANUAL</span> rule by cliking on "Remove" button of the desired rule and saving your changes.', 'autoptimize' ); ?></li>
177
+                        <li><?php _e('When a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> API key is in place, Autoptimize CriticalCSS Power-Up starts to operate <strong>automatically</strong>.', 'autoptimize'); ?></li>
178
+                        <li><?php _e('Upon a request to any of the frontend pages made by a <strong>not logged in user</strong>, it will <strong>asynchronously</strong> fetch and update the critical CSS from <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for conditional tags you have on your site (e.g. is_page, is_single, is_archive etc.)', 'autoptimize'); ?></li>
179
+                        <li><?php _e('These requests also creates an <span class="badge auto">AUTO</span> rule for you. The critical CSS files from <span class="badge auto">AUTO</span> <strong>rules are updated automatically</strong> when a CSS file in your theme or frontend plugins changes.', 'autoptimize'); ?></li>
180
+                        <li><?php _e('If you want to make any fine tunning in the critical CSS file of an <span class="badge auto">AUTO</span> rule, click on "Edit" button of that rule, change what you need, submit and save it. The rule you\'ve just edited becomes a <span class="badge manual">MANUAL</span> rule then.', 'autoptimize'); ?></li>
181
+                        <li><?php _e('You can create <span class="badge manual">MANUAL</span> rules for specific page paths (URL). Longer, more specific paths have higher priority over shorter ones, which in turn have higher priority over <span class="badge auto">AUTO</span> rules. Also, critical CSS files from <span class="badge manual">MANUAL</span> <strong>rules are NEVER updated automatically.</strong>', 'autoptimize'); ?></li>
182
+                        <li><?php _e('You can also create an <span class="badge auto">AUTO</span> rule for a path by leaving its critical CSS content empty. The critical CSS for that path will be automatically fetched from <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for you and updated whenever it changes.', 'autoptimize'); ?></li>
183
+                        <li><?php _e("If you see an <span class='badge auto'>AUTO</span> rule with a <span class='badge review'>R</span> besides it (R is after REVIEW), it means that the fetched critical CSS for that rule is not 100% garanteed to work according to <a href='https://criticalcss.com/?aff=1' target='_blank'>criticalcss.com</a> analysis. It's advised that you edit and review that rule to make any required adjustments.", 'autoptimize'); ?></li>
184
+                        <li><?php _e('At any time you can delete an <span class="badge auto">AUTO</span> or <span class="badge manual">MANUAL</span> rule by cliking on "Remove" button of the desired rule and saving your changes.', 'autoptimize'); ?></li>
185 185
                     </ol>
186 186
                 </div>
187 187
             </div>
188
-            <textarea id="autoptimize_css_defer_inline" name="autoptimize_css_defer_inline" rows="19" cols="10" style="width:100%;"><?php echo get_option( 'autoptimize_css_defer_inline', '' ); ?></textarea>
189
-            <textarea id="autoptimize_ccss_additional" name="autoptimize_ccss_additional" rows="19" cols="10" style="width:100%;"><?php echo get_option( 'autoptimize_ccss_additional', '' ); ?></textarea>
188
+            <textarea id="autoptimize_css_defer_inline" name="autoptimize_css_defer_inline" rows="19" cols="10" style="width:100%;"><?php echo get_option('autoptimize_css_defer_inline', ''); ?></textarea>
189
+            <textarea id="autoptimize_ccss_additional" name="autoptimize_ccss_additional" rows="19" cols="10" style="width:100%;"><?php echo get_option('autoptimize_ccss_additional', ''); ?></textarea>
190 190
             <table class="rules-list" cellspacing="0"><tbody id="rules-list"></tbody></table>
191
-            <input class="hidden" type="text" id="critCssOrigin" name="autoptimize_ccss_rules" value='<?php echo ( json_encode( $ao_ccss_rules, JSON_FORCE_OBJECT ) ); ?>'>
191
+            <input class="hidden" type="text" id="critCssOrigin" name="autoptimize_ccss_rules" value='<?php echo (json_encode($ao_ccss_rules, JSON_FORCE_OBJECT)); ?>'>
192 192
             <div class="submit rules-btn">
193 193
                 <div class="alignleft">
194
-                    <span id="addCritCssButton" class="button-secondary"><?php _e( 'Add New Rule', 'autoptimize' ); ?></span>
195
-                    <span id="editDefaultButton" class="button-secondary"><?php _e( 'Edit Default Rule CSS', 'autoptimize' ); ?></span>
196
-                    <span id="editAdditionalButton" class="button-secondary"><?php _e( 'Add CSS To All Rules', 'autoptimize' ); ?></span>
194
+                    <span id="addCritCssButton" class="button-secondary"><?php _e('Add New Rule', 'autoptimize'); ?></span>
195
+                    <span id="editDefaultButton" class="button-secondary"><?php _e('Edit Default Rule CSS', 'autoptimize'); ?></span>
196
+                    <span id="editAdditionalButton" class="button-secondary"><?php _e('Add CSS To All Rules', 'autoptimize'); ?></span>
197 197
                 </div>
198 198
                 <div class="alignright">
199
-                    <span id="removeAllRules" class="button-secondary" style="color:red;"><?php _e( 'Remove all rules', 'autoptimize' ); ?></span>
199
+                    <span id="removeAllRules" class="button-secondary" style="color:red;"><?php _e('Remove all rules', 'autoptimize'); ?></span>
200 200
                 </div>
201 201
             </div>
202 202
             <!-- END Rules UI -->
Please login to merge, or discard this patch.
classes/critcss-inc/admin_settings_debug.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 $ao_options = $wpdb->get_results('
11 11
   SELECT option_name  AS name,
12 12
          option_value AS value
13
-  FROM ' . $wpdb->options . '
13
+  FROM ' . $wpdb->options.'
14 14
   WHERE option_name LIKE "autoptimize_%%"
15 15
   ORDER BY name
16 16
 ', ARRAY_A);
@@ -19,27 +19,27 @@  discard block
 block discarded – undo
19 19
 $ao_trans = $wpdb->get_results('
20 20
   SELECT option_name  AS name,
21 21
          option_value AS value
22
-  FROM ' . $wpdb->options . '
22
+  FROM ' . $wpdb->options.'
23 23
   WHERE option_name LIKE "_transient_autoptimize_%%"
24 24
      OR option_name LIKE "_transient_timeout_autoptimize_%%"
25 25
 ', ARRAY_A);
26 26
 
27 27
 // Render debug panel if there's something to show.
28
-if ( $ao_options || $ao_trans ) {
28
+if ($ao_options || $ao_trans) {
29 29
 ?>
30 30
 <!-- BEGIN: Settings Debug -->
31 31
 <ul>
32 32
     <li class="itemDetail">
33
-        <h2 class="itemTitle"><?php _e( 'Debug Information', 'autoptimize' ); ?></h2>
33
+        <h2 class="itemTitle"><?php _e('Debug Information', 'autoptimize'); ?></h2>
34 34
 
35 35
         <?php
36 36
         // Render options.
37
-        if ( $ao_options ) {
37
+        if ($ao_options) {
38 38
         ?>
39
-            <h4><?php _e( 'Options', 'autoptimize' ); ?>:</h4>
39
+            <h4><?php _e('Options', 'autoptimize'); ?>:</h4>
40 40
             <table class="form-table debug">
41 41
             <?php
42
-            foreach ( $ao_options as $option ) {
42
+            foreach ($ao_options as $option) {
43 43
             ?>
44 44
                 <tr>
45 45
                     <th scope="row">
@@ -47,10 +47,10 @@  discard block
 block discarded – undo
47 47
                     </th>
48 48
                     <td>
49 49
                         <?php
50
-                        if ( 'autoptimize_ccss_queue' == $option['name'] || 'autoptimize_ccss_rules' == $option['name'] ) {
51
-                            $value = print_r( json_decode( $option['value'], true ), true );
52
-                            if ( $value ) {
53
-                                echo "Raw JSON:\n<pre>" . $option['value'] . "</pre>\n\nDecoded JSON:\n<pre>" . $value . '</pre>';
50
+                        if ('autoptimize_ccss_queue' == $option['name'] || 'autoptimize_ccss_rules' == $option['name']) {
51
+                            $value = print_r(json_decode($option['value'], true), true);
52
+                            if ($value) {
53
+                                echo "Raw JSON:\n<pre>".$option['value']."</pre>\n\nDecoded JSON:\n<pre>".$value.'</pre>';
54 54
                             } else {
55 55
                                 echo 'Empty';
56 56
                             }
@@ -69,11 +69,11 @@  discard block
 block discarded – undo
69 69
         }
70 70
         // Render WP-Cron intervals and scheduled events.
71 71
         ?>
72
-        <h4><?php _e( 'WP-Cron Intervals', 'autoptimize' ); ?>:</h4>
73
-        <pre><?php print_r( wp_get_schedules() ); ?></pre>
72
+        <h4><?php _e('WP-Cron Intervals', 'autoptimize'); ?>:</h4>
73
+        <pre><?php print_r(wp_get_schedules()); ?></pre>
74 74
         <hr />
75
-        <h4><?php _e( 'WP-Cron Scheduled Events', 'autoptimize' ); ?>:</h4>
76
-        <pre><?php print_r( _get_cron_array() ); ?></pre>
75
+        <h4><?php _e('WP-Cron Scheduled Events', 'autoptimize'); ?>:</h4>
76
+        <pre><?php print_r(_get_cron_array()); ?></pre>
77 77
     </li>
78 78
 </ul>
79 79
 <!-- END: Settings Debug -->
Please login to merge, or discard this patch.
classes/autoptimizeUtils.php 1 patch
Spacing   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * General helpers.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -16,15 +16,15 @@  discard block
 block discarded – undo
16 16
      *
17 17
      * @return bool
18 18
      */
19
-    public static function mbstring_available( $override = null )
19
+    public static function mbstring_available($override = null)
20 20
     {
21 21
         static $available = null;
22 22
 
23
-        if ( null === $available ) {
24
-            $available = \extension_loaded( 'mbstring' );
23
+        if (null === $available) {
24
+            $available = \extension_loaded('mbstring');
25 25
         }
26 26
 
27
-        if ( null !== $override ) {
27
+        if (null !== $override) {
28 28
             $available = $override;
29 29
         }
30 30
 
@@ -42,12 +42,12 @@  discard block
 block discarded – undo
42 42
      *
43 43
      * @return int|false
44 44
      */
45
-    public static function strpos( $haystack, $needle, $offset = 0, $encoding = null )
45
+    public static function strpos($haystack, $needle, $offset = 0, $encoding = null)
46 46
     {
47
-        if ( self::mbstring_available() ) {
48
-            return ( null === $encoding ) ? \mb_strpos( $haystack, $needle, $offset ) : \mb_strpos( $haystack, $needle, $offset, $encoding );
47
+        if (self::mbstring_available()) {
48
+            return (null === $encoding) ? \mb_strpos($haystack, $needle, $offset) : \mb_strpos($haystack, $needle, $offset, $encoding);
49 49
         } else {
50
-            return \strpos( $haystack, $needle, $offset );
50
+            return \strpos($haystack, $needle, $offset);
51 51
         }
52 52
     }
53 53
 
@@ -62,12 +62,12 @@  discard block
 block discarded – undo
62 62
      * @return int Number of characters or bytes in given $string
63 63
      *             (characters if/when supported, bytes otherwise).
64 64
      */
65
-    public static function strlen( $string, $encoding = null )
65
+    public static function strlen($string, $encoding = null)
66 66
     {
67
-        if ( self::mbstring_available() ) {
68
-            return ( null === $encoding ) ? \mb_strlen( $string ) : \mb_strlen( $string, $encoding );
67
+        if (self::mbstring_available()) {
68
+            return (null === $encoding) ? \mb_strlen($string) : \mb_strlen($string, $encoding);
69 69
         } else {
70
-            return \strlen( $string );
70
+            return \strlen($string);
71 71
         }
72 72
     }
73 73
 
@@ -85,44 +85,44 @@  discard block
 block discarded – undo
85 85
      *
86 86
      * @return string
87 87
      */
88
-    public static function substr_replace( $string, $replacement, $start, $length = null, $encoding = null )
88
+    public static function substr_replace($string, $replacement, $start, $length = null, $encoding = null)
89 89
     {
90
-        if ( self::mbstring_available() ) {
91
-            $strlen = self::strlen( $string, $encoding );
90
+        if (self::mbstring_available()) {
91
+            $strlen = self::strlen($string, $encoding);
92 92
 
93
-            if ( $start < 0 ) {
93
+            if ($start < 0) {
94 94
                 if ( -$start < $strlen ) {
95 95
                     $start = $strlen + $start;
96 96
                 } else {
97 97
                     $start = 0;
98 98
                 }
99
-            } elseif ( $start > $strlen ) {
99
+            } elseif ($start > $strlen) {
100 100
                 $start = $strlen;
101 101
             }
102 102
 
103
-            if ( null === $length || '' === $length ) {
103
+            if (null === $length || '' === $length) {
104 104
                 $start2 = $strlen;
105
-            } elseif ( $length < 0 ) {
105
+            } elseif ($length < 0) {
106 106
                 $start2 = $strlen + $length;
107
-                if ( $start2 < $start ) {
107
+                if ($start2 < $start) {
108 108
                     $start2 = $start;
109 109
                 }
110 110
             } else {
111 111
                 $start2 = $start + $length;
112 112
             }
113 113
 
114
-            if ( null === $encoding ) {
115
-                $leader  = $start ? \mb_substr( $string, 0, $start ) : '';
116
-                $trailer = ( $start2 < $strlen ) ? \mb_substr( $string, $start2, null ) : '';
114
+            if (null === $encoding) {
115
+                $leader  = $start ? \mb_substr($string, 0, $start) : '';
116
+                $trailer = ($start2 < $strlen) ? \mb_substr($string, $start2, null) : '';
117 117
             } else {
118
-                $leader  = $start ? \mb_substr( $string, 0, $start, $encoding ) : '';
119
-                $trailer = ( $start2 < $strlen ) ? \mb_substr( $string, $start2, null, $encoding ) : '';
118
+                $leader  = $start ? \mb_substr($string, 0, $start, $encoding) : '';
119
+                $trailer = ($start2 < $strlen) ? \mb_substr($string, $start2, null, $encoding) : '';
120 120
             }
121 121
 
122 122
             return "{$leader}{$replacement}{$trailer}";
123 123
         }
124 124
 
125
-        return ( null === $length ) ? \substr_replace( $string, $replacement, $start ) : \substr_replace( $string, $replacement, $start, $length );
125
+        return (null === $length) ? \substr_replace($string, $replacement, $start) : \substr_replace($string, $replacement, $start, $length);
126 126
     }
127 127
 
128 128
     /**
@@ -132,16 +132,16 @@  discard block
 block discarded – undo
132 132
      *
133 133
      * @return bool
134 134
      */
135
-    public static function siteurl_not_root( $override = null )
135
+    public static function siteurl_not_root($override = null)
136 136
     {
137 137
         static $subdir = null;
138 138
 
139
-        if ( null === $subdir ) {
139
+        if (null === $subdir) {
140 140
             $parts  = self::get_ao_wp_site_url_parts();
141
-            $subdir = ( isset( $parts['path'] ) && ( '/' !== $parts['path'] ) );
141
+            $subdir = (isset($parts['path']) && ('/' !== $parts['path']));
142 142
         }
143 143
 
144
-        if ( null !== $override ) {
144
+        if (null !== $override) {
145 145
             $subdir = $override;
146 146
         }
147 147
 
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
     {
159 159
         static $parts = array();
160 160
 
161
-        if ( empty( $parts ) ) {
162
-            $parts = \parse_url( AUTOPTIMIZE_WP_SITE_URL );
161
+        if (empty($parts)) {
162
+            $parts = \parse_url(AUTOPTIMIZE_WP_SITE_URL);
163 163
         }
164 164
 
165 165
         return $parts;
@@ -174,33 +174,33 @@  discard block
 block discarded – undo
174 174
      *
175 175
      * @return string
176 176
      */
177
-    public static function tweak_cdn_url_if_needed( $cdn_url, $force_cache_miss = false )
177
+    public static function tweak_cdn_url_if_needed($cdn_url, $force_cache_miss = false)
178 178
     {
179 179
         static $results = array();
180 180
 
181
-        if ( ! isset( $results[ $cdn_url ] ) || $force_cache_miss ) {
181
+        if (!isset($results[$cdn_url]) || $force_cache_miss) {
182 182
 
183 183
             // In order to return unmodified input when there's no need to tweak.
184
-            $results[ $cdn_url ] = $cdn_url;
184
+            $results[$cdn_url] = $cdn_url;
185 185
 
186 186
             // Behind a default true filter for backcompat, and only for sites
187 187
             // in a subfolder/subdirectory, but still easily turned off if
188 188
             // not wanted/needed...
189
-            if ( autoptimizeUtils::siteurl_not_root() ) {
190
-                $check = apply_filters( 'autoptimize_filter_cdn_magic_path_check', true, $cdn_url );
191
-                if ( $check ) {
189
+            if (autoptimizeUtils::siteurl_not_root()) {
190
+                $check = apply_filters('autoptimize_filter_cdn_magic_path_check', true, $cdn_url);
191
+                if ($check) {
192 192
                     $site_url_parts = autoptimizeUtils::get_ao_wp_site_url_parts();
193
-                    $cdn_url_parts  = \parse_url( $cdn_url );
194
-                    $schemeless     = self::is_protocol_relative( $cdn_url );
195
-                    $cdn_url_parts  = self::maybe_replace_cdn_path( $site_url_parts, $cdn_url_parts );
196
-                    if ( false !== $cdn_url_parts ) {
197
-                        $results[ $cdn_url ] = self::assemble_parsed_url( $cdn_url_parts, $schemeless );
193
+                    $cdn_url_parts  = \parse_url($cdn_url);
194
+                    $schemeless     = self::is_protocol_relative($cdn_url);
195
+                    $cdn_url_parts  = self::maybe_replace_cdn_path($site_url_parts, $cdn_url_parts);
196
+                    if (false !== $cdn_url_parts) {
197
+                        $results[$cdn_url] = self::assemble_parsed_url($cdn_url_parts, $schemeless);
198 198
                     }
199 199
                 }
200 200
             }
201 201
         }
202 202
 
203
-        return $results[ $cdn_url ];
203
+        return $results[$cdn_url];
204 204
     }
205 205
 
206 206
     /**
@@ -214,10 +214,10 @@  discard block
 block discarded – undo
214 214
      *
215 215
      * @return array|false
216 216
      */
217
-    public static function maybe_replace_cdn_path( array $site_url_parts, array $cdn_url_parts )
217
+    public static function maybe_replace_cdn_path(array $site_url_parts, array $cdn_url_parts)
218 218
     {
219
-        if ( isset( $site_url_parts['path'] ) && '/' !== $site_url_parts['path'] ) {
220
-            if ( ! isset( $cdn_url_parts['path'] ) || '/' === $cdn_url_parts['path'] ) {
219
+        if (isset($site_url_parts['path']) && '/' !== $site_url_parts['path']) {
220
+            if (!isset($cdn_url_parts['path']) || '/' === $cdn_url_parts['path']) {
221 221
                 $cdn_url_parts['path'] = $site_url_parts['path'];
222 222
                 return $cdn_url_parts;
223 223
             }
@@ -237,20 +237,20 @@  discard block
 block discarded – undo
237 237
      *
238 238
      * @return string
239 239
      */
240
-    public static function assemble_parsed_url( array $parsed_url, $schemeless = false )
240
+    public static function assemble_parsed_url(array $parsed_url, $schemeless = false)
241 241
     {
242
-        $scheme = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] . '://' : '';
243
-        if ( $schemeless ) {
242
+        $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'].'://' : '';
243
+        if ($schemeless) {
244 244
             $scheme = '//';
245 245
         }
246
-        $host     = isset( $parsed_url['host'] ) ? $parsed_url['host'] : '';
247
-        $port     = isset( $parsed_url['port'] ) ? ':' . $parsed_url['port'] : '';
248
-        $user     = isset( $parsed_url['user'] ) ? $parsed_url['user'] : '';
249
-        $pass     = isset( $parsed_url['pass'] ) ? ':' . $parsed_url['pass'] : '';
250
-        $pass     = ( $user || $pass ) ? "$pass@" : '';
251
-        $path     = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '';
252
-        $query    = isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : '';
253
-        $fragment = isset( $parsed_url['fragment'] ) ? '#' . $parsed_url['fragment'] : '';
246
+        $host     = isset($parsed_url['host']) ? $parsed_url['host'] : '';
247
+        $port     = isset($parsed_url['port']) ? ':'.$parsed_url['port'] : '';
248
+        $user     = isset($parsed_url['user']) ? $parsed_url['user'] : '';
249
+        $pass     = isset($parsed_url['pass']) ? ':'.$parsed_url['pass'] : '';
250
+        $pass     = ($user || $pass) ? "$pass@" : '';
251
+        $path     = isset($parsed_url['path']) ? $parsed_url['path'] : '';
252
+        $query    = isset($parsed_url['query']) ? '?'.$parsed_url['query'] : '';
253
+        $fragment = isset($parsed_url['fragment']) ? '#'.$parsed_url['fragment'] : '';
254 254
 
255 255
         return "$scheme$user$pass$host$port$path$query$fragment";
256 256
     }
@@ -262,12 +262,12 @@  discard block
 block discarded – undo
262 262
      *
263 263
      * @return bool
264 264
      */
265
-    public static function is_protocol_relative( $url )
265
+    public static function is_protocol_relative($url)
266 266
     {
267 267
         $result = false;
268 268
 
269
-        if ( ! empty( $url ) ) {
270
-            $result = ( 0 === strpos( $url, '//' ) );
269
+        if (!empty($url)) {
270
+            $result = (0 === strpos($url, '//'));
271 271
         }
272 272
 
273 273
         return $result;
@@ -280,9 +280,9 @@  discard block
 block discarded – undo
280 280
      *
281 281
      * @return string
282 282
      */
283
-    public static function path_canonicalize( $path )
283
+    public static function path_canonicalize($path)
284 284
     {
285
-        $patterns     = array(
285
+        $patterns = array(
286 286
             '~/{2,}~',
287 287
             '~/(\./)+~',
288 288
             '~([^/\.]+/(?R)*\.{2,}/)~',
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
             '',
296 296
         );
297 297
 
298
-        return preg_replace( $patterns, $replacements, $path );
298
+        return preg_replace($patterns, $replacements, $path);
299 299
     }
300 300
 
301 301
     /**
@@ -307,15 +307,15 @@  discard block
 block discarded – undo
307 307
      *
308 308
      * @return null|array Service status or null.
309 309
      */
310
-    public static function check_service_availability( $return_result = false )
310
+    public static function check_service_availability($return_result = false)
311 311
     {
312
-        $service_availability_resp = wp_remote_get( 'https://misc.optimizingmatters.com/api/autoptimize_service_availablity.json?from=aomain&ver=' . AUTOPTIMIZE_PLUGIN_VERSION );
313
-        if ( ! is_wp_error( $service_availability_resp ) ) {
314
-            if ( '200' == wp_remote_retrieve_response_code( $service_availability_resp ) ) {
315
-                $availabilities = json_decode( wp_remote_retrieve_body( $service_availability_resp ), true );
316
-                if ( is_array( $availabilities ) ) {
317
-                    autoptimizeOptionWrapper::update_option( 'autoptimize_service_availablity', $availabilities );
318
-                    if ( $return_result ) {
312
+        $service_availability_resp = wp_remote_get('https://misc.optimizingmatters.com/api/autoptimize_service_availablity.json?from=aomain&ver='.AUTOPTIMIZE_PLUGIN_VERSION);
313
+        if (!is_wp_error($service_availability_resp)) {
314
+            if ('200' == wp_remote_retrieve_response_code($service_availability_resp)) {
315
+                $availabilities = json_decode(wp_remote_retrieve_body($service_availability_resp), true);
316
+                if (is_array($availabilities)) {
317
+                    autoptimizeOptionWrapper::update_option('autoptimize_service_availablity', $availabilities);
318
+                    if ($return_result) {
319 319
                         return $availabilities;
320 320
                     }
321 321
                 }
@@ -331,10 +331,10 @@  discard block
 block discarded – undo
331 331
      *
332 332
      * @return bool
333 333
      */
334
-    public static function str_is_valid_regex( $string )
334
+    public static function str_is_valid_regex($string)
335 335
     {
336
-        set_error_handler( function() {}, E_WARNING );
337
-        $is_regex = ( false !== preg_match( $string, '' ) );
336
+        set_error_handler(function() {}, E_WARNING);
337
+        $is_regex = (false !== preg_match($string, ''));
338 338
         restore_error_handler();
339 339
 
340 340
         return $is_regex;
@@ -347,17 +347,17 @@  discard block
 block discarded – undo
347 347
      *
348 348
      * @return bool
349 349
      */
350
-    public static function is_plugin_active( $plugin_file )
350
+    public static function is_plugin_active($plugin_file)
351 351
     {
352 352
         static $ipa_exists = null;
353
-        if ( null === $ipa_exists ) {
354
-            if ( ! function_exists( '\is_plugin_active' ) ) {
355
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
353
+        if (null === $ipa_exists) {
354
+            if (!function_exists('\is_plugin_active')) {
355
+                require_once ABSPATH.'wp-admin/includes/plugin.php';
356 356
             }
357
-            $ipa_exists = function_exists( '\is_plugin_active' );
357
+            $ipa_exists = function_exists('\is_plugin_active');
358 358
         }
359 359
 
360
-        return $ipa_exists && \is_plugin_active( $plugin_file );
360
+        return $ipa_exists && \is_plugin_active($plugin_file);
361 361
     }
362 362
 
363 363
     /**
@@ -367,11 +367,11 @@  discard block
 block discarded – undo
367 367
      *
368 368
      * @return string
369 369
      */
370
-    public static function remove_id_from_node( $node ) {
371
-        if ( strpos( $node, 'id=' ) === false || apply_filters( 'autoptimize_filter_utils_keep_ids', false ) ) {
370
+    public static function remove_id_from_node($node) {
371
+        if (strpos($node, 'id=') === false || apply_filters('autoptimize_filter_utils_keep_ids', false)) {
372 372
             return $node;
373 373
         } else {
374
-            return preg_replace( '#(.*) id=[\'|"].*[\'|"] (.*)#Um', '$1 $2', $node );
374
+            return preg_replace('#(.*) id=[\'|"].*[\'|"] (.*)#Um', '$1 $2', $node);
375 375
         }
376 376
     }
377 377
 
@@ -383,15 +383,15 @@  discard block
 block discarded – undo
383 383
      *
384 384
      * @return bool
385 385
      */
386
-    public static function str_ends_in( $str, $test )
386
+    public static function str_ends_in($str, $test)
387 387
     {
388 388
         // @codingStandardsIgnoreStart
389 389
         // substr_compare() is bugged on 5.5.11: https://3v4l.org/qGYBH
390 390
         // return ( 0 === substr_compare( $str, $test, -strlen( $test ) ) );
391 391
         // @codingStandardsIgnoreEnd
392 392
 
393
-        $length = strlen( $test );
393
+        $length = strlen($test);
394 394
 
395
-        return ( substr( $str, -$length, $length ) === $test );
395
+        return (substr($str, -$length, $length) === $test);
396 396
     }
397 397
 }
Please login to merge, or discard this patch.