-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PR Redo - Purge actions and filter #776
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,14 +51,17 @@ class Purge extends Base | |
public function init() | ||
{ | ||
//register purge actions | ||
$purge_post_events = array( | ||
// 'edit_post', | ||
// 'save_post', | ||
'delete_post', | ||
'wp_trash_post', | ||
// 'clean_post_cache', // This will disable wc's not purge product when stock status not change setting | ||
'wp_update_comment_count', // TODO: check if needed for non ESI | ||
// Mostly used values: edit_post, save_post, delete_post, wp_trash_post, clean_post_cache, wp_update_comment_count | ||
$purge_post_events = add_filter( | ||
'litespeed_purge_post_events', | ||
array( | ||
'delete_post', | ||
'wp_trash_post', | ||
// 'clean_post_cache', // This will disable wc's not purge product when stock status not change setting | ||
'wp_update_comment_count', // TODO: check if needed for non ESI | ||
) | ||
); | ||
|
||
foreach ($purge_post_events as $event) { | ||
// this will purge all related tags | ||
add_action($event, array($this, 'purge_post')); | ||
|
@@ -230,6 +233,8 @@ private function _purge_all_lscache($silence = false) | |
{ | ||
$this->_add('*'); | ||
|
||
do_action('litespeed_purged_all_lscache'); | ||
|
||
if (!$silence) { | ||
$msg = __('Notified LiteSpeed Web Server to purge all LSCache entries.', 'litespeed-cache'); | ||
!defined('LITESPEED_PURGE_SILENT') && Admin_Display::success($msg); | ||
|
@@ -406,6 +411,8 @@ public function purge_all_opcache($silence = false) | |
return false; | ||
} | ||
|
||
do_action('litespeed_purged_all_opcache'); | ||
|
||
// Purge opcode cache | ||
opcache_reset(); | ||
self::debug('Reset opcode cache'); | ||
|
@@ -607,6 +614,7 @@ private function _prepend_bid($tags) | |
public static function set_purge_related() | ||
{ | ||
self::cls()->_purge_related = true; | ||
do_action('litespeed_purged_related'); | ||
} | ||
|
||
/** | ||
|
@@ -618,6 +626,7 @@ public static function set_purge_related() | |
public static function set_purge_single() | ||
{ | ||
self::cls()->_purge_single = true; | ||
do_action('litespeed_purged_single'); | ||
} | ||
|
||
/** | ||
|
@@ -677,6 +686,7 @@ private function _purge_frontpage() | |
|
||
$msg = __('Notified LiteSpeed Web Server to purge the front page.', 'litespeed-cache'); | ||
!defined('LITESPEED_PURGE_SILENT') && Admin_Display::success($msg); | ||
do_action('litespeed_purged_frontpage'); | ||
} | ||
|
||
/** | ||
|
@@ -691,6 +701,7 @@ private function _purge_pages() | |
|
||
$msg = __('Notified LiteSpeed Web Server to purge all pages.', 'litespeed-cache'); | ||
!defined('LITESPEED_PURGE_SILENT') && Admin_Display::success($msg); | ||
do_action('litespeed_purged_pages'); | ||
} | ||
|
||
/** | ||
|
@@ -738,6 +749,7 @@ public function purge_cat($value) | |
self::add(Tag::TYPE_ARCHIVE_TERM . $cat->term_id); | ||
|
||
!defined('LITESPEED_PURGE_SILENT') && Admin_Display::success(sprintf(__('Purge category %s', 'litespeed-cache'), $val)); | ||
do_action('litespeed_purged_cat'); | ||
} | ||
|
||
/** | ||
|
@@ -765,6 +777,7 @@ public function purge_tag($val) | |
self::add(Tag::TYPE_ARCHIVE_TERM . $term->term_id); | ||
|
||
!defined('LITESPEED_PURGE_SILENT') && Admin_Display::success(sprintf(__('Purge tag %s', 'litespeed-cache'), $val)); | ||
do_action('litespeed_purged_tag'); | ||
} | ||
|
||
/** | ||
|
@@ -797,6 +810,7 @@ public function purge_url($url, $purge2 = false, $quite = false) | |
self::add($hash, $purge2); | ||
|
||
!$quite && !defined('LITESPEED_PURGE_SILENT') && Admin_Display::success(sprintf(__('Purge url %s', 'litespeed-cache'), $val)); | ||
do_action('litespeed_purged_link'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @timotei-litespeed Maybe add the url as param? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added and looked over other functions and made a few changes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good try. There are still some places you may miss. Also some comments added |
||
} | ||
|
||
/** | ||
|
@@ -849,6 +863,7 @@ public function purge_list() | |
public static function purge_esi($tag) | ||
{ | ||
self::add(Tag::TYPE_ESI . $tag); | ||
do_action('litespeed_purged_esi'); | ||
} | ||
|
||
/** | ||
|
@@ -861,6 +876,8 @@ public static function purge_posttype($post_type) | |
{ | ||
self::add(Tag::TYPE_ARCHIVE_POSTTYPE . $post_type); | ||
self::add($post_type); | ||
|
||
do_action('litespeed_purged_posttype', $post_type); | ||
} | ||
|
||
/** | ||
|
@@ -888,6 +905,7 @@ public function purge_post($pid) | |
} | ||
|
||
// $this->cls( 'Control' )->set_stale(); | ||
do_action('litespeed_purged_post', $pid); | ||
} | ||
|
||
/** | ||
|
@@ -906,8 +924,11 @@ public static function purge_widget($widget_id = null) | |
return; | ||
} | ||
} | ||
|
||
self::add(Tag::TYPE_WIDGET . $widget_id); | ||
self::add_private(Tag::TYPE_WIDGET . $widget_id); | ||
|
||
do_action('litespeed_purged_widget', $widget_id); | ||
} | ||
|
||
/** | ||
|
@@ -924,11 +945,14 @@ public static function purge_comment_widget() | |
if (!isset($wp_widget_factory->widgets['WP_Widget_Recent_Comments'])) { | ||
return; | ||
} | ||
|
||
$recent_comments = $wp_widget_factory->widgets['WP_Widget_Recent_Comments']; | ||
if (!is_null($recent_comments)) { | ||
self::add(Tag::TYPE_WIDGET . $recent_comments->id); | ||
self::add_private(Tag::TYPE_WIDGET . $recent_comments->id); | ||
} | ||
|
||
do_action('litespeed_purged_comment_widget', $recent_comments->id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will result in error if you don't use the way L950 does. |
||
} | ||
|
||
/** | ||
|
@@ -942,6 +966,7 @@ public function purge_feeds() | |
if ($this->conf(self::O_CACHE_TTL_FEED) > 0) { | ||
self::add(Tag::TYPE_FEED); | ||
} | ||
do_action('litespeed_purged_feeds'); | ||
} | ||
|
||
/** | ||
|
@@ -953,6 +978,7 @@ public function purge_feeds() | |
public static function purge_on_logout() | ||
{ | ||
self::add_private('*'); | ||
do_action('litespeed_purged_on_logout'); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here may also need?