Skip to content
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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 37 additions & 6 deletions src/purge.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ class Purge extends Base
*/
public function init()
{
//register purge actions
$purge_post_events = array(
// 'edit_post',
// 'save_post',
// Register purge actions.
// Most 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'));
Expand Down Expand Up @@ -230,6 +230,9 @@ private function _purge_all_lscache($silence = false)
{
$this->_add('*');

// Action to run after server was notified to delete LSCache entries.
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);
Expand Down Expand Up @@ -406,6 +409,9 @@ public function purge_all_opcache($silence = false)
return false;
}

// Action to run after opcache purge.
do_action('litespeed_purged_all_opcache');

// Purge opcode cache
opcache_reset();
self::debug('Reset opcode cache');
Expand Down Expand Up @@ -607,6 +613,7 @@ private function _prepend_bid($tags)
public static function set_purge_related()
{
self::cls()->_purge_related = true;
do_action('litespeed_purged_related');
}

/**
Expand All @@ -618,6 +625,7 @@ public static function set_purge_related()
public static function set_purge_single()
{
self::cls()->_purge_single = true;
do_action('litespeed_purged_single');
}

/**
Expand Down Expand Up @@ -677,6 +685,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');
}

/**
Expand All @@ -691,6 +700,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');
}

/**
Expand Down Expand Up @@ -738,6 +748,9 @@ 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));

// Action to run after category purge.
do_action('litespeed_purged_cat', $value);
}

/**
Expand Down Expand Up @@ -765,6 +778,9 @@ 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));

// Action to run after tag purge.
do_action('litespeed_purged_tag', $val);
}

/**
Expand Down Expand Up @@ -797,6 +813,9 @@ 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));

// Action to run after url purge.
do_action('litespeed_purged_link', $url);
}

/**
Expand Down Expand Up @@ -849,6 +868,7 @@ public function purge_list()
public static function purge_esi($tag)
{
self::add(Tag::TYPE_ESI . $tag);
do_action('litespeed_purged_esi', $tag);
}

/**
Expand All @@ -861,6 +881,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);
}

/**
Expand Down Expand Up @@ -888,6 +910,7 @@ public function purge_post($pid)
}

// $this->cls( 'Control' )->set_stale();
do_action('litespeed_purged_post', $pid);
}

/**
Expand All @@ -906,8 +929,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);
}

/**
Expand All @@ -924,10 +950,13 @@ 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);
}
}

Expand All @@ -942,6 +971,7 @@ public function purge_feeds()
if ($this->conf(self::O_CACHE_TTL_FEED) > 0) {
self::add(Tag::TYPE_FEED);
}
do_action('litespeed_purged_feeds');
}

/**
Expand All @@ -952,7 +982,8 @@ public function purge_feeds()
*/
public static function purge_on_logout()
{
self::add_private('*');
self::add_private_all();
do_action('litespeed_purged_on_logout');
}

/**
Expand Down
Loading