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 1 commit
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
40 changes: 33 additions & 7 deletions src/purge.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
}

/**
Expand All @@ -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');
}

/**
Expand Down Expand Up @@ -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');
}

/**
Expand All @@ -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');
}

/**
Expand Down Expand Up @@ -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');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here may also need?

}

/**
Expand Down Expand Up @@ -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');
}

/**
Expand Down Expand Up @@ -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');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timotei-litespeed Maybe add the url as param?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added and looked over other functions and made a few changes

Copy link
Collaborator

Choose a reason for hiding this comment

The 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

}

/**
Expand Down Expand Up @@ -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');
}

/**
Expand All @@ -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);
}

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

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

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

}

/**
Expand All @@ -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');
}

/**
Expand All @@ -953,6 +978,7 @@ public function purge_feeds()
public static function purge_on_logout()
{
self::add_private('*');
do_action('litespeed_purged_on_logout');
}

/**
Expand Down
Loading