Skip to content

Commit

Permalink
3.0.0-rc8: woo api refactored; API ESI refactored;
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-hai committed Mar 21, 2020
1 parent c19d46c commit a8bb08a
Show file tree
Hide file tree
Showing 23 changed files with 128 additions and 302 deletions.
4 changes: 2 additions & 2 deletions litespeed-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Plugin Name: LiteSpeed Cache
* Plugin URI: https://www.litespeedtech.com/products/cache-plugins/wordpress-acceleration
* Description: High-performance page caching and site optimization from LiteSpeed
* Version: 3.0.0-rc7
* Version: 3.0.0-rc8
* Author: LiteSpeed Technologies
* Author URI: https://www.litespeedtech.com
* License: GPLv3
Expand Down Expand Up @@ -45,7 +45,7 @@
return;
}

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

! defined( 'LSCWP_CONTENT_DIR' ) && define( 'LSCWP_CONTENT_DIR', WP_CONTENT_DIR ) ;
! defined( 'LSCWP_DIR' ) && define( 'LSCWP_DIR', dirname( __FILE__ ) . '/' ) ;// Full absolute path '/var/www/html/***/wp-content/plugins/litespeed-cache/' or MU
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ Click on the `Advanced View` link at the top of the page, and several more tabs
* Avoid crawler PHP fatal error on Windows OS. (@technisolutions)
* **GUI** human readable seconds. (@MarkCanada)
* **3rd** Default added parallax-image to webp replacement for BB.
* API refactored. * NOTE: All 3rd party plugins that are using previous APIs, especially `LiteSpeed_Cache_API`, need to be adjusted to the latest one.*
* 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.
* **API** New hook `litespeed_update_confs` to settings update.
* **API** New Hooks `litespeed_frontend_shortcut` and `litespeed_backend_shortcut` for dropdown menu. (@callaloo)
* **API** Removed `litespeed_option_*` hooks. Use `litespeed_force_option` hook insteadly
Expand Down
7 changes: 2 additions & 5 deletions src/admin-display.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,15 +486,12 @@ public function display_messages()
* Appends LiteSpeed Cache settings to the widget edit settings screen.
* This will append the esi on/off selector and ttl text.
*
* @access public
* @since 1.1.0
* @param type $widget
* @param type $return
* @param type $instance
* @access public
*/
public function show_widget_edit($widget, $return, $instance)
{
require LSCWP_DIR . 'tpl/esi_widget_edit.php' ;
require LSCWP_DIR . 'tpl/esi_widget_edit.php';
}

/**
Expand Down
154 changes: 33 additions & 121 deletions src/api.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,26 @@ class API extends Base
const WIDGET_O_ESIENABLE = ESI::WIDGET_O_ESIENABLE ;
const WIDGET_O_TTL = ESI::WIDGET_O_TTL ;

protected static $_instance;

/**
* Instance
*
* @since 3.0
* @access protected
*/
protected function __construct()
{
}

/**
* Define hooks to be used in other plugins.
*
* The benefit to use hooks other than functions is no need to detech if LSCWP enabled and function existed or not anymore
*
* @since 3.0
*/
public static function init()
public function init()
{
/**
* Init
Expand Down Expand Up @@ -101,7 +113,12 @@ public static function init()
* ESI
*/
// API::nonce_action( $action ) & API::nonce( $action = -1, $defence_for_html_filter = true ) -> Action `litespeed_nonce`

add_filter( 'litespeed_esi_status', __NAMESPACE__ . '\Router::esi_enabled' ); // API::esi_enabled() -> Filter `litespeed_esi_status` // Get ESI enable status
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
// API::hook_widget_default_options( $hook ) -> Filter `litespeed_widget_default_options` // Hook widget default settings value. Currently used in Woo 3rd
// API::hook_esi_param( $hook ) -> Filter `litespeed_esi_params`
// API::hook_tpl_not_esi($hook) && Action `litespeed_is_not_esi_template` -> Action `litespeed_tpl_normal`
// API::hook_tpl_esi($block, $hook) -> Action `litespeed_esi_block-$block` // add_action( 'litespeed_esi_load-' . $block, $hook )

/**
* Vary
Expand All @@ -115,13 +132,22 @@ public static function init()

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

/**
* GUI
*/
// API::clean_wrapper_begin( $counter = false ) -> Filter `litespeed_clean_wrapper_begin` // Start a to-be-removed html wrapper
add_filter( 'litespeed_clean_wrapper_begin', __NAMESPACE__ . '\GUI::clean_wrapper_begin' );
// API::clean_wrapper_end( $counter = false ) -> Filter `litespeed_clean_wrapper_end` // End a to-be-removed html wrapper
add_filter( 'litespeed_clean_wrapper_end', __NAMESPACE__ . '\GUI::clean_wrapper_end' );

/**
* Mist
*/
add_action( 'litespeed_debug', __NAMESPACE__ . '\Debug2::debug' ); // API::debug()-> Action `litespeed_debug`
add_action( 'litespeed_debug2', __NAMESPACE__ . '\Debug2::debug2' ); // API::debug2()-> Action `litespeed_debug2`
add_action( 'litespeed_disable_all', array( $this, '_disable_all' ) ); // API::disable_all( $reason ) -> Action `litespeed_disable_all`

add_action( 'litspeed_after_admin_init', __CLASS__ . '::after_admin_init' );
add_action( 'litspeed_after_admin_init', array( $this, '_after_admin_init' ) );
}

/**
Expand All @@ -130,7 +156,7 @@ public static function init()
* @since 3.0
* @access public
*/
public static function after_admin_init()
public function _after_admin_init()
{
/**
* GUI
Expand All @@ -142,38 +168,16 @@ public static function after_admin_init()
}

/**
* Disable All
* Disable All (Note: Not for direct call, always use Hooks)
*
* @since 2.9.7.2
* @access public
*/
public static function disable_all( $reason )
public function _disable_all( $reason )
{
do_action( 'litespeed_debug', '[API] Disabled_all due to ' . $reason );

! defined( 'LITESPEED_DISABLE_ALL' ) && define( 'LITESPEED_DISABLE_ALL', true ) ;
}

/**
* Start a to-be-removed html wrapper
*
* @since 1.4
* @access public
*/
public static function clean_wrapper_begin( $counter = false )
{
return GUI::clean_wrapper_begin( $counter ) ;
}

/**
* End a to-be-removed html wrapper
*
* @since 1.4
* @access public
*/
public static function clean_wrapper_end( $counter = false )
{
return GUI::clean_wrapper_end( $counter ) ;
! defined( 'LITESPEED_DISABLE_ALL' ) && define( 'LITESPEED_DISABLE_ALL', true );
}

/**
Expand Down Expand Up @@ -238,96 +242,4 @@ public static function vary_append_commenter()
Vary::get_instance()->append_commenter() ;
}

/**
* Hook not ESI template
*
* @since 1.1.3
* @access public
*/
public static function hook_tpl_not_esi($hook)
{
add_action('litespeed_is_not_esi_template', $hook) ;
}

/**
* Hook ESI template block
*
* @since 1.1.3
* @access public
*/
public static function hook_tpl_esi($block, $hook)
{
add_action('litespeed_load_esi_block-' . $block, $hook) ;
}

/**
* Hook ESI params
*
* @since 1.1.3
* @since 2.9.8.1 Changed hook name and params
* @access public
*/
public static function hook_esi_param( $hook, $priority = 10, $args = 2 )
{
add_filter( 'litespeed_esi_params', $hook, $priority, $args ) ;
}

/**
* Hook widget default settings value
*
* @since 1.1.3
* @access public
*/
public static function hook_widget_default_options($hook, $priority = 10, $args = 1)
{
add_filter('litespeed_widget_default_options', $hook, $priority, $args) ;
}

/**
* Generate ESI block url
*
* @since 1.1.3
* @access public
* @param string $control Cache control tag
*/
public static function esi_url( $block_id, $wrapper, $params = array(), $control = 'default', $silence = false, $preserved = false, $svar = false, $inline_val = false )
{
if ( $control === 'default' ) {
$control = 'private,no-vary' ;
}
return ESI::sub_esi_block( $block_id, $wrapper, $params, $control, $silence, $preserved, $svar, $inline_val ) ;
}

/**
* Get ESI enable setting value
*
* @since 1.2.0
* @access public
*/
public static function esi_enabled()
{
return Router::esi_enabled() ;
}

/**
* Get cache enable setting value
*
* @since 1.3
* @access public
*/
public static function cache_enabled()
{
return defined( 'LITESPEED_ON' ) ;
}

/**
* Hook to check if need to bypass CDN or not
*
* @since 3.0
*/
public static function hook_can_cdn( $hook )
{
add_filter( 'litespeed_can_cdn', $hook ) ;
}

}
4 changes: 1 addition & 3 deletions src/core.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ protected function __construct()

/**
* Load API hooks
*
* @since 3.0
*/
API::init();
API::get_instance()->init();

if ( defined( 'LITESPEED_ON' ) ) {
// Load third party detection if lscache enabled.
Expand All @@ -72,7 +71,6 @@ protected function __construct()
/**
* Register plugin activate/deactivate/uninstall hooks
* NOTE: this can't be moved under after_setup_theme, otherwise activation will be bypassed somehow
*
* @since 2.7.1 Disabled admin&CLI check to make frontend able to enable cache too
*/
// if( is_admin() || defined( 'LITESPEED_CLI' ) ) {
Expand Down
27 changes: 12 additions & 15 deletions src/esi.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,12 @@ private function _register_esi_actions()
add_action( 'rest_api_init', array( $this, 'load_esi_block' ), 101 ) ;

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

add_action('litespeed_load_esi_block-nonce', array( $this, 'load_nonce_block' ) ) ;
add_action('litespeed_load_esi_block-esi', array( $this, 'load_esi_shortcode' ) ) ;
add_action('litespeed_esi_load-nonce', array( $this, 'load_nonce_block' ) ) ;
add_action('litespeed_esi_load-esi', array( $this, 'load_esi_shortcode' ) ) ;
}

/**
Expand All @@ -285,20 +285,20 @@ public function esi_template( $template )

return LSCWP_DIR . 'tpl/esi.tpl.php' ;
}
$this->register_not_esi_actions() ;
return $template ;
$this->_register_not_esi_actions();
return $template;
}

/**
* Register all of the hooks related to the esi logic of the plugin.
* Specifically when the page is NOT an esi page.
*
* @since 1.1.3
* @access public
* @access private
*/
public function register_not_esi_actions()
private function _register_not_esi_actions()
{
do_action('litespeed_is_not_esi_template') ;
do_action( 'litespeed_tpl_normal' );

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

$params = apply_filters( 'litespeed_esi_params', $params, $block_id ) ;
$params = apply_filters( 'litespeed_esi_params', $params, $block_id );
$control = apply_filters('litespeed_esi_control', $control, $block_id ) ;

if ( !is_array($params) || !is_string($control) ) {
Expand Down Expand Up @@ -528,7 +528,7 @@ public function load_esi_block()
}
}

do_action('litespeed_load_esi_block-' . LSCACHE_IS_ESI, $params) ;
do_action('litespeed_esi_load-' . LSCACHE_IS_ESI, $params) ;
}

// BEGIN helper functions
Expand All @@ -540,9 +540,6 @@ public function load_esi_block()
*
* @since 1.1.3
* @access public
* @param array $options The current options selected.
* @param WP_Widget $widget The widget to be configured.
* @return array The updated options.
*/
public static function widget_default_options($options, $widget)
{
Expand Down
5 changes: 0 additions & 5 deletions thirdparty/autoptimize.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
* The Third Party integration with the Autoptimize plugin.
*
* @since 1.0.12
* @package LiteSpeed_Cache
* @subpackage LiteSpeed_Cache/thirdparty
* @author LiteSpeed Technologies <[email protected]>
*/
namespace LiteSpeed\Thirdparty;

defined( 'WPINC' ) || exit;

use \LiteSpeed\API;

class Autoptimize
{
/**
Expand Down
5 changes: 0 additions & 5 deletions thirdparty/avada.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
* The Third Party integration with the Avada plugin.
*
* @since 1.1.0
* @package LiteSpeed_Cache
* @subpackage LiteSpeed_Cache/thirdparty
* @author LiteSpeed Technologies <[email protected]>
*/
namespace LiteSpeed\Thirdparty;

defined( 'WPINC' ) || exit;

use \LiteSpeed\API;

class Avada
{
/**
Expand Down
Loading

0 comments on commit a8bb08a

Please sign in to comment.