Last active
August 5, 2024 07:08
-
-
Save herewithme/055a44497e7ad51920a9 to your computer and use it in GitHub Desktop.
Purge all WP rocket cache when a post is modified/edited
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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