Last active
December 1, 2018 13:41
-
-
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.
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 | |
/** | |
* 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