@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * new in Autoptimize 2.2 |
5 | 5 | */ |
6 | 6 | |
7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
7 | +if (!defined('ABSPATH')) { |
|
8 | 8 | exit; |
9 | 9 | } |
10 | 10 | |
@@ -17,94 +17,94 @@ discard block |
||
17 | 17 | |
18 | 18 | public function add_hooks() |
19 | 19 | { |
20 | - if ( apply_filters( 'autoptimize_js_do_minify', true ) ) { |
|
21 | - add_filter( 'autoptimize_js_individual_script', array( $this, 'js_snippetcacher' ), 10, 2 ); |
|
22 | - add_filter( 'autoptimize_js_after_minify', array( $this, 'js_cleanup' ), 10, 1 ); |
|
20 | + if (apply_filters('autoptimize_js_do_minify', true)) { |
|
21 | + add_filter('autoptimize_js_individual_script', array($this, 'js_snippetcacher'), 10, 2); |
|
22 | + add_filter('autoptimize_js_after_minify', array($this, 'js_cleanup'), 10, 1); |
|
23 | 23 | } |
24 | - if ( apply_filters( 'autoptimize_css_do_minify', true ) ) { |
|
25 | - add_filter( 'autoptimize_css_individual_style', array( $this, 'css_snippetcacher' ), 10, 2 ); |
|
26 | - add_filter( 'autoptimize_css_after_minify', array( $this, 'css_cleanup' ), 10, 1 ); |
|
24 | + if (apply_filters('autoptimize_css_do_minify', true)) { |
|
25 | + add_filter('autoptimize_css_individual_style', array($this, 'css_snippetcacher'), 10, 2); |
|
26 | + add_filter('autoptimize_css_after_minify', array($this, 'css_cleanup'), 10, 1); |
|
27 | 27 | } |
28 | 28 | } |
29 | 29 | |
30 | - public function js_snippetcacher( $jsin, $jsfilename ) |
|
30 | + public function js_snippetcacher($jsin, $jsfilename) |
|
31 | 31 | { |
32 | - $md5hash = 'snippet_' . md5( $jsin ); |
|
33 | - $ccheck = new autoptimizeCache( $md5hash, 'js' ); |
|
34 | - if ( $ccheck->check() ) { |
|
32 | + $md5hash = 'snippet_'.md5($jsin); |
|
33 | + $ccheck = new autoptimizeCache($md5hash, 'js'); |
|
34 | + if ($ccheck->check()) { |
|
35 | 35 | $scriptsrc = $ccheck->retrieve(); |
36 | 36 | } else { |
37 | - if ( false === ( strpos( $jsfilename, 'min.js' ) ) && ( false === strpos( $jsfilename, 'js/jquery/jquery.js' ) ) && ( str_replace( apply_filters( 'autoptimize_filter_js_consider_minified', false ), '', $jsfilename ) === $jsfilename ) ) { |
|
38 | - $tmp_jscode = trim( JSMin::minify( $jsin ) ); |
|
39 | - if ( ! empty( $tmp_jscode ) ) { |
|
37 | + if (false === (strpos($jsfilename, 'min.js')) && (false === strpos($jsfilename, 'js/jquery/jquery.js')) && (str_replace(apply_filters('autoptimize_filter_js_consider_minified', false), '', $jsfilename) === $jsfilename)) { |
|
38 | + $tmp_jscode = trim(JSMin::minify($jsin)); |
|
39 | + if (!empty($tmp_jscode)) { |
|
40 | 40 | $scriptsrc = $tmp_jscode; |
41 | - unset( $tmp_jscode ); |
|
41 | + unset($tmp_jscode); |
|
42 | 42 | } else { |
43 | 43 | $scriptsrc = $jsin; |
44 | 44 | } |
45 | 45 | } else { |
46 | 46 | // Removing comments, linebreaks and stuff! |
47 | - $scriptsrc = preg_replace( '#^\s*\/\/.*$#Um', '', $jsin ); |
|
48 | - $scriptsrc = preg_replace( '#^\s*\/\*[^!].*\*\/\s?#Us', '', $scriptsrc ); |
|
49 | - $scriptsrc = preg_replace( "#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $scriptsrc ); |
|
47 | + $scriptsrc = preg_replace('#^\s*\/\/.*$#Um', '', $jsin); |
|
48 | + $scriptsrc = preg_replace('#^\s*\/\*[^!].*\*\/\s?#Us', '', $scriptsrc); |
|
49 | + $scriptsrc = preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $scriptsrc); |
|
50 | 50 | } |
51 | 51 | |
52 | - $last_char = substr( $scriptsrc, -1, 1 ); |
|
53 | - if ( ';' !== $last_char && '}' !== $last_char ) { |
|
52 | + $last_char = substr($scriptsrc, -1, 1); |
|
53 | + if (';' !== $last_char && '}' !== $last_char) { |
|
54 | 54 | $scriptsrc .= ';'; |
55 | 55 | } |
56 | 56 | |
57 | - if ( ! empty( $jsfilename ) && str_replace( apply_filters( 'autoptimize_filter_js_speedup_cache', false ), '', $jsfilename ) === $jsfilename ) { |
|
57 | + if (!empty($jsfilename) && str_replace(apply_filters('autoptimize_filter_js_speedup_cache', false), '', $jsfilename) === $jsfilename) { |
|
58 | 58 | // Don't cache inline CSS or if filter says no! |
59 | - $ccheck->cache( $scriptsrc, 'text/javascript' ); |
|
59 | + $ccheck->cache($scriptsrc, 'text/javascript'); |
|
60 | 60 | } |
61 | 61 | } |
62 | - unset( $ccheck ); |
|
62 | + unset($ccheck); |
|
63 | 63 | |
64 | 64 | return $scriptsrc; |
65 | 65 | } |
66 | 66 | |
67 | - public function css_snippetcacher( $cssin, $cssfilename ) |
|
67 | + public function css_snippetcacher($cssin, $cssfilename) |
|
68 | 68 | { |
69 | - $md5hash = 'snippet_' . md5( $cssin ); |
|
70 | - $ccheck = new autoptimizeCache( $md5hash, 'css' ); |
|
71 | - if ( $ccheck->check() ) { |
|
69 | + $md5hash = 'snippet_'.md5($cssin); |
|
70 | + $ccheck = new autoptimizeCache($md5hash, 'css'); |
|
71 | + if ($ccheck->check()) { |
|
72 | 72 | $stylesrc = $ccheck->retrieve(); |
73 | 73 | } else { |
74 | - if ( ( false === strpos( $cssfilename, 'min.css' ) ) && ( str_replace( apply_filters( 'autoptimize_filter_css_consider_minified', false ), '', $cssfilename ) === $cssfilename ) ) { |
|
74 | + if ((false === strpos($cssfilename, 'min.css')) && (str_replace(apply_filters('autoptimize_filter_css_consider_minified', false), '', $cssfilename) === $cssfilename)) { |
|
75 | 75 | $cssmin = new autoptimizeCSSmin(); |
76 | - $tmp_code = trim( $cssmin->run( $cssin ) ); |
|
76 | + $tmp_code = trim($cssmin->run($cssin)); |
|
77 | 77 | |
78 | - if ( ! empty( $tmp_code ) ) { |
|
78 | + if (!empty($tmp_code)) { |
|
79 | 79 | $stylesrc = $tmp_code; |
80 | - unset( $tmp_code ); |
|
80 | + unset($tmp_code); |
|
81 | 81 | } else { |
82 | 82 | $stylesrc = $cssin; |
83 | 83 | } |
84 | 84 | } else { |
85 | 85 | // .min.css -> no heavy-lifting, just some cleanup! |
86 | - $stylesrc = preg_replace( '#^\s*\/\*[^!].*\*\/\s?#Us', '', $cssin ); |
|
87 | - $stylesrc = preg_replace( "#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $stylesrc ); |
|
88 | - $stylesrc = autoptimizeStyles::fixurls( $cssfilename, $stylesrc ); |
|
86 | + $stylesrc = preg_replace('#^\s*\/\*[^!].*\*\/\s?#Us', '', $cssin); |
|
87 | + $stylesrc = preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $stylesrc); |
|
88 | + $stylesrc = autoptimizeStyles::fixurls($cssfilename, $stylesrc); |
|
89 | 89 | } |
90 | - if ( ! empty( $cssfilename ) && ( str_replace( apply_filters( 'autoptimize_filter_css_speedup_cache', false ), '', $cssfilename ) === $cssfilename ) ) { |
|
90 | + if (!empty($cssfilename) && (str_replace(apply_filters('autoptimize_filter_css_speedup_cache', false), '', $cssfilename) === $cssfilename)) { |
|
91 | 91 | // Only caching CSS if it's not inline and is allowed by filter! |
92 | - $ccheck->cache( $stylesrc, 'text/css' ); |
|
92 | + $ccheck->cache($stylesrc, 'text/css'); |
|
93 | 93 | } |
94 | 94 | } |
95 | - unset( $ccheck ); |
|
95 | + unset($ccheck); |
|
96 | 96 | |
97 | 97 | return $stylesrc; |
98 | 98 | } |
99 | 99 | |
100 | - public function css_cleanup( $cssin ) |
|
100 | + public function css_cleanup($cssin) |
|
101 | 101 | { |
102 | 102 | // Speedupper results in aggregated CSS not being minified, so the filestart-marker AO adds when aggregating needs to be removed. |
103 | - return trim( str_replace( array( '/*FILESTART*/', '/*FILESTART2*/' ), '', $cssin ) ); |
|
103 | + return trim(str_replace(array('/*FILESTART*/', '/*FILESTART2*/'), '', $cssin)); |
|
104 | 104 | } |
105 | 105 | |
106 | - public function js_cleanup( $jsin ) |
|
106 | + public function js_cleanup($jsin) |
|
107 | 107 | { |
108 | - return trim( $jsin ); |
|
108 | + return trim($jsin); |
|
109 | 109 | } |
110 | 110 | } |
@@ -3,7 +3,7 @@ discard block |
||
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 |
||
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 |
||
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,81 +70,81 @@ discard block |
||
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' ), |
|
136 | - '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;"' ), |
|
137 | - 'dismiss_msg' => __( 'Dismiss this notice.' ), |
|
138 | - 'nonce' => wp_create_nonce( 'ao_delcache_nonce' ), |
|
139 | - ) ); |
|
134 | + wp_localize_script('autoptimize-toolbar', 'autoptimize_ajax_object', array( |
|
135 | + 'ajaxurl' => admin_url('admin-ajax.php'), |
|
136 | + '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;"'), |
|
137 | + 'dismiss_msg' => __('Dismiss this notice.'), |
|
138 | + 'nonce' => wp_create_nonce('ao_delcache_nonce'), |
|
139 | + )); |
|
140 | 140 | } |
141 | 141 | |
142 | - public function format_filesize( $bytes, $decimals = 2 ) |
|
142 | + public function format_filesize($bytes, $decimals = 2) |
|
143 | 143 | { |
144 | - $units = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' ); |
|
144 | + $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); |
|
145 | 145 | |
146 | - for ( $i = 0; ( $bytes / 1024) > 0.9; $i++, $bytes /= 1024 ) {} // @codingStandardsIgnoreLine |
|
146 | + for ($i = 0; ($bytes/1024) > 0.9; $i++, $bytes /= 1024) {} // @codingStandardsIgnoreLine |
|
147 | 147 | |
148 | - return sprintf( "%1.{$decimals}f %s", round( $bytes, $decimals ), $units[ $i ] ); |
|
148 | + return sprintf("%1.{$decimals}f %s", round($bytes, $decimals), $units[$i]); |
|
149 | 149 | } |
150 | 150 | } |
@@ -6,7 +6,7 @@ discard block |
||
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,48 +25,48 @@ discard block |
||
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', 'daily' ); |
|
40 | - if ( ! in_array( $frequency, array( 'hourly', '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', 'daily'); |
|
40 | + if (!in_array($frequency, array('hourly', 'daily', 'weekly', 'monthly'))) { |
|
41 | 41 | $frequency = 'daily'; |
42 | 42 | } |
43 | - if ( $do_cache_check && ( ! $schedule || $schedule !== $frequency ) ) { |
|
44 | - wp_schedule_event( time(), $frequency, self::SCHEDULE_HOOK ); |
|
45 | - } elseif ( $schedule && ! $do_cache_check ) { |
|
46 | - wp_clear_scheduled_hook( self::SCHEDULE_HOOK ); |
|
43 | + if ($do_cache_check && (!$schedule || $schedule !== $frequency)) { |
|
44 | + wp_schedule_event(time(), $frequency, self::SCHEDULE_HOOK); |
|
45 | + } elseif ($schedule && !$do_cache_check) { |
|
46 | + wp_clear_scheduled_hook(self::SCHEDULE_HOOK); |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
50 | 50 | public function cronjob() |
51 | 51 | { |
52 | 52 | // Check cachesize and act accordingly. |
53 | - $max_size = (int) apply_filters( 'autoptimize_filter_cachecheck_maxsize', 536870912 ); |
|
54 | - $do_cache_check = (bool) apply_filters( 'autoptimize_filter_cachecheck_do', true ); |
|
53 | + $max_size = (int) apply_filters('autoptimize_filter_cachecheck_maxsize', 536870912); |
|
54 | + $do_cache_check = (bool) apply_filters('autoptimize_filter_cachecheck_do', true); |
|
55 | 55 | $stat_array = autoptimizeCache::stats(); |
56 | - $cache_size = round( $stat_array[1] ); |
|
57 | - if ( ( $cache_size > $max_size ) && ( $do_cache_check ) ) { |
|
58 | - update_option( 'autoptimize_cachesize_notice', true ); |
|
59 | - if ( apply_filters( 'autoptimize_filter_cachecheck_sendmail', true ) ) { |
|
60 | - $site_url = esc_url( site_url() ); |
|
61 | - $ao_mailto = apply_filters( 'autoptimize_filter_cachecheck_mailto', get_option( 'admin_email', '' ) ); |
|
62 | - |
|
63 | - $ao_mailsubject = __( 'Autoptimize cache size warning', 'autoptimize' ) . ' (' . $site_url . ')'; |
|
64 | - $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: ' . $site_url . ')'; |
|
65 | - |
|
66 | - if ( ! empty( $ao_mailto ) ) { |
|
67 | - $ao_mailresult = wp_mail( $ao_mailto, $ao_mailsubject, $ao_mailbody ); |
|
68 | - if ( ! $ao_mailresult ) { |
|
69 | - error_log( 'Autoptimize could not send cache size warning mail.' ); |
|
56 | + $cache_size = round($stat_array[1]); |
|
57 | + if (($cache_size > $max_size) && ($do_cache_check)) { |
|
58 | + update_option('autoptimize_cachesize_notice', true); |
|
59 | + if (apply_filters('autoptimize_filter_cachecheck_sendmail', true)) { |
|
60 | + $site_url = esc_url(site_url()); |
|
61 | + $ao_mailto = apply_filters('autoptimize_filter_cachecheck_mailto', get_option('admin_email', '')); |
|
62 | + |
|
63 | + $ao_mailsubject = __('Autoptimize cache size warning', 'autoptimize').' ('.$site_url.')'; |
|
64 | + $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: '.$site_url.')'; |
|
65 | + |
|
66 | + if (!empty($ao_mailto)) { |
|
67 | + $ao_mailresult = wp_mail($ao_mailto, $ao_mailsubject, $ao_mailbody); |
|
68 | + if (!$ao_mailresult) { |
|
69 | + error_log('Autoptimize could not send cache size warning mail.'); |
|
70 | 70 | } |
71 | 71 | } |
72 | 72 | } |
@@ -85,16 +85,16 @@ discard block |
||
85 | 85 | public function show_admin_notice() |
86 | 86 | { |
87 | 87 | // fixme: make notices dismissable. |
88 | - if ( (bool) get_option( 'autoptimize_cachesize_notice', false ) ) { |
|
88 | + if ((bool) get_option('autoptimize_cachesize_notice', false)) { |
|
89 | 89 | echo '<div class="notice notice-warning"><p>'; |
90 | - _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' ); |
|
90 | + _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'); |
|
91 | 91 | echo '</p></div>'; |
92 | - update_option( 'autoptimize_cachesize_notice', false ); |
|
92 | + update_option('autoptimize_cachesize_notice', false); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | // Notice for image proxy usage. |
96 | 96 | $_imgopt_notice = autoptimizeExtra::get_imgopt_status_notice_wrapper(); |
97 | - if ( is_array( $_imgopt_notice ) && array_key_exists( 'status', $_imgopt_notice ) && in_array( $_imgopt_notice['status'], array( 1, -1 ) ) ) { |
|
97 | + if (is_array($_imgopt_notice) && array_key_exists('status', $_imgopt_notice) && in_array($_imgopt_notice['status'], array(1, -1))) { |
|
98 | 98 | $_dismissible = 'ao-img-opt-notice-'; |
99 | 99 | $_hide_notice = '7'; |
100 | 100 | |
@@ -102,10 +102,10 @@ discard block |
||
102 | 102 | $_hide_notice = '1'; |
103 | 103 | } |
104 | 104 | |
105 | - $_imgopt_notice_dismissible = apply_filters( 'autoptimize_filter_imgopt_notice_dismissable', $_dismissible . $_hide_notice ); |
|
105 | + $_imgopt_notice_dismissible = apply_filters('autoptimize_filter_imgopt_notice_dismissable', $_dismissible.$_hide_notice); |
|
106 | 106 | |
107 | - if ( $_imgopt_notice && PAnD::is_admin_notice_active( $_imgopt_notice_dismissible ) ) { |
|
108 | - echo '<div class="notice notice-warning is-dismissible" data-dismissible="' . $_imgopt_notice_dismissible . '"><p>' . $_imgopt_notice['notice'] . '</p></div>'; |
|
107 | + if ($_imgopt_notice && PAnD::is_admin_notice_active($_imgopt_notice_dismissible)) { |
|
108 | + echo '<div class="notice notice-warning is-dismissible" data-dismissible="'.$_imgopt_notice_dismissible.'"><p>'.$_imgopt_notice['notice'].'</p></div>'; |
|
109 | 109 | } |
110 | 110 | } |
111 | 111 | } |