Skip to content

Commit a8bb08a

Browse files
committed
3.0.0-rc8: woo api refactored; API ESI refactored;
1 parent c19d46c commit a8bb08a

23 files changed

+128
-302
lines changed

litespeed-cache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Plugin Name: LiteSpeed Cache
1616
* Plugin URI: https://www.litespeedtech.com/products/cache-plugins/wordpress-acceleration
1717
* Description: High-performance page caching and site optimization from LiteSpeed
18-
* Version: 3.0.0-rc7
18+
* Version: 3.0.0-rc8
1919
* Author: LiteSpeed Technologies
2020
* Author URI: https://www.litespeedtech.com
2121
* License: GPLv3
@@ -45,7 +45,7 @@
4545
return;
4646
}
4747

48-
! defined( 'LSCWP_V' ) && define( 'LSCWP_V', '3.0.0-rc7' );
48+
! defined( 'LSCWP_V' ) && define( 'LSCWP_V', '3.0.0-rc8' );
4949

5050
! defined( 'LSCWP_CONTENT_DIR' ) && define( 'LSCWP_CONTENT_DIR', WP_CONTENT_DIR ) ;
5151
! defined( 'LSCWP_DIR' ) && define( 'LSCWP_DIR', dirname( __FILE__ ) . '/' ) ;// Full absolute path '/var/www/html/***/wp-content/plugins/litespeed-cache/' or MU

readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ Click on the `Advanced View` link at the top of the page, and several more tabs
366366
* Avoid crawler PHP fatal error on Windows OS. (@technisolutions)
367367
* **GUI** human readable seconds. (@MarkCanada)
368368
* **3rd** Default added parallax-image to webp replacement for BB.
369-
* API refactored. * NOTE: All 3rd party plugins that are using previous APIs, especially `LiteSpeed_Cache_API`, need to be adjusted to the latest one.*
369+
* API refactored. * NOTE: All 3rd party plugins that are using previous APIs, especially `LiteSpeed_Cache_API`, need to be adjusted to the latest one. Same for ESI blocks.* ESI shortcode doesn't change.
370370
* **API** New hook `litespeed_update_confs` to settings update.
371371
* **API** New Hooks `litespeed_frontend_shortcut` and `litespeed_backend_shortcut` for dropdown menu. (@callaloo)
372372
* **API** Removed `litespeed_option_*` hooks. Use `litespeed_force_option` hook insteadly

src/admin-display.cls.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,15 +486,12 @@ public function display_messages()
486486
* Appends LiteSpeed Cache settings to the widget edit settings screen.
487487
* This will append the esi on/off selector and ttl text.
488488
*
489-
* @access public
490489
* @since 1.1.0
491-
* @param type $widget
492-
* @param type $return
493-
* @param type $instance
490+
* @access public
494491
*/
495492
public function show_widget_edit($widget, $return, $instance)
496493
{
497-
require LSCWP_DIR . 'tpl/esi_widget_edit.php' ;
494+
require LSCWP_DIR . 'tpl/esi_widget_edit.php';
498495
}
499496

500497
/**

src/api.cls.php

Lines changed: 33 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,26 @@ class API extends Base
3636
const WIDGET_O_ESIENABLE = ESI::WIDGET_O_ESIENABLE ;
3737
const WIDGET_O_TTL = ESI::WIDGET_O_TTL ;
3838

39+
protected static $_instance;
40+
41+
/**
42+
* Instance
43+
*
44+
* @since 3.0
45+
* @access protected
46+
*/
47+
protected function __construct()
48+
{
49+
}
50+
3951
/**
4052
* Define hooks to be used in other plugins.
4153
*
4254
* The benefit to use hooks other than functions is no need to detech if LSCWP enabled and function existed or not anymore
4355
*
4456
* @since 3.0
4557
*/
46-
public static function init()
58+
public function init()
4759
{
4860
/**
4961
* Init
@@ -101,7 +113,12 @@ public static function init()
101113
* ESI
102114
*/
103115
// API::nonce_action( $action ) & API::nonce( $action = -1, $defence_for_html_filter = true ) -> Action `litespeed_nonce`
104-
116+
add_filter( 'litespeed_esi_status', __NAMESPACE__ . '\Router::esi_enabled' ); // API::esi_enabled() -> Filter `litespeed_esi_status` // Get ESI enable status
117+
add_filter( 'litespeed_esi_url', __NAMESPACE__ . '\ESI::sub_esi_block', 10, 8 ); // API::esi_url( $block_id, $wrapper, $params = array(), $control = 'private,no-vary', $silence = false, $preserved = false, $svar = false, $inline_val = false ) // Generate ESI block url
118+
// API::hook_widget_default_options( $hook ) -> Filter `litespeed_widget_default_options` // Hook widget default settings value. Currently used in Woo 3rd
119+
// API::hook_esi_param( $hook ) -> Filter `litespeed_esi_params`
120+
// API::hook_tpl_not_esi($hook) && Action `litespeed_is_not_esi_template` -> Action `litespeed_tpl_normal`
121+
// API::hook_tpl_esi($block, $hook) -> Action `litespeed_esi_block-$block` // add_action( 'litespeed_esi_load-' . $block, $hook )
105122

106123
/**
107124
* Vary
@@ -115,13 +132,22 @@ public static function init()
115132

116133
add_filter( 'litespeed_is_mobile', __NAMESPACE__ . '\Control::is_mobile' ); // API::set_mobile() -> Filter `litespeed_is_mobile`
117134

135+
/**
136+
* GUI
137+
*/
138+
// API::clean_wrapper_begin( $counter = false ) -> Filter `litespeed_clean_wrapper_begin` // Start a to-be-removed html wrapper
139+
add_filter( 'litespeed_clean_wrapper_begin', __NAMESPACE__ . '\GUI::clean_wrapper_begin' );
140+
// API::clean_wrapper_end( $counter = false ) -> Filter `litespeed_clean_wrapper_end` // End a to-be-removed html wrapper
141+
add_filter( 'litespeed_clean_wrapper_end', __NAMESPACE__ . '\GUI::clean_wrapper_end' );
142+
118143
/**
119144
* Mist
120145
*/
121146
add_action( 'litespeed_debug', __NAMESPACE__ . '\Debug2::debug' ); // API::debug()-> Action `litespeed_debug`
122147
add_action( 'litespeed_debug2', __NAMESPACE__ . '\Debug2::debug2' ); // API::debug2()-> Action `litespeed_debug2`
148+
add_action( 'litespeed_disable_all', array( $this, '_disable_all' ) ); // API::disable_all( $reason ) -> Action `litespeed_disable_all`
123149

124-
add_action( 'litspeed_after_admin_init', __CLASS__ . '::after_admin_init' );
150+
add_action( 'litspeed_after_admin_init', array( $this, '_after_admin_init' ) );
125151
}
126152

127153
/**
@@ -130,7 +156,7 @@ public static function init()
130156
* @since 3.0
131157
* @access public
132158
*/
133-
public static function after_admin_init()
159+
public function _after_admin_init()
134160
{
135161
/**
136162
* GUI
@@ -142,38 +168,16 @@ public static function after_admin_init()
142168
}
143169

144170
/**
145-
* Disable All
171+
* Disable All (Note: Not for direct call, always use Hooks)
146172
*
147173
* @since 2.9.7.2
148174
* @access public
149175
*/
150-
public static function disable_all( $reason )
176+
public function _disable_all( $reason )
151177
{
152178
do_action( 'litespeed_debug', '[API] Disabled_all due to ' . $reason );
153179

154-
! defined( 'LITESPEED_DISABLE_ALL' ) && define( 'LITESPEED_DISABLE_ALL', true ) ;
155-
}
156-
157-
/**
158-
* Start a to-be-removed html wrapper
159-
*
160-
* @since 1.4
161-
* @access public
162-
*/
163-
public static function clean_wrapper_begin( $counter = false )
164-
{
165-
return GUI::clean_wrapper_begin( $counter ) ;
166-
}
167-
168-
/**
169-
* End a to-be-removed html wrapper
170-
*
171-
* @since 1.4
172-
* @access public
173-
*/
174-
public static function clean_wrapper_end( $counter = false )
175-
{
176-
return GUI::clean_wrapper_end( $counter ) ;
180+
! defined( 'LITESPEED_DISABLE_ALL' ) && define( 'LITESPEED_DISABLE_ALL', true );
177181
}
178182

179183
/**
@@ -238,96 +242,4 @@ public static function vary_append_commenter()
238242
Vary::get_instance()->append_commenter() ;
239243
}
240244

241-
/**
242-
* Hook not ESI template
243-
*
244-
* @since 1.1.3
245-
* @access public
246-
*/
247-
public static function hook_tpl_not_esi($hook)
248-
{
249-
add_action('litespeed_is_not_esi_template', $hook) ;
250-
}
251-
252-
/**
253-
* Hook ESI template block
254-
*
255-
* @since 1.1.3
256-
* @access public
257-
*/
258-
public static function hook_tpl_esi($block, $hook)
259-
{
260-
add_action('litespeed_load_esi_block-' . $block, $hook) ;
261-
}
262-
263-
/**
264-
* Hook ESI params
265-
*
266-
* @since 1.1.3
267-
* @since 2.9.8.1 Changed hook name and params
268-
* @access public
269-
*/
270-
public static function hook_esi_param( $hook, $priority = 10, $args = 2 )
271-
{
272-
add_filter( 'litespeed_esi_params', $hook, $priority, $args ) ;
273-
}
274-
275-
/**
276-
* Hook widget default settings value
277-
*
278-
* @since 1.1.3
279-
* @access public
280-
*/
281-
public static function hook_widget_default_options($hook, $priority = 10, $args = 1)
282-
{
283-
add_filter('litespeed_widget_default_options', $hook, $priority, $args) ;
284-
}
285-
286-
/**
287-
* Generate ESI block url
288-
*
289-
* @since 1.1.3
290-
* @access public
291-
* @param string $control Cache control tag
292-
*/
293-
public static function esi_url( $block_id, $wrapper, $params = array(), $control = 'default', $silence = false, $preserved = false, $svar = false, $inline_val = false )
294-
{
295-
if ( $control === 'default' ) {
296-
$control = 'private,no-vary' ;
297-
}
298-
return ESI::sub_esi_block( $block_id, $wrapper, $params, $control, $silence, $preserved, $svar, $inline_val ) ;
299-
}
300-
301-
/**
302-
* Get ESI enable setting value
303-
*
304-
* @since 1.2.0
305-
* @access public
306-
*/
307-
public static function esi_enabled()
308-
{
309-
return Router::esi_enabled() ;
310-
}
311-
312-
/**
313-
* Get cache enable setting value
314-
*
315-
* @since 1.3
316-
* @access public
317-
*/
318-
public static function cache_enabled()
319-
{
320-
return defined( 'LITESPEED_ON' ) ;
321-
}
322-
323-
/**
324-
* Hook to check if need to bypass CDN or not
325-
*
326-
* @since 3.0
327-
*/
328-
public static function hook_can_cdn( $hook )
329-
{
330-
add_filter( 'litespeed_can_cdn', $hook ) ;
331-
}
332-
333245
}

src/core.cls.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,9 @@ protected function __construct()
5555

5656
/**
5757
* Load API hooks
58-
*
5958
* @since 3.0
6059
*/
61-
API::init();
60+
API::get_instance()->init();
6261

6362
if ( defined( 'LITESPEED_ON' ) ) {
6463
// Load third party detection if lscache enabled.
@@ -72,7 +71,6 @@ protected function __construct()
7271
/**
7372
* Register plugin activate/deactivate/uninstall hooks
7473
* NOTE: this can't be moved under after_setup_theme, otherwise activation will be bypassed somehow
75-
*
7674
* @since 2.7.1 Disabled admin&CLI check to make frontend able to enable cache too
7775
*/
7876
// if( is_admin() || defined( 'LITESPEED_CLI' ) ) {

src/esi.cls.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,12 @@ private function _register_esi_actions()
260260
add_action( 'rest_api_init', array( $this, 'load_esi_block' ), 101 ) ;
261261

262262
// Register ESI blocks
263-
add_action('litespeed_load_esi_block-widget', array($this, 'load_widget_block')) ;
264-
add_action('litespeed_load_esi_block-admin-bar', array($this, 'load_admin_bar_block')) ;
265-
add_action('litespeed_load_esi_block-comment-form', array($this, 'load_comment_form_block')) ;
263+
add_action('litespeed_esi_load-widget', array($this, 'load_widget_block')) ;
264+
add_action('litespeed_esi_load-admin-bar', array($this, 'load_admin_bar_block')) ;
265+
add_action('litespeed_esi_load-comment-form', array($this, 'load_comment_form_block')) ;
266266

267-
add_action('litespeed_load_esi_block-nonce', array( $this, 'load_nonce_block' ) ) ;
268-
add_action('litespeed_load_esi_block-esi', array( $this, 'load_esi_shortcode' ) ) ;
267+
add_action('litespeed_esi_load-nonce', array( $this, 'load_nonce_block' ) ) ;
268+
add_action('litespeed_esi_load-esi', array( $this, 'load_esi_shortcode' ) ) ;
269269
}
270270

271271
/**
@@ -285,20 +285,20 @@ public function esi_template( $template )
285285

286286
return LSCWP_DIR . 'tpl/esi.tpl.php' ;
287287
}
288-
$this->register_not_esi_actions() ;
289-
return $template ;
288+
$this->_register_not_esi_actions();
289+
return $template;
290290
}
291291

292292
/**
293293
* Register all of the hooks related to the esi logic of the plugin.
294294
* Specifically when the page is NOT an esi page.
295295
*
296296
* @since 1.1.3
297-
* @access public
297+
* @access private
298298
*/
299-
public function register_not_esi_actions()
299+
private function _register_not_esi_actions()
300300
{
301-
do_action('litespeed_is_not_esi_template') ;
301+
do_action( 'litespeed_tpl_normal' );
302302

303303
if ( ! Control::is_cacheable() ) {
304304
return ;
@@ -355,7 +355,7 @@ public static function sub_esi_block( $block_id, $wrapper, $params = array(), $c
355355
$params[ 'is_json' ] = 1 ;
356356
}
357357

358-
$params = apply_filters( 'litespeed_esi_params', $params, $block_id ) ;
358+
$params = apply_filters( 'litespeed_esi_params', $params, $block_id );
359359
$control = apply_filters('litespeed_esi_control', $control, $block_id ) ;
360360

361361
if ( !is_array($params) || !is_string($control) ) {
@@ -528,7 +528,7 @@ public function load_esi_block()
528528
}
529529
}
530530

531-
do_action('litespeed_load_esi_block-' . LSCACHE_IS_ESI, $params) ;
531+
do_action('litespeed_esi_load-' . LSCACHE_IS_ESI, $params) ;
532532
}
533533

534534
// BEGIN helper functions
@@ -540,9 +540,6 @@ public function load_esi_block()
540540
*
541541
* @since 1.1.3
542542
* @access public
543-
* @param array $options The current options selected.
544-
* @param WP_Widget $widget The widget to be configured.
545-
* @return array The updated options.
546543
*/
547544
public static function widget_default_options($options, $widget)
548545
{

thirdparty/autoptimize.cls.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@
33
* The Third Party integration with the Autoptimize plugin.
44
*
55
* @since 1.0.12
6-
* @package LiteSpeed_Cache
7-
* @subpackage LiteSpeed_Cache/thirdparty
8-
* @author LiteSpeed Technologies <[email protected]>
96
*/
107
namespace LiteSpeed\Thirdparty;
118

129
defined( 'WPINC' ) || exit;
1310

14-
use \LiteSpeed\API;
15-
1611
class Autoptimize
1712
{
1813
/**

thirdparty/avada.cls.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@
33
* The Third Party integration with the Avada plugin.
44
*
55
* @since 1.1.0
6-
* @package LiteSpeed_Cache
7-
* @subpackage LiteSpeed_Cache/thirdparty
8-
* @author LiteSpeed Technologies <[email protected]>
96
*/
107
namespace LiteSpeed\Thirdparty;
118

129
defined( 'WPINC' ) || exit;
1310

14-
use \LiteSpeed\API;
15-
1611
class Avada
1712
{
1813
/**

0 commit comments

Comments
 (0)