PluginProbe
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score / 3.6.3
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score v3.6.3
trunk 1.0 1.0.1 1.1 1.1.1 1.1.2 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1 2.1.1 2.1.2 2.2 2.2.1 All 69 releases
← All changes | includes/admin/notices.php +301 -96 1.2.63.6.3 View file →
@@ -1,81 +1,109 @@
1 1 <?php
2 -// Exit if accessed directly
3 -if ( ! defined( 'ABSPATH' ) ) {
4 - exit;
5 -}
2 +/**
3 + * Admin Notices
4 + *
5 + * @package PoweredCache
6 + */
6 7
7 -add_action( 'admin_notices', 'powered_cache_flash_messages' );
8 +namespace PoweredCache\Admin\Notices;
8 9
10 +use function PoweredCache\Utils\can_configure_htaccess;
11 +use function PoweredCache\Utils\can_configure_object_cache;
12 +use function PoweredCache\Utils\can_control_all_settings;
13 +use function PoweredCache\Utils\get_object_cache_dropins;
14 +use function PoweredCache\Utils\is_premium;
15 +use const PoweredCache\Constants\PURGE_CACHE_PLUGIN_NOTICE_TRANSIENT;
16 +
9 17 /**
10 - * Display flash messages
18 + * Default setup routine
11 19 *
12 - * @since 1.0
20 + * @return void
13 21 */
14 -function powered_cache_flash_messages() {
15 - Powered_Cache_Admin_Helper::get_flash_message();
22 +function setup() {
23 + if ( POWERED_CACHE_IS_NETWORK ) {
24 + add_action( 'network_admin_notices', __NAMESPACE__ . '\\maybe_display_plugin_compatibility_notices' );
25 + add_action( 'network_admin_notices', __NAMESPACE__ . '\\maybe_display_advanced_cache_notices' );
26 + add_action( 'network_admin_notices', __NAMESPACE__ . '\\maybe_display_object_cache_notices' );
27 + add_action( 'network_admin_notices', __NAMESPACE__ . '\\maybe_display_htaccess_notice' );
28 + add_action( 'network_admin_notices', __NAMESPACE__ . '\\maybe_display_purge_cache_plugin_notice' );
29 + add_action( 'network_admin_notices', __NAMESPACE__ . '\\maybe_display_dev_mode_notice' );
30 + } else {
31 + add_action( 'admin_notices', __NAMESPACE__ . '\\maybe_display_plugin_compatibility_notices' );
32 + add_action( 'admin_notices', __NAMESPACE__ . '\\maybe_display_advanced_cache_notices' );
33 + add_action( 'admin_notices', __NAMESPACE__ . '\\maybe_display_object_cache_notices' );
34 + add_action( 'admin_notices', __NAMESPACE__ . '\\maybe_display_htaccess_notice' );
35 + add_action( 'admin_notices', __NAMESPACE__ . '\\maybe_display_purge_cache_plugin_notice' );
36 + add_action( 'admin_notices', __NAMESPACE__ . '\\maybe_display_dev_mode_notice' );
37 + }
38 +
39 + add_action( 'activated_plugin', __NAMESPACE__ . '\\observe_plugin_changes', 10, 2 );
40 + add_action( 'deactivated_plugin', __NAMESPACE__ . '\\observe_plugin_changes', 10, 2 );
41 + add_action( 'admin_post_powered_cache_dismiss_notice', __NAMESPACE__ . '\\dismiss_notice' );
16 42 }
17 43
18 -
19 -add_action( 'admin_notices', 'powered_cache_plugin_compatability_notices' );
20 -
21 44 /**
22 45 * Display incompatible plugins
23 46 *
24 47 * @since 1.0
25 48 */
26 -function powered_cache_plugin_compatability_notices() {
49 +function maybe_display_plugin_compatibility_notices() {
50 + $settings = \PoweredCache\Utils\get_settings();
27 51
28 52 $plugins = array(
29 - 'w3-total-cache' => 'w3-total-cache/w3-total-cache.php',
30 - 'wp-super-cache' => 'wp-super-cache/wp-cache.php',
31 - 'quick-cache' => 'quick-cache/quick-cache.php',
32 - 'hyper-cache' => 'hyper-cache/plugin.php',
33 - 'hyper-cache-extended' => 'hyper-cache-extended/plugin.php',
34 - 'wp-fast-cache' => 'wp-fast-cache/wp-fast-cache.php',
35 - 'flexicache' => 'flexicache/wp-plugin.php',
36 - 'wp-fastest-cache' => 'wp-fastest-cache/wpFastestCache.php',
37 - 'lite-cache' => 'lite-cache/plugin.php',
38 - 'gator-cache' => 'gator-cache/gator-cache.php',
39 - 'wp-http-compression' => 'wp-http-compression/wp-http-compression.php',
40 - 'wordpress-gzip-compression' => 'wordpress-gzip-compression/ezgz.php',
41 - 'gzip-ninja-speed-compression' => 'gzip-ninja-speed-compression/gzip-ninja-speed.php',
42 - 'speed-booster-pack' => 'speed-booster-pack/speed-booster-pack.php',
43 - 'wp-performance-score-booster' => 'wp-performance-score-booster/wp-performance-score-booster.php',
44 - 'remove-query-strings-from-static-resources' => 'remove-query-strings-from-static-resources/remove-query-strings.php',
45 - 'query-strings-remover' => 'query-strings-remover/query-strings-remover.php',
46 - 'wp-ffpc' => 'wp-ffpc/wp-ffpc.php',
47 - 'far-future-expiry-header' => 'far-future-expiry-header/far-future-expiration.php',
48 - 'combine-css' => 'combine-css/combine-css.php',
49 - 'super-static-cache' => 'super-static-cache/super-static-cache.php',
50 - 'wpcompressor' => 'wpcompressor/wpcompressor.php',
51 - 'check-and-enable-gzip-compression' => 'check-and-enable-gzip-compression/richards-toolbox.php',
52 - 'leverage-browser-caching-ninjas' => 'leverage-browser-caching-ninjas/leverage-browser-caching-ninja.php',
53 - 'force-gzip' => 'force-gzip/force-gzip.php'
53 + 'hummingbird-performance' => 'hummingbird-performance/wp-hummingbird.php',
54 + 'wp-rocket' => 'wp-rocket/wp-rocket.php',
55 + 'w3-total-cache' => 'w3-total-cache/w3-total-cache.php',
56 + 'wp-super-cache' => 'wp-super-cache/wp-cache.php',
57 + 'hyper-cache' => 'hyper-cache/plugin.php',
58 + 'hyper-cache-extended' => 'hyper-cache-extended/plugin.php',
59 + 'wp-fast-cache' => 'wp-fast-cache/wp-fast-cache.php',
60 + 'flexicache' => 'flexicache/wp-plugin.php',
61 + 'wp-fastest-cache' => 'wp-fastest-cache/wpFastestCache.php',
62 + 'wp-http-compression' => 'wp-http-compression/wp-http-compression.php',
63 + 'wordpress-gzip-compression' => 'wordpress-gzip-compression/ezgz.php',
64 + 'gzip-ninja-speed-compression' => 'gzip-ninja-speed-compression/gzip-ninja-speed.php',
65 + 'speed-booster-pack' => 'speed-booster-pack/speed-booster-pack.php',
66 + 'wp-performance-score-booster' => 'wp-performance-score-booster/wp-performance-score-booster.php',
67 + 'check-and-enable-gzip-compression' => 'check-and-enable-gzip-compression/richards-toolbox.php',
68 + 'swift-performance-lite' => 'swift-performance-lite/performance.php',
69 + 'swift-performance' => 'swift-performance/performance.php',
70 + 'litespeed-cache' => 'litespeed-cache/litespeed-cache.php',
71 + 'wp-optimize' => 'wp-optimize/wp-optimize.php',
54 72 );
55 73
74 + if ( $settings['prefetch_links'] && is_premium() ) {
75 + $plugins['quicklink'] = 'quicklink/quicklink.php';
76 + $plugins['flying-pages'] = 'flying-pages/flying-pages.php';
77 + $plugins['instant-page'] = 'instant-page/instantpage.php';
78 + }
56 79
57 - $plugins = array_filter( $plugins, 'is_plugin_active' );
80 + $callback = POWERED_CACHE_IS_NETWORK ? 'is_plugin_active_for_network' : 'is_plugin_active';
58 81
59 - if ( count( $plugins ) > 0 && current_user_can( apply_filters( 'powered_cache_cap', 'manage_options' ) ) ) { ?>
82 + $plugins = array_filter( $plugins, $callback );
83 +
84 + if ( 0 >= count( $plugins ) ) {
85 + return;
86 + }
87 + ?>
88 +
89 + <?php if ( current_user_can( 'activate_plugins' ) ) : ?>
60 90 <div class="error">
61 - <h2><?php _e( 'Powered Cache', 'powered-cache' ); ?></h2>
62 -
63 - <p><?php printf( __( 'The following plugins are not compatible with <b>%s</b> and will cause unintended results:', 'powered-cache' ), __( 'Powered Cache', 'powered-cache' ) ); ?></p>
91 + <p><?php esc_html_e( 'The following plugins are not compatible with Powered Cache and may cause unintended results:', 'powered-cache' ); ?></p>
64 92 <ul class="incompatible-plugin-list">
65 93 <?php
66 94 foreach ( $plugins as $plugin ) {
67 95 $plugin_data = get_plugin_data( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $plugin );
68 - echo '<li>' . $plugin_data['Name'] . '</span> <a href="' . wp_nonce_url( admin_url( 'admin-post.php?action=deactivate_plugin&plugin=' . urlencode( $plugin ) ), 'deactivate_plugin' ) . '" class="button-secondary">' . __( 'Deactivate', 'powered-cache' ) . '</a></li>';
96 + echo '<li>' . esc_attr( $plugin_data['Name'] ) . '</span> <a href="' . esc_url_raw( wp_nonce_url( admin_url( 'admin-post.php?action=deactivate_plugin&plugin=' . rawurlencode( $plugin ) ), 'deactivate_plugin' ) ) . '" class="button-secondary">' . esc_html__( 'Deactivate', 'powered-cache' ) . '</a></li>'; // phpcs:ignore WordPressVIPMinimum.Security.ProperEscapingFunction.notAttrEscAttr
69 97 }
70 98 ?>
71 99 </ul>
72 100 </div>
73 - <?php
74 - }
101 + <?php endif; ?>
102 +
103 + <?php
75 104 }
76 105
77 -add_action( 'admin_notices', 'powered_cache_advanced_cache_notices' );
78 106
79 107 /**
80 108 * Show notices about page cache
81 109 *
@@ -80,30 +108,36 @@
80 108 * Show notices about page cache
81 109 *
82 110 * @since 1.0
83 111 */
84 -function powered_cache_advanced_cache_notices() {
85 -
112 +function maybe_display_advanced_cache_notices() {
86 113 /**
87 - * Users might want to control this notice.
114 + * Determine whether show or not show advanced cache related notices
88 115 * eg: Varnish users don't need to turning on page cache.
89 - * Yeah! they can use remove_action as well
90 116 *
91 - * @since 1.2
117 + * @hook powered_cache_disable_advanced_cache_notices
118 + *
119 + * @param {boolean} $status false
120 + *
121 + * @return {boolean} New value
122 + * @since 1.2
92 123 */
93 124 if ( apply_filters( 'powered_cache_disable_advanced_cache_notices', false ) ) {
94 125 return;
95 126 }
96 127
97 - if ( powered_cache_is_saving_options() ) {
98 - return;
99 - }
128 + $settings = \PoweredCache\Utils\get_settings();
100 129
130 + if ( ! $settings['enable_page_cache'] ) {
101 131
102 - if ( true !== powered_cache_get_option( 'enable_page_caching' ) ) {
132 + $settings_page = POWERED_CACHE_IS_NETWORK ? network_admin_url( 'admin.php?page=powered-cache#basic-options' ) : admin_url( 'admin.php?page=powered-cache#basic-options' );
133 +
134 + /* translators: %s: Powered Cache settings page URL */
135 + $message = sprintf( __( '<strong>Powered Cache:</strong> Page caching needs to be activated in order to speed up your website. Please activate it on <a href="%s">settings page</a>', 'powered-cache' ), esc_url( $settings_page ) );
103 136 ?>
104 - <div class="notice notice-warning"><p>
105 - <?php echo sprintf( __( '<strong>Important:</strong> please enable page caching on the Powered Cache <a href="%s">settings page</a>', 'powered-cache' ), admin_url( 'admin.php?page=powered-cache' ) ); ?>
137 + <div class="notice notice-warning">
138 + <p>
139 + <?php echo wp_kses_post( $message ); ?>
106 140 </p>
107 141 </div>
108 142 <?php
109 143 return;
@@ -108,20 +142,36 @@
108 142 <?php
109 143 return;
110 144 }
111 145
146 + if ( file_exists( untrailingslashit( WP_CONTENT_DIR ) . '/advanced-cache.php' ) ) {
147 + $modify_time = filemtime( untrailingslashit( WP_CONTENT_DIR ) . '/advanced-cache.php' );
148 + if ( time() - absint( $modify_time ) < 10 ) {
149 + /**
150 + * Modify drop-ins and can take ~5 seconds to place the configuration and it might cause misinformation to the user
151 + * So, suppress the error message here when doing something related to settings.
152 + *
153 + * This wouldn't be an issue if there is no immediate redirection right after saving the settings. However, in that case
154 + * the admin bar items won't be properly utilized unless refreshing the page
155 + */
156 + return;
157 + }
158 + }
159 +
112 160 $err = array();
113 161
114 162 if ( ! defined( 'WP_CACHE' ) || true !== WP_CACHE ) {
115 - $err['wp_cache'] = sprintf( __( '<code>%s</code> is not in wp-config.php.', 'powered-cache' ), 'define("WP_CACHE", true);' );
163 + /* translators: %s: WP_CACHE definition*/
164 + $err['wp_cache'] = sprintf( __( '<code>%s</code> is not found in wp-config.php.', 'powered-cache' ), 'define("WP_CACHE", true);' );
116 165 }
117 166
118 - if ( ! defined( 'POWERED_CACHE_PAGE_CACHING' ) || true !== POWERED_CACHE_PAGE_CACHING ) {
119 - $err['powered_cache_page_cache'] = sprintf( __( '<code>%s</code> file was edited or deleted. You can re-create correct configuration files by saving settings.', 'powered-cache' ), basename( WP_CONTENT_DIR ) . '/advanced-cache.php' );
167 + if ( defined( 'WP_CACHE' ) && WP_CACHE && ( ! defined( 'POWERED_CACHE_PAGE_CACHING' ) || true !== POWERED_CACHE_PAGE_CACHING ) ) {
168 + /* translators: %s: advanced-cache.php drop-in path */
169 + $err['powered_cache_page_cache'] = sprintf( __( '<code>%s</code> file was edited or deleted. You can recreate the correct configuration files by saving Powered Cache settings.', 'powered-cache' ), basename( WP_CONTENT_DIR ) . '/advanced-cache.php' );
120 170 }
121 171
122 -
123 - if ( defined( 'POWERED_CACHE_PAGE_CACHING_HAS_PROBLEM' ) && true === POWERED_CACHE_PAGE_CACHING_HAS_PROBLEM ) {
172 + if ( defined( 'POWERED_CACHE_PAGE_CACHING_HAS_PROBLEM' ) && POWERED_CACHE_PAGE_CACHING_HAS_PROBLEM ) {
173 + /* translators: %s: page-cache.php drop-in path */
124 174 $err['powered_cache_page_cache_has_problem'] = sprintf( __( 'Powered Cache could not access dropin. Please check <code>%s</code> exist and accessible on your server.', 'powered-cache' ), POWERED_CACHE_DROPIN_DIR . 'page-cache.php' );
125 175 }
126 176
127 177 // everything ok
@@ -128,26 +178,31 @@
128 178 if ( empty( $err ) ) {
129 179 return;
130 180 }
131 181
132 - if ( ! current_user_can( apply_filters( 'powered_cache_cap', 'manage_options' ) ) ) {
182 + // dont show when settings just saved
183 + if ( did_action( 'powered_cache_settings_saved' ) ) {
133 184 return;
134 185 }
186 +
187 + $capability = POWERED_CACHE_IS_NETWORK ? 'manage_network' : 'manage_options';
188 +
189 + if ( ! current_user_can( $capability ) ) {
190 + return;
191 + }
135 192 ?>
136 193 <div class="error">
137 - <h2><?php _e( 'Powered Cache', 'powered-cache' ); ?></h2>
138 - <strong><?php echo __( 'Page Caching feature could not work because:', 'powered-cache' ); ?></strong>
139 -
140 - <?php foreach ( $err as $error_msg ): ?>
141 - <p><?php echo $error_msg; ?></p>
194 + <p>
195 + <strong><?php esc_html_e( 'Page Cache is not working, because:', 'powered-cache' ); ?></strong>
196 + </p>
197 + <?php foreach ( $err as $error_msg ) : ?>
198 + <p><?php echo wp_kses_post( $error_msg ); ?></p>
142 199 <?php endforeach; ?>
143 200 </div>
144 201 <?php
145 202
146 -
147 203 }
148 204
149 -add_action( 'admin_notices', 'powered_cache_object_cache_notices' );
150 205
151 206 /**
152 207 * Display object cache broken msg
153 208 *
@@ -152,25 +207,39 @@
152 207 * Display object cache broken msg
153 208 *
154 209 * @since 1.0
155 210 */
156 -function powered_cache_object_cache_notices() {
157 - $object_cache_backends = Powered_Cache_Admin_Helper::object_cache_dropins();
158 - $object_cache_driver = powered_cache_get_option( 'object_cache' );
211 +function maybe_display_object_cache_notices() {
212 + $settings = \PoweredCache\Utils\get_settings();
213 +
214 + $object_cache_backends = get_object_cache_dropins();
215 + $object_cache_driver = $settings['object_cache'];
159 216 $object_cache_dropin = untrailingslashit( WP_CONTENT_DIR ) . '/object-cache.php';
160 217
218 + if ( ! can_configure_object_cache() ) {
219 + return;
220 + }
161 221
162 - if ( ! current_user_can( apply_filters( 'powered_cache_cap', 'manage_options' ) ) ) {
222 + // dont show when settings just saved
223 + if ( did_action( 'powered_cache_settings_saved' ) ) {
163 224 return;
164 225 }
165 226
227 + if ( file_exists( $object_cache_dropin ) ) {
228 + $modify_time = filemtime( $object_cache_dropin );
229 + if ( time() - absint( $modify_time ) < 10 ) { // just created
230 + return;
231 + }
232 + }
233 +
166 234 // first check object cache file exist
167 235 if ( isset( $object_cache_backends[ $object_cache_driver ] ) && ! file_exists( $object_cache_dropin ) ) {
168 - $message = sprintf( __( 'Phew! It looks your object cache file missing. Please check <code>%s</code> exist, writable and accessible on your server.', 'powered-cache' ), $object_cache_dropin );
236 + /* translators: %s: object cache dropin path */
237 + $message = sprintf( __( 'The object cache file seems missing. Please check <code>%s</code> exist, writable and accessible on your server.', 'powered-cache' ), $object_cache_dropin );
169 238 ?>
170 239 <div class="error">
171 - <p><strong><?php echo __( 'Powered Cache:', 'powered-cache' ); ?></strong>
172 - <?php echo $message; ?>
240 + <p><strong><?php esc_html_e( 'Powered Cache:', 'powered-cache' ); ?></strong>
241 + <?php echo wp_kses_post( $message ); ?>
173 242 </p>
174 243 </div>
175 244 <?php
176 245 return;
@@ -175,20 +244,20 @@
175 244 <?php
176 245 return;
177 246 }
178 247
248 + if ( defined( 'POWERED_OBJECT_CACHE_HAS_PROBLEM' ) && POWERED_OBJECT_CACHE_HAS_PROBLEM ) {
249 + $broken_file = '';
179 250
180 -
181 - if ( defined( 'POWERED_OBJECT_CACHE_HAS_PROBLEM' ) && true === POWERED_OBJECT_CACHE_HAS_PROBLEM ) {
182 - if ( isset( $object_cache_backends[ $object_cache_driver] ) ) {
251 + if ( isset( $object_cache_backends[ $object_cache_driver ] ) ) {
183 252 $broken_file = $object_cache_backends[ $object_cache_driver ];
184 253 }
185 -
186 - $message = sprintf( __( 'Powered Cache could not access object cache backend. Please check <code>%s</code> exist and accessible on your server.', 'powered-cache' ), $broken_file );
254 + /* translators: %s: object cache dropin path */
255 + $message = sprintf( __( 'The object cache file couldn\'t be loaded. Please check <code>%s</code> exist and accessible on your server.', 'powered-cache' ), $broken_file );
187 256 ?>
188 257 <div class="error">
189 - <p><strong><?php echo __( 'Powered Cache:', 'powered-cache' ); ?></strong>
190 - <?php echo $message; ?>
258 + <p><strong><?php esc_html_e( 'Powered Cache:', 'powered-cache' ); ?></strong>
259 + <?php echo wp_kses_post( $message ); ?>
191 260 </p>
192 261 </div>
193 262 <?php
194 263 }
@@ -194,36 +263,50 @@
194 263 }
195 264
196 265 }
197 266
198 -add_action( 'admin_notices', 'powered_cache_maybe_htaccess_warning' );
199 -
200 267 /**
201 268 * Notices for the .htaccess
202 269 *
203 270 * @since 1.2
204 271 */
205 -function powered_cache_maybe_htaccess_warning() {
272 +function maybe_display_htaccess_notice() {
206 273 global $is_apache;
207 274
208 - if ( true !== powered_cache_get_option( 'configure_htaccess' ) ) {
275 + if ( ! $is_apache ) {
209 276 return;
210 277 }
211 278
212 - if ( ! $is_apache ) {
279 + $settings = \PoweredCache\Utils\get_settings();
280 +
281 + if ( ! $settings['auto_configure_htaccess'] ) {
213 282 return;
214 283 }
215 284
216 - if ( ! current_user_can( apply_filters( 'powered_cache_cap', 'manage_options' ) ) ) {
285 + if ( ! can_configure_htaccess() ) {
217 286 return;
218 287 }
219 288
289 + // dont show when settings just saved
290 + if ( did_action( 'powered_cache_settings_saved' ) ) {
291 + return;
292 + }
293 +
220 294 $htaccess_file = get_home_path() . '.htaccess';
221 - $message = '';
295 +
296 + if ( file_exists( $htaccess_file ) ) {
297 + $modify_time = filemtime( $htaccess_file );
298 + if ( time() - absint( $modify_time ) < 10 ) { // just modified
299 + return;
300 + }
301 + }
302 +
303 + $message = '';
304 +
222 305 if ( ! file_exists( $htaccess_file ) ) {
223 - $message = sprintf( __( 'We can\'t find <code>%s</code> file on your server. Please create a new <code>.htaccess</code> file. <a href="%s">Codex</a> might help!.', 'powered-cache' ), '.htaccess', 'https://codex.wordpress.org/htaccess' );
306 + $message = __( 'The <code>.htaccess</code> couldn\'t be found on your server. Please create a new <code>.htaccess</code> file. (<a href="https://wordpress.org/support/article/htaccess/" target="_blank" rel="noopener">?</a>)', 'powered-cache' );
224 307 } elseif ( ! is_writeable( $htaccess_file ) ) {
225 - $message = sprintf( __( 'Oh no! It looks your <code>%s</code> file is not writable. Please make sure it is writable by the web server. Your website will much more faster when configured for Powered Cache.', 'powered-cache' ), '.htaccess' );
308 + $message = __( 'Oh no! It looks <code>.htaccess</code> file is not writable. Please make sure it is writable by the application server. Your website will be much faster when .htaccess is configured for Powered Cache.', 'powered-cache' );
226 309 }
227 310
228 311 if ( empty( $message ) ) {
229 312 return;
@@ -231,12 +314,134 @@
231 314
232 315 ?>
233 316
234 317 <div class="error">
235 - <p><strong><?php echo __( 'Powered Cache:', 'powered-cache' ); ?></strong>
236 - <?php echo $message; ?>
318 + <p><strong><?php esc_html_e( 'Powered Cache:', 'powered-cache' ); ?></strong>
319 + <?php echo wp_kses_post( $message ); ?>
237 320 </p>
238 321 </div>
239 322
240 323 <?php
324 +}
241 325
326 +/**
327 + * Observe new plugin activation/deactivation
328 + *
329 + * @param string $plugin file
330 + * @param boolean $network_wide Whether plugin de/activated network wide or not
331 + *
332 + * @return void
333 + * @since 3.2
334 + */
335 +function observe_plugin_changes( $plugin, $network_wide ) {
336 + if ( false !== stripos( $plugin, 'powered-cache' ) ) {
337 + return;
338 + }
339 +
340 + if ( $network_wide ) {
341 + set_site_transient( PURGE_CACHE_PLUGIN_NOTICE_TRANSIENT, '1' );
342 +
343 + return;
344 + }
345 +
346 + set_transient( PURGE_CACHE_PLUGIN_NOTICE_TRANSIENT, '1' );
347 +}
348 +
349 +/**
350 + * Display cache purging notice upon a new plugin activated/deactivated
351 + *
352 + * @return void
353 + * @since 3.2
354 + */
355 +function maybe_display_purge_cache_plugin_notice() {
356 + $has_notice = false;
357 +
358 + if ( POWERED_CACHE_IS_NETWORK && current_user_can( 'manage_network' ) ) {
359 + $has_notice = get_site_transient( PURGE_CACHE_PLUGIN_NOTICE_TRANSIENT );
360 + $purge_url = wp_nonce_url( admin_url( 'admin-post.php?action=powered_cache_purge_page_cache_network' ), 'powered_cache_purge_page_cache_network' );
361 + } elseif ( current_user_can( 'activate_plugins' ) ) {
362 + $has_notice = get_transient( PURGE_CACHE_PLUGIN_NOTICE_TRANSIENT );
363 + $purge_url = wp_nonce_url( admin_url( 'admin-post.php?action=powered_cache_purge_all_cache' ), 'powered_cache_purge_all_cache' );
364 + }
365 +
366 + if ( $has_notice ) {
367 + $message = __( '<strong>Powered Cache:</strong> One or more plugins have been activated or deactivated; consider clearing the cache if these changes impact your site\'s front end.', 'powered-cache' );
368 + ?>
369 + <div class="notice notice-warning is-dismissible">
370 + <p>
371 + <?php echo wp_kses_post( $message ); ?>
372 + </p>
373 + <p>
374 + <a href="<?php echo esc_url_raw( $purge_url ); ?>" class="button-primary">
375 + <?php esc_html_e( 'Purge Cache', 'powered-cache' ); ?>
376 + </a>
377 + <a href="<?php echo esc_url_raw( wp_nonce_url( admin_url( 'admin-post.php?action=powered_cache_dismiss_notice&notice=' . PURGE_CACHE_PLUGIN_NOTICE_TRANSIENT ), 'powered_cache_dismiss_notice' ) ); ?>" class="button-secondary">
378 + <?php esc_html_e( 'Dismiss this notice', 'powered-cache' ); ?>
379 + </a>
380 + </p>
381 + <a href="<?php echo esc_url_raw( wp_nonce_url( admin_url( 'admin-post.php?action=powered_cache_dismiss_notice&notice=' . PURGE_CACHE_PLUGIN_NOTICE_TRANSIENT ), 'powered_cache_dismiss_notice' ) ); ?>" type="button" class="notice-dismiss" style="text-decoration:none;">
382 + <span class="screen-reader-text"><?php esc_html_e( 'Dismiss this notice', 'powered-cache' ); ?></span>
383 + </a>
384 + </div>
385 + <?php
386 + }
387 +}
388 +
389 +/**
390 + * Dismis given notice
391 + *
392 + * @return void
393 + * @since 3.2
394 + */
395 +function dismiss_notice() {
396 + if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'powered_cache_dismiss_notice' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
397 + wp_nonce_ays( '' );
398 + }
399 +
400 + if ( current_user_can( 'manage_options' ) && ! empty( $_GET['notice'] ) ) {
401 + $notice = sanitize_text_field( wp_unslash( $_GET['notice'] ) );
402 +
403 + if ( POWERED_CACHE_IS_NETWORK ) {
404 + delete_site_transient( $notice );
405 + } else {
406 + delete_transient( $notice );
407 + }
408 + }
409 +
410 + wp_safe_redirect( esc_url_raw( wp_get_referer() ) );
411 + exit;
412 +}
413 +
414 +/**
415 + * Display a notice when development mode is active
416 + *
417 + * @return void
418 + * @since 3.6
419 + * @related \PoweredCache\DevMode
420 + */
421 +function maybe_display_dev_mode_notice() {
422 + if ( ! \PoweredCache\Utils\is_dev_mode_active() ) {
423 + return;
424 + }
425 +
426 + if ( ! current_user_can( 'manage_options' ) ) {
427 + return;
428 + }
429 +
430 + // Only display on Powered Cache settings page
431 + $current_screen = get_current_screen();
432 +
433 + if (
434 + ! $current_screen
435 + || ( ! isset( $current_screen->id ) || false === strpos( $current_screen->id, 'powered-cache' ) )
436 + ) {
437 + return;
438 + }
439 +
440 + ?>
441 + <div class="notice notice-warning is-dismissible">
442 + <p><strong><?php esc_html_e( 'Development Mode is active.', 'powered-cache' ); ?></strong>
443 + <?php esc_html_e( 'Caching and optimizations are currently disabled. Don’t forget to disable it when done.', 'powered-cache' ); ?>
444 + </p>
445 + </div>
446 + <?php
242 447 }