Completed
Push — master ( a3ebdc...98ed08 )
by frank
56:55
created
classes/autoptimizeMain.php 1 patch
Spacing   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Wraps base plugin logic/hooks and handles activation/deactivation/uninstall.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      * @param string $version Version.
34 34
      * @param string $filepath Filepath. Needed for activation/deactivation/uninstall hooks.
35 35
      */
36
-    public function __construct( $version, $filepath )
36
+    public function __construct($version, $filepath)
37 37
     {
38 38
         $this->version  = $version;
39 39
         $this->filepath = $filepath;
@@ -50,94 +50,94 @@  discard block
 block discarded – undo
50 50
 
51 51
     protected function add_hooks()
52 52
     {
53
-        add_action( 'plugins_loaded', array( $this, 'setup' ) );
53
+        add_action('plugins_loaded', array($this, 'setup'));
54 54
 
55
-        add_action( 'autoptimize_setup_done', array( $this, 'version_upgrades_check' ) );
56
-        add_action( 'autoptimize_setup_done', array( $this, 'check_cache_and_run' ) );
57
-        add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_ao_extra' ) );
58
-        add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_partners_tab' ) );
55
+        add_action('autoptimize_setup_done', array($this, 'version_upgrades_check'));
56
+        add_action('autoptimize_setup_done', array($this, 'check_cache_and_run'));
57
+        add_action('autoptimize_setup_done', array($this, 'maybe_run_ao_extra'));
58
+        add_action('autoptimize_setup_done', array($this, 'maybe_run_partners_tab'));
59 59
 
60
-        add_action( 'init', array( $this, 'load_textdomain' ) );
61
-        add_action( 'plugins_loaded', array( $this, 'hook_page_cache_purge' ) );
62
-        add_action( 'admin_init', array( 'PAnD', 'init' ) );
60
+        add_action('init', array($this, 'load_textdomain'));
61
+        add_action('plugins_loaded', array($this, 'hook_page_cache_purge'));
62
+        add_action('admin_init', array('PAnD', 'init'));
63 63
 
64
-        register_activation_hook( $this->filepath, array( $this, 'on_activate' ) );
64
+        register_activation_hook($this->filepath, array($this, 'on_activate'));
65 65
     }
66 66
 
67 67
     public function on_activate()
68 68
     {
69
-        register_uninstall_hook( $this->filepath, 'autoptimizeMain::on_uninstall' );
69
+        register_uninstall_hook($this->filepath, 'autoptimizeMain::on_uninstall');
70 70
     }
71 71
 
72 72
     public function load_textdomain()
73 73
     {
74
-        load_plugin_textdomain( 'autoptimize' );
74
+        load_plugin_textdomain('autoptimize');
75 75
     }
76 76
 
77 77
     public function setup()
78 78
     {
79 79
         // Do we gzip in php when caching or is the webserver doing it?
80
-        define( 'AUTOPTIMIZE_CACHE_NOGZIP', (bool) get_option( 'autoptimize_cache_nogzip' ) );
80
+        define('AUTOPTIMIZE_CACHE_NOGZIP', (bool) get_option('autoptimize_cache_nogzip'));
81 81
 
82 82
         // These can be overridden by specifying them in wp-config.php or such.
83
-        if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_NAME' ) ) {
84
-            define( 'AUTOPTIMIZE_WP_CONTENT_NAME', '/' . wp_basename( WP_CONTENT_DIR ) );
83
+        if (!defined('AUTOPTIMIZE_WP_CONTENT_NAME')) {
84
+            define('AUTOPTIMIZE_WP_CONTENT_NAME', '/'.wp_basename(WP_CONTENT_DIR));
85 85
         }
86
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_CHILD_DIR' ) ) {
87
-            define( 'AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/' );
86
+        if (!defined('AUTOPTIMIZE_CACHE_CHILD_DIR')) {
87
+            define('AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/');
88 88
         }
89
-        if ( ! defined( 'AUTOPTIMIZE_CACHEFILE_PREFIX' ) ) {
90
-            define( 'AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_' );
89
+        if (!defined('AUTOPTIMIZE_CACHEFILE_PREFIX')) {
90
+            define('AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_');
91 91
         }
92 92
         // Note: trailing slash is not optional!
93
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_DIR' ) ) {
94
-            define( 'AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname() );
93
+        if (!defined('AUTOPTIMIZE_CACHE_DIR')) {
94
+            define('AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname());
95 95
         }
96 96
 
97
-        define( 'WP_ROOT_DIR', substr( WP_CONTENT_DIR, 0, strlen( WP_CONTENT_DIR ) - strlen( AUTOPTIMIZE_WP_CONTENT_NAME ) ) );
97
+        define('WP_ROOT_DIR', substr(WP_CONTENT_DIR, 0, strlen(WP_CONTENT_DIR) - strlen(AUTOPTIMIZE_WP_CONTENT_NAME)));
98 98
 
99
-        if ( ! defined( 'AUTOPTIMIZE_WP_SITE_URL' ) ) {
100
-            if ( function_exists( 'domain_mapping_siteurl' ) ) {
101
-                define( 'AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl( get_current_blog_id() ) );
99
+        if (!defined('AUTOPTIMIZE_WP_SITE_URL')) {
100
+            if (function_exists('domain_mapping_siteurl')) {
101
+                define('AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl(get_current_blog_id()));
102 102
             } else {
103
-                define( 'AUTOPTIMIZE_WP_SITE_URL', site_url() );
103
+                define('AUTOPTIMIZE_WP_SITE_URL', site_url());
104 104
             }
105 105
         }
106
-        if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_URL' ) ) {
107
-            if ( function_exists( 'domain_mapping_siteurl' ) ) {
108
-                define( 'AUTOPTIMIZE_WP_CONTENT_URL', str_replace( get_original_url( AUTOPTIMIZE_WP_SITE_URL ), AUTOPTIMIZE_WP_SITE_URL, content_url() ) );
106
+        if (!defined('AUTOPTIMIZE_WP_CONTENT_URL')) {
107
+            if (function_exists('domain_mapping_siteurl')) {
108
+                define('AUTOPTIMIZE_WP_CONTENT_URL', str_replace(get_original_url(AUTOPTIMIZE_WP_SITE_URL), AUTOPTIMIZE_WP_SITE_URL, content_url()));
109 109
             } else {
110
-                define( 'AUTOPTIMIZE_WP_CONTENT_URL', content_url() );
110
+                define('AUTOPTIMIZE_WP_CONTENT_URL', content_url());
111 111
             }
112 112
         }
113
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_URL' ) ) {
114
-            if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) {
113
+        if (!defined('AUTOPTIMIZE_CACHE_URL')) {
114
+            if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) {
115 115
                 $blog_id = get_current_blog_id();
116
-                define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR . $blog_id . '/' );
116
+                define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR.$blog_id.'/');
117 117
             } else {
118
-                define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR );
118
+                define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR);
119 119
             }
120 120
         }
121
-        if ( ! defined( 'AUTOPTIMIZE_WP_ROOT_URL' ) ) {
122
-            define( 'AUTOPTIMIZE_WP_ROOT_URL', str_replace( AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL ) );
121
+        if (!defined('AUTOPTIMIZE_WP_ROOT_URL')) {
122
+            define('AUTOPTIMIZE_WP_ROOT_URL', str_replace(AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL));
123 123
         }
124
-        if ( ! defined( 'AUTOPTIMIZE_HASH' ) ) {
125
-            define( 'AUTOPTIMIZE_HASH', wp_hash( AUTOPTIMIZE_CACHE_URL ) );
124
+        if (!defined('AUTOPTIMIZE_HASH')) {
125
+            define('AUTOPTIMIZE_HASH', wp_hash(AUTOPTIMIZE_CACHE_URL));
126 126
         }
127
-        if ( ! defined( 'AUTOPTIMIZE_SITE_DOMAIN' ) ) {
128
-            define( 'AUTOPTIMIZE_SITE_DOMAIN', parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) );
127
+        if (!defined('AUTOPTIMIZE_SITE_DOMAIN')) {
128
+            define('AUTOPTIMIZE_SITE_DOMAIN', parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST));
129 129
         }
130 130
 
131 131
         // Multibyte-capable string replacements are available with a filter.
132 132
         // Also requires 'mbstring' extension.
133
-        $with_mbstring = apply_filters( 'autoptimize_filter_main_use_mbstring', false );
134
-        if ( $with_mbstring ) {
135
-            autoptimizeUtils::mbstring_available( \extensions_loaded( 'mbstring' ) );
133
+        $with_mbstring = apply_filters('autoptimize_filter_main_use_mbstring', false);
134
+        if ($with_mbstring) {
135
+            autoptimizeUtils::mbstring_available(\extensions_loaded('mbstring'));
136 136
         } else {
137
-            autoptimizeUtils::mbstring_available( false );
137
+            autoptimizeUtils::mbstring_available(false);
138 138
         }
139 139
 
140
-        do_action( 'autoptimize_setup_done' );
140
+        do_action('autoptimize_setup_done');
141 141
     }
142 142
 
143 143
     /**
@@ -147,52 +147,52 @@  discard block
 block discarded – undo
147 147
      */
148 148
     public function version_upgrades_check()
149 149
     {
150
-        autoptimizeVersionUpdatesHandler::check_installed_and_update( $this->version );
150
+        autoptimizeVersionUpdatesHandler::check_installed_and_update($this->version);
151 151
     }
152 152
 
153 153
     public function check_cache_and_run()
154 154
     {
155
-        if ( autoptimizeCache::cacheavail() ) {
155
+        if (autoptimizeCache::cacheavail()) {
156 156
             $conf = autoptimizeConfig::instance();
157
-            if ( $conf->get( 'autoptimize_html' ) || $conf->get( 'autoptimize_js' ) || $conf->get( 'autoptimize_css' ) ) {
157
+            if ($conf->get('autoptimize_html') || $conf->get('autoptimize_js') || $conf->get('autoptimize_css')) {
158 158
                 // Hook into WordPress frontend.
159
-                if ( defined( 'AUTOPTIMIZE_INIT_EARLIER' ) ) {
159
+                if (defined('AUTOPTIMIZE_INIT_EARLIER')) {
160 160
                     add_action(
161 161
                         'init',
162
-                        array( $this, 'start_buffering' ),
162
+                        array($this, 'start_buffering'),
163 163
                         self::INIT_EARLIER_PRIORITY
164 164
                     );
165 165
                 } else {
166
-                    if ( ! defined( 'AUTOPTIMIZE_HOOK_INTO' ) ) {
167
-                        define( 'AUTOPTIMIZE_HOOK_INTO', 'template_redirect' );
166
+                    if (!defined('AUTOPTIMIZE_HOOK_INTO')) {
167
+                        define('AUTOPTIMIZE_HOOK_INTO', 'template_redirect');
168 168
                     }
169 169
                     add_action(
170
-                        constant( 'AUTOPTIMIZE_HOOK_INTO' ),
171
-                        array( $this, 'start_buffering' ),
170
+                        constant('AUTOPTIMIZE_HOOK_INTO'),
171
+                        array($this, 'start_buffering'),
172 172
                         self::DEFAULT_HOOK_PRIORITY
173 173
                     );
174 174
                 }
175 175
             }
176 176
         } else {
177
-            add_action( 'admin_notices', 'autoptimizeMain::notice_cache_unavailable' );
177
+            add_action('admin_notices', 'autoptimizeMain::notice_cache_unavailable');
178 178
         }
179 179
     }
180 180
 
181 181
     public function maybe_run_ao_extra()
182 182
     {
183
-        if ( apply_filters( 'autoptimize_filter_extra_activate', true ) ) {
183
+        if (apply_filters('autoptimize_filter_extra_activate', true)) {
184 184
             $ao_extra = new autoptimizeExtra();
185 185
             $ao_extra->run();
186 186
 
187 187
             // And show the imgopt notice.
188
-            add_action( 'admin_notices', 'autoptimizeMain::notice_plug_imgopt' );
188
+            add_action('admin_notices', 'autoptimizeMain::notice_plug_imgopt');
189 189
         }
190 190
     }
191 191
 
192 192
     public function maybe_run_partners_tab()
193 193
     {
194 194
         // Loads partners tab code if in admin (and not in admin-ajax.php)!
195
-        if ( autoptimizeConfig::is_admin_and_not_ajax() ) {
195
+        if (autoptimizeConfig::is_admin_and_not_ajax()) {
196 196
             new autoptimizePartners();
197 197
         }
198 198
     }
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
     public function hook_page_cache_purge()
201 201
     {
202 202
         // hook into a collection of page cache purge actions if filter allows.
203
-        if ( apply_filters( 'autoptimize_filter_main_hookpagecachepurge', true ) ) {
203
+        if (apply_filters('autoptimize_filter_main_hookpagecachepurge', true)) {
204 204
             $page_cache_purge_actions = array(
205 205
                 'after_rocket_clean_domain', // exists.
206 206
                 'hyper_cache_purged', // Stefano confirmed this will be added.
@@ -212,9 +212,9 @@  discard block
 block discarded – undo
212 212
                 'wpfc_delete_cache', // Emre confirmed this will be added this.
213 213
                 'swift_performance_after_clear_all_cache', // swift perf. yeah!
214 214
             );
215
-            $page_cache_purge_actions = apply_filters( 'autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions );
216
-            foreach ( $page_cache_purge_actions as $purge_action ) {
217
-                add_action( $purge_action, 'autoptimizeCache::clearall_actionless' );
215
+            $page_cache_purge_actions = apply_filters('autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions);
216
+            foreach ($page_cache_purge_actions as $purge_action) {
217
+                add_action($purge_action, 'autoptimizeCache::clearall_actionless');
218 218
             }
219 219
         }
220 220
     }
@@ -226,38 +226,38 @@  discard block
 block discarded – undo
226 226
      */
227 227
     public function start_buffering()
228 228
     {
229
-        if ( $this->should_buffer() ) {
229
+        if ($this->should_buffer()) {
230 230
 
231 231
             // Load speedupper conditionally (true by default).
232
-            if ( apply_filters( 'autoptimize_filter_speedupper', true ) ) {
232
+            if (apply_filters('autoptimize_filter_speedupper', true)) {
233 233
                 $ao_speedupper = new autoptimizeSpeedupper();
234 234
             }
235 235
 
236 236
             $conf = autoptimizeConfig::instance();
237 237
 
238
-            if ( $conf->get( 'autoptimize_js' ) ) {
239
-                if ( ! defined( 'CONCATENATE_SCRIPTS' ) ) {
240
-                    define( 'CONCATENATE_SCRIPTS', false );
238
+            if ($conf->get('autoptimize_js')) {
239
+                if (!defined('CONCATENATE_SCRIPTS')) {
240
+                    define('CONCATENATE_SCRIPTS', false);
241 241
                 }
242
-                if ( ! defined( 'COMPRESS_SCRIPTS' ) ) {
243
-                    define( 'COMPRESS_SCRIPTS', false );
242
+                if (!defined('COMPRESS_SCRIPTS')) {
243
+                    define('COMPRESS_SCRIPTS', false);
244 244
                 }
245 245
             }
246 246
 
247
-            if ( $conf->get( 'autoptimize_css' ) ) {
248
-                if ( ! defined( 'COMPRESS_CSS' ) ) {
249
-                    define( 'COMPRESS_CSS', false );
247
+            if ($conf->get('autoptimize_css')) {
248
+                if (!defined('COMPRESS_CSS')) {
249
+                    define('COMPRESS_CSS', false);
250 250
                 }
251 251
             }
252 252
 
253
-            if ( apply_filters( 'autoptimize_filter_obkiller', false ) ) {
254
-                while ( ob_get_level() > 0 ) {
253
+            if (apply_filters('autoptimize_filter_obkiller', false)) {
254
+                while (ob_get_level() > 0) {
255 255
                     ob_end_clean();
256 256
                 }
257 257
             }
258 258
 
259 259
             // Now, start the real thing!
260
-            ob_start( array( $this, 'end_buffering' ) );
260
+            ob_start(array($this, 'end_buffering'));
261 261
         }
262 262
     }
263 263
 
@@ -268,31 +268,31 @@  discard block
 block discarded – undo
268 268
      *                          deciding once per request (for use in tests).
269 269
      * @return bool
270 270
      */
271
-    public function should_buffer( $doing_tests = false )
271
+    public function should_buffer($doing_tests = false)
272 272
     {
273 273
         static $do_buffering = null;
274 274
 
275 275
         // Only check once in case we're called multiple times by others but
276 276
         // still allows multiple calls when doing tests.
277
-        if ( null === $do_buffering || $doing_tests ) {
277
+        if (null === $do_buffering || $doing_tests) {
278 278
 
279 279
             $ao_noptimize = false;
280 280
 
281 281
             // Checking for DONOTMINIFY constant as used by e.g. WooCommerce POS.
282
-            if ( defined( 'DONOTMINIFY' ) && ( constant( 'DONOTMINIFY' ) === true || constant( 'DONOTMINIFY' ) === 'true' ) ) {
282
+            if (defined('DONOTMINIFY') && (constant('DONOTMINIFY') === true || constant('DONOTMINIFY') === 'true')) {
283 283
                 $ao_noptimize = true;
284 284
             }
285 285
 
286 286
             // Skip checking query strings if they're disabled.
287
-            if ( apply_filters( 'autoptimize_filter_honor_qs_noptimize', true ) ) {
287
+            if (apply_filters('autoptimize_filter_honor_qs_noptimize', true)) {
288 288
                 // Check for `ao_noptimize` (and other) keys in the query string
289 289
                 // to get non-optimized page for debugging.
290 290
                 $keys = array(
291 291
                     'ao_noptimize',
292 292
                     'ao_noptirocket',
293 293
                 );
294
-                foreach ( $keys as $key ) {
295
-                    if ( array_key_exists( $key, $_GET ) && '1' === $_GET[ $key ] ) {
294
+                foreach ($keys as $key) {
295
+                    if (array_key_exists($key, $_GET) && '1' === $_GET[$key]) {
296 296
                         $ao_noptimize = true;
297 297
                         break;
298 298
                     }
@@ -300,15 +300,15 @@  discard block
 block discarded – undo
300 300
             }
301 301
 
302 302
             // If setting says not to optimize logged in user and user is logged in...
303
-            if ( 'on' !== get_option( 'autoptimize_optimize_logged', 'on' ) && is_user_logged_in() && current_user_can( 'edit_posts' ) ) {
303
+            if ('on' !== get_option('autoptimize_optimize_logged', 'on') && is_user_logged_in() && current_user_can('edit_posts')) {
304 304
                 $ao_noptimize = true;
305 305
             }
306 306
 
307 307
             // If setting says not to optimize cart/checkout.
308
-            if ( 'on' !== get_option( 'autoptimize_optimize_checkout', 'on' ) ) {
308
+            if ('on' !== get_option('autoptimize_optimize_checkout', 'on')) {
309 309
                 // Checking for woocommerce, easy digital downloads and wp ecommerce...
310
-                foreach ( array( 'is_checkout', 'is_cart', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout' ) as $func ) {
311
-                    if ( function_exists( $func ) && $func() ) {
310
+                foreach (array('is_checkout', 'is_cart', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout') as $func) {
311
+                    if (function_exists($func) && $func()) {
312 312
                         $ao_noptimize = true;
313 313
                         break;
314 314
                     }
@@ -316,11 +316,11 @@  discard block
 block discarded – undo
316 316
             }
317 317
 
318 318
             // Allows blocking of autoptimization on your own terms regardless of above decisions.
319
-            $ao_noptimize = (bool) apply_filters( 'autoptimize_filter_noptimize', $ao_noptimize );
319
+            $ao_noptimize = (bool) apply_filters('autoptimize_filter_noptimize', $ao_noptimize);
320 320
 
321 321
             // Check for site being previewed in the Customizer (available since WP 4.0).
322 322
             $is_customize_preview = false;
323
-            if ( function_exists( 'is_customize_preview' ) && is_customize_preview() ) {
323
+            if (function_exists('is_customize_preview') && is_customize_preview()) {
324 324
                 $is_customize_preview = is_customize_preview();
325 325
             }
326 326
 
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
              * while the main query hasn't been ran yet. Thats why we use
332 332
              * AUTOPTIMIZE_INIT_EARLIER in tests.
333 333
              */
334
-            $do_buffering = ( ! is_admin() && ! is_feed() && ! $ao_noptimize && ! $is_customize_preview );
334
+            $do_buffering = (!is_admin() && !is_feed() && !$ao_noptimize && !$is_customize_preview);
335 335
         }
336 336
 
337 337
         return $do_buffering;
@@ -344,24 +344,24 @@  discard block
 block discarded – undo
344 344
      *
345 345
      * @return bool
346 346
      */
347
-    public function is_valid_buffer( $content )
347
+    public function is_valid_buffer($content)
348 348
     {
349 349
         // Defaults to true.
350 350
         $valid = true;
351 351
 
352
-        $has_no_html_tag    = ( false === stripos( $content, '<html' ) );
353
-        $has_xsl_stylesheet = ( false !== stripos( $content, '<xsl:stylesheet' ) );
354
-        $has_html5_doctype  = ( preg_match( '/^<!DOCTYPE.+html>/i', $content ) > 0 );
352
+        $has_no_html_tag    = (false === stripos($content, '<html'));
353
+        $has_xsl_stylesheet = (false !== stripos($content, '<xsl:stylesheet'));
354
+        $has_html5_doctype  = (preg_match('/^<!DOCTYPE.+html>/i', $content) > 0);
355 355
 
356
-        if ( $has_no_html_tag ) {
356
+        if ($has_no_html_tag) {
357 357
             // Can't be valid amp markup without an html tag preceding it.
358 358
             $is_amp_markup = false;
359 359
         } else {
360
-            $is_amp_markup = self::is_amp_markup( $content );
360
+            $is_amp_markup = self::is_amp_markup($content);
361 361
         }
362 362
 
363 363
         // If it's not html, or if it's amp or contains xsl stylesheets we don't touch it.
364
-        if ( $has_no_html_tag && ! $has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet ) {
364
+        if ($has_no_html_tag && !$has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet) {
365 365
             $valid = false;
366 366
         }
367 367
 
@@ -376,9 +376,9 @@  discard block
 block discarded – undo
376 376
      *
377 377
      * @return bool
378 378
      */
379
-    public static function is_amp_markup( $content )
379
+    public static function is_amp_markup($content)
380 380
     {
381
-        $is_amp_markup = preg_match( '/<html[^>]*(?:amp|⚡)/i', $content );
381
+        $is_amp_markup = preg_match('/<html[^>]*(?:amp|⚡)/i', $content);
382 382
 
383 383
         return (bool) $is_amp_markup;
384 384
     }
@@ -391,10 +391,10 @@  discard block
 block discarded – undo
391 391
      *
392 392
      * @return string
393 393
      */
394
-    public function end_buffering( $content )
394
+    public function end_buffering($content)
395 395
     {
396 396
         // Bail early without modifying anything if we can't handle the content.
397
-        if ( ! $this->is_valid_buffer( $content ) ) {
397
+        if (!$this->is_valid_buffer($content)) {
398 398
             return $content;
399 399
         }
400 400
 
@@ -402,57 +402,57 @@  discard block
 block discarded – undo
402 402
 
403 403
         // Determine what needs to be ran.
404 404
         $classes = array();
405
-        if ( $conf->get( 'autoptimize_js' ) ) {
405
+        if ($conf->get('autoptimize_js')) {
406 406
             $classes[] = 'autoptimizeScripts';
407 407
         }
408
-        if ( $conf->get( 'autoptimize_css' ) ) {
408
+        if ($conf->get('autoptimize_css')) {
409 409
             $classes[] = 'autoptimizeStyles';
410 410
         }
411
-        if ( $conf->get( 'autoptimize_html' ) ) {
411
+        if ($conf->get('autoptimize_html')) {
412 412
             $classes[] = 'autoptimizeHTML';
413 413
         }
414 414
 
415 415
         $classoptions = array(
416 416
             'autoptimizeScripts' => array(
417
-                'aggregate'      => $conf->get( 'autoptimize_js_aggregate' ),
418
-                'justhead'       => $conf->get( 'autoptimize_js_justhead' ),
419
-                'forcehead'      => $conf->get( 'autoptimize_js_forcehead' ),
420
-                'trycatch'       => $conf->get( 'autoptimize_js_trycatch' ),
421
-                'js_exclude'     => $conf->get( 'autoptimize_js_exclude' ),
422
-                'cdn_url'        => $conf->get( 'autoptimize_cdn_url' ),
423
-                'include_inline' => $conf->get( 'autoptimize_js_include_inline' ),
417
+                'aggregate'      => $conf->get('autoptimize_js_aggregate'),
418
+                'justhead'       => $conf->get('autoptimize_js_justhead'),
419
+                'forcehead'      => $conf->get('autoptimize_js_forcehead'),
420
+                'trycatch'       => $conf->get('autoptimize_js_trycatch'),
421
+                'js_exclude'     => $conf->get('autoptimize_js_exclude'),
422
+                'cdn_url'        => $conf->get('autoptimize_cdn_url'),
423
+                'include_inline' => $conf->get('autoptimize_js_include_inline'),
424 424
             ),
425 425
             'autoptimizeStyles'  => array(
426
-                'aggregate'      => $conf->get( 'autoptimize_css_aggregate' ),
427
-                'justhead'       => $conf->get( 'autoptimize_css_justhead' ),
428
-                'datauris'       => $conf->get( 'autoptimize_css_datauris' ),
429
-                'defer'          => $conf->get( 'autoptimize_css_defer' ),
430
-                'defer_inline'   => $conf->get( 'autoptimize_css_defer_inline' ),
431
-                'inline'         => $conf->get( 'autoptimize_css_inline' ),
432
-                'css_exclude'    => $conf->get( 'autoptimize_css_exclude' ),
433
-                'cdn_url'        => $conf->get( 'autoptimize_cdn_url' ),
434
-                'include_inline' => $conf->get( 'autoptimize_css_include_inline' ),
435
-                'nogooglefont'   => $conf->get( 'autoptimize_css_nogooglefont' ),
426
+                'aggregate'      => $conf->get('autoptimize_css_aggregate'),
427
+                'justhead'       => $conf->get('autoptimize_css_justhead'),
428
+                'datauris'       => $conf->get('autoptimize_css_datauris'),
429
+                'defer'          => $conf->get('autoptimize_css_defer'),
430
+                'defer_inline'   => $conf->get('autoptimize_css_defer_inline'),
431
+                'inline'         => $conf->get('autoptimize_css_inline'),
432
+                'css_exclude'    => $conf->get('autoptimize_css_exclude'),
433
+                'cdn_url'        => $conf->get('autoptimize_cdn_url'),
434
+                'include_inline' => $conf->get('autoptimize_css_include_inline'),
435
+                'nogooglefont'   => $conf->get('autoptimize_css_nogooglefont'),
436 436
             ),
437 437
             'autoptimizeHTML'    => array(
438
-                'keepcomments' => $conf->get( 'autoptimize_html_keepcomments' ),
438
+                'keepcomments' => $conf->get('autoptimize_html_keepcomments'),
439 439
             ),
440 440
         );
441 441
 
442
-        $content = apply_filters( 'autoptimize_filter_html_before_minify', $content );
442
+        $content = apply_filters('autoptimize_filter_html_before_minify', $content);
443 443
 
444 444
         // Run the classes!
445
-        foreach ( $classes as $name ) {
446
-            $instance = new $name( $content );
447
-            if ( $instance->read( $classoptions[ $name ] ) ) {
445
+        foreach ($classes as $name) {
446
+            $instance = new $name($content);
447
+            if ($instance->read($classoptions[$name])) {
448 448
                 $instance->minify();
449 449
                 $instance->cache();
450 450
                 $content = $instance->getcontent();
451 451
             }
452
-            unset( $instance );
452
+            unset($instance);
453 453
         }
454 454
 
455
-        $content = apply_filters( 'autoptimize_html_after_minify', $content );
455
+        $content = apply_filters('autoptimize_html_after_minify', $content);
456 456
 
457 457
         return $content;
458 458
     }
@@ -494,74 +494,74 @@  discard block
 block discarded – undo
494 494
             'autoptimize_imgopt_launched',
495 495
         );
496 496
 
497
-        if ( ! is_multisite() ) {
498
-            foreach ( $delete_options as $del_opt ) {
499
-                delete_option( $del_opt );
497
+        if (!is_multisite()) {
498
+            foreach ($delete_options as $del_opt) {
499
+                delete_option($del_opt);
500 500
             }
501 501
         } else {
502 502
             global $wpdb;
503
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
503
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
504 504
             $original_blog_id = get_current_blog_id();
505
-            foreach ( $blog_ids as $blog_id ) {
506
-                switch_to_blog( $blog_id );
507
-                foreach ( $delete_options as $del_opt ) {
508
-                    delete_option( $del_opt );
505
+            foreach ($blog_ids as $blog_id) {
506
+                switch_to_blog($blog_id);
507
+                foreach ($delete_options as $del_opt) {
508
+                    delete_option($del_opt);
509 509
                 }
510 510
             }
511
-            switch_to_blog( $original_blog_id );
511
+            switch_to_blog($original_blog_id);
512 512
         }
513 513
 
514
-        if ( wp_get_schedule( 'ao_cachechecker' ) ) {
515
-            wp_clear_scheduled_hook( 'ao_cachechecker' );
514
+        if (wp_get_schedule('ao_cachechecker')) {
515
+            wp_clear_scheduled_hook('ao_cachechecker');
516 516
         }
517 517
 
518 518
         // remove "persist admin noctice dismissal" options
519 519
         global $wpdb;
520
-        $table         = is_multisite() ? $wpdb->base_prefix . 'sitemeta' : $wpdb->base_prefix . 'options';
520
+        $table         = is_multisite() ? $wpdb->base_prefix.'sitemeta' : $wpdb->base_prefix.'options';
521 521
         $column        = is_multisite() ? 'meta_key' : 'option_name';
522
-        $delete_string = 'DELETE FROM ' . $table . ' WHERE ' . $column . ' LIKE %s LIMIT 1000';
523
-        $wpdb->query( $wpdb->prepare( $delete_string, array( '%pand-%' ) ) );
522
+        $delete_string = 'DELETE FROM '.$table.' WHERE '.$column.' LIKE %s LIMIT 1000';
523
+        $wpdb->query($wpdb->prepare($delete_string, array('%pand-%')));
524 524
     }
525 525
 
526 526
     public static function notice_cache_unavailable()
527 527
     {
528 528
         echo '<div class="error"><p>';
529 529
         // Translators: %s is the cache directory location.
530
-        printf( __( 'Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize' ), AUTOPTIMIZE_CACHE_DIR );
530
+        printf(__('Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize'), AUTOPTIMIZE_CACHE_DIR);
531 531
         echo '</p></div>';
532 532
     }
533 533
 
534 534
     public static function notice_installed()
535 535
     {
536 536
         echo '<div class="updated"><p>';
537
-        _e( 'Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize' );
537
+        _e('Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize');
538 538
         echo '</p></div>';
539 539
     }
540 540
 
541 541
     public static function notice_updated()
542 542
     {
543 543
         echo '<div class="updated"><p>';
544
-        _e( 'Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize' );
544
+        _e('Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize');
545 545
         echo '</p></div>';
546 546
     }
547 547
 
548 548
     public static function notice_plug_imgopt()
549 549
     {
550 550
         // Translators: the URL added points to the Autopmize Extra settings.
551
-        $_ao_imgopt_plug_notice      = sprintf( __( 'Did you know Autoptimize includes on-the-fly image optimization and CDN via ShortPixel? Check out the %1$sAutoptimize Extra settings%2$s to activate this option.', 'autoptimize' ), '<a href="options-general.php?page=autoptimize_extra">', '</a>' );
552
-        $_ao_imgopt_plug_notice      = apply_filters( 'autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice );
551
+        $_ao_imgopt_plug_notice      = sprintf(__('Did you know Autoptimize includes on-the-fly image optimization and CDN via ShortPixel? Check out the %1$sAutoptimize Extra settings%2$s to activate this option.', 'autoptimize'), '<a href="options-general.php?page=autoptimize_extra">', '</a>');
552
+        $_ao_imgopt_plug_notice      = apply_filters('autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice);
553 553
         $_ao_imgopt_launch_ok        = autoptimizeExtra::imgopt_launch_ok_wrapper();
554 554
         $_ao_imgopt_plug_dismissible = 'ao-img-opt-plug-123';
555 555
 
556 556
         // check if AO is optimizing images already.
557 557
         $_ao_imgopt_active = false;
558
-        $_ao_extra_options = get_option( 'autoptimize_extra_settings', '' );
559
-        if ( is_array( $_ao_extra_options ) && array_key_exists( 'autoptimize_extra_checkbox_field_5', $_ao_extra_options ) && ! empty( $_ao_extra_options['autoptimize_extra_checkbox_field_5'] ) ) {
558
+        $_ao_extra_options = get_option('autoptimize_extra_settings', '');
559
+        if (is_array($_ao_extra_options) && array_key_exists('autoptimize_extra_checkbox_field_5', $_ao_extra_options) && !empty($_ao_extra_options['autoptimize_extra_checkbox_field_5'])) {
560 560
             $_ao_imgopt_active = true;
561 561
         }
562 562
 
563
-        if ( '' !== $_ao_imgopt_plug_notice && ! $_ao_imgopt_active && $_ao_imgopt_launch_ok && PAnD::is_admin_notice_active( $_ao_imgopt_plug_dismissible ) ) {
564
-            echo '<div class="notice notice-info is-dismissible" data-dismissible="' . $_ao_imgopt_plug_dismissible . '"><p>';
563
+        if ('' !== $_ao_imgopt_plug_notice && !$_ao_imgopt_active && $_ao_imgopt_launch_ok && PAnD::is_admin_notice_active($_ao_imgopt_plug_dismissible)) {
564
+            echo '<div class="notice notice-info is-dismissible" data-dismissible="'.$_ao_imgopt_plug_dismissible.'"><p>';
565 565
             echo $_ao_imgopt_plug_notice;
566 566
             echo '</p></div>';
567 567
         }
Please login to merge, or discard this patch.
php/persist-admin-notices-dismissal/persist-admin-notices-dismissal.php 2 patches
Indentation   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -29,131 +29,131 @@
 block discarded – undo
29 29
  * Exit if called directly.
30 30
  */
31 31
 if ( ! defined( 'ABSPATH' ) ) {
32
-	die;
32
+    die;
33 33
 }
34 34
 
35 35
 if ( ! class_exists( 'PAnD' ) ) {
36 36
 
37
-	/**
38
-	 * Class PAnD
39
-	 */
40
-	class PAnD {
41
-
42
-		/**
43
-		 * Init hooks.
44
-		 */
45
-		public static function init() {
46
-			add_action( 'admin_enqueue_scripts', array( __CLASS__, 'load_script' ) );
47
-			add_action( 'wp_ajax_dismiss_admin_notice', array( __CLASS__, 'dismiss_admin_notice' ) );
48
-		}
49
-
50
-		/**
51
-		 * Enqueue javascript and variables.
52
-		 */
53
-		public static function load_script() {
54
-
55
-			if ( is_customize_preview() ) {
56
-				return;
57
-			}
58
-
59
-			wp_enqueue_script(
60
-				'dismissible-notices',
61
-				plugins_url( 'dismiss-notice.js', __FILE__ ),
62
-				array( 'jquery', 'common' ),
63
-				false,
64
-				true
65
-			);
66
-
67
-			wp_localize_script(
68
-				'dismissible-notices',
69
-				'dismissible_notice',
70
-				array(
71
-					'nonce' => wp_create_nonce( 'dismissible-notice' ),
72
-				)
73
-			);
74
-		}
75
-
76
-		/**
77
-		 * Handles Ajax request to persist notices dismissal.
78
-		 * Uses check_ajax_referer to verify nonce.
79
-		 */
80
-		public static function dismiss_admin_notice() {
81
-			$option_name        = sanitize_text_field( $_POST['option_name'] );
82
-			$dismissible_length = sanitize_text_field( $_POST['dismissible_length'] );
83
-
84
-			if ( 'forever' != $dismissible_length ) {
85
-				// If $dismissible_length is not an integer default to 1
86
-				$dismissible_length = ( 0 == absint( $dismissible_length ) ) ? 1 : $dismissible_length;
87
-				$dismissible_length = strtotime( absint( $dismissible_length ) . ' days' );
88
-			}
89
-
90
-			check_ajax_referer( 'dismissible-notice', 'nonce' );
91
-			self::set_admin_notice_cache( $option_name, $dismissible_length );
92
-			wp_die();
93
-		}
94
-
95
-		/**
96
-		 * Is admin notice active?
97
-		 *
98
-		 * @param string $arg data-dismissible content of notice.
99
-		 *
100
-		 * @return bool
101
-		 */
102
-		public static function is_admin_notice_active( $arg ) {
103
-			$array       = explode( '-', $arg );
104
-			$length      = array_pop( $array );
105
-			$option_name = implode( '-', $array );
106
-			$db_record   = self::get_admin_notice_cache( $option_name );
107
-			if ( 'forever' == $db_record ) {
108
-				return false;
109
-			} elseif ( absint( $db_record ) >= time() ) {
110
-				return false;
111
-			} else {
112
-				return true;
113
-			}
114
-		}
115
-
116
-		/**
117
-		 * Returns admin notice cached timeout.
118
-		 *
119
-		 * @access public
120
-		 *
121
-		 * @param string|bool $id admin notice name or false.
122
-		 *
123
-		 * @return array|bool The timeout. False if expired.
124
-		 */
125
-		public static function get_admin_notice_cache( $id = false ) {
126
-			if ( ! $id ) {
127
-				return false;
128
-			}
129
-			$cache_key = 'pand-' . md5( $id );
130
-			$timeout   = get_site_option( $cache_key );
131
-			$timeout   = 'forever' === $timeout ? time() + 60 : $timeout;
132
-
133
-			if ( empty( $timeout ) || time() > $timeout ) {
134
-				return false;
135
-			}
136
-
137
-			return $timeout;
138
-		}
139
-
140
-		/**
141
-		 * Sets admin notice timeout in site option.
142
-		 *
143
-		 * @access public
144
-		 *
145
-		 * @param string      $id       Data Identifier.
146
-		 * @param string|bool $timeout  Timeout for admin notice.
147
-		 *
148
-		 * @return bool
149
-		 */
150
-		public static function set_admin_notice_cache( $id, $timeout ) {
151
-			$cache_key = 'pand-' . md5( $id );
152
-			update_site_option( $cache_key, $timeout );
153
-
154
-			return true;
155
-		}
156
-
157
-	}
37
+    /**
38
+     * Class PAnD
39
+     */
40
+    class PAnD {
41
+
42
+        /**
43
+         * Init hooks.
44
+         */
45
+        public static function init() {
46
+            add_action( 'admin_enqueue_scripts', array( __CLASS__, 'load_script' ) );
47
+            add_action( 'wp_ajax_dismiss_admin_notice', array( __CLASS__, 'dismiss_admin_notice' ) );
48
+        }
49
+
50
+        /**
51
+         * Enqueue javascript and variables.
52
+         */
53
+        public static function load_script() {
54
+
55
+            if ( is_customize_preview() ) {
56
+                return;
57
+            }
58
+
59
+            wp_enqueue_script(
60
+                'dismissible-notices',
61
+                plugins_url( 'dismiss-notice.js', __FILE__ ),
62
+                array( 'jquery', 'common' ),
63
+                false,
64
+                true
65
+            );
66
+
67
+            wp_localize_script(
68
+                'dismissible-notices',
69
+                'dismissible_notice',
70
+                array(
71
+                    'nonce' => wp_create_nonce( 'dismissible-notice' ),
72
+                )
73
+            );
74
+        }
75
+
76
+        /**
77
+         * Handles Ajax request to persist notices dismissal.
78
+         * Uses check_ajax_referer to verify nonce.
79
+         */
80
+        public static function dismiss_admin_notice() {
81
+            $option_name        = sanitize_text_field( $_POST['option_name'] );
82
+            $dismissible_length = sanitize_text_field( $_POST['dismissible_length'] );
83
+
84
+            if ( 'forever' != $dismissible_length ) {
85
+                // If $dismissible_length is not an integer default to 1
86
+                $dismissible_length = ( 0 == absint( $dismissible_length ) ) ? 1 : $dismissible_length;
87
+                $dismissible_length = strtotime( absint( $dismissible_length ) . ' days' );
88
+            }
89
+
90
+            check_ajax_referer( 'dismissible-notice', 'nonce' );
91
+            self::set_admin_notice_cache( $option_name, $dismissible_length );
92
+            wp_die();
93
+        }
94
+
95
+        /**
96
+         * Is admin notice active?
97
+         *
98
+         * @param string $arg data-dismissible content of notice.
99
+         *
100
+         * @return bool
101
+         */
102
+        public static function is_admin_notice_active( $arg ) {
103
+            $array       = explode( '-', $arg );
104
+            $length      = array_pop( $array );
105
+            $option_name = implode( '-', $array );
106
+            $db_record   = self::get_admin_notice_cache( $option_name );
107
+            if ( 'forever' == $db_record ) {
108
+                return false;
109
+            } elseif ( absint( $db_record ) >= time() ) {
110
+                return false;
111
+            } else {
112
+                return true;
113
+            }
114
+        }
115
+
116
+        /**
117
+         * Returns admin notice cached timeout.
118
+         *
119
+         * @access public
120
+         *
121
+         * @param string|bool $id admin notice name or false.
122
+         *
123
+         * @return array|bool The timeout. False if expired.
124
+         */
125
+        public static function get_admin_notice_cache( $id = false ) {
126
+            if ( ! $id ) {
127
+                return false;
128
+            }
129
+            $cache_key = 'pand-' . md5( $id );
130
+            $timeout   = get_site_option( $cache_key );
131
+            $timeout   = 'forever' === $timeout ? time() + 60 : $timeout;
132
+
133
+            if ( empty( $timeout ) || time() > $timeout ) {
134
+                return false;
135
+            }
136
+
137
+            return $timeout;
138
+        }
139
+
140
+        /**
141
+         * Sets admin notice timeout in site option.
142
+         *
143
+         * @access public
144
+         *
145
+         * @param string      $id       Data Identifier.
146
+         * @param string|bool $timeout  Timeout for admin notice.
147
+         *
148
+         * @return bool
149
+         */
150
+        public static function set_admin_notice_cache( $id, $timeout ) {
151
+            $cache_key = 'pand-' . md5( $id );
152
+            update_site_option( $cache_key, $timeout );
153
+
154
+            return true;
155
+        }
156
+
157
+    }
158 158
 
159 159
 }
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -28,11 +28,11 @@  discard block
 block discarded – undo
28 28
 /**
29 29
  * Exit if called directly.
30 30
  */
31
-if ( ! defined( 'ABSPATH' ) ) {
31
+if (!defined('ABSPATH')) {
32 32
 	die;
33 33
 }
34 34
 
35
-if ( ! class_exists( 'PAnD' ) ) {
35
+if (!class_exists('PAnD')) {
36 36
 
37 37
 	/**
38 38
 	 * Class PAnD
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
 		 * Init hooks.
44 44
 		 */
45 45
 		public static function init() {
46
-			add_action( 'admin_enqueue_scripts', array( __CLASS__, 'load_script' ) );
47
-			add_action( 'wp_ajax_dismiss_admin_notice', array( __CLASS__, 'dismiss_admin_notice' ) );
46
+			add_action('admin_enqueue_scripts', array(__CLASS__, 'load_script'));
47
+			add_action('wp_ajax_dismiss_admin_notice', array(__CLASS__, 'dismiss_admin_notice'));
48 48
 		}
49 49
 
50 50
 		/**
@@ -52,14 +52,14 @@  discard block
 block discarded – undo
52 52
 		 */
53 53
 		public static function load_script() {
54 54
 
55
-			if ( is_customize_preview() ) {
55
+			if (is_customize_preview()) {
56 56
 				return;
57 57
 			}
58 58
 
59 59
 			wp_enqueue_script(
60 60
 				'dismissible-notices',
61
-				plugins_url( 'dismiss-notice.js', __FILE__ ),
62
-				array( 'jquery', 'common' ),
61
+				plugins_url('dismiss-notice.js', __FILE__),
62
+				array('jquery', 'common'),
63 63
 				false,
64 64
 				true
65 65
 			);
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 				'dismissible-notices',
69 69
 				'dismissible_notice',
70 70
 				array(
71
-					'nonce' => wp_create_nonce( 'dismissible-notice' ),
71
+					'nonce' => wp_create_nonce('dismissible-notice'),
72 72
 				)
73 73
 			);
74 74
 		}
@@ -78,17 +78,17 @@  discard block
 block discarded – undo
78 78
 		 * Uses check_ajax_referer to verify nonce.
79 79
 		 */
80 80
 		public static function dismiss_admin_notice() {
81
-			$option_name        = sanitize_text_field( $_POST['option_name'] );
82
-			$dismissible_length = sanitize_text_field( $_POST['dismissible_length'] );
81
+			$option_name        = sanitize_text_field($_POST['option_name']);
82
+			$dismissible_length = sanitize_text_field($_POST['dismissible_length']);
83 83
 
84
-			if ( 'forever' != $dismissible_length ) {
84
+			if ('forever' != $dismissible_length) {
85 85
 				// If $dismissible_length is not an integer default to 1
86
-				$dismissible_length = ( 0 == absint( $dismissible_length ) ) ? 1 : $dismissible_length;
87
-				$dismissible_length = strtotime( absint( $dismissible_length ) . ' days' );
86
+				$dismissible_length = (0 == absint($dismissible_length)) ? 1 : $dismissible_length;
87
+				$dismissible_length = strtotime(absint($dismissible_length).' days');
88 88
 			}
89 89
 
90
-			check_ajax_referer( 'dismissible-notice', 'nonce' );
91
-			self::set_admin_notice_cache( $option_name, $dismissible_length );
90
+			check_ajax_referer('dismissible-notice', 'nonce');
91
+			self::set_admin_notice_cache($option_name, $dismissible_length);
92 92
 			wp_die();
93 93
 		}
94 94
 
@@ -99,14 +99,14 @@  discard block
 block discarded – undo
99 99
 		 *
100 100
 		 * @return bool
101 101
 		 */
102
-		public static function is_admin_notice_active( $arg ) {
103
-			$array       = explode( '-', $arg );
104
-			$length      = array_pop( $array );
105
-			$option_name = implode( '-', $array );
106
-			$db_record   = self::get_admin_notice_cache( $option_name );
107
-			if ( 'forever' == $db_record ) {
102
+		public static function is_admin_notice_active($arg) {
103
+			$array       = explode('-', $arg);
104
+			$length      = array_pop($array);
105
+			$option_name = implode('-', $array);
106
+			$db_record   = self::get_admin_notice_cache($option_name);
107
+			if ('forever' == $db_record) {
108 108
 				return false;
109
-			} elseif ( absint( $db_record ) >= time() ) {
109
+			} elseif (absint($db_record) >= time()) {
110 110
 				return false;
111 111
 			} else {
112 112
 				return true;
@@ -122,15 +122,15 @@  discard block
 block discarded – undo
122 122
 		 *
123 123
 		 * @return array|bool The timeout. False if expired.
124 124
 		 */
125
-		public static function get_admin_notice_cache( $id = false ) {
126
-			if ( ! $id ) {
125
+		public static function get_admin_notice_cache($id = false) {
126
+			if (!$id) {
127 127
 				return false;
128 128
 			}
129
-			$cache_key = 'pand-' . md5( $id );
130
-			$timeout   = get_site_option( $cache_key );
129
+			$cache_key = 'pand-'.md5($id);
130
+			$timeout   = get_site_option($cache_key);
131 131
 			$timeout   = 'forever' === $timeout ? time() + 60 : $timeout;
132 132
 
133
-			if ( empty( $timeout ) || time() > $timeout ) {
133
+			if (empty($timeout) || time() > $timeout) {
134 134
 				return false;
135 135
 			}
136 136
 
@@ -147,9 +147,9 @@  discard block
 block discarded – undo
147 147
 		 *
148 148
 		 * @return bool
149 149
 		 */
150
-		public static function set_admin_notice_cache( $id, $timeout ) {
151
-			$cache_key = 'pand-' . md5( $id );
152
-			update_site_option( $cache_key, $timeout );
150
+		public static function set_admin_notice_cache($id, $timeout) {
151
+			$cache_key = 'pand-'.md5($id);
152
+			update_site_option($cache_key, $timeout);
153 153
 
154 154
 			return true;
155 155
 		}
Please login to merge, or discard this patch.