WP Rocket缓存插件会自动清除缓存,感觉用了这个缓存插件之后,到处是地雷和各种机关,稍不注意就可能把以前缓存的文章给删了。这种效果对于那些八百年不更新旧文章的人来说,简直就是灾难啊!幸好WP Rocket插件的官方给出了解决办法,给出了一个叫 wp-rocket-no-cache-auto-purge
的插件,可以禁止WP Rocket自动删除缓存。
插件的主要代码如下所示:
- <?php
- / **
- * Plugin Name: WP Rocket | Disable Cache Clearing
- * Description: Disables all of WP Rocket’s automatic cache clearing.
- * Plugin URI: https://github.com/wp-media/wp-rocket-helpers/tree/master/cache/wp-rocket-no-cache-auto-purge/
- * Author: WP Rocket Support Team
- * Copyright SAS WP MEDIA 2018
- * /
- namespace WP_Rocket\Helpers\cache\no_cache_auto_purge;
- //Standard plugin security, keep this line in place.
- defined( 'ABSPATH' ) or die();
- / **
- * Remove all of WP Rocket’s cache purging actions.
- *
- * @author Caspar Hübinger
- * /
- function remove_purge_hooks() {
- //WP core action hooks rocket_clean_domain() gets hooked into.
- $clean_domain_hooks = array(
- //When user changes the theme
- 'switch_theme',
- //When a user is added
- 'user_register',
- //When a user is updated
- 'profile_update',
- //When a user is deleted
- 'deleted_user',
- //When a custom menu is updated
- 'wp_update_nav_menu',
- //When any theme modifications are updated
- 'update_option_theme_mods_' . get_option( 'stylesheet' ),
- //When you change the order of widgets
- 'update_option_sidebars_widgets',
- //When category permalink prefix is update
- 'update_option_category_base',
- //When tag permalink prefix is update
- 'update_option_tag_base',
- //When permalink structure is update
- 'permalink_structure_changed',
- //When a term is created
- 'create_term',
- //When a term is updated
- 'edited_terms',
- //When a term is deleted
- 'delete_term',
- //When a link (post type) is added
- 'add_link',
- //When a link (post type) is updated
- 'edit_link',
- //When a link (post type) is deleted
- 'delete_link',
- //When resulty are saved in the Customizer
- 'customize_save',
- //When Avada theme purges its own cache
- 'avada_clear_dynamic_css_cache',
- );
- //WP core action hooks rocket_clean_post() gets hooked into.
- $clean_post_hooks = array(
- //Disables the refreshing of partial cache when content is edited
- 'wp_trash_post',
- 'delete_post',
- 'clean_post_cache',
- 'wp_update_comment_count',
- );
- //Remove rocket_clean_domain() from core action hooks.
- foreach ( $clean_domain_hooks as $key => $handle ) {
- remove_action( $handle, 'rocket_clean_domain' );
- }
- //Remove rocket_clean_post() from core action hooks.
- foreach ( $clean_post_hooks as $key => $handle ) {
- remove_action( $handle, 'rocket_clean_post' );
- }
- remove_filter( 'widget_update_callback' , 'rocket_widget_update_callback' );
- }
- add_action( 'wp_rocket_loaded', __NAMESPACE__ . '\remove_purge_hooks' );
需要下载的朋友可以从此处下载WP-ROCKET插件(更新至3.11.2版本) 以及 wp-rocket-no-cache-auto-purge 插件: 百度网盘 提取码: n5vp
安装方法与其他WordPress插件无异。