Skip to content
Open
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions src/gui.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ public function frontend_enqueue_style() {
* Load frontend menu shortcut
*
* @since 1.3
* @since 7.6 Add VPI clear.
* @access public
*/
public function frontend_shortcut() {
Expand Down Expand Up @@ -641,6 +642,15 @@ public function frontend_shortcut() {
));
}

if ( $this->has_cache_folder( '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',
Expand Down Expand Up @@ -823,6 +833,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',
Expand Down
2 changes: 1 addition & 1 deletion src/media.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ private function _finalize() {
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' );
}
Expand Down
4 changes: 2 additions & 2 deletions src/metabox.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function setting( $conf, $post_id = false ) {
* @since 4.7
*/
public function save( $post_id, $name, $val, $is_append = false ) {
if (strpos($name, 'litespeed_vpi_list') !== false) {
if ( strpos( $name, VPI::POST_META ) !== false ) {
$val = Utility::sanitize_lines($val, 'basename,drop_webp');
}

Expand All @@ -157,7 +157,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 ? VPI::POST_META_POST : VPI::POST_META );
if ($excludes !== null) {
$excludes = Utility::sanitize_lines($excludes, 'basename');
if ($excludes) {
Expand Down
27 changes: 27 additions & 0 deletions src/purge.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,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';
Expand Down Expand Up @@ -91,6 +92,7 @@ public function purge_publish( $new_status, $old_status, $post ) {
* Handle all request actions from main cls
*
* @since 1.8
* @since 7.6 Add VPI clear.
* @access public
*/
public function handler() {
Expand Down Expand Up @@ -124,6 +126,10 @@ public function handler() {
case self::TYPE_PURGE_ALL_LQIP:
$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();
Expand Down Expand Up @@ -313,6 +319,27 @@ private function _purge_all_lqip( $silence = false ) {
}
}

/**
* Delete all VPI data generated
*
* @since 7.6
* @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 = '" . VPI::POST_META . "'" );
$wpdb->query( "DELETE FROM `$wpdb->postmeta` WHERE meta_key = '" . 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
*
Expand Down
16 changes: 15 additions & 1 deletion src/vpi.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ class VPI extends Base {
const TYPE_GEN = 'gen';
const TYPE_CLEAR_Q = 'clear_q';


/**
* VPI Desktop Meta name.
*
* @since 7.6
*/
const POST_META = 'litespeed_vpi_list';
/**
* VPI Mobile Meta name.
*
* @since 7.6
*/
const POST_META_MOBILE = 'litespeed_vpi_list_mobile';

protected $_summary;
private $_queue;

Expand Down Expand Up @@ -129,7 +143,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);
Expand Down
9 changes: 9 additions & 0 deletions tpl/toolbox/purge.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,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' => esc_html__( 'Purge All', 'litespeed-cache' ) . ' - ' . esc_html__( 'Gravatar Cache', 'litespeed-cache' ),
Expand Down