Skip to content

Instantly share code, notes, and snippets.

@reuhno
Last active June 6, 2022 11:05
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save reuhno/f7daa2690488003fa64077fb8247c769 to your computer and use it in GitHub Desktop.
WP Rocket helper for Super Page Cache for Cloudflare
<?php
/**
* Plugin Name: WP Rocket helper for Super Page Cache for Cloudflare
* Description: Remove HTML expires rules from .htaccess rules and other things
* Plugin URI: https://gist.github.com/reuhno/f7daa2690488003fa64077fb8247c769
* Author: Reuhno & Saumya Majumder & WP Rocket Support Team
* Author URI: http://wp-rocket.me/
* License: GNU General Public License v2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
namespace WP_Rocket\Helpers\htaccess\super_page_cache_with_wp_rocket;
// Standard plugin security, keep this line in place.
defined( 'ABSPATH' ) or die();
/**
* Disable page caching in WP Rocket.
*
* @link http://docs.wp-rocket.me/article/61-disable-page-caching
*/
// Disable generating the advanced-cache.php file by WP Rocket
add_filter( 'rocket_generate_advanced_cache_file', '__return_false' );
// Disable WP Rocket Mandetory Cookies
add_filter( 'rocket_cache_mandatory_cookies', '__return_empty_array' );
// Prevent WP Rocket from changing the WP_CACHE constant
add_filter( 'rocket_set_wp_cache_constant', '__return_false' );
// Prevent WP Rocket from writing to the htaccess file
add_filter( 'rocket_disable_htaccess', '__return_true' );
// Disable other WP Rocket stuffs that are not needed and handelled by this plugin
add_filter( 'rocket_display_input_varnish_auto_purge', '__return_false' );
//Disable page caching in WP Rocket.
add_filter( 'do_rocket_generate_caching_files', '__return_false' );
/**
* Cleans entire cache folder on activation.
*
* @author Arun Basil Lal
*/
function clean_wp_rocket_cache() {
if ( ! function_exists( 'rocket_clean_domain' ) ) {
return false;
}
// Purge entire WP Rocket cache.
rocket_clean_domain();
}
register_activation_hook( __FILE__, __NAMESPACE__ . '\clean_wp_rocket_cache' );
/**
* Clear .htaccess of all WP Rocket rules on activation.
*
* @author Arun Basil Lal
*/
function flush_htaccess() {
if ( function_exists( 'update_rocket_option' ) ) {
update_rocket_option('purge_cron_interval', 15);
update_rocket_option('purge_cron_unit', 'DAY_IN_SECONDS');
}
if ( function_exists( 'flush_rocket_htaccess' ) ) {
flush_rocket_htaccess( true );
}
}
register_activation_hook( __FILE__, __NAMESPACE__ . '\flush_htaccess' );
/**
* Regenerate the .htaccess file and add rules back on deactivation.
*
* @author Arun Basil Lal
*/
function deactivate() {
remove_filter( 'rocket_disable_htaccess', '__return_true' );
if ( function_exists( 'flush_rocket_htaccess' ) ) {
flush_rocket_htaccess();
}
}
register_deactivation_hook( __FILE__, __NAMESPACE__ . '\deactivate' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment