Skip to content

Add Clear VPI #827

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

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions src/gui.cls.php
Original file line number Diff line number Diff line change
@@ -574,6 +574,15 @@ public function frontend_shortcut()
));
}

if ($this->conf(self::O_MEDIA_VPI)) {
$wp_admin_bar->add_menu(array(
'parent' => 'litespeed-menu',
'id' => 'litespeed-purge-vpi',
'title' => __('Purge All', 'litespeed-cache') . ' - VPI',
'href' => Utility::build_url(Router::ACTION_PURGE, Purge::TYPE_PURGE_ALL_VPI, false, '_ori'),
));
}

if ($this->has_cache_folder('avatar')) {
$wp_admin_bar->add_menu(array(
'parent' => 'litespeed-menu',
@@ -734,6 +743,16 @@ public function backend_shortcut()
));
}

if ($this->conf(self::O_MEDIA_VPI)) {
$wp_admin_bar->add_menu(array(
'parent' => 'litespeed-menu',
'id' => 'litespeed-purge-vpi',
'title' => __('Purge All', 'litespeed-cache') . ' - VPI',
'href' => Utility::build_url(Router::ACTION_PURGE, Purge::TYPE_PURGE_ALL_VPI),
'meta' => array('tabindex' => '0'),
));
}

if ($this->has_cache_folder('avatar')) {
$wp_admin_bar->add_menu(array(
'parent' => 'litespeed-menu',
2 changes: 1 addition & 1 deletion src/media.cls.php
Original file line number Diff line number Diff line change
@@ -646,7 +646,7 @@ private function _parse_img_for_preload()
{
// Load VPI setting
$is_mobile = $this->_separate_mobile();
$vpi_files = $this->cls('Metabox')->setting($is_mobile ? 'litespeed_vpi_list_mobile' : 'litespeed_vpi_list');
$vpi_files = $this->cls('Metabox')->setting($is_mobile ? VPI::POST_META_MOBILE : VPI::POST_META);
if ($vpi_files) {
$vpi_files = Utility::sanitize_lines($vpi_files, 'basename');
}
4 changes: 2 additions & 2 deletions src/metabox.cls.php
Original file line number Diff line number Diff line change
@@ -131,7 +131,7 @@ public function setting($conf, $post_id = false)
*/
public function save($post_id, $name, $val, $is_append = false)
{
if (strpos($name, 'litespeed_vpi_list') !== false) {
if (strpos($name, $this->cls('Vpi')::POST_META) !== false) {
$val = Utility::sanitize_lines($val, 'basename,drop_webp');
}

@@ -158,7 +158,7 @@ public function save($post_id, $name, $val, $is_append = false)
public function lazy_img_excludes($list)
{
$is_mobile = $this->_separate_mobile();
$excludes = $this->setting($is_mobile ? 'litespeed_vpi_list_mobile' : 'litespeed_vpi_list');
$excludes = $this->setting($is_mobile ? $this->cls('Vpi')::POST_META_POST : $this->cls('Vpi')::POST_META);
if ($excludes !== null) {
$excludes = Utility::sanitize_lines($excludes, 'basename');
if ($excludes) {
26 changes: 26 additions & 0 deletions src/purge.cls.php
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ class Purge extends Base
const TYPE_PURGE_ALL_CCSS = 'purge_all_ccss';
const TYPE_PURGE_ALL_UCSS = 'purge_all_ucss';
const TYPE_PURGE_ALL_LQIP = 'purge_all_lqip';
const TYPE_PURGE_ALL_VPI = 'purge_all_vpi';
const TYPE_PURGE_ALL_AVATAR = 'purge_all_avatar';
const TYPE_PURGE_ALL_OBJECT = 'purge_all_object';
const TYPE_PURGE_ALL_OPCACHE = 'purge_all_opcache';
@@ -127,6 +128,10 @@ public function handler()
$this->_purge_all_lqip();
break;

case self::TYPE_PURGE_ALL_VPI:
$this->_purge_all_vpi();
break;

case self::TYPE_PURGE_ALL_AVATAR:
$this->_purge_all_avatar();
break;
@@ -318,6 +323,27 @@ private function _purge_all_lqip($silence = false)
}
}

/**
* Delete all VPI data generated
*
* @since 7.1
* @access private
*/
private function _purge_all_vpi($silence = false)
{
global $wpdb;
do_action('litespeed_purged_all_vpi');

$wpdb->query("DELETE FROM `$wpdb->postmeta` WHERE meta_key = '" . $this->cls('Vpi')::POST_META . "'");
$wpdb->query("DELETE FROM `$wpdb->postmeta` WHERE meta_key = '" . $this->cls('Vpi')::POST_META_MOBILE . "'");
$this->cls('Placeholder')->rm_cache_folder('vpi');

if (!$silence) {
$msg = __('Cleaned all VPI data.', 'litespeed-cache');
!defined('LITESPEED_PURGE_SILENT') && Admin_Display::success($msg);
}
}

/**
* Delete all avatar images
*
5 changes: 4 additions & 1 deletion src/vpi.cls.php
Original file line number Diff line number Diff line change
@@ -17,6 +17,9 @@ class VPI extends Base
const TYPE_GEN = 'gen';
const TYPE_CLEAR_Q = 'clear_q';

const POST_META = 'litespeed_vpi_list';
const POST_META_MOBILE = 'litespeed_vpi_list_mobile';

protected $_summary;
private $_queue;

@@ -126,7 +129,7 @@ public function notify()
// Save data
if (!empty($v['data_vpi'])) {
$post_id = $this->_queue[$queue_k]['post_id'];
$name = !empty($v['is_mobile']) ? 'litespeed_vpi_list_mobile' : 'litespeed_vpi_list';
$name = !empty($v['is_mobile']) ? self::POST_META_MOBILE : self::POST_META;
$urldecode = is_array($v['data_vpi']) ? array_map('urldecode', $v['data_vpi']) : urldecode($v['data_vpi']);
self::debug('save data_vpi', $urldecode);
$this->cls('Metabox')->save($post_id, $name, $urldecode);
9 changes: 9 additions & 0 deletions tpl/toolbox/purge.tpl.php
Original file line number Diff line number Diff line change
@@ -93,6 +93,15 @@
);
}

if ($this->conf(self::O_MEDIA_VPI)) {
$_panels[] = array(
'title' => __('Purge All', 'litespeed-cache') . ' - VPI',
'desc' => __('This will delete all generated Viewport Images', 'litespeed-cache'),
'icon' => 'purge-front',
'append_url' => Purge::TYPE_PURGE_ALL_VPI,
);
}

if ($this->has_cache_folder('avatar')) {
$_panels[] = array(
'title' => __('Purge All', 'litespeed-cache') . ' - ' . __('Gravatar Cache', 'litespeed-cache'),