|
@@ -1,5 +1,5 @@ discard block |
|
|
block discarded – undo |
|
1
|
1
|
<?php |
|
2
|
|
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
|
2
|
+if (!defined('ABSPATH')) exit; // Exit if accessed directly |
|
3
|
3
|
|
|
4
|
4
|
/* |
|
5
|
5
|
* cachechecker code |
|
@@ -13,39 +13,39 @@ discard block |
|
|
block discarded – undo |
|
13
|
13
|
*/ |
|
14
|
14
|
|
|
15
|
15
|
if (is_admin()) { |
|
16
|
|
- add_action('plugins_loaded','ao_cachechecker_setup'); |
|
|
16
|
+ add_action('plugins_loaded', 'ao_cachechecker_setup'); |
|
17
|
17
|
} |
|
18
|
18
|
|
|
19
|
19
|
function ao_cachechecker_setup() { |
|
20
|
|
- $doCacheCheck = (bool) apply_filters( 'autoptimize_filter_cachecheck_do', true); |
|
21
|
|
- $cacheCheckSchedule = wp_get_schedule( 'ao_cachechecker' ); |
|
22
|
|
- $AOCCfreq = apply_filters('autoptimize_filter_cachecheck_frequency','daily'); |
|
23
|
|
- if (!in_array($AOCCfreq,array('hourly','daily','monthly'))) { |
|
24
|
|
- $AOCCfreq='daily'; |
|
|
20
|
+ $doCacheCheck = (bool) apply_filters('autoptimize_filter_cachecheck_do', true); |
|
|
21
|
+ $cacheCheckSchedule = wp_get_schedule('ao_cachechecker'); |
|
|
22
|
+ $AOCCfreq = apply_filters('autoptimize_filter_cachecheck_frequency', 'daily'); |
|
|
23
|
+ if (!in_array($AOCCfreq, array('hourly', 'daily', 'monthly'))) { |
|
|
24
|
+ $AOCCfreq = 'daily'; |
|
25
|
25
|
} |
|
26
|
|
- if ( $doCacheCheck && ( !$cacheCheckSchedule || $cacheCheckSchedule !== $AOCCfreq ) ) { |
|
|
26
|
+ if ($doCacheCheck && (!$cacheCheckSchedule || $cacheCheckSchedule !== $AOCCfreq)) { |
|
27
|
27
|
wp_schedule_event(time(), $AOCCfreq, 'ao_cachechecker'); |
|
28
|
|
- } else if ( $cacheCheckSchedule && !$doCacheCheck ) { |
|
29
|
|
- wp_clear_scheduled_hook( 'ao_cachechecker' ); |
|
|
28
|
+ } else if ($cacheCheckSchedule && !$doCacheCheck) { |
|
|
29
|
+ wp_clear_scheduled_hook('ao_cachechecker'); |
|
30
|
30
|
} |
|
31
|
31
|
} |
|
32
|
32
|
|
|
33
|
33
|
add_action('ao_cachechecker', 'ao_cachechecker_cronjob'); |
|
34
|
34
|
function ao_cachechecker_cronjob() { |
|
35
|
|
- $maxSize = (int) apply_filters( "autoptimize_filter_cachecheck_maxsize", 512000); |
|
36
|
|
- $doCacheCheck = (bool) apply_filters( "autoptimize_filter_cachecheck_do", true); |
|
37
|
|
- $statArr=autoptimizeCache::stats(); |
|
38
|
|
- $cacheSize=round($statArr[1]/1024); |
|
39
|
|
- if (($cacheSize>$maxSize) && ($doCacheCheck)) { |
|
40
|
|
- update_option("autoptimize_cachesize_notice",true); |
|
41
|
|
- if (apply_filters('autoptimize_filter_cachecheck_sendmail',true)) { |
|
42
|
|
- $saniSiteUrl=esc_url(site_url()); |
|
43
|
|
- $ao_mailto=apply_filters('autoptimize_filter_cachecheck_mailto',get_option('admin_email','')); |
|
44
|
|
- $ao_mailsubject=__('Autoptimize cache size warning','autoptimize')." (".$saniSiteUrl.")"; |
|
45
|
|
- $ao_mailbody=__('<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">the Autoptimize FAQ</a> to see how you can keep the cache size under control.', 'autoptimize')." (site: ".$saniSiteUrl.")"; |
|
|
35
|
+ $maxSize = (int) apply_filters("autoptimize_filter_cachecheck_maxsize", 512000); |
|
|
36
|
+ $doCacheCheck = (bool) apply_filters("autoptimize_filter_cachecheck_do", true); |
|
|
37
|
+ $statArr = autoptimizeCache::stats(); |
|
|
38
|
+ $cacheSize = round($statArr[1]/1024); |
|
|
39
|
+ if (($cacheSize > $maxSize) && ($doCacheCheck)) { |
|
|
40
|
+ update_option("autoptimize_cachesize_notice", true); |
|
|
41
|
+ if (apply_filters('autoptimize_filter_cachecheck_sendmail', true)) { |
|
|
42
|
+ $saniSiteUrl = esc_url(site_url()); |
|
|
43
|
+ $ao_mailto = apply_filters('autoptimize_filter_cachecheck_mailto', get_option('admin_email', '')); |
|
|
44
|
+ $ao_mailsubject = __('Autoptimize cache size warning', 'autoptimize')." (".$saniSiteUrl.")"; |
|
|
45
|
+ $ao_mailbody = __('<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">the Autoptimize FAQ</a> to see how you can keep the cache size under control.', 'autoptimize')." (site: ".$saniSiteUrl.")"; |
|
46
|
46
|
|
|
47
|
47
|
if (!empty($ao_mailto)) { |
|
48
|
|
- $ao_mailresult=wp_mail($ao_mailto,$ao_mailsubject,$ao_mailbody); |
|
|
48
|
+ $ao_mailresult = wp_mail($ao_mailto, $ao_mailsubject, $ao_mailbody); |
|
49
|
49
|
if (!$ao_mailresult) { |
|
50
|
50
|
error_log("Autoptimize could not send cache size warning mail."); |
|
51
|
51
|
} |
|
@@ -56,10 +56,10 @@ discard block |
|
|
block discarded – undo |
|
56
|
56
|
|
|
57
|
57
|
add_action('admin_notices', 'autoptimize_cachechecker_notice'); |
|
58
|
58
|
function autoptimize_cachechecker_notice() { |
|
59
|
|
- if ((bool) get_option("autoptimize_cachesize_notice",false)) { |
|
|
59
|
+ if ((bool) get_option("autoptimize_cachesize_notice", false)) { |
|
60
|
60
|
echo '<div class="notice notice-warning"><p>'; |
|
61
|
|
- _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">the Autoptimize FAQ</a> to see how you can keep the cache size under control.', 'autoptimize' ); |
|
|
61
|
+ _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">the Autoptimize FAQ</a> to see how you can keep the cache size under control.', 'autoptimize'); |
|
62
|
62
|
echo '</p></div>'; |
|
63
|
|
- update_option("autoptimize_cachesize_notice",false); |
|
|
63
|
+ update_option("autoptimize_cachesize_notice", false); |
|
64
|
64
|
} |
|
65
|
65
|
} |