@@ -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,51 +25,51 @@ 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 | - if ( $schedule ) { |
|
45 | - wp_clear_scheduled_hook( self::SCHEDULE_HOOK ); |
|
43 | + if ($do_cache_check && (!$schedule || $schedule !== $frequency)) { |
|
44 | + if ($schedule) { |
|
45 | + wp_clear_scheduled_hook(self::SCHEDULE_HOOK); |
|
46 | 46 | } |
47 | - wp_schedule_event( time(), $frequency, self::SCHEDULE_HOOK ); |
|
48 | - } elseif ( $schedule && ! $do_cache_check ) { |
|
49 | - wp_clear_scheduled_hook( self::SCHEDULE_HOOK ); |
|
47 | + wp_schedule_event(time(), $frequency, self::SCHEDULE_HOOK); |
|
48 | + } elseif ($schedule && !$do_cache_check) { |
|
49 | + wp_clear_scheduled_hook(self::SCHEDULE_HOOK); |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
53 | 53 | public function cronjob() |
54 | 54 | { |
55 | 55 | // Check cachesize and act accordingly. |
56 | - $max_size = (int) apply_filters( 'autoptimize_filter_cachecheck_maxsize', 536870912 ); |
|
57 | - $do_cache_check = (bool) apply_filters( 'autoptimize_filter_cachecheck_do', true ); |
|
56 | + $max_size = (int) apply_filters('autoptimize_filter_cachecheck_maxsize', 536870912); |
|
57 | + $do_cache_check = (bool) apply_filters('autoptimize_filter_cachecheck_do', true); |
|
58 | 58 | $stat_array = autoptimizeCache::stats(); |
59 | - $cache_size = round( $stat_array[1] ); |
|
60 | - if ( ( $cache_size > $max_size ) && ( $do_cache_check ) ) { |
|
61 | - update_option( 'autoptimize_cachesize_notice', true ); |
|
62 | - if ( apply_filters( 'autoptimize_filter_cachecheck_sendmail', true ) ) { |
|
63 | - $home_url = esc_url( home_url() ); |
|
64 | - $ao_mailto = apply_filters( 'autoptimize_filter_cachecheck_mailto', get_option( 'admin_email', '' ) ); |
|
65 | - |
|
66 | - $ao_mailsubject = __( 'Autoptimize cache size warning', 'autoptimize' ) . ' (' . $home_url . ')'; |
|
67 | - $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: ' . $home_url . ')'; |
|
68 | - |
|
69 | - if ( ! empty( $ao_mailto ) ) { |
|
70 | - $ao_mailresult = wp_mail( $ao_mailto, $ao_mailsubject, $ao_mailbody ); |
|
71 | - if ( ! $ao_mailresult ) { |
|
72 | - error_log( 'Autoptimize could not send cache size warning mail.' ); |
|
59 | + $cache_size = round($stat_array[1]); |
|
60 | + if (($cache_size > $max_size) && ($do_cache_check)) { |
|
61 | + update_option('autoptimize_cachesize_notice', true); |
|
62 | + if (apply_filters('autoptimize_filter_cachecheck_sendmail', true)) { |
|
63 | + $home_url = esc_url(home_url()); |
|
64 | + $ao_mailto = apply_filters('autoptimize_filter_cachecheck_mailto', get_option('admin_email', '')); |
|
65 | + |
|
66 | + $ao_mailsubject = __('Autoptimize cache size warning', 'autoptimize').' ('.$home_url.')'; |
|
67 | + $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: '.$home_url.')'; |
|
68 | + |
|
69 | + if (!empty($ao_mailto)) { |
|
70 | + $ao_mailresult = wp_mail($ao_mailto, $ao_mailsubject, $ao_mailbody); |
|
71 | + if (!$ao_mailresult) { |
|
72 | + error_log('Autoptimize could not send cache size warning mail.'); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 | } |
@@ -87,16 +87,16 @@ discard block |
||
87 | 87 | |
88 | 88 | public function show_admin_notice() |
89 | 89 | { |
90 | - if ( (bool) get_option( 'autoptimize_cachesize_notice', false ) && current_user_can( 'manage_options' ) ) { |
|
90 | + if ((bool) get_option('autoptimize_cachesize_notice', false) && current_user_can('manage_options')) { |
|
91 | 91 | echo '<div class="notice notice-warning"><p>'; |
92 | - _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' ); |
|
92 | + _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'); |
|
93 | 93 | echo '</p></div>'; |
94 | - update_option( 'autoptimize_cachesize_notice', false ); |
|
94 | + update_option('autoptimize_cachesize_notice', false); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | // Notice for image proxy usage. |
98 | 98 | $_imgopt_notice = autoptimizeExtra::get_imgopt_status_notice_wrapper(); |
99 | - if ( current_user_can( 'manage_options' ) && is_array( $_imgopt_notice ) && array_key_exists( 'status', $_imgopt_notice ) && in_array( $_imgopt_notice['status'], array( 1, -1, -2 ) ) ) { |
|
99 | + if (current_user_can('manage_options') && is_array($_imgopt_notice) && array_key_exists('status', $_imgopt_notice) && in_array($_imgopt_notice['status'], array(1, -1, -2))) { |
|
100 | 100 | $_dismissible = 'ao-img-opt-notice-'; |
101 | 101 | $_hide_notice = '7'; |
102 | 102 | |
@@ -104,10 +104,10 @@ discard block |
||
104 | 104 | $_hide_notice = '1'; |
105 | 105 | } |
106 | 106 | |
107 | - $_imgopt_notice_dismissible = apply_filters( 'autoptimize_filter_imgopt_notice_dismissable', $_dismissible . $_hide_notice ); |
|
107 | + $_imgopt_notice_dismissible = apply_filters('autoptimize_filter_imgopt_notice_dismissable', $_dismissible.$_hide_notice); |
|
108 | 108 | |
109 | - if ( $_imgopt_notice && PAnD::is_admin_notice_active( $_imgopt_notice_dismissible ) ) { |
|
110 | - echo '<div class="notice notice-warning is-dismissible" data-dismissible="' . $_imgopt_notice_dismissible . '"><p>' . $_imgopt_notice['notice'] . '</p></div>'; |
|
109 | + if ($_imgopt_notice && PAnD::is_admin_notice_active($_imgopt_notice_dismissible)) { |
|
110 | + echo '<div class="notice notice-warning is-dismissible" data-dismissible="'.$_imgopt_notice_dismissible.'"><p>'.$_imgopt_notice['notice'].'</p></div>'; |
|
111 | 111 | } |
112 | 112 | } |
113 | 113 | } |