| @@ -1,65 +1,64 @@ | ||
| 1 | -<?php | |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
| 3 | - | |
| 4 | -/* | |
| 5 | - * cachechecker code | |
| 6 | - * new in AO 2.0 | |
| 7 | - * | |
| 8 | - * daily cronned job (filter to change freq. + filter to disable) | |
| 9 | - * checks if cachesize is > 0.5GB (filter to change maxsize) | |
| 10 | - * if so an option is set | |
| 11 | - * if that option is set, notice on admin is shown | |
| 12 | - * | |
| 13 | - */ | |
| 14 | - | |
| 15 | -if (is_admin()) { | |
| 16 | - add_action('plugins_loaded','ao_cachechecker_setup'); | |
| 17 | -} | |
| 18 | - | |
| 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'; | |
| 25 | - } | |
| 26 | - if ( $doCacheCheck && ( !$cacheCheckSchedule || $cacheCheckSchedule !== $AOCCfreq ) ) { | |
| 27 | - wp_schedule_event(time(), $AOCCfreq, 'ao_cachechecker'); | |
| 28 | - } else if ( $cacheCheckSchedule && !$doCacheCheck ) { | |
| 29 | - wp_clear_scheduled_hook( 'ao_cachechecker' ); | |
| 30 | - } | |
| 31 | -} | |
| 32 | - | |
| 33 | -add_action('ao_cachechecker', 'ao_cachechecker_cronjob'); | |
| 34 | -function ao_cachechecker_cronjob() { | |
| 35 | - $maxSize = (int) apply_filters( "autoptimize_filter_cachecheck_maxsize", 536870912); | |
| 36 | - $doCacheCheck = (bool) apply_filters( "autoptimize_filter_cachecheck_do", true); | |
| 37 | - $statArr=autoptimizeCache::stats(); | |
| 38 | - $cacheSize=round($statArr[1]); | |
| 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=__('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: ".$saniSiteUrl.")"; | |
| 46 | - | |
| 47 | - if (!empty($ao_mailto)) { | |
| 48 | - $ao_mailresult=wp_mail($ao_mailto,$ao_mailsubject,$ao_mailbody); | |
| 49 | - if (!$ao_mailresult) { | |
| 50 | - error_log("Autoptimize could not send cache size warning mail."); | |
| 51 | - } | |
| 52 | - } | |
| 53 | - } | |
| 54 | - } | |
| 55 | -} | |
| 56 | - | |
| 57 | -add_action('admin_notices', 'autoptimize_cachechecker_notice'); | |
| 58 | -function autoptimize_cachechecker_notice() { | |
| 59 | - if ((bool) get_option("autoptimize_cachesize_notice",false)) { | |
| 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' ); | |
| 62 | - echo '</p></div>'; | |
| 63 | - update_option("autoptimize_cachesize_notice",false); | |
| 64 | - } | |
| 65 | -} | |
| 1 | +<?php | |
| 2 | +if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
| 3 | + | |
| 4 | +/* | |
| 5 | + * cachechecker code | |
| 6 | + * new in AO 2.0 | |
| 7 | + * | |
| 8 | + * daily cronned job (filter to change freq. + filter to disable) | |
| 9 | + * checks if cachesize is > 0.5GB (filter to change maxsize) | |
| 10 | + * if so an option is set | |
| 11 | + * if that option is set, notice on admin is shown | |
| 12 | + * | |
| 13 | + */ | |
| 14 | + | |
| 15 | +if (is_admin()) { | |
| 16 | + add_action('plugins_loaded','ao_cachechecker_setup'); | |
| 17 | +} | |
| 18 | + | |
| 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'; | |
| 25 | + } | |
| 26 | + if ( $doCacheCheck && ( !$cacheCheckSchedule || $cacheCheckSchedule !== $AOCCfreq ) ) { | |
| 27 | + wp_schedule_event(time(), $AOCCfreq, 'ao_cachechecker'); | |
| 28 | + } else if ( $cacheCheckSchedule && !$doCacheCheck ) { | |
| 29 | + wp_clear_scheduled_hook( 'ao_cachechecker' ); | |
| 30 | + } | |
| 31 | +} | |
| 32 | + | |
| 33 | +add_action('ao_cachechecker', 'ao_cachechecker_cronjob'); | |
| 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 | + $ao_mailto=apply_filters('autoptimize_filter_cachecheck_mailto',get_option('admin_email','')); | |
| 43 | + $ao_mailsubject=__('Autoptimize cache size warning','autoptimize'); | |
| 44 | + $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'); | |
| 45 | + | |
| 46 | + if (!empty($ao_mailto)) { | |
| 47 | + $ao_mailresult=wp_mail($ao_mailto,$ao_mailsubject,$ao_mailbody); | |
| 48 | + if (!$ao_mailresult) { | |
| 49 | + error_log("Autoptimize could not send cache size warning mail."); | |
| 50 | + } | |
| 51 | + } | |
| 52 | + } | |
| 53 | + } | |
| 54 | +} | |
| 55 | + | |
| 56 | +add_action('admin_notices', 'autoptimize_cachechecker_notice'); | |
| 57 | +function autoptimize_cachechecker_notice() { | |
| 58 | + if ((bool) get_option("autoptimize_cachesize_notice",false)) { | |
| 59 | + echo '<div class="notice notice-warning"><p>'; | |
| 60 | + _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 | + echo '</p></div>'; | |
| 62 | + update_option("autoptimize_cachesize_notice",false); | |
| 63 | + } | |
| 64 | +} | |