Skip to content

Instantly share code, notes, and snippets.

@herewithme
Last active May 6, 2022 12:08
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save herewithme/055a44497e7ad51920a9 to your computer and use it in GitHub Desktop.
Save herewithme/055a44497e7ad51920a9 to your computer and use it in GitHub Desktop.
Purge all WP rocket cache when a post is modified/edited
<?php
/*
Plugin Name: Purge all WP Rocket cache
Plugin URI: http://www.beapi.fr
Description: Purge all WP rocket cache when a post is modified/edited
Version: 1.0
Author: BeAPI
Author URI: http://www.beapi.fr
Network: true
*/
class WP_Rocket_Purge_All {
public function __construct() {
// Define registered purge events
$actions = array(
'save_post', // Save a post
'deleted_post', // Delete a post
'trashed_post', // Empty Trashed post
'edit_post', // Edit a post - includes leaving comments
'delete_attachment', // Delete an attachment - includes re-uploading
'switch_theme', // Change theme
);
// Add the action for each event
foreach ( $actions as $event ) {
add_action( $event, array($this, 'purge_all'), 10 );
}
}
public function purge_all() {
if ( !defined('WP_ROCKET_VERSION') ) {
return false;
}
rocket_clean_domain();
return true;
}
}
new WP_Rocket_Purge_All();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment