@@ -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', '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 | - 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 | } |