| @@ -10,8 +10,10 @@ | ||
| 10 | 10 | use function PoweredCache\Utils\can_configure_htaccess; |
| 11 | 11 | use function PoweredCache\Utils\can_configure_object_cache; |
| 12 | 12 | use function PoweredCache\Utils\can_control_all_settings; |
| 13 | 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; | |
| 14 | 16 | |
| 15 | 17 | /** |
| 16 | 18 | * Default setup routine |
| 17 | 19 | * |
| @@ -18,18 +20,26 @@ | ||
| 18 | 20 | * @return void |
| 19 | 21 | */ |
| 20 | 22 | function setup() { |
| 21 | 23 | if ( POWERED_CACHE_IS_NETWORK ) { |
| 22 | - add_action( 'network_admin_notices', __NAMESPACE__ . '\\maybe_display_plugin_compatability_notices' ); | |
| 24 | + add_action( 'network_admin_notices', __NAMESPACE__ . '\\maybe_display_plugin_compatibility_notices' ); | |
| 23 | 25 | add_action( 'network_admin_notices', __NAMESPACE__ . '\\maybe_display_advanced_cache_notices' ); |
| 24 | 26 | add_action( 'network_admin_notices', __NAMESPACE__ . '\\maybe_display_object_cache_notices' ); |
| 25 | 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' ); | |
| 26 | 30 | } else { |
| 27 | - add_action( 'admin_notices', __NAMESPACE__ . '\\maybe_display_plugin_compatability_notices' ); | |
| 31 | + add_action( 'admin_notices', __NAMESPACE__ . '\\maybe_display_plugin_compatibility_notices' ); | |
| 28 | 32 | add_action( 'admin_notices', __NAMESPACE__ . '\\maybe_display_advanced_cache_notices' ); |
| 29 | 33 | add_action( 'admin_notices', __NAMESPACE__ . '\\maybe_display_object_cache_notices' ); |
| 30 | 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' ); | |
| 31 | 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' ); | |
| 32 | 42 | } |
| 33 | 43 | |
| 34 | 44 | /** |
| 35 | 45 | * Display incompatible plugins |
| @@ -35,9 +45,11 @@ | ||
| 35 | 45 | * Display incompatible plugins |
| 36 | 46 | * |
| 37 | 47 | * @since 1.0 |
| 38 | 48 | */ |
| 39 | -function maybe_display_plugin_compatability_notices() { | |
| 49 | +function maybe_display_plugin_compatibility_notices() { | |
| 50 | + $settings = \PoweredCache\Utils\get_settings(); | |
| 51 | + | |
| 40 | 52 | $plugins = array( |
| 41 | 53 | 'hummingbird-performance' => 'hummingbird-performance/wp-hummingbird.php', |
| 42 | 54 | 'wp-rocket' => 'wp-rocket/wp-rocket.php', |
| 43 | 55 | 'w3-total-cache' => 'w3-total-cache/w3-total-cache.php', |
| @@ -52,10 +64,20 @@ | ||
| 52 | 64 | 'gzip-ninja-speed-compression' => 'gzip-ninja-speed-compression/gzip-ninja-speed.php', |
| 53 | 65 | 'speed-booster-pack' => 'speed-booster-pack/speed-booster-pack.php', |
| 54 | 66 | 'wp-performance-score-booster' => 'wp-performance-score-booster/wp-performance-score-booster.php', |
| 55 | 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', | |
| 56 | 72 | ); |
| 57 | 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 | + } | |
| 79 | + | |
| 58 | 80 | $callback = POWERED_CACHE_IS_NETWORK ? 'is_plugin_active_for_network' : 'is_plugin_active'; |
| 59 | 81 | |
| 60 | 82 | $plugins = array_filter( $plugins, $callback ); |
| 61 | 83 | |
| @@ -65,14 +87,14 @@ | ||
| 65 | 87 | ?> |
| 66 | 88 | |
| 67 | 89 | <?php if ( current_user_can( 'activate_plugins' ) ) : ?> |
| 68 | 90 | <div class="error"> |
| 69 | - <p><?php esc_html_e( 'The following plugins are not compatible with Powered Cache and may cause unintended results:', '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> | |
| 70 | 92 | <ul class="incompatible-plugin-list"> |
| 71 | 93 | <?php |
| 72 | 94 | foreach ( $plugins as $plugin ) { |
| 73 | 95 | $plugin_data = get_plugin_data( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $plugin ); |
| 74 | - 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>'; | |
| 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 | |
| 75 | 97 | } |
| 76 | 98 | ?> |
| 77 | 99 | </ul> |
| 78 | 100 | </div> |
| @@ -297,6 +319,129 @@ | ||
| 297 | 319 | <?php echo wp_kses_post( $message ); ?> |
| 298 | 320 | </p> |
| 299 | 321 | </div> |
| 300 | 322 | |
| 323 | + <?php | |
| 324 | +} | |
| 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¬ice=' . 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¬ice=' . 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> | |
| 301 | 446 | <?php |
| 302 | 447 | } |