LiteSpeed Cache - Version 2.9.4

Version Description

  • Feb 27 2019 =
  • REST: New REST class with better WP5 Gutenberg and internal REST call support when ESI is embedded.
  • ESI: ESI block ID is now in plain text in ESI URL parameters.
  • ESI: Fixed a redundant ESI 301 redirect when comma is in ESI URL.
  • ESI: REST call can now parse shortcodes in ESI.
  • API: Changed ESI parse_esi_param() function to private and load_esi_block function to non-static.
  • API: Added litespeed_is_json hook for buffer JSON conversion.
  • GUI: Prepended plugin name to new version notification banner.
  • 3rd: WPML multi domains can now be handled in optimization without CDN tricks.
Download this release

Release Info

Developer LiteSpeedTech
Plugin Icon 128x128 LiteSpeed Cache
Version 2.9.4
Comparing to
See all releases

Code changes from version 2.9.3 to 2.9.4

admin/tpl/inc/banner_promo.new_version.php CHANGED
@@ -53,7 +53,7 @@ if ( $check_only ) {
53
  <div class="litespeed-banner-promo-logo"></div>
54
 
55
  <div class="litespeed-banner-promo-content">
56
- <h3 class="litespeed-banner-title litespeed-top15"><?php echo __( 'New Version Available!', 'litespeed-cache' ) ; ?></h3>
57
  <div class="litespeed-banner-description">
58
  <div class="litespeed-banner-description-padding-right-15">
59
  <p class="litespeed-banner-desciption-content">
53
  <div class="litespeed-banner-promo-logo"></div>
54
 
55
  <div class="litespeed-banner-promo-content">
56
+ <h3 class="litespeed-banner-title litespeed-top15"><?php echo __( 'LiteSpeed Cache', 'litespeed-cache' ) ; ?>: <?php echo __( 'New Version Available!', 'litespeed-cache' ) ; ?></h3>
57
  <div class="litespeed-banner-description">
58
  <div class="litespeed-banner-description-padding-right-15">
59
  <p class="litespeed-banner-desciption-content">
inc/control.class.php CHANGED
@@ -547,16 +547,8 @@ class LiteSpeed_Cache_Control
547
  $instance = self::get_instance() ;
548
 
549
  // Apply 3rd party filter
550
- // Parse ESI block id
551
- $esi_id = false ;
552
- if ( defined( 'LSCACHE_IS_ESI' ) ) {
553
- $params = LiteSpeed_Cache_ESI::parse_esi_param() ;
554
- if ( $params !== false ) {
555
- $esi_id = $params[LiteSpeed_Cache_ESI::PARAM_BLOCK_ID] ;
556
- }
557
- }
558
  // NOTE: Hook always needs to run asap because some 3rd party set is_mobile in this hook
559
- do_action('litespeed_cache_api_control', $esi_id) ;
560
 
561
  // if is not cacheable, terminate check
562
  if ( ! self::is_cacheable() ) {
547
  $instance = self::get_instance() ;
548
 
549
  // Apply 3rd party filter
 
 
 
 
 
 
 
 
550
  // NOTE: Hook always needs to run asap because some 3rd party set is_mobile in this hook
551
+ do_action('litespeed_cache_api_control', defined( 'LSCACHE_IS_ESI' ) ? LSCACHE_IS_ESI : false ) ; // Pass ESI block id
552
 
553
  // if is not cacheable, terminate check
554
  if ( ! self::is_cacheable() ) {
inc/esi.class.php CHANGED
@@ -24,11 +24,9 @@ class LiteSpeed_Cache_ESI
24
  private $_esi_preserve_list = array() ;
25
 
26
  const QS_ACTION = 'lsesi' ;
27
- const POSTTYPE = 'lswcp' ;
28
  const QS_PARAMS = 'esi' ;
29
 
30
  const PARAM_ARGS = 'args' ;
31
- const PARAM_BLOCK_ID = 'block_id' ;
32
  const PARAM_ID = 'id' ;
33
  const PARAM_INSTANCE = 'instance' ;
34
  const PARAM_NAME = 'name' ;
@@ -45,6 +43,7 @@ class LiteSpeed_Cache_ESI
45
  private function __construct()
46
  {
47
  add_action( 'template_include', 'LiteSpeed_Cache_ESI::esi_template', 100 ) ;
 
48
  add_action( 'load-widgets.php', 'LiteSpeed_Cache_Purge::purge_widget' ) ;
49
  add_action( 'wp_update_comment_count', 'LiteSpeed_Cache_Purge::purge_comment_widget' ) ;
50
 
@@ -55,18 +54,8 @@ class LiteSpeed_Cache_ESI
55
  * Recover REQUEST_URI
56
  * @since 1.8.1
57
  */
58
- if ( ! empty( $_GET[ self::QS_ACTION ] ) && $_GET[ self::QS_ACTION ] == self::POSTTYPE ) {
59
- define( 'LSCACHE_IS_ESI', true ) ;
60
-
61
- ! empty( $_SERVER[ 'ESI_REFERER' ] ) && defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( '[ESI] ESI_REFERER: ' . $_SERVER[ 'ESI_REFERER' ] ) ;
62
-
63
- /**
64
- * Only when ESI's parent is not REST, replace REQUEST_URI to avoid breaking WP5 editor REST call
65
- * @since 2.9.3
66
- */
67
- if ( ! empty( $_SERVER[ 'ESI_REFERER' ] ) && ! LiteSpeed_Cache_Utility::is_rest( $_SERVER[ 'ESI_REFERER' ] ) ) {
68
- $_SERVER[ 'REQUEST_URI' ] = $_SERVER[ 'ESI_REFERER' ] ;
69
- }
70
  }
71
 
72
  /**
@@ -136,6 +125,47 @@ class LiteSpeed_Cache_ESI
136
  self::$has_esi = true ;
137
  }
138
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  /**
140
  * Hooked to the template_include action.
141
  * Selects the esi template file when the post type is a LiteSpeed ESI page.
@@ -149,8 +179,6 @@ class LiteSpeed_Cache_ESI
149
  {
150
  // Check if is an ESI request
151
  if ( defined( 'LSCACHE_IS_ESI' ) ) {
152
- self::get_instance()->register_esi_actions() ;
153
-
154
  LiteSpeed_Cache_Log::debug( '[ESI] calling template' ) ;
155
 
156
  return LSCWP_DIR . 'tpl/esi.tpl.php' ;
@@ -159,23 +187,6 @@ class LiteSpeed_Cache_ESI
159
  return $template ;
160
  }
161
 
162
- /**
163
- * Register all of the hooks related to the esi logic of the plugin.
164
- * Specifically when the page IS an esi page.
165
- *
166
- * @since 1.1.3
167
- * @access public
168
- */
169
- public function register_esi_actions()
170
- {
171
- add_action('litespeed_cache_load_esi_block-widget', array($this, 'load_widget_block')) ;
172
- add_action('litespeed_cache_load_esi_block-admin-bar', array($this, 'load_admin_bar_block')) ;
173
- add_action('litespeed_cache_load_esi_block-comment-form', array($this, 'load_comment_form_block')) ;
174
-
175
- add_action('litespeed_cache_load_esi_block-lscwp_nonce_esi', array( $this, 'load_nonce_block' ) ) ;
176
- add_action('litespeed_cache_load_esi_block-esi', array( $this, 'load_esi_shortcode' ) ) ;
177
- }
178
-
179
  /**
180
  * Register all of the hooks related to the esi logic of the plugin.
181
  * Specifically when the page is NOT an esi page.
@@ -233,25 +244,42 @@ class LiteSpeed_Cache_ESI
233
  return false ;
234
  }
235
 
236
- $params[ self::PARAM_BLOCK_ID ] = $block_id ;
237
  if ( $silence ) {
238
  // Don't add comment to esi block ( orignal for nonce used in tag property data-nonce='esi_block' )
239
  $params[ '_ls_silence' ] = true ;
240
  }
241
 
 
 
 
 
242
  $params = apply_filters('litespeed_cache_sub_esi_params-' . $block_id, $params) ;
243
  $control = apply_filters('litespeed_cache_sub_esi_control-' . $block_id, $control) ;
244
  if ( !is_array($params) || !is_string($control) ) {
245
- defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( "Sub esi hooks returned Params: \n" . var_export($params, true) . "\ncache control: \n" . var_export($control, true) ) ;
246
 
247
  return false ;
248
  }
249
 
250
- $url = trailingslashit( wp_make_link_relative( home_url() ) ) . '?' . self::QS_ACTION . '=' . self::POSTTYPE ;
 
 
 
251
  if ( ! empty( $control ) ) {
252
- $url .= '&_control=' . $control ;
 
 
 
253
  }
254
- $url .= '&' . self::QS_PARAMS . '=' . urlencode(base64_encode(serialize($params))) ;
 
 
 
 
 
 
 
 
255
 
256
  $output = "<esi:include src='$url'" ;
257
  if ( ! empty( $control ) ) {
@@ -288,9 +316,9 @@ class LiteSpeed_Cache_ESI
288
  * Parses the request parameters on an ESI request
289
  *
290
  * @since 1.1.3
291
- * @access public
292
  */
293
- public static function parse_esi_param()
294
  {
295
  if ( ! isset($_REQUEST[self::QS_PARAMS]) ) {
296
  return false ;
@@ -300,9 +328,11 @@ class LiteSpeed_Cache_ESI
300
  if ( $unencrypted === false ) {
301
  return false ;
302
  }
303
- $unencoded = urldecode($unencrypted) ;
304
- $params = unserialize($unencoded) ;
305
- if ( $params === false || ! isset($params[self::PARAM_BLOCK_ID]) ) {
 
 
306
  return false ;
307
  }
308
 
@@ -315,19 +345,16 @@ class LiteSpeed_Cache_ESI
315
  * @since 1.1.3
316
  * @access public
317
  */
318
- public static function load_esi_block()
319
  {
320
- $params = self::parse_esi_param() ;
321
- if ( $params === false ) {
322
- return ;
323
- }
324
- $esi_id = $params[ self::PARAM_BLOCK_ID ] ;
325
  if ( defined( 'LSCWP_LOG' ) ) {
326
  $logInfo = '------- ESI ------- ' ;
327
  if( ! empty( $params[ self::PARAM_NAME ] ) ) {
328
  $logInfo .= ' Name: ' . $params[ self::PARAM_NAME ] . ' ----- ' ;
329
  }
330
- $logInfo .= $esi_id . ' -------' ;
331
  LiteSpeed_Cache_Log::debug( $logInfo ) ;
332
  }
333
 
@@ -335,8 +362,16 @@ class LiteSpeed_Cache_ESI
335
  define( 'LSCACHE_ESI_SILENCE', true ) ;
336
  }
337
 
 
 
 
 
 
 
 
 
338
  LiteSpeed_Cache_Tag::add( rtrim( LiteSpeed_Cache_Tag::TYPE_ESI, '.' ) ) ;
339
- LiteSpeed_Cache_Tag::add( LiteSpeed_Cache_Tag::TYPE_ESI . $esi_id ) ;
340
 
341
  // LiteSpeed_Cache_Log::debug(var_export($params, true ));
342
 
@@ -356,7 +391,7 @@ class LiteSpeed_Cache_ESI
356
  }
357
  }
358
 
359
- do_action('litespeed_cache_load_esi_block-' . $esi_id, $params) ;
360
  }
361
 
362
  // BEGIN helper functions
@@ -530,17 +565,7 @@ class LiteSpeed_Cache_ESI
530
  */
531
  public function load_admin_bar_block( $params )
532
  {
533
- ob_start() ;
534
  wp_admin_bar_render() ;
535
- $output = ob_get_contents() ;
536
- ob_end_clean() ;
537
-
538
- if ( ! empty( $params[ 'is_json' ] ) ) {
539
- $output = json_encode( $output ) ;
540
- $output = trim( $output, '"' ) ;
541
- }
542
-
543
- echo $output ;
544
 
545
  if ( ! LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_ESI_CACHE_ADMBAR ) ) {
546
  LiteSpeed_Cache_Control::set_nocache( 'build-in set to not cacheable' ) ;
@@ -563,17 +588,7 @@ class LiteSpeed_Cache_ESI
563
  */
564
  public function load_comment_form_block( $params )
565
  {
566
- ob_start() ;
567
  comment_form( $params[ self::PARAM_ARGS ], $params[ self::PARAM_ID ] ) ;
568
- $output = ob_get_contents() ;
569
- ob_end_clean() ;
570
-
571
- if ( ! empty( $params[ 'is_json' ] ) ) {
572
- $output = json_encode( $output ) ;
573
- $output = trim( $output, '"' ) ;
574
- }
575
-
576
- echo $output ;
577
 
578
  if ( ! LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_ESI_CACHE_COMMFORM ) ) {
579
  LiteSpeed_Cache_Control::set_nocache( 'build-in set to not cacheable' ) ;
@@ -617,8 +632,6 @@ class LiteSpeed_Cache_ESI
617
  */
618
  public function load_esi_shortcode( $params )
619
  {
620
- unset( $params[ self::PARAM_BLOCK_ID ] ) ;
621
-
622
  if ( isset( $params[ 'ttl' ] ) ) {
623
  if ( ! $params[ 'ttl' ] ) {
624
  LiteSpeed_Cache_Control::set_nocache( 'ESI shortcode att ttl=0' ) ;
24
  private $_esi_preserve_list = array() ;
25
 
26
  const QS_ACTION = 'lsesi' ;
 
27
  const QS_PARAMS = 'esi' ;
28
 
29
  const PARAM_ARGS = 'args' ;
 
30
  const PARAM_ID = 'id' ;
31
  const PARAM_INSTANCE = 'instance' ;
32
  const PARAM_NAME = 'name' ;
43
  private function __construct()
44
  {
45
  add_action( 'template_include', 'LiteSpeed_Cache_ESI::esi_template', 100 ) ;
46
+
47
  add_action( 'load-widgets.php', 'LiteSpeed_Cache_Purge::purge_widget' ) ;
48
  add_action( 'wp_update_comment_count', 'LiteSpeed_Cache_Purge::purge_comment_widget' ) ;
49
 
54
  * Recover REQUEST_URI
55
  * @since 1.8.1
56
  */
57
+ if ( ! empty( $_GET[ self::QS_ACTION ] ) ) {
58
+ $this->_register_esi_actions() ;
 
 
 
 
 
 
 
 
 
 
59
  }
60
 
61
  /**
125
  self::$has_esi = true ;
126
  }
127
 
128
+ /**
129
+ * Register all of the hooks related to the esi logic of the plugin.
130
+ * Specifically when the page IS an esi page.
131
+ *
132
+ * @since 1.1.3
133
+ * @access private
134
+ */
135
+ private function _register_esi_actions()
136
+ {
137
+ define( 'LSCACHE_IS_ESI', $_GET[ self::QS_ACTION ] ) ;// Reused this to ESI block ID
138
+
139
+ ! empty( $_SERVER[ 'ESI_REFERER' ] ) && defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( '[ESI] ESI_REFERER: ' . $_SERVER[ 'ESI_REFERER' ] ) ;
140
+
141
+ /**
142
+ * Only when ESI's parent is not REST, replace REQUEST_URI to avoid breaking WP5 editor REST call
143
+ * @since 2.9.3
144
+ */
145
+ if ( ! empty( $_SERVER[ 'ESI_REFERER' ] ) && ! LiteSpeed_Cache_REST::get_instance()->is_rest( $_SERVER[ 'ESI_REFERER' ] ) ) {
146
+ $_SERVER[ 'REQUEST_URI' ] = $_SERVER[ 'ESI_REFERER' ] ;
147
+ }
148
+
149
+ if ( ! empty( $_SERVER[ 'ESI_CONTENT_TYPE' ] ) && strpos( $_SERVER[ 'ESI_CONTENT_TYPE' ], 'application/json' ) === 0 ) {
150
+ add_filter( 'litespeed_is_json', '__return_true' ) ;
151
+ }
152
+
153
+ /**
154
+ * Make REST call be able to parse ESI
155
+ * NOTE: Not effective due to ESI req are all to `/` yet
156
+ * @since 2.9.4
157
+ */
158
+ add_action( 'rest_api_init', array( $this, 'load_esi_block' ), 101 ) ;
159
+
160
+ // Register ESI blocks
161
+ add_action('litespeed_cache_load_esi_block-widget', array($this, 'load_widget_block')) ;
162
+ add_action('litespeed_cache_load_esi_block-admin-bar', array($this, 'load_admin_bar_block')) ;
163
+ add_action('litespeed_cache_load_esi_block-comment-form', array($this, 'load_comment_form_block')) ;
164
+
165
+ add_action('litespeed_cache_load_esi_block-lscwp_nonce_esi', array( $this, 'load_nonce_block' ) ) ;
166
+ add_action('litespeed_cache_load_esi_block-esi', array( $this, 'load_esi_shortcode' ) ) ;
167
+ }
168
+
169
  /**
170
  * Hooked to the template_include action.
171
  * Selects the esi template file when the post type is a LiteSpeed ESI page.
179
  {
180
  // Check if is an ESI request
181
  if ( defined( 'LSCACHE_IS_ESI' ) ) {
 
 
182
  LiteSpeed_Cache_Log::debug( '[ESI] calling template' ) ;
183
 
184
  return LSCWP_DIR . 'tpl/esi.tpl.php' ;
187
  return $template ;
188
  }
189
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  /**
191
  * Register all of the hooks related to the esi logic of the plugin.
192
  * Specifically when the page is NOT an esi page.
244
  return false ;
245
  }
246
 
 
247
  if ( $silence ) {
248
  // Don't add comment to esi block ( orignal for nonce used in tag property data-nonce='esi_block' )
249
  $params[ '_ls_silence' ] = true ;
250
  }
251
 
252
+ if ( LiteSpeed_Cache_REST::get_instance()->is_rest() || LiteSpeed_Cache_REST::get_instance()->is_internal_rest() ) {
253
+ $params[ 'is_json' ] = 1 ;
254
+ }
255
+
256
  $params = apply_filters('litespeed_cache_sub_esi_params-' . $block_id, $params) ;
257
  $control = apply_filters('litespeed_cache_sub_esi_control-' . $block_id, $control) ;
258
  if ( !is_array($params) || !is_string($control) ) {
259
+ defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( "[ESI] 🛑 Sub hooks returned Params: \n" . var_export($params, true) . "\ncache control: \n" . var_export($control, true) ) ;
260
 
261
  return false ;
262
  }
263
 
264
+ // Build params for URL
265
+ $appended_params = array(
266
+ self::QS_ACTION => $block_id,
267
+ ) ;
268
  if ( ! empty( $control ) ) {
269
+ $appended_params[ '_control' ] = $control ;
270
+ }
271
+ if ( $params ) {
272
+ $appended_params[ self::QS_PARAMS ] = base64_encode( serialize( $params ) ) ;
273
  }
274
+
275
+ /**
276
+ * Escape potential chars
277
+ * @since 2.9.4
278
+ */
279
+ $appended_params = array_map( 'urlencode', $appended_params ) ;
280
+
281
+ // Generate ESI URL
282
+ $url = add_query_arg( $appended_params, trailingslashit( wp_make_link_relative( home_url() ) ) ) ;
283
 
284
  $output = "<esi:include src='$url'" ;
285
  if ( ! empty( $control ) ) {
316
  * Parses the request parameters on an ESI request
317
  *
318
  * @since 1.1.3
319
+ * @access private
320
  */
321
+ private function _parse_esi_param()
322
  {
323
  if ( ! isset($_REQUEST[self::QS_PARAMS]) ) {
324
  return false ;
328
  if ( $unencrypted === false ) {
329
  return false ;
330
  }
331
+
332
+ LiteSpeed_Cache_Log::debug2( '[ESI] parms', $unencrypted ) ;
333
+ // $unencoded = urldecode($unencrypted) ; no need to do this as $_GET is already parsed
334
+ $params = unserialize( $unencrypted ) ;
335
+ if ( $params === false ) {
336
  return false ;
337
  }
338
 
345
  * @since 1.1.3
346
  * @access public
347
  */
348
+ public function load_esi_block()
349
  {
350
+ $params = $this->_parse_esi_param() ;
351
+
 
 
 
352
  if ( defined( 'LSCWP_LOG' ) ) {
353
  $logInfo = '------- ESI ------- ' ;
354
  if( ! empty( $params[ self::PARAM_NAME ] ) ) {
355
  $logInfo .= ' Name: ' . $params[ self::PARAM_NAME ] . ' ----- ' ;
356
  }
357
+ $logInfo .= LSCACHE_IS_ESI . ' -------' ;
358
  LiteSpeed_Cache_Log::debug( $logInfo ) ;
359
  }
360
 
362
  define( 'LSCACHE_ESI_SILENCE', true ) ;
363
  }
364
 
365
+ /**
366
+ * Buffer needs to be JSON format
367
+ * @since 2.9.4
368
+ */
369
+ if ( ! empty( $params[ 'is_json' ] ) ) {
370
+ add_filter( 'litespeed_is_json', '__return_true' ) ;
371
+ }
372
+
373
  LiteSpeed_Cache_Tag::add( rtrim( LiteSpeed_Cache_Tag::TYPE_ESI, '.' ) ) ;
374
+ LiteSpeed_Cache_Tag::add( LiteSpeed_Cache_Tag::TYPE_ESI . LSCACHE_IS_ESI ) ;
375
 
376
  // LiteSpeed_Cache_Log::debug(var_export($params, true ));
377
 
391
  }
392
  }
393
 
394
+ do_action('litespeed_cache_load_esi_block-' . LSCACHE_IS_ESI, $params) ;
395
  }
396
 
397
  // BEGIN helper functions
565
  */
566
  public function load_admin_bar_block( $params )
567
  {
 
568
  wp_admin_bar_render() ;
 
 
 
 
 
 
 
 
 
569
 
570
  if ( ! LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_ESI_CACHE_ADMBAR ) ) {
571
  LiteSpeed_Cache_Control::set_nocache( 'build-in set to not cacheable' ) ;
588
  */
589
  public function load_comment_form_block( $params )
590
  {
 
591
  comment_form( $params[ self::PARAM_ARGS ], $params[ self::PARAM_ID ] ) ;
 
 
 
 
 
 
 
 
 
592
 
593
  if ( ! LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_ESI_CACHE_COMMFORM ) ) {
594
  LiteSpeed_Cache_Control::set_nocache( 'build-in set to not cacheable' ) ;
632
  */
633
  public function load_esi_shortcode( $params )
634
  {
 
 
635
  if ( isset( $params[ 'ttl' ] ) ) {
636
  if ( ! $params[ 'ttl' ] ) {
637
  LiteSpeed_Cache_Control::set_nocache( 'ESI shortcode att ttl=0' ) ;
inc/litespeed-cache.class.php CHANGED
@@ -26,7 +26,7 @@ class LiteSpeed_Cache
26
  const NAME = 'LiteSpeed Cache' ;
27
  const PLUGIN_NAME = 'litespeed-cache' ;
28
  const PLUGIN_FILE = 'litespeed-cache/litespeed-cache.php' ;
29
- const PLUGIN_VERSION = '2.9.3' ;
30
 
31
  const PAGE_EDIT_HTACCESS = 'lscache-edit-htaccess' ;
32
 
@@ -130,6 +130,12 @@ class LiteSpeed_Cache
130
  delete_option( LiteSpeed_Cache_Purge::PURGE_QUEUE ) ;
131
  }
132
 
 
 
 
 
 
 
133
  /**
134
  * Added hook before init
135
  * @since 1.6.6
@@ -561,21 +567,25 @@ class LiteSpeed_Cache
561
  $buffer .= $this->footer_comment ;
562
  }
563
 
564
- // If ESI req is JSON, give the content json format @since 2.9.3
 
 
 
 
565
  if ( defined( 'LSCACHE_IS_ESI' ) ) {
566
  LiteSpeed_Cache_Log::debug( '[Core] ESI----------Start--------' ) ;
567
  LiteSpeed_Cache_Log::debug( $buffer ) ;
568
  LiteSpeed_Cache_Log::debug( '[Core] ESI----------End--------' ) ;
 
569
 
570
- if ( ! empty( $_SERVER[ 'ESI_CONTENT_TYPE' ] ) && strpos( $_SERVER[ 'ESI_CONTENT_TYPE' ], 'application/json' ) === 0 ) {
571
- if ( json_decode( $buffer, true ) == NULL ) {
572
- LiteSpeed_Cache_Log::debug( '[Core] Buffer converting to JSON' ) ;
573
- $buffer = json_encode( $buffer ) ;
574
- $buffer = trim( $buffer, '"' ) ;
575
- }
576
- else {
577
- LiteSpeed_Cache_Log::debug( '[Core] JSON Buffer' ) ;
578
- }
579
  }
580
  }
581
 
@@ -628,8 +638,11 @@ class LiteSpeed_Cache
628
  $running_info_showing = false ;
629
  LiteSpeed_Cache_Log::debug( '[Core] ESI silence' ) ;
630
  }
631
- // Silence comment for json req @since 2.9.3
632
- if ( LiteSpeed_Cache_Utility::is_rest() || LiteSpeed_Cache_Router::is_ajax() ) {
 
 
 
633
  $running_info_showing = false ;
634
  LiteSpeed_Cache_Log::debug( '[Core] Silence Comment due to REST/AJAX' ) ;
635
  }
26
  const NAME = 'LiteSpeed Cache' ;
27
  const PLUGIN_NAME = 'litespeed-cache' ;
28
  const PLUGIN_FILE = 'litespeed-cache/litespeed-cache.php' ;
29
+ const PLUGIN_VERSION = '2.9.4' ;
30
 
31
  const PAGE_EDIT_HTACCESS = 'lscache-edit-htaccess' ;
32
 
130
  delete_option( LiteSpeed_Cache_Purge::PURGE_QUEUE ) ;
131
  }
132
 
133
+ /**
134
+ * Hook internal REST
135
+ * @since 2.9.4
136
+ */
137
+ LiteSpeed_Cache_REST::get_instance() ;
138
+
139
  /**
140
  * Added hook before init
141
  * @since 1.6.6
567
  $buffer .= $this->footer_comment ;
568
  }
569
 
570
+ /**
571
+ * If ESI req is JSON, give the content JSON format
572
+ * @since 2.9.3
573
+ * @since 2.9.4 ESI req could be from internal REST call, so moved json_encode out of this cond
574
+ */
575
  if ( defined( 'LSCACHE_IS_ESI' ) ) {
576
  LiteSpeed_Cache_Log::debug( '[Core] ESI----------Start--------' ) ;
577
  LiteSpeed_Cache_Log::debug( $buffer ) ;
578
  LiteSpeed_Cache_Log::debug( '[Core] ESI----------End--------' ) ;
579
+ }
580
 
581
+ if ( apply_filters( 'litespeed_is_json', false ) ) {
582
+ if ( json_decode( $buffer, true ) == NULL ) {
583
+ LiteSpeed_Cache_Log::debug( '[Core] Buffer converting to JSON' ) ;
584
+ $buffer = json_encode( $buffer ) ;
585
+ $buffer = trim( $buffer, '"' ) ;
586
+ }
587
+ else {
588
+ LiteSpeed_Cache_Log::debug( '[Core] JSON Buffer' ) ;
 
589
  }
590
  }
591
 
638
  $running_info_showing = false ;
639
  LiteSpeed_Cache_Log::debug( '[Core] ESI silence' ) ;
640
  }
641
+ /**
642
+ * Silence comment for json req
643
+ * @since 2.9.3
644
+ */
645
+ if ( LiteSpeed_Cache_REST::get_instance()->is_rest() || LiteSpeed_Cache_Router::is_ajax() ) {
646
  $running_info_showing = false ;
647
  LiteSpeed_Cache_Log::debug( '[Core] Silence Comment due to REST/AJAX' ) ;
648
  }
inc/litespeed.autoload.php CHANGED
@@ -46,6 +46,7 @@ if ( !function_exists('_litespeed_autoload') ) {
46
  'LiteSpeed_Cache_Optimize' => 'inc/optimize.class.php',
47
  'LiteSpeed_Cache_Optimizer' => 'inc/optimizer.class.php',
48
  'LiteSpeed_Cache_Purge' => 'inc/purge.class.php',
 
49
  'LiteSpeed_Cache_Router' => 'inc/router.class.php',
50
  'LiteSpeed_Cache_Tag' => 'inc/tag.class.php',
51
  'LiteSpeed_Cache_Task' => 'inc/task.class.php',
46
  'LiteSpeed_Cache_Optimize' => 'inc/optimize.class.php',
47
  'LiteSpeed_Cache_Optimizer' => 'inc/optimizer.class.php',
48
  'LiteSpeed_Cache_Purge' => 'inc/purge.class.php',
49
+ 'LiteSpeed_Cache_REST' => 'inc/rest.cls.php',
50
  'LiteSpeed_Cache_Router' => 'inc/router.class.php',
51
  'LiteSpeed_Cache_Tag' => 'inc/tag.class.php',
52
  'LiteSpeed_Cache_Task' => 'inc/task.class.php',
inc/log.class.php CHANGED
@@ -139,6 +139,7 @@ class LiteSpeed_Cache_Log
139
  'X-LSCACHE' => '',
140
  'LSCACHE_VARY_COOKIE' => '',
141
  'LSCACHE_VARY_VALUE' => '',
 
142
  ) ;
143
  $server = array_merge( $servervars, $_SERVER ) ;
144
  $params = array() ;
@@ -188,6 +189,9 @@ class LiteSpeed_Cache_Log
188
  if( $server['LSCACHE_VARY_VALUE'] ) {
189
  $params[] = 'LSCACHE_VARY_VALUE: ' . $server['LSCACHE_VARY_VALUE'] ;
190
  }
 
 
 
191
 
192
  $request = array_map( 'self::format_message', $params ) ;
193
 
139
  'X-LSCACHE' => '',
140
  'LSCACHE_VARY_COOKIE' => '',
141
  'LSCACHE_VARY_VALUE' => '',
142
+ 'ESI_CONTENT_TYPE' => '',
143
  ) ;
144
  $server = array_merge( $servervars, $_SERVER ) ;
145
  $params = array() ;
189
  if( $server['LSCACHE_VARY_VALUE'] ) {
190
  $params[] = 'LSCACHE_VARY_VALUE: ' . $server['LSCACHE_VARY_VALUE'] ;
191
  }
192
+ if( $server['ESI_CONTENT_TYPE'] ) {
193
+ $params[] = 'ESI_CONTENT_TYPE: ' . $server['ESI_CONTENT_TYPE'] ;
194
+ }
195
 
196
  $request = array_map( 'self::format_message', $params ) ;
197
 
inc/rest.cls.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * The REST related class.
4
+ *
5
+ * @since 2.9.4
6
+ */
7
+ defined( 'WPINC' ) || exit ;
8
+
9
+ class LiteSpeed_Cache_REST
10
+ {
11
+ private static $_instance ;
12
+
13
+ private $_internal_rest_status = false ;
14
+
15
+ /**
16
+ * Constructor of ESI
17
+ *
18
+ * @since 2.9.4
19
+ * @access private
20
+ */
21
+ private function __construct()
22
+ {
23
+ // Hook to internal REST call
24
+ add_filter( 'rest_request_before_callbacks', array( $this, 'set_internal_rest_on' ) ) ;
25
+ add_filter( 'rest_request_after_callbacks', array( $this, 'set_internal_rest_off' ) ) ;
26
+
27
+ }
28
+
29
+ /**
30
+ * Set internal REST tag to ON
31
+ *
32
+ * @since 2.9.4
33
+ * @access public
34
+ */
35
+ public function set_internal_rest_on( $not_used = null )
36
+ {
37
+ $this->_internal_rest_status = true ;
38
+ LiteSpeed_Cache_Log::debug2( '[REST] ✅ Internal REST ON [filter] rest_request_before_callbacks' ) ;
39
+
40
+ return $not_used ;
41
+ }
42
+
43
+ /**
44
+ * Set internal REST tag to OFF
45
+ *
46
+ * @since 2.9.4
47
+ * @access public
48
+ */
49
+ public function set_internal_rest_off( $not_used = null )
50
+ {
51
+ $this->_internal_rest_status = false ;
52
+ LiteSpeed_Cache_Log::debug2( '[REST] ❎ Internal REST OFF [filter] rest_request_after_callbacks' ) ;
53
+
54
+ return $not_used ;
55
+ }
56
+
57
+ /**
58
+ * Get internal REST tag
59
+ *
60
+ * @since 2.9.4
61
+ * @access public
62
+ */
63
+ public function is_internal_rest()
64
+ {
65
+ return $this->_internal_rest_status ;
66
+ }
67
+
68
+ /**
69
+ * Check if an URL or current page is REST req or not
70
+ *
71
+ * @since 2.9.3
72
+ * @since 2.9.4 Moved here from LiteSpeed_Cache_Utility, dropped static
73
+ * @access public
74
+ */
75
+ public function is_rest( $url = false )
76
+ {
77
+ // For WP 4.4.0- compatibility
78
+ if ( ! function_exists( 'rest_get_url_prefix' ) ) {
79
+ return defined( 'REST_REQUEST' ) && REST_REQUEST ;
80
+ }
81
+
82
+ $prefix = rest_get_url_prefix() ;
83
+
84
+ // Case #1: After WP_REST_Request initialisation
85
+ if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
86
+ return true ;
87
+ }
88
+
89
+ // Case #2: Support "plain" permalink settings
90
+ if ( isset( $_GET[ 'rest_route' ] ) && strpos( trim( $_GET[ 'rest_route' ], '\\/' ), $prefix , 0 ) === 0 ) {
91
+ return true ;
92
+ }
93
+
94
+ if ( ! $url ) {
95
+ return false ;
96
+ }
97
+
98
+ // Case #3: URL Path begins with wp-json/ (REST prefix) Safe for subfolder installation
99
+ $rest_url = wp_parse_url( site_url( $prefix ) ) ;
100
+ $current_url = wp_parse_url( $url ) ;
101
+ // LiteSpeed_Cache_Log::debug( '[Util] is_rest check [base] ', $rest_url ) ;
102
+ // LiteSpeed_Cache_Log::debug( '[Util] is_rest check [curr] ', $current_url ) ;
103
+ // LiteSpeed_Cache_Log::debug( '[Util] is_rest check [curr2] ', wp_parse_url( add_query_arg( array( ) ) ) ) ;
104
+ return strpos( $current_url[ 'path' ], $rest_url[ 'path' ] ) === 0 ;
105
+ }
106
+
107
+
108
+ /**
109
+ * Get the current instance object.
110
+ *
111
+ * @since 2.9
112
+ * @access public
113
+ * @return Current class instance.
114
+ */
115
+ public static function get_instance()
116
+ {
117
+ if ( ! isset( self::$_instance ) ) {
118
+ self::$_instance = new self() ;
119
+ }
120
+
121
+ return self::$_instance ;
122
+ }
123
+ }
inc/tag.class.php CHANGED
@@ -303,7 +303,7 @@ class LiteSpeed_Cache_Tag
303
  }
304
 
305
  // Check REST API
306
- if ( LiteSpeed_Cache_Utility::is_rest() ) {
307
  $tags[] = self::TYPE_REST ;
308
 
309
  $path = ! empty( $_SERVER[ 'SCRIPT_URL' ] ) ? $_SERVER[ 'SCRIPT_URL' ] : false ;
303
  }
304
 
305
  // Check REST API
306
+ if ( LiteSpeed_Cache_REST::get_instance()->is_rest() ) {
307
  $tags[] = self::TYPE_REST ;
308
 
309
  $path = ! empty( $_SERVER[ 'SCRIPT_URL' ] ) ? $_SERVER[ 'SCRIPT_URL' ] : false ;
inc/utility.class.php CHANGED
@@ -13,47 +13,10 @@ if ( ! defined( 'WPINC' ) ) {
13
  class LiteSpeed_Cache_Utility
14
  {
15
  private static $_instance ;
 
16
 
17
  const TYPE_SCORE_CHK = 'score_chk' ;
18
 
19
- /**
20
- * Check if an URL or current page is REST req or not
21
- *
22
- * @since 2.9.3
23
- * @access public
24
- */
25
- public static function is_rest( $url = false )
26
- {
27
- // For WP 4.4.0- compatibility
28
- if ( ! function_exists( 'rest_get_url_prefix' ) ) {
29
- return defined( 'REST_REQUEST' ) && REST_REQUEST ;
30
- }
31
-
32
- $prefix = rest_get_url_prefix() ;
33
-
34
- // Case #1: After WP_REST_Request initialisation
35
- if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
36
- return true ;
37
- }
38
-
39
- // Case #2: Support "plain" permalink settings
40
- if ( isset( $_GET[ 'rest_route' ] ) && strpos( trim( $_GET[ 'rest_route' ], '\\/' ), $prefix , 0 ) === 0 ) {
41
- return true ;
42
- }
43
-
44
- if ( ! $url ) {
45
- return false ;
46
- }
47
-
48
- // Case #3: URL Path begins with wp-json/ (REST prefix) Safe for subfolder installation
49
- $rest_url = wp_parse_url( site_url( $prefix ) ) ;
50
- $current_url = wp_parse_url( $url ) ;
51
- // LiteSpeed_Cache_Log::debug( '[Util] is_rest check [base] ', $rest_url ) ;
52
- // LiteSpeed_Cache_Log::debug( '[Util] is_rest check [curr] ', $current_url ) ;
53
- // LiteSpeed_Cache_Log::debug( '[Util] is_rest check [curr2] ', wp_parse_url( add_query_arg( array( ) ) ) ) ;
54
- return strpos( $current_url[ 'path' ], $rest_url[ 'path' ] ) === 0 ;
55
- }
56
-
57
  /**
58
  * Check page score
59
  *
@@ -646,7 +609,23 @@ class LiteSpeed_Cache_Utility
646
  define( 'LITESPEED_FRONTEND_HOST', parse_url( $home_host, PHP_URL_HOST ) ) ;
647
  }
648
 
649
- return $host === LITESPEED_FRONTEND_HOST ;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
650
  }
651
 
652
  /**
13
  class LiteSpeed_Cache_Utility
14
  {
15
  private static $_instance ;
16
+ private static $_internal_domains ;
17
 
18
  const TYPE_SCORE_CHK = 'score_chk' ;
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  /**
21
  * Check page score
22
  *
609
  define( 'LITESPEED_FRONTEND_HOST', parse_url( $home_host, PHP_URL_HOST ) ) ;
610
  }
611
 
612
+ if ( $host === LITESPEED_FRONTEND_HOST ) {
613
+ return true ;
614
+ }
615
+
616
+ /**
617
+ * Filter for multiple domains
618
+ * @since 2.9.4
619
+ */
620
+ if ( ! isset( self::$_internal_domains ) ) {
621
+ self::$_internal_domains = apply_filters( 'litespeed_internal_domains', array() ) ;
622
+ }
623
+
624
+ if ( self::$_internal_domains ) {
625
+ return in_array( $host, self::$_internal_domains ) ;
626
+ }
627
+
628
+ return false ;
629
  }
630
 
631
  /**
includes/litespeed-cache-control.class.php CHANGED
@@ -547,16 +547,8 @@ class LiteSpeed_Cache_Control
547
  $instance = self::get_instance() ;
548
 
549
  // Apply 3rd party filter
550
- // Parse ESI block id
551
- $esi_id = false ;
552
- if ( defined( 'LSCACHE_IS_ESI' ) ) {
553
- $params = LiteSpeed_Cache_ESI::parse_esi_param() ;
554
- if ( $params !== false ) {
555
- $esi_id = $params[LiteSpeed_Cache_ESI::PARAM_BLOCK_ID] ;
556
- }
557
- }
558
  // NOTE: Hook always needs to run asap because some 3rd party set is_mobile in this hook
559
- do_action('litespeed_cache_api_control', $esi_id) ;
560
 
561
  // if is not cacheable, terminate check
562
  if ( ! self::is_cacheable() ) {
547
  $instance = self::get_instance() ;
548
 
549
  // Apply 3rd party filter
 
 
 
 
 
 
 
 
550
  // NOTE: Hook always needs to run asap because some 3rd party set is_mobile in this hook
551
+ do_action('litespeed_cache_api_control', defined( 'LSCACHE_IS_ESI' ) ? LSCACHE_IS_ESI : false ) ; // Pass ESI block id
552
 
553
  // if is not cacheable, terminate check
554
  if ( ! self::is_cacheable() ) {
includes/litespeed-cache-esi.class.php CHANGED
@@ -24,11 +24,9 @@ class LiteSpeed_Cache_ESI
24
  private $_esi_preserve_list = array() ;
25
 
26
  const QS_ACTION = 'lsesi' ;
27
- const POSTTYPE = 'lswcp' ;
28
  const QS_PARAMS = 'esi' ;
29
 
30
  const PARAM_ARGS = 'args' ;
31
- const PARAM_BLOCK_ID = 'block_id' ;
32
  const PARAM_ID = 'id' ;
33
  const PARAM_INSTANCE = 'instance' ;
34
  const PARAM_NAME = 'name' ;
@@ -45,6 +43,7 @@ class LiteSpeed_Cache_ESI
45
  private function __construct()
46
  {
47
  add_action( 'template_include', 'LiteSpeed_Cache_ESI::esi_template', 100 ) ;
 
48
  add_action( 'load-widgets.php', 'LiteSpeed_Cache_Purge::purge_widget' ) ;
49
  add_action( 'wp_update_comment_count', 'LiteSpeed_Cache_Purge::purge_comment_widget' ) ;
50
 
@@ -55,18 +54,8 @@ class LiteSpeed_Cache_ESI
55
  * Recover REQUEST_URI
56
  * @since 1.8.1
57
  */
58
- if ( ! empty( $_GET[ self::QS_ACTION ] ) && $_GET[ self::QS_ACTION ] == self::POSTTYPE ) {
59
- define( 'LSCACHE_IS_ESI', true ) ;
60
-
61
- ! empty( $_SERVER[ 'ESI_REFERER' ] ) && defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( '[ESI] ESI_REFERER: ' . $_SERVER[ 'ESI_REFERER' ] ) ;
62
-
63
- /**
64
- * Only when ESI's parent is not REST, replace REQUEST_URI to avoid breaking WP5 editor REST call
65
- * @since 2.9.3
66
- */
67
- if ( ! empty( $_SERVER[ 'ESI_REFERER' ] ) && ! LiteSpeed_Cache_Utility::is_rest( $_SERVER[ 'ESI_REFERER' ] ) ) {
68
- $_SERVER[ 'REQUEST_URI' ] = $_SERVER[ 'ESI_REFERER' ] ;
69
- }
70
  }
71
 
72
  /**
@@ -136,6 +125,47 @@ class LiteSpeed_Cache_ESI
136
  self::$has_esi = true ;
137
  }
138
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  /**
140
  * Hooked to the template_include action.
141
  * Selects the esi template file when the post type is a LiteSpeed ESI page.
@@ -149,8 +179,6 @@ class LiteSpeed_Cache_ESI
149
  {
150
  // Check if is an ESI request
151
  if ( defined( 'LSCACHE_IS_ESI' ) ) {
152
- self::get_instance()->register_esi_actions() ;
153
-
154
  LiteSpeed_Cache_Log::debug( '[ESI] calling template' ) ;
155
 
156
  return LSCWP_DIR . 'tpl/esi.tpl.php' ;
@@ -159,23 +187,6 @@ class LiteSpeed_Cache_ESI
159
  return $template ;
160
  }
161
 
162
- /**
163
- * Register all of the hooks related to the esi logic of the plugin.
164
- * Specifically when the page IS an esi page.
165
- *
166
- * @since 1.1.3
167
- * @access public
168
- */
169
- public function register_esi_actions()
170
- {
171
- add_action('litespeed_cache_load_esi_block-widget', array($this, 'load_widget_block')) ;
172
- add_action('litespeed_cache_load_esi_block-admin-bar', array($this, 'load_admin_bar_block')) ;
173
- add_action('litespeed_cache_load_esi_block-comment-form', array($this, 'load_comment_form_block')) ;
174
-
175
- add_action('litespeed_cache_load_esi_block-lscwp_nonce_esi', array( $this, 'load_nonce_block' ) ) ;
176
- add_action('litespeed_cache_load_esi_block-esi', array( $this, 'load_esi_shortcode' ) ) ;
177
- }
178
-
179
  /**
180
  * Register all of the hooks related to the esi logic of the plugin.
181
  * Specifically when the page is NOT an esi page.
@@ -233,25 +244,42 @@ class LiteSpeed_Cache_ESI
233
  return false ;
234
  }
235
 
236
- $params[ self::PARAM_BLOCK_ID ] = $block_id ;
237
  if ( $silence ) {
238
  // Don't add comment to esi block ( orignal for nonce used in tag property data-nonce='esi_block' )
239
  $params[ '_ls_silence' ] = true ;
240
  }
241
 
 
 
 
 
242
  $params = apply_filters('litespeed_cache_sub_esi_params-' . $block_id, $params) ;
243
  $control = apply_filters('litespeed_cache_sub_esi_control-' . $block_id, $control) ;
244
  if ( !is_array($params) || !is_string($control) ) {
245
- defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( "Sub esi hooks returned Params: \n" . var_export($params, true) . "\ncache control: \n" . var_export($control, true) ) ;
246
 
247
  return false ;
248
  }
249
 
250
- $url = trailingslashit( wp_make_link_relative( home_url() ) ) . '?' . self::QS_ACTION . '=' . self::POSTTYPE ;
 
 
 
251
  if ( ! empty( $control ) ) {
252
- $url .= '&_control=' . $control ;
 
 
 
253
  }
254
- $url .= '&' . self::QS_PARAMS . '=' . urlencode(base64_encode(serialize($params))) ;
 
 
 
 
 
 
 
 
255
 
256
  $output = "<esi:include src='$url'" ;
257
  if ( ! empty( $control ) ) {
@@ -288,9 +316,9 @@ class LiteSpeed_Cache_ESI
288
  * Parses the request parameters on an ESI request
289
  *
290
  * @since 1.1.3
291
- * @access public
292
  */
293
- public static function parse_esi_param()
294
  {
295
  if ( ! isset($_REQUEST[self::QS_PARAMS]) ) {
296
  return false ;
@@ -300,9 +328,11 @@ class LiteSpeed_Cache_ESI
300
  if ( $unencrypted === false ) {
301
  return false ;
302
  }
303
- $unencoded = urldecode($unencrypted) ;
304
- $params = unserialize($unencoded) ;
305
- if ( $params === false || ! isset($params[self::PARAM_BLOCK_ID]) ) {
 
 
306
  return false ;
307
  }
308
 
@@ -315,19 +345,16 @@ class LiteSpeed_Cache_ESI
315
  * @since 1.1.3
316
  * @access public
317
  */
318
- public static function load_esi_block()
319
  {
320
- $params = self::parse_esi_param() ;
321
- if ( $params === false ) {
322
- return ;
323
- }
324
- $esi_id = $params[ self::PARAM_BLOCK_ID ] ;
325
  if ( defined( 'LSCWP_LOG' ) ) {
326
  $logInfo = '------- ESI ------- ' ;
327
  if( ! empty( $params[ self::PARAM_NAME ] ) ) {
328
  $logInfo .= ' Name: ' . $params[ self::PARAM_NAME ] . ' ----- ' ;
329
  }
330
- $logInfo .= $esi_id . ' -------' ;
331
  LiteSpeed_Cache_Log::debug( $logInfo ) ;
332
  }
333
 
@@ -335,8 +362,16 @@ class LiteSpeed_Cache_ESI
335
  define( 'LSCACHE_ESI_SILENCE', true ) ;
336
  }
337
 
 
 
 
 
 
 
 
 
338
  LiteSpeed_Cache_Tag::add( rtrim( LiteSpeed_Cache_Tag::TYPE_ESI, '.' ) ) ;
339
- LiteSpeed_Cache_Tag::add( LiteSpeed_Cache_Tag::TYPE_ESI . $esi_id ) ;
340
 
341
  // LiteSpeed_Cache_Log::debug(var_export($params, true ));
342
 
@@ -356,7 +391,7 @@ class LiteSpeed_Cache_ESI
356
  }
357
  }
358
 
359
- do_action('litespeed_cache_load_esi_block-' . $esi_id, $params) ;
360
  }
361
 
362
  // BEGIN helper functions
@@ -530,17 +565,7 @@ class LiteSpeed_Cache_ESI
530
  */
531
  public function load_admin_bar_block( $params )
532
  {
533
- ob_start() ;
534
  wp_admin_bar_render() ;
535
- $output = ob_get_contents() ;
536
- ob_end_clean() ;
537
-
538
- if ( ! empty( $params[ 'is_json' ] ) ) {
539
- $output = json_encode( $output ) ;
540
- $output = trim( $output, '"' ) ;
541
- }
542
-
543
- echo $output ;
544
 
545
  if ( ! LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_ESI_CACHE_ADMBAR ) ) {
546
  LiteSpeed_Cache_Control::set_nocache( 'build-in set to not cacheable' ) ;
@@ -563,17 +588,7 @@ class LiteSpeed_Cache_ESI
563
  */
564
  public function load_comment_form_block( $params )
565
  {
566
- ob_start() ;
567
  comment_form( $params[ self::PARAM_ARGS ], $params[ self::PARAM_ID ] ) ;
568
- $output = ob_get_contents() ;
569
- ob_end_clean() ;
570
-
571
- if ( ! empty( $params[ 'is_json' ] ) ) {
572
- $output = json_encode( $output ) ;
573
- $output = trim( $output, '"' ) ;
574
- }
575
-
576
- echo $output ;
577
 
578
  if ( ! LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_ESI_CACHE_COMMFORM ) ) {
579
  LiteSpeed_Cache_Control::set_nocache( 'build-in set to not cacheable' ) ;
@@ -617,8 +632,6 @@ class LiteSpeed_Cache_ESI
617
  */
618
  public function load_esi_shortcode( $params )
619
  {
620
- unset( $params[ self::PARAM_BLOCK_ID ] ) ;
621
-
622
  if ( isset( $params[ 'ttl' ] ) ) {
623
  if ( ! $params[ 'ttl' ] ) {
624
  LiteSpeed_Cache_Control::set_nocache( 'ESI shortcode att ttl=0' ) ;
24
  private $_esi_preserve_list = array() ;
25
 
26
  const QS_ACTION = 'lsesi' ;
 
27
  const QS_PARAMS = 'esi' ;
28
 
29
  const PARAM_ARGS = 'args' ;
 
30
  const PARAM_ID = 'id' ;
31
  const PARAM_INSTANCE = 'instance' ;
32
  const PARAM_NAME = 'name' ;
43
  private function __construct()
44
  {
45
  add_action( 'template_include', 'LiteSpeed_Cache_ESI::esi_template', 100 ) ;
46
+
47
  add_action( 'load-widgets.php', 'LiteSpeed_Cache_Purge::purge_widget' ) ;
48
  add_action( 'wp_update_comment_count', 'LiteSpeed_Cache_Purge::purge_comment_widget' ) ;
49
 
54
  * Recover REQUEST_URI
55
  * @since 1.8.1
56
  */
57
+ if ( ! empty( $_GET[ self::QS_ACTION ] ) ) {
58
+ $this->_register_esi_actions() ;
 
 
 
 
 
 
 
 
 
 
59
  }
60
 
61
  /**
125
  self::$has_esi = true ;
126
  }
127
 
128
+ /**
129
+ * Register all of the hooks related to the esi logic of the plugin.
130
+ * Specifically when the page IS an esi page.
131
+ *
132
+ * @since 1.1.3
133
+ * @access private
134
+ */
135
+ private function _register_esi_actions()
136
+ {
137
+ define( 'LSCACHE_IS_ESI', $_GET[ self::QS_ACTION ] ) ;// Reused this to ESI block ID
138
+
139
+ ! empty( $_SERVER[ 'ESI_REFERER' ] ) && defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( '[ESI] ESI_REFERER: ' . $_SERVER[ 'ESI_REFERER' ] ) ;
140
+
141
+ /**
142
+ * Only when ESI's parent is not REST, replace REQUEST_URI to avoid breaking WP5 editor REST call
143
+ * @since 2.9.3
144
+ */
145
+ if ( ! empty( $_SERVER[ 'ESI_REFERER' ] ) && ! LiteSpeed_Cache_REST::get_instance()->is_rest( $_SERVER[ 'ESI_REFERER' ] ) ) {
146
+ $_SERVER[ 'REQUEST_URI' ] = $_SERVER[ 'ESI_REFERER' ] ;
147
+ }
148
+
149
+ if ( ! empty( $_SERVER[ 'ESI_CONTENT_TYPE' ] ) && strpos( $_SERVER[ 'ESI_CONTENT_TYPE' ], 'application/json' ) === 0 ) {
150
+ add_filter( 'litespeed_is_json', '__return_true' ) ;
151
+ }
152
+
153
+ /**
154
+ * Make REST call be able to parse ESI
155
+ * NOTE: Not effective due to ESI req are all to `/` yet
156
+ * @since 2.9.4
157
+ */
158
+ add_action( 'rest_api_init', array( $this, 'load_esi_block' ), 101 ) ;
159
+
160
+ // Register ESI blocks
161
+ add_action('litespeed_cache_load_esi_block-widget', array($this, 'load_widget_block')) ;
162
+ add_action('litespeed_cache_load_esi_block-admin-bar', array($this, 'load_admin_bar_block')) ;
163
+ add_action('litespeed_cache_load_esi_block-comment-form', array($this, 'load_comment_form_block')) ;
164
+
165
+ add_action('litespeed_cache_load_esi_block-lscwp_nonce_esi', array( $this, 'load_nonce_block' ) ) ;
166
+ add_action('litespeed_cache_load_esi_block-esi', array( $this, 'load_esi_shortcode' ) ) ;
167
+ }
168
+
169
  /**
170
  * Hooked to the template_include action.
171
  * Selects the esi template file when the post type is a LiteSpeed ESI page.
179
  {
180
  // Check if is an ESI request
181
  if ( defined( 'LSCACHE_IS_ESI' ) ) {
 
 
182
  LiteSpeed_Cache_Log::debug( '[ESI] calling template' ) ;
183
 
184
  return LSCWP_DIR . 'tpl/esi.tpl.php' ;
187
  return $template ;
188
  }
189
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  /**
191
  * Register all of the hooks related to the esi logic of the plugin.
192
  * Specifically when the page is NOT an esi page.
244
  return false ;
245
  }
246
 
 
247
  if ( $silence ) {
248
  // Don't add comment to esi block ( orignal for nonce used in tag property data-nonce='esi_block' )
249
  $params[ '_ls_silence' ] = true ;
250
  }
251
 
252
+ if ( LiteSpeed_Cache_REST::get_instance()->is_rest() || LiteSpeed_Cache_REST::get_instance()->is_internal_rest() ) {
253
+ $params[ 'is_json' ] = 1 ;
254
+ }
255
+
256
  $params = apply_filters('litespeed_cache_sub_esi_params-' . $block_id, $params) ;
257
  $control = apply_filters('litespeed_cache_sub_esi_control-' . $block_id, $control) ;
258
  if ( !is_array($params) || !is_string($control) ) {
259
+ defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( "[ESI] 🛑 Sub hooks returned Params: \n" . var_export($params, true) . "\ncache control: \n" . var_export($control, true) ) ;
260
 
261
  return false ;
262
  }
263
 
264
+ // Build params for URL
265
+ $appended_params = array(
266
+ self::QS_ACTION => $block_id,
267
+ ) ;
268
  if ( ! empty( $control ) ) {
269
+ $appended_params[ '_control' ] = $control ;
270
+ }
271
+ if ( $params ) {
272
+ $appended_params[ self::QS_PARAMS ] = base64_encode( serialize( $params ) ) ;
273
  }
274
+
275
+ /**
276
+ * Escape potential chars
277
+ * @since 2.9.4
278
+ */
279
+ $appended_params = array_map( 'urlencode', $appended_params ) ;
280
+
281
+ // Generate ESI URL
282
+ $url = add_query_arg( $appended_params, trailingslashit( wp_make_link_relative( home_url() ) ) ) ;
283
 
284
  $output = "<esi:include src='$url'" ;
285
  if ( ! empty( $control ) ) {
316
  * Parses the request parameters on an ESI request
317
  *
318
  * @since 1.1.3
319
+ * @access private
320
  */
321
+ private function _parse_esi_param()
322
  {
323
  if ( ! isset($_REQUEST[self::QS_PARAMS]) ) {
324
  return false ;
328
  if ( $unencrypted === false ) {
329
  return false ;
330
  }
331
+
332
+ LiteSpeed_Cache_Log::debug2( '[ESI] parms', $unencrypted ) ;
333
+ // $unencoded = urldecode($unencrypted) ; no need to do this as $_GET is already parsed
334
+ $params = unserialize( $unencrypted ) ;
335
+ if ( $params === false ) {
336
  return false ;
337
  }
338
 
345
  * @since 1.1.3
346
  * @access public
347
  */
348
+ public function load_esi_block()
349
  {
350
+ $params = $this->_parse_esi_param() ;
351
+
 
 
 
352
  if ( defined( 'LSCWP_LOG' ) ) {
353
  $logInfo = '------- ESI ------- ' ;
354
  if( ! empty( $params[ self::PARAM_NAME ] ) ) {
355
  $logInfo .= ' Name: ' . $params[ self::PARAM_NAME ] . ' ----- ' ;
356
  }
357
+ $logInfo .= LSCACHE_IS_ESI . ' -------' ;
358
  LiteSpeed_Cache_Log::debug( $logInfo ) ;
359
  }
360
 
362
  define( 'LSCACHE_ESI_SILENCE', true ) ;
363
  }
364
 
365
+ /**
366
+ * Buffer needs to be JSON format
367
+ * @since 2.9.4
368
+ */
369
+ if ( ! empty( $params[ 'is_json' ] ) ) {
370
+ add_filter( 'litespeed_is_json', '__return_true' ) ;
371
+ }
372
+
373
  LiteSpeed_Cache_Tag::add( rtrim( LiteSpeed_Cache_Tag::TYPE_ESI, '.' ) ) ;
374
+ LiteSpeed_Cache_Tag::add( LiteSpeed_Cache_Tag::TYPE_ESI . LSCACHE_IS_ESI ) ;
375
 
376
  // LiteSpeed_Cache_Log::debug(var_export($params, true ));
377
 
391
  }
392
  }
393
 
394
+ do_action('litespeed_cache_load_esi_block-' . LSCACHE_IS_ESI, $params) ;
395
  }
396
 
397
  // BEGIN helper functions
565
  */
566
  public function load_admin_bar_block( $params )
567
  {
 
568
  wp_admin_bar_render() ;
 
 
 
 
 
 
 
 
 
569
 
570
  if ( ! LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_ESI_CACHE_ADMBAR ) ) {
571
  LiteSpeed_Cache_Control::set_nocache( 'build-in set to not cacheable' ) ;
588
  */
589
  public function load_comment_form_block( $params )
590
  {
 
591
  comment_form( $params[ self::PARAM_ARGS ], $params[ self::PARAM_ID ] ) ;
 
 
 
 
 
 
 
 
 
592
 
593
  if ( ! LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_ESI_CACHE_COMMFORM ) ) {
594
  LiteSpeed_Cache_Control::set_nocache( 'build-in set to not cacheable' ) ;
632
  */
633
  public function load_esi_shortcode( $params )
634
  {
 
 
635
  if ( isset( $params[ 'ttl' ] ) ) {
636
  if ( ! $params[ 'ttl' ] ) {
637
  LiteSpeed_Cache_Control::set_nocache( 'ESI shortcode att ttl=0' ) ;
includes/litespeed-cache-log.class.php CHANGED
@@ -139,6 +139,7 @@ class LiteSpeed_Cache_Log
139
  'X-LSCACHE' => '',
140
  'LSCACHE_VARY_COOKIE' => '',
141
  'LSCACHE_VARY_VALUE' => '',
 
142
  ) ;
143
  $server = array_merge( $servervars, $_SERVER ) ;
144
  $params = array() ;
@@ -188,6 +189,9 @@ class LiteSpeed_Cache_Log
188
  if( $server['LSCACHE_VARY_VALUE'] ) {
189
  $params[] = 'LSCACHE_VARY_VALUE: ' . $server['LSCACHE_VARY_VALUE'] ;
190
  }
 
 
 
191
 
192
  $request = array_map( 'self::format_message', $params ) ;
193
 
139
  'X-LSCACHE' => '',
140
  'LSCACHE_VARY_COOKIE' => '',
141
  'LSCACHE_VARY_VALUE' => '',
142
+ 'ESI_CONTENT_TYPE' => '',
143
  ) ;
144
  $server = array_merge( $servervars, $_SERVER ) ;
145
  $params = array() ;
189
  if( $server['LSCACHE_VARY_VALUE'] ) {
190
  $params[] = 'LSCACHE_VARY_VALUE: ' . $server['LSCACHE_VARY_VALUE'] ;
191
  }
192
+ if( $server['ESI_CONTENT_TYPE'] ) {
193
+ $params[] = 'ESI_CONTENT_TYPE: ' . $server['ESI_CONTENT_TYPE'] ;
194
+ }
195
 
196
  $request = array_map( 'self::format_message', $params ) ;
197
 
includes/litespeed-cache-tag.class.php CHANGED
@@ -303,7 +303,7 @@ class LiteSpeed_Cache_Tag
303
  }
304
 
305
  // Check REST API
306
- if ( LiteSpeed_Cache_Utility::is_rest() ) {
307
  $tags[] = self::TYPE_REST ;
308
 
309
  $path = ! empty( $_SERVER[ 'SCRIPT_URL' ] ) ? $_SERVER[ 'SCRIPT_URL' ] : false ;
303
  }
304
 
305
  // Check REST API
306
+ if ( LiteSpeed_Cache_REST::get_instance()->is_rest() ) {
307
  $tags[] = self::TYPE_REST ;
308
 
309
  $path = ! empty( $_SERVER[ 'SCRIPT_URL' ] ) ? $_SERVER[ 'SCRIPT_URL' ] : false ;
includes/litespeed-cache-utility.class.php CHANGED
@@ -13,47 +13,10 @@ if ( ! defined( 'WPINC' ) ) {
13
  class LiteSpeed_Cache_Utility
14
  {
15
  private static $_instance ;
 
16
 
17
  const TYPE_SCORE_CHK = 'score_chk' ;
18
 
19
- /**
20
- * Check if an URL or current page is REST req or not
21
- *
22
- * @since 2.9.3
23
- * @access public
24
- */
25
- public static function is_rest( $url = false )
26
- {
27
- // For WP 4.4.0- compatibility
28
- if ( ! function_exists( 'rest_get_url_prefix' ) ) {
29
- return defined( 'REST_REQUEST' ) && REST_REQUEST ;
30
- }
31
-
32
- $prefix = rest_get_url_prefix() ;
33
-
34
- // Case #1: After WP_REST_Request initialisation
35
- if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
36
- return true ;
37
- }
38
-
39
- // Case #2: Support "plain" permalink settings
40
- if ( isset( $_GET[ 'rest_route' ] ) && strpos( trim( $_GET[ 'rest_route' ], '\\/' ), $prefix , 0 ) === 0 ) {
41
- return true ;
42
- }
43
-
44
- if ( ! $url ) {
45
- return false ;
46
- }
47
-
48
- // Case #3: URL Path begins with wp-json/ (REST prefix) Safe for subfolder installation
49
- $rest_url = wp_parse_url( site_url( $prefix ) ) ;
50
- $current_url = wp_parse_url( $url ) ;
51
- // LiteSpeed_Cache_Log::debug( '[Util] is_rest check [base] ', $rest_url ) ;
52
- // LiteSpeed_Cache_Log::debug( '[Util] is_rest check [curr] ', $current_url ) ;
53
- // LiteSpeed_Cache_Log::debug( '[Util] is_rest check [curr2] ', wp_parse_url( add_query_arg( array( ) ) ) ) ;
54
- return strpos( $current_url[ 'path' ], $rest_url[ 'path' ] ) === 0 ;
55
- }
56
-
57
  /**
58
  * Check page score
59
  *
@@ -646,7 +609,23 @@ class LiteSpeed_Cache_Utility
646
  define( 'LITESPEED_FRONTEND_HOST', parse_url( $home_host, PHP_URL_HOST ) ) ;
647
  }
648
 
649
- return $host === LITESPEED_FRONTEND_HOST ;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
650
  }
651
 
652
  /**
13
  class LiteSpeed_Cache_Utility
14
  {
15
  private static $_instance ;
16
+ private static $_internal_domains ;
17
 
18
  const TYPE_SCORE_CHK = 'score_chk' ;
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  /**
21
  * Check page score
22
  *
609
  define( 'LITESPEED_FRONTEND_HOST', parse_url( $home_host, PHP_URL_HOST ) ) ;
610
  }
611
 
612
+ if ( $host === LITESPEED_FRONTEND_HOST ) {
613
+ return true ;
614
+ }
615
+
616
+ /**
617
+ * Filter for multiple domains
618
+ * @since 2.9.4
619
+ */
620
+ if ( ! isset( self::$_internal_domains ) ) {
621
+ self::$_internal_domains = apply_filters( 'litespeed_internal_domains', array() ) ;
622
+ }
623
+
624
+ if ( self::$_internal_domains ) {
625
+ return in_array( $host, self::$_internal_domains ) ;
626
+ }
627
+
628
+ return false ;
629
  }
630
 
631
  /**
includes/litespeed-cache.class.php CHANGED
@@ -26,7 +26,7 @@ class LiteSpeed_Cache
26
  const NAME = 'LiteSpeed Cache' ;
27
  const PLUGIN_NAME = 'litespeed-cache' ;
28
  const PLUGIN_FILE = 'litespeed-cache/litespeed-cache.php' ;
29
- const PLUGIN_VERSION = '2.9.3' ;
30
 
31
  const PAGE_EDIT_HTACCESS = 'lscache-edit-htaccess' ;
32
 
@@ -130,6 +130,12 @@ class LiteSpeed_Cache
130
  delete_option( LiteSpeed_Cache_Purge::PURGE_QUEUE ) ;
131
  }
132
 
 
 
 
 
 
 
133
  /**
134
  * Added hook before init
135
  * @since 1.6.6
@@ -561,21 +567,25 @@ class LiteSpeed_Cache
561
  $buffer .= $this->footer_comment ;
562
  }
563
 
564
- // If ESI req is JSON, give the content json format @since 2.9.3
 
 
 
 
565
  if ( defined( 'LSCACHE_IS_ESI' ) ) {
566
  LiteSpeed_Cache_Log::debug( '[Core] ESI----------Start--------' ) ;
567
  LiteSpeed_Cache_Log::debug( $buffer ) ;
568
  LiteSpeed_Cache_Log::debug( '[Core] ESI----------End--------' ) ;
 
569
 
570
- if ( ! empty( $_SERVER[ 'ESI_CONTENT_TYPE' ] ) && strpos( $_SERVER[ 'ESI_CONTENT_TYPE' ], 'application/json' ) === 0 ) {
571
- if ( json_decode( $buffer, true ) == NULL ) {
572
- LiteSpeed_Cache_Log::debug( '[Core] Buffer converting to JSON' ) ;
573
- $buffer = json_encode( $buffer ) ;
574
- $buffer = trim( $buffer, '"' ) ;
575
- }
576
- else {
577
- LiteSpeed_Cache_Log::debug( '[Core] JSON Buffer' ) ;
578
- }
579
  }
580
  }
581
 
@@ -628,8 +638,11 @@ class LiteSpeed_Cache
628
  $running_info_showing = false ;
629
  LiteSpeed_Cache_Log::debug( '[Core] ESI silence' ) ;
630
  }
631
- // Silence comment for json req @since 2.9.3
632
- if ( LiteSpeed_Cache_Utility::is_rest() || LiteSpeed_Cache_Router::is_ajax() ) {
 
 
 
633
  $running_info_showing = false ;
634
  LiteSpeed_Cache_Log::debug( '[Core] Silence Comment due to REST/AJAX' ) ;
635
  }
26
  const NAME = 'LiteSpeed Cache' ;
27
  const PLUGIN_NAME = 'litespeed-cache' ;
28
  const PLUGIN_FILE = 'litespeed-cache/litespeed-cache.php' ;
29
+ const PLUGIN_VERSION = '2.9.4' ;
30
 
31
  const PAGE_EDIT_HTACCESS = 'lscache-edit-htaccess' ;
32
 
130
  delete_option( LiteSpeed_Cache_Purge::PURGE_QUEUE ) ;
131
  }
132
 
133
+ /**
134
+ * Hook internal REST
135
+ * @since 2.9.4
136
+ */
137
+ LiteSpeed_Cache_REST::get_instance() ;
138
+
139
  /**
140
  * Added hook before init
141
  * @since 1.6.6
567
  $buffer .= $this->footer_comment ;
568
  }
569
 
570
+ /**
571
+ * If ESI req is JSON, give the content JSON format
572
+ * @since 2.9.3
573
+ * @since 2.9.4 ESI req could be from internal REST call, so moved json_encode out of this cond
574
+ */
575
  if ( defined( 'LSCACHE_IS_ESI' ) ) {
576
  LiteSpeed_Cache_Log::debug( '[Core] ESI----------Start--------' ) ;
577
  LiteSpeed_Cache_Log::debug( $buffer ) ;
578
  LiteSpeed_Cache_Log::debug( '[Core] ESI----------End--------' ) ;
579
+ }
580
 
581
+ if ( apply_filters( 'litespeed_is_json', false ) ) {
582
+ if ( json_decode( $buffer, true ) == NULL ) {
583
+ LiteSpeed_Cache_Log::debug( '[Core] Buffer converting to JSON' ) ;
584
+ $buffer = json_encode( $buffer ) ;
585
+ $buffer = trim( $buffer, '"' ) ;
586
+ }
587
+ else {
588
+ LiteSpeed_Cache_Log::debug( '[Core] JSON Buffer' ) ;
 
589
  }
590
  }
591
 
638
  $running_info_showing = false ;
639
  LiteSpeed_Cache_Log::debug( '[Core] ESI silence' ) ;
640
  }
641
+ /**
642
+ * Silence comment for json req
643
+ * @since 2.9.3
644
+ */
645
+ if ( LiteSpeed_Cache_REST::get_instance()->is_rest() || LiteSpeed_Cache_Router::is_ajax() ) {
646
  $running_info_showing = false ;
647
  LiteSpeed_Cache_Log::debug( '[Core] Silence Comment due to REST/AJAX' ) ;
648
  }
includes/litespeed.autoload.php CHANGED
@@ -46,6 +46,7 @@ if ( !function_exists('_litespeed_autoload') ) {
46
  'LiteSpeed_Cache_Optimize' => 'inc/optimize.class.php',
47
  'LiteSpeed_Cache_Optimizer' => 'inc/optimizer.class.php',
48
  'LiteSpeed_Cache_Purge' => 'inc/purge.class.php',
 
49
  'LiteSpeed_Cache_Router' => 'inc/router.class.php',
50
  'LiteSpeed_Cache_Tag' => 'inc/tag.class.php',
51
  'LiteSpeed_Cache_Task' => 'inc/task.class.php',
46
  'LiteSpeed_Cache_Optimize' => 'inc/optimize.class.php',
47
  'LiteSpeed_Cache_Optimizer' => 'inc/optimizer.class.php',
48
  'LiteSpeed_Cache_Purge' => 'inc/purge.class.php',
49
+ 'LiteSpeed_Cache_REST' => 'inc/rest.cls.php',
50
  'LiteSpeed_Cache_Router' => 'inc/router.class.php',
51
  'LiteSpeed_Cache_Tag' => 'inc/tag.class.php',
52
  'LiteSpeed_Cache_Task' => 'inc/task.class.php',
languages/litespeed-cache.pot CHANGED
@@ -2,9 +2,9 @@
2
  # This file is distributed under the same license as the LiteSpeed Cache package.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: LiteSpeed Cache 2.9.3\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/litespeed-cache\n"
7
- "POT-Creation-Date: 2019-02-20 21:20:32+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
@@ -852,9 +852,10 @@ msgstr ""
852
  msgid "Rate %s on %s"
853
  msgstr ""
854
 
855
- #. #-#-#-#-# litespeed-cache.pot (LiteSpeed Cache 2.9.3) #-#-#-#-#
856
  #. Plugin Name of the plugin/theme
857
- #: admin/tpl/inc/admin_footer.php:6 inc/gui.class.php:477
 
858
  #: includes/litespeed-cache-gui.class.php:477
859
  msgid "LiteSpeed Cache"
860
  msgstr ""
@@ -4228,15 +4229,15 @@ msgstr ""
4228
  msgid "Reset successfully."
4229
  msgstr ""
4230
 
4231
- #: inc/litespeed-cache.class.php:320 includes/litespeed-cache.class.php:320
4232
  msgid "Crawler blacklist is saved."
4233
  msgstr ""
4234
 
4235
- #: inc/litespeed-cache.class.php:331 includes/litespeed-cache.class.php:331
4236
  msgid "Notified LiteSpeed Web Server to purge everything."
4237
  msgstr ""
4238
 
4239
- #: inc/litespeed-cache.class.php:341 includes/litespeed-cache.class.php:341
4240
  msgid "Notified LiteSpeed Web Server to purge the list."
4241
  msgstr ""
4242
 
@@ -4340,15 +4341,15 @@ msgstr ""
4340
  msgid "LiteSpeed Cache Custom Cron Crawler"
4341
  msgstr ""
4342
 
4343
- #: inc/utility.class.php:260 includes/litespeed-cache-utility.class.php:260
4344
  msgid "just now"
4345
  msgstr ""
4346
 
4347
- #: inc/utility.class.php:260 includes/litespeed-cache-utility.class.php:260
4348
  msgid "right now"
4349
  msgstr ""
4350
 
4351
- #: inc/utility.class.php:263 includes/litespeed-cache-utility.class.php:263
4352
  msgid " %s ago"
4353
  msgstr ""
4354
 
2
  # This file is distributed under the same license as the LiteSpeed Cache package.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: LiteSpeed Cache 2.9.4\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/litespeed-cache\n"
7
+ "POT-Creation-Date: 2019-02-27 15:22:04+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
852
  msgid "Rate %s on %s"
853
  msgstr ""
854
 
855
+ #. #-#-#-#-# litespeed-cache.pot (LiteSpeed Cache 2.9.4) #-#-#-#-#
856
  #. Plugin Name of the plugin/theme
857
+ #: admin/tpl/inc/admin_footer.php:6
858
+ #: admin/tpl/inc/banner_promo.new_version.php:56 inc/gui.class.php:477
859
  #: includes/litespeed-cache-gui.class.php:477
860
  msgid "LiteSpeed Cache"
861
  msgstr ""
4229
  msgid "Reset successfully."
4230
  msgstr ""
4231
 
4232
+ #: inc/litespeed-cache.class.php:326 includes/litespeed-cache.class.php:326
4233
  msgid "Crawler blacklist is saved."
4234
  msgstr ""
4235
 
4236
+ #: inc/litespeed-cache.class.php:337 includes/litespeed-cache.class.php:337
4237
  msgid "Notified LiteSpeed Web Server to purge everything."
4238
  msgstr ""
4239
 
4240
+ #: inc/litespeed-cache.class.php:347 includes/litespeed-cache.class.php:347
4241
  msgid "Notified LiteSpeed Web Server to purge the list."
4242
  msgstr ""
4243
 
4341
  msgid "LiteSpeed Cache Custom Cron Crawler"
4342
  msgstr ""
4343
 
4344
+ #: inc/utility.class.php:223 includes/litespeed-cache-utility.class.php:223
4345
  msgid "just now"
4346
  msgstr ""
4347
 
4348
+ #: inc/utility.class.php:223 includes/litespeed-cache-utility.class.php:223
4349
  msgid "right now"
4350
  msgstr ""
4351
 
4352
+ #: inc/utility.class.php:226 includes/litespeed-cache-utility.class.php:226
4353
  msgid " %s ago"
4354
  msgstr ""
4355
 
litespeed-cache.php CHANGED
@@ -15,7 +15,7 @@
15
  * Plugin Name: LiteSpeed Cache
16
  * Plugin URI: https://www.litespeedtech.com/products/cache-plugins/wordpress-acceleration
17
  * Description: High-performance page caching and site optimization from LiteSpeed
18
- * Version: 2.9.3
19
  * Author: LiteSpeed Technologies
20
  * Author URI: https://www.litespeedtech.com
21
  * License: GPLv3
15
  * Plugin Name: LiteSpeed Cache
16
  * Plugin URI: https://www.litespeedtech.com/products/cache-plugins/wordpress-acceleration
17
  * Description: High-performance page caching and site optimization from LiteSpeed
18
+ * Version: 2.9.4
19
  * Author: LiteSpeed Technologies
20
  * Author URI: https://www.litespeedtech.com
21
  * License: GPLv3
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: LiteSpeedTech
3
  Tags: caching, optimize, performance, pagespeed, seo, speed, image optimize, compress, object cache, redis, memcached, database cleaner
4
  Requires at least: 4.0
5
- Tested up to: 5.0.3
6
- Stable tag: 2.9.3
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl.html
9
 
@@ -283,6 +283,16 @@ Click on the `Advanced View` link at the top of the page, and several more tabs
283
 
284
  == Changelog ==
285
 
 
 
 
 
 
 
 
 
 
 
286
  = 2.9.3 - Feb 20 2019 =
287
  * <strong>ESI</strong>: ESI shortcodes can now be saved in Gutenberg editor.
288
  * <strong>ESI</strong>: ESI now honors the parent page JSON data type to avoid breaking REST calls (LSWS 5.3.6+).
2
  Contributors: LiteSpeedTech
3
  Tags: caching, optimize, performance, pagespeed, seo, speed, image optimize, compress, object cache, redis, memcached, database cleaner
4
  Requires at least: 4.0
5
+ Tested up to: 5.1
6
+ Stable tag: 2.9.4
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl.html
9
 
283
 
284
  == Changelog ==
285
 
286
+ = 2.9.4 - Feb 27 2019 =
287
+ * 🐞<strong>REST</strong>: New REST class with better WP5 Gutenberg and internal REST call support when ESI is embedded.
288
+ * <strong>ESI</strong>: ESI block ID is now in plain text in ESI URL parameters.
289
+ * 🐞<strong>ESI</strong>: Fixed a redundant ESI 301 redirect when comma is in ESI URL.
290
+ * <strong>ESI</strong>: REST call can now parse shortcodes in ESI.
291
+ * <strong>API</strong>: Changed ESI `parse_esi_param()` function to private and `load_esi_block` function to non-static.
292
+ * <strong>API</strong>: Added `litespeed_is_json` hook for buffer JSON conversion.
293
+ * <strong>GUI</strong>: Prepended plugin name to new version notification banner.
294
+ * <strong>3rd</strong>: WPML multi domains can now be handled in optimization without CDN tricks.
295
+
296
  = 2.9.3 - Feb 20 2019 =
297
  * <strong>ESI</strong>: ESI shortcodes can now be saved in Gutenberg editor.
298
  * <strong>ESI</strong>: ESI now honors the parent page JSON data type to avoid breaking REST calls (LSWS 5.3.6+).
thirdparty/lscwp-3rd-wpml.cls.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * The Third Party integration with WPML.
4
+ *
5
+ * @since 2.9.4
6
+ * @package LiteSpeed_Cache
7
+ * @subpackage LiteSpeed_Cache/thirdparty
8
+ * @author LiteSpeed Technologies <info@litespeedtech.com>
9
+ */
10
+ defined( 'WPINC' ) || exit ;
11
+
12
+ LiteSpeed_Cache_API::register( 'LiteSpeed_Cache_ThirdParty_WPML' ) ;
13
+
14
+
15
+ class LiteSpeed_Cache_ThirdParty_WPML
16
+ {
17
+
18
+ public static function detect()
19
+ {
20
+ if ( ! defined( 'WPML_PLUGIN_BASENAME' ) ) return ;
21
+
22
+ add_filter( 'litespeed_internal_domains', __CLASS__ . '::append_domains' ) ;
23
+ }
24
+
25
+ /**
26
+ * Take language domains as internal domains
27
+ */
28
+ public static function append_domains( $domains )
29
+ {
30
+ $wpml_domains = apply_filters( 'wpml_setting', false, 'language_domains' ) ;
31
+ if ( $wpml_domains ) {
32
+ $domains = array_merge( $domains, array_values( $wpml_domains ) ) ;
33
+ }
34
+
35
+ return $domains ;
36
+ }
37
+
38
+ }
thirdparty/lscwp-registry-3rd.php CHANGED
@@ -31,6 +31,7 @@ $thirdparty_list = array(
31
  'avada',
32
  'wp-postratings',
33
  'divi-theme-builder',
 
34
  ) ;
35
 
36
  foreach ($thirdparty_list as $val) {
31
  'avada',
32
  'wp-postratings',
33
  'divi-theme-builder',
34
+ 'wpml',
35
  ) ;
36
 
37
  foreach ($thirdparty_list as $val) {
tpl/dummy.tpl.php DELETED
@@ -1,9 +0,0 @@
1
- <?php
2
-
3
- /*
4
- * This file is a dummy template file.
5
- *
6
- * It is meant to be used to skip comment processing on the main request
7
- * when using esi comments.
8
- */
9
-
 
 
 
 
 
 
 
 
 
tpl/esi.tpl.php CHANGED
@@ -4,6 +4,6 @@ if ( ! defined('ABSPATH') ) {
4
  die() ;
5
  }
6
 
7
- LiteSpeed_Cache_ESI::load_esi_block() ;
8
 
9
 
4
  die() ;
5
  }
6
 
7
+ LiteSpeed_Cache_ESI::get_instance()->load_esi_block() ;
8
 
9