Skip to content

Commit 29af4c7

Browse files
Add Clear VPI
VPI class add constants
1 parent 78f942b commit 29af4c7

File tree

6 files changed

+61
-4
lines changed

6 files changed

+61
-4
lines changed

src/gui.cls.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,15 @@ public function frontend_shortcut()
574574
));
575575
}
576576

577+
if ($this->has_cache_folder('vpi')) {
578+
$wp_admin_bar->add_menu(array(
579+
'parent' => 'litespeed-menu',
580+
'id' => 'litespeed-purge-vpi',
581+
'title' => __('Purge All', 'litespeed-cache') . ' - VPI',
582+
'href' => Utility::build_url(Router::ACTION_PURGE, Purge::TYPE_PURGE_ALL_VPI, false, '_ori'),
583+
));
584+
}
585+
577586
if ($this->has_cache_folder('avatar')) {
578587
$wp_admin_bar->add_menu(array(
579588
'parent' => 'litespeed-menu',
@@ -734,6 +743,16 @@ public function backend_shortcut()
734743
));
735744
}
736745

746+
if ($this->has_cache_folder('vpi')) {
747+
$wp_admin_bar->add_menu(array(
748+
'parent' => 'litespeed-menu',
749+
'id' => 'litespeed-purge-placeholder',
750+
'title' => __('Purge All', 'litespeed-cache') . ' - ' . __('VPI data', 'litespeed-cache'),
751+
'href' => Utility::build_url(Router::ACTION_PURGE, Purge::TYPE_PURGE_ALL_VPI),
752+
'meta' => array('tabindex' => '0'),
753+
));
754+
}
755+
737756
if ($this->has_cache_folder('avatar')) {
738757
$wp_admin_bar->add_menu(array(
739758
'parent' => 'litespeed-menu',

src/media.cls.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ private function _parse_img_for_preload()
646646
{
647647
// Load VPI setting
648648
$is_mobile = $this->_separate_mobile();
649-
$vpi_files = $this->cls('Metabox')->setting($is_mobile ? 'litespeed_vpi_list_mobile' : 'litespeed_vpi_list');
649+
$vpi_files = $this->cls('Metabox')->setting($is_mobile ? $this->cls('Vpi')::POST_META_MOBILE : $this->cls('Vpi')::POST_META);
650650
if ($vpi_files) {
651651
$vpi_files = Utility::sanitize_lines($vpi_files, 'basename');
652652
}

src/metabox.cls.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function setting($conf, $post_id = false)
131131
*/
132132
public function save($post_id, $name, $val, $is_append = false)
133133
{
134-
if (strpos($name, 'litespeed_vpi_list') !== false) {
134+
if (strpos($name, $this->cls('Vpi')::POST_META) !== false) {
135135
$val = Utility::sanitize_lines($val, 'basename,drop_webp');
136136
}
137137

@@ -158,7 +158,7 @@ public function save($post_id, $name, $val, $is_append = false)
158158
public function lazy_img_excludes($list)
159159
{
160160
$is_mobile = $this->_separate_mobile();
161-
$excludes = $this->setting($is_mobile ? 'litespeed_vpi_list_mobile' : 'litespeed_vpi_list');
161+
$excludes = $this->setting($is_mobile ? $this->cls('Vpi')::POST_META_POST : $this->cls('Vpi')::POST_META);
162162
if ($excludes !== null) {
163163
$excludes = Utility::sanitize_lines($excludes, 'basename');
164164
if ($excludes) {

src/purge.cls.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Purge extends Base
3232
const TYPE_PURGE_ALL_CCSS = 'purge_all_ccss';
3333
const TYPE_PURGE_ALL_UCSS = 'purge_all_ucss';
3434
const TYPE_PURGE_ALL_LQIP = 'purge_all_lqip';
35+
const TYPE_PURGE_ALL_VPI = 'purge_all_vpi';
3536
const TYPE_PURGE_ALL_AVATAR = 'purge_all_avatar';
3637
const TYPE_PURGE_ALL_OBJECT = 'purge_all_object';
3738
const TYPE_PURGE_ALL_OPCACHE = 'purge_all_opcache';
@@ -127,6 +128,10 @@ public function handler()
127128
$this->_purge_all_lqip();
128129
break;
129130

131+
case self::TYPE_PURGE_ALL_VPI:
132+
$this->_purge_all_vpi();
133+
break;
134+
130135
case self::TYPE_PURGE_ALL_AVATAR:
131136
$this->_purge_all_avatar();
132137
break;
@@ -318,6 +323,27 @@ private function _purge_all_lqip($silence = false)
318323
}
319324
}
320325

326+
/**
327+
* Delete all VPI data generated
328+
*
329+
* @since 7.1
330+
* @access private
331+
*/
332+
private function _purge_all_vpi($silence = false)
333+
{
334+
global $wpdb;
335+
do_action('litespeed_purged_all_vpi');
336+
337+
$wpdb->query("DELETE FROM `$wpdb->postmeta` WHERE meta_key = '" . $this->cls('Vpi')::POST_META . "'");
338+
$wpdb->query("DELETE FROM `$wpdb->postmeta` WHERE meta_key = '" . $this->cls('Vpi')::POST_META_MOBILE . "'");
339+
$this->cls('Placeholder')->rm_cache_folder('vpi');
340+
341+
if (!$silence) {
342+
$msg = __('Cleaned all VPI data.', 'litespeed-cache');
343+
!defined('LITESPEED_PURGE_SILENT') && Admin_Display::success($msg);
344+
}
345+
}
346+
321347
/**
322348
* Delete all avatar images
323349
*

src/vpi.cls.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class VPI extends Base
1717
const TYPE_GEN = 'gen';
1818
const TYPE_CLEAR_Q = 'clear_q';
1919

20+
const POST_META = 'litespeed_vpi_list';
21+
const POST_META_MOBILE = 'litespeed_vpi_list_mobile';
22+
2023
protected $_summary;
2124
private $_queue;
2225

@@ -126,7 +129,7 @@ public function notify()
126129
// Save data
127130
if (!empty($v['data_vpi'])) {
128131
$post_id = $this->_queue[$queue_k]['post_id'];
129-
$name = !empty($v['is_mobile']) ? 'litespeed_vpi_list_mobile' : 'litespeed_vpi_list';
132+
$name = !empty($v['is_mobile']) ? self::POST_META_MOBILE : self::POST_META;
130133
$urldecode = is_array($v['data_vpi']) ? array_map('urldecode', $v['data_vpi']) : urldecode($v['data_vpi']);
131134
self::debug('save data_vpi', $urldecode);
132135
$this->cls('Metabox')->save($post_id, $name, $urldecode);

tpl/toolbox/purge.tpl.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@
9393
);
9494
}
9595

96+
if ($this->has_cache_folder('vpi')) {
97+
$_panels[] = array(
98+
'title' => __('Purge All', 'litespeed-cache') . ' - ' . __('VPI', 'litespeed-cache'),
99+
'desc' => __('This will delete all generated Viewport Images', 'litespeed-cache'),
100+
'icon' => 'purge-front',
101+
'append_url' => Purge::TYPE_PURGE_ALL_VPI,
102+
);
103+
}
104+
96105
if ($this->has_cache_folder('avatar')) {
97106
$_panels[] = array(
98107
'title' => __('Purge All', 'litespeed-cache') . ' - ' . __('Gravatar Cache', 'litespeed-cache'),

0 commit comments

Comments
 (0)