Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
After WP Plugin update Hook
/**
* Purge LiteSpeed Cache after updates.
*
* This snippet will check if LS plugin is activated & then Purge all Cache
* after any Core, Theme or Plugin Installation, Update or rollback. Then it
* will email the results to the given address on line 35. Disable by commenting out
* line 39.
*
* @howto: Update line 35 with your email address and save the code snippet to Execute on Child Sites.
*
* @snippetType: Execute on Child Sites
*/
function my_upgrade_function( $upgrader_object, $options ) {
$purged = 'has not been purged.';
// Purge all LS Cache.
if ( defined( 'LSCWP_V' )) {
do_action( 'litespeed_purge_all' );
$purged = 'has been purged.';
}
// Grab Admin Notices.
ob_start(); // start capturing output.
do_action( 'admin_notices' );
$admin_notice_output = ob_get_contents(); // the actions output will now be stored in the variable as a string!
ob_end_clean(); // never forget this or you will keep capturing output.
// Grab Site Name.
$site_name = get_bloginfo('name');
// Build Email.
$email_subject = 'Notification: ' . $site_name . ' status has changed.';
$email_body = 'The child site ' . $site_name . ' ' . $purged . '.<br>
The current Admin Notices are as follows:<br><br>' . $admin_notice_output;
// Set Email Headers.
$to = 'YOU_EMAIL@email.com';
$subject = $email_subject;
$body = $email_body;
$headers = array('Content-Type: text/html; charset=UTF-8');
// Send Email.
wp_mail( $to, $subject, $body, $headers );
}
add_action( 'upgrader_process_complete', 'my_upgrade_function',10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment