Skip to content

Instantly share code, notes, and snippets.

@andykillen
Last active December 1, 2018 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andykillen/c665d999163cbf31a411b4dd604fe4db to your computer and use it in GitHub Desktop.
Save andykillen/c665d999163cbf31a411b4dd604fe4db to your computer and use it in GitHub Desktop.
PSR-0 style class with static methods to delete the SWIFT caches on comment approval.
<?php
/**
* PSR-0 style class with static methods to delete the SWIFT caches on comment approval.
*
* To make this PSR-4 add a namespace, and prefix Swift_Performance_Cache with a \
* I think its much better that way and saves the much larger Class name.
*
* I've included the init at the bottom, but normally I would have that in a place with all
* other calls so that they are easily visible, like the functions.php
*
* @Author Andrew Killen
*/
class ClearSwiftCacheCommentApproved {
public static function init(){
add_action('transition_comment_status', [__CLASS__ , 'approve_comments'], 10, 2);
}
/**
* Will try to delete all caches if the Swift Plugin is installed and a comment is approved.
*
* @param string $new_status
* @param string $old_status
* @return void
*/
function approve_comments($new_status, $old_status) {
if($old_status != $new_status && $new_status == 'approved' && class_exists('Swift_Performance_Cache') ){
Swift_Performance_Cache::clear_all_cache();
}
}
}
ClearSwiftCacheCommentApproved::init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment