Version Description
- Apr 10 2018 =
- [NEW FEATURE] Included Directories setting in CDN tab. (@Dave)
- [NEW FEATURE] Purge All Hooks setting in Advanced tab.
- [UPDATE] Added background-image WebP replacement support. (@vengen)
- [UPDATE] Show recommended values for textarea items in settings.
- [UPDATE] Moved CSS/JS optimizer log to Advanced level.
- [INTEGRATION] Added WebP support for Avada Fusion Sliders. (@vengen)
Download this release
Release Info
Developer | LiteSpeedTech |
Plugin | LiteSpeed Cache |
Version | 2.2.1 |
Comparing to | |
See all releases |
Code changes from version 2.2.0.2 to 2.2.1
- admin/litespeed-cache-admin-display.class.php +12 -9
- admin/litespeed-cache-admin-report.class.php +8 -0
- admin/litespeed-cache-admin-settings.class.php +38 -8
- admin/litespeed-cache-admin.class.php +2 -6
- admin/tpl/setting/settings_advanced.php +15 -0
- admin/tpl/setting/settings_cdn.php +15 -2
- inc/cdn.class.php +65 -59
- inc/config.class.php +63 -5
- inc/import.class.php +1 -20
- inc/litespeed-cache.class.php +1 -8
- inc/media.class.php +16 -0
- inc/object.class.php +2 -0
- inc/optimize.class.php +4 -4
- inc/optimizer.class.php +2 -2
- inc/utility.class.php +4 -0
- includes/litespeed-cache-cdn.class.php +65 -59
- includes/litespeed-cache-config.class.php +63 -5
- includes/litespeed-cache-optimize.class.php +4 -4
- includes/litespeed-cache-utility.class.php +4 -0
- includes/litespeed-cache.class.php +1 -8
- litespeed-cache.php +10 -1
- readme.txt +13 -4
admin/litespeed-cache-admin-display.class.php
CHANGED
@@ -703,13 +703,7 @@ class LiteSpeed_Cache_Admin_Display
|
|
703 |
public function build_textarea2( $id, $cols = false )
|
704 |
{
|
705 |
// Get default val for separate item
|
706 |
-
$
|
707 |
-
|
708 |
-
$val = get_option( $id, $default_val ) ;
|
709 |
-
|
710 |
-
if ( is_array( $val ) ) {
|
711 |
-
$val = implode( "\n", $val ) ;
|
712 |
-
}
|
713 |
|
714 |
$this->build_textarea( $id, $cols, $val ) ;
|
715 |
}
|
@@ -902,9 +896,18 @@ class LiteSpeed_Cache_Admin_Display
|
|
902 |
* @access public
|
903 |
* @param string $id The setting tag
|
904 |
*/
|
905 |
-
public function recommended( $id )
|
906 |
{
|
907 |
-
$val =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
908 |
if ( $val ) {
|
909 |
if ( ! is_numeric( $val ) && strpos( $val, "\n" ) !== false ) {
|
910 |
$val = "<textarea readonly rows='5' class='litespeed-left10'>$val</textarea>" ;
|
703 |
public function build_textarea2( $id, $cols = false )
|
704 |
{
|
705 |
// Get default val for separate item
|
706 |
+
$val = $this->config->get_item( $id, true ) ;
|
|
|
|
|
|
|
|
|
|
|
|
|
707 |
|
708 |
$this->build_textarea( $id, $cols, $val ) ;
|
709 |
}
|
896 |
* @access public
|
897 |
* @param string $id The setting tag
|
898 |
*/
|
899 |
+
public function recommended( $id, $is_item = false )
|
900 |
{
|
901 |
+
$val = '' ;
|
902 |
+
if ( ! $is_item ) {
|
903 |
+
if ( isset( $this->default_settings[ $id ] ) ) {
|
904 |
+
$val = $this->default_settings[ $id ] ;
|
905 |
+
}
|
906 |
+
}
|
907 |
+
else {
|
908 |
+
$val = $this->config->default_item( $id ) ;
|
909 |
+
}
|
910 |
+
|
911 |
if ( $val ) {
|
912 |
if ( ! is_numeric( $val ) && strpos( $val, "\n" ) !== false ) {
|
913 |
$val = "<textarea readonly rows='5' class='litespeed-left10'>$val</textarea>" ;
|
admin/litespeed-cache-admin-report.class.php
CHANGED
@@ -172,8 +172,16 @@ class LiteSpeed_Cache_Admin_Report
|
|
172 |
}
|
173 |
|
174 |
$item_options = array(
|
|
|
|
|
|
|
175 |
LiteSpeed_Cache_Config::ITEM_CDN_MAPPING,
|
176 |
LiteSpeed_Cache_Config::ITEM_SETTING_MODE,
|
|
|
|
|
|
|
|
|
|
|
177 |
) ;
|
178 |
|
179 |
foreach ( $item_options as $v ) {
|
172 |
}
|
173 |
|
174 |
$item_options = array(
|
175 |
+
LiteSpeed_Cache_Config::EXCLUDE_OPTIMIZATION_ROLES,
|
176 |
+
LiteSpeed_Cache_Config::EXCLUDE_CACHE_ROLES,
|
177 |
+
LiteSpeed_Cache_Config::ITEM_CACHE_DROP_QS,
|
178 |
LiteSpeed_Cache_Config::ITEM_CDN_MAPPING,
|
179 |
LiteSpeed_Cache_Config::ITEM_SETTING_MODE,
|
180 |
+
LiteSpeed_Cache_Config::ITEM_OPTM_JS_DEFER_EXC,
|
181 |
+
LiteSpeed_Cache_Config::ITEM_MEDIA_LAZY_IMG_EXC,
|
182 |
+
LiteSpeed_Cache_Config::ITEM_CRWL_AS_UIDS,
|
183 |
+
LiteSpeed_Cache_Config::ITEM_ADV_PURGE_ALL_HOOKS,
|
184 |
+
LiteSpeed_Cache_Config::ITEM_CDN_ORI_DIR,
|
185 |
) ;
|
186 |
|
187 |
foreach ( $item_options as $v ) {
|
admin/litespeed-cache-admin-settings.class.php
CHANGED
@@ -409,7 +409,7 @@ class LiteSpeed_Cache_Admin_Settings
|
|
409 |
LiteSpeed_Cache_Config::ITEM_CACHE_DROP_QS, // Update Drop Query String @since 1.7
|
410 |
);
|
411 |
foreach ( $ids as $id ) {
|
412 |
-
|
413 |
}
|
414 |
|
415 |
}
|
@@ -590,6 +590,13 @@ class LiteSpeed_Cache_Admin_Settings
|
|
590 |
$this->_options[ $id ] = LiteSpeed_Cache_Utility::sanitize_lines( $this->_input[ $id ] ) ;
|
591 |
}
|
592 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
593 |
/**
|
594 |
* Handle multiple CDN setting
|
595 |
* @since 1.7
|
@@ -697,8 +704,7 @@ class LiteSpeed_Cache_Admin_Settings
|
|
697 |
|
698 |
// Update lazyload image excludes
|
699 |
$id = LiteSpeed_Cache_Config::ITEM_MEDIA_LAZY_IMG_EXC ;
|
700 |
-
|
701 |
-
|
702 |
}
|
703 |
|
704 |
/**
|
@@ -759,18 +765,18 @@ class LiteSpeed_Cache_Admin_Settings
|
|
759 |
|
760 |
// Update js deferred excludes
|
761 |
$id = LiteSpeed_Cache_Config::ITEM_OPTM_JS_DEFER_EXC ;
|
762 |
-
|
763 |
|
764 |
// Update Role Excludes
|
765 |
$id = LiteSpeed_Cache_Config::EXCLUDE_OPTIMIZATION_ROLES ;
|
766 |
-
|
767 |
|
768 |
/**
|
769 |
* DNS prefetch
|
770 |
* @since 1.7.1
|
771 |
*/
|
772 |
$id = LiteSpeed_Cache_Config::ITEM_DNS_PREFETCH ;
|
773 |
-
|
774 |
|
775 |
/**
|
776 |
* Combined file max size
|
@@ -797,6 +803,13 @@ class LiteSpeed_Cache_Admin_Settings
|
|
797 |
$this->_options[ $id ] = self::parse_onoff( $this->_input, $id ) ;
|
798 |
}
|
799 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
800 |
/**
|
801 |
* Added Favicon
|
802 |
* @since 1.7.2
|
@@ -896,7 +909,7 @@ class LiteSpeed_Cache_Admin_Settings
|
|
896 |
LiteSpeed_Cache_Config::ITEM_LOG_IGNORE_PART_FILTERS,
|
897 |
) ;
|
898 |
foreach ( $ids as $id ) {
|
899 |
-
|
900 |
}
|
901 |
}
|
902 |
|
@@ -983,7 +996,7 @@ class LiteSpeed_Cache_Admin_Settings
|
|
983 |
}
|
984 |
|
985 |
$id = LiteSpeed_Cache_Config::ITEM_CRWL_AS_UIDS ;
|
986 |
-
|
987 |
|
988 |
}
|
989 |
|
@@ -1316,6 +1329,23 @@ class LiteSpeed_Cache_Admin_Settings
|
|
1316 |
return LiteSpeed_Cache_Config::VAL_OFF ;
|
1317 |
}
|
1318 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1319 |
/**
|
1320 |
* Get the current instance object.
|
1321 |
*
|
409 |
LiteSpeed_Cache_Config::ITEM_CACHE_DROP_QS, // Update Drop Query String @since 1.7
|
410 |
);
|
411 |
foreach ( $ids as $id ) {
|
412 |
+
$this->_save_item( $id ) ;
|
413 |
}
|
414 |
|
415 |
}
|
590 |
$this->_options[ $id ] = LiteSpeed_Cache_Utility::sanitize_lines( $this->_input[ $id ] ) ;
|
591 |
}
|
592 |
|
593 |
+
$ids = array(
|
594 |
+
LiteSpeed_Cache_Config::ITEM_CDN_ORI_DIR,
|
595 |
+
) ;
|
596 |
+
foreach ( $ids as $id ) {
|
597 |
+
$this->_save_item( $id ) ;
|
598 |
+
}
|
599 |
+
|
600 |
/**
|
601 |
* Handle multiple CDN setting
|
602 |
* @since 1.7
|
704 |
|
705 |
// Update lazyload image excludes
|
706 |
$id = LiteSpeed_Cache_Config::ITEM_MEDIA_LAZY_IMG_EXC ;
|
707 |
+
$this->_save_item( $id, 'uri' ) ;
|
|
|
708 |
}
|
709 |
|
710 |
/**
|
765 |
|
766 |
// Update js deferred excludes
|
767 |
$id = LiteSpeed_Cache_Config::ITEM_OPTM_JS_DEFER_EXC ;
|
768 |
+
$this->_save_item( $id, 'uri' ) ;
|
769 |
|
770 |
// Update Role Excludes
|
771 |
$id = LiteSpeed_Cache_Config::EXCLUDE_OPTIMIZATION_ROLES ;
|
772 |
+
$this->_save_item( $id ) ;
|
773 |
|
774 |
/**
|
775 |
* DNS prefetch
|
776 |
* @since 1.7.1
|
777 |
*/
|
778 |
$id = LiteSpeed_Cache_Config::ITEM_DNS_PREFETCH ;
|
779 |
+
$this->_save_item( $id, 'domain' ) ;
|
780 |
|
781 |
/**
|
782 |
* Combined file max size
|
803 |
$this->_options[ $id ] = self::parse_onoff( $this->_input, $id ) ;
|
804 |
}
|
805 |
|
806 |
+
$ids = array(
|
807 |
+
LiteSpeed_Cache_Config::ITEM_ADV_PURGE_ALL_HOOKS,
|
808 |
+
) ;
|
809 |
+
foreach ( $ids as $id ) {
|
810 |
+
$this->_save_item( $id ) ;
|
811 |
+
}
|
812 |
+
|
813 |
/**
|
814 |
* Added Favicon
|
815 |
* @since 1.7.2
|
909 |
LiteSpeed_Cache_Config::ITEM_LOG_IGNORE_PART_FILTERS,
|
910 |
) ;
|
911 |
foreach ( $ids as $id ) {
|
912 |
+
$this->_save_item( $id ) ;
|
913 |
}
|
914 |
}
|
915 |
|
996 |
}
|
997 |
|
998 |
$id = LiteSpeed_Cache_Config::ITEM_CRWL_AS_UIDS ;
|
999 |
+
$this->_save_item( $id ) ;
|
1000 |
|
1001 |
}
|
1002 |
|
1329 |
return LiteSpeed_Cache_Config::VAL_OFF ;
|
1330 |
}
|
1331 |
|
1332 |
+
/**
|
1333 |
+
* To save item in options
|
1334 |
+
*
|
1335 |
+
* @since 2.2.1
|
1336 |
+
* @access private
|
1337 |
+
*/
|
1338 |
+
private function _save_item( $id, $sanitize_filter = false )
|
1339 |
+
{
|
1340 |
+
$val = '' ;
|
1341 |
+
|
1342 |
+
if ( ! empty( $this->_input[ $id ] ) ) {
|
1343 |
+
$val = LiteSpeed_Cache_Utility::sanitize_lines( $this->_input[ $id ], $sanitize_filter ) ;
|
1344 |
+
}
|
1345 |
+
|
1346 |
+
update_option( $id, $val ) ;
|
1347 |
+
}
|
1348 |
+
|
1349 |
/**
|
1350 |
* Get the current instance object.
|
1351 |
*
|
admin/litespeed-cache-admin.class.php
CHANGED
@@ -41,12 +41,8 @@ class LiteSpeed_Cache_Admin
|
|
41 |
|
42 |
if ( defined( 'LITESPEED_ON' ) ) {
|
43 |
// register purge_all actions
|
44 |
-
$purge_all_events =
|
45 |
-
|
46 |
-
'wp_create_nav_menu', 'wp_update_nav_menu', 'wp_delete_nav_menu',
|
47 |
-
'create_term', 'edit_terms', 'delete_term',
|
48 |
-
'add_link', 'edit_link', 'delete_link'
|
49 |
-
) ;
|
50 |
// purge all on upgrade
|
51 |
if ( LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_PURGE_ON_UPGRADE ) ) {
|
52 |
$purge_all_events[] = 'upgrader_process_complete' ;
|
41 |
|
42 |
if ( defined( 'LITESPEED_ON' ) ) {
|
43 |
// register purge_all actions
|
44 |
+
$purge_all_events = $this->config->get_item( LiteSpeed_Cache_Config::ITEM_ADV_PURGE_ALL_HOOKS ) ;
|
45 |
+
|
|
|
|
|
|
|
|
|
46 |
// purge all on upgrade
|
47 |
if ( LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_PURGE_ON_UPGRADE ) ) {
|
48 |
$purge_all_events[] = 'upgrader_process_complete' ;
|
admin/tpl/setting/settings_advanced.php
CHANGED
@@ -27,6 +27,21 @@ if (!defined('WPINC')) die;
|
|
27 |
endif ;
|
28 |
?>
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
<tr>
|
31 |
<th><?php echo __( 'Improve HTTP/HTTPS Compatibility', 'litespeed-cache' ) ; ?></th>
|
32 |
<td>
|
27 |
endif ;
|
28 |
?>
|
29 |
|
30 |
+
<tr>
|
31 |
+
<th><?php echo __( 'Purge All Hooks', 'litespeed-cache' ) ; ?></th>
|
32 |
+
<td>
|
33 |
+
<?php $id = LiteSpeed_Cache_Config::ITEM_ADV_PURGE_ALL_HOOKS ; ?>
|
34 |
+
<?php $this->build_textarea2( $id, 50 ) ; ?>
|
35 |
+
<?php $this->recommended( $id, true ) ; ?>
|
36 |
+
|
37 |
+
<div class="litespeed-desc">
|
38 |
+
<?php echo __( 'A Purge All will be executed when WordPress runs these hooks.', 'litespeed-cache' ) ; ?>
|
39 |
+
<a href="https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:cache:lscwp:configuration:advanced#hooks_to_purge_all" target="_blank"><?php echo __('Learn More', 'litespeed-cache') ; ?></a>
|
40 |
+
|
41 |
+
</div>
|
42 |
+
</td>
|
43 |
+
</tr>
|
44 |
+
|
45 |
<tr>
|
46 |
<th><?php echo __( 'Improve HTTP/HTTPS Compatibility', 'litespeed-cache' ) ; ?></th>
|
47 |
<td>
|
admin/tpl/setting/settings_cdn.php
CHANGED
@@ -122,7 +122,7 @@ if ( ! $cdn_mapping ) {
|
|
122 |
</tr>
|
123 |
|
124 |
<tr>
|
125 |
-
<th><?php echo __( 'Original
|
126 |
<td>
|
127 |
<?php $this->build_input( LiteSpeed_Cache_Config::OPID_CDN_ORI, 'litespeed-input-long' ) ; ?>
|
128 |
<div class="litespeed-desc">
|
@@ -133,6 +133,19 @@ if ( ! $cdn_mapping ) {
|
|
133 |
</td>
|
134 |
</tr>
|
135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
<tr>
|
137 |
<th><?php echo __( 'Exclude Path', 'litespeed-cache' ) ; ?></th>
|
138 |
<td>
|
@@ -152,7 +165,7 @@ if ( ! $cdn_mapping ) {
|
|
152 |
<?php echo $this->build_radio(
|
153 |
LiteSpeed_Cache_Config::OPID_CDN_REMOTE_JQUERY,
|
154 |
LiteSpeed_Cache_Config::VAL_OFF,
|
155 |
-
__( '
|
156 |
) ; ?>
|
157 |
|
158 |
<?php echo $this->build_radio(
|
122 |
</tr>
|
123 |
|
124 |
<tr>
|
125 |
+
<th><?php echo __( 'Original URLs', 'litespeed-cache' ) ; ?></th>
|
126 |
<td>
|
127 |
<?php $this->build_input( LiteSpeed_Cache_Config::OPID_CDN_ORI, 'litespeed-input-long' ) ; ?>
|
128 |
<div class="litespeed-desc">
|
133 |
</td>
|
134 |
</tr>
|
135 |
|
136 |
+
<tr>
|
137 |
+
<th><?php echo __( 'Included Directories', 'litespeed-cache' ) ; ?></th>
|
138 |
+
<td>
|
139 |
+
<?php $id = LiteSpeed_Cache_Config::ITEM_CDN_ORI_DIR ; ?>
|
140 |
+
<?php $this->build_textarea2( $id, 40 ) ; ?>
|
141 |
+
<?php $this->recommended( $id, true ) ; ?>
|
142 |
+
<div class="litespeed-desc">
|
143 |
+
<?php echo __( 'Only files within these directories will be pointed to the CDN.', 'litespeed-cache' ) ; ?>
|
144 |
+
<?php echo __('One per line.', 'litespeed-cache'); ?>
|
145 |
+
</div>
|
146 |
+
</td>
|
147 |
+
</tr>
|
148 |
+
|
149 |
<tr>
|
150 |
<th><?php echo __( 'Exclude Path', 'litespeed-cache' ) ; ?></th>
|
151 |
<td>
|
165 |
<?php echo $this->build_radio(
|
166 |
LiteSpeed_Cache_Config::OPID_CDN_REMOTE_JQUERY,
|
167 |
LiteSpeed_Cache_Config::VAL_OFF,
|
168 |
+
__( 'OFF', 'litespeed-cache' )
|
169 |
) ; ?>
|
170 |
|
171 |
<?php echo $this->build_radio(
|
inc/cdn.class.php
CHANGED
@@ -18,11 +18,12 @@ class LiteSpeed_Cache_CDN
|
|
18 |
|
19 |
private $content ;
|
20 |
|
21 |
-
private $
|
22 |
-
private $
|
23 |
-
private $
|
24 |
-
private $
|
25 |
-
private $
|
|
|
26 |
|
27 |
private $cdn_mapping_hosts = array() ;
|
28 |
|
@@ -48,20 +49,20 @@ class LiteSpeed_Cache_CDN
|
|
48 |
* This is separate from CDN on/off
|
49 |
* @since 1.5
|
50 |
*/
|
51 |
-
$this->
|
52 |
-
if ( $this->
|
53 |
add_action( 'init', array( $this, 'load_jquery_remotely' ) ) ;
|
54 |
}
|
55 |
|
56 |
-
$this->
|
57 |
-
if ( ! $this->
|
58 |
if ( ! defined( self::BYPASS ) ) {
|
59 |
define( self::BYPASS, true ) ;
|
60 |
}
|
61 |
return ;
|
62 |
}
|
63 |
|
64 |
-
$this->
|
65 |
$cfg_cdn_url = get_option( LiteSpeed_Cache_Config::ITEM_CDN_MAPPING, array() ) ;
|
66 |
// Parse cdn mapping data to array( 'filetype' => 'url' )
|
67 |
$mapping_to_check = array(
|
@@ -78,7 +79,7 @@ class LiteSpeed_Cache_CDN
|
|
78 |
// Check img/css/js
|
79 |
foreach ( $mapping_to_check as $to_check ) {
|
80 |
if ( $v[ $to_check ] ) {
|
81 |
-
LiteSpeed_Cache_Log::debug2( 'CDN
|
82 |
|
83 |
// If filetype to url is one to many, make url be an array
|
84 |
$this->_append_cdn_mapping( $to_check, $this_url ) ;
|
@@ -93,7 +94,7 @@ class LiteSpeed_Cache_CDN
|
|
93 |
$filetypes = array_map( 'trim', explode( "\n", $v[ LiteSpeed_Cache_Config::ITEM_CDN_MAPPING_FILETYPE ] ) ) ;
|
94 |
foreach ( $filetypes as $v2 ) {
|
95 |
if ( $v2 ) {
|
96 |
-
$this->
|
97 |
|
98 |
// If filetype to url is one to many, make url be an array
|
99 |
$this->_append_cdn_mapping( $v2, $this_url ) ;
|
@@ -103,30 +104,37 @@ class LiteSpeed_Cache_CDN
|
|
103 |
}
|
104 |
}
|
105 |
}
|
106 |
-
LiteSpeed_Cache_Log::debug2( 'CDN
|
107 |
}
|
108 |
}
|
109 |
-
|
|
|
110 |
if ( ! defined( self::BYPASS ) ) {
|
111 |
define( self::BYPASS, true ) ;
|
112 |
}
|
113 |
return ;
|
114 |
}
|
115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
// Check if need preg_replace
|
117 |
-
if ( strpos( $this->
|
118 |
-
LiteSpeed_Cache_Log::debug( 'CDN
|
119 |
-
$this->
|
120 |
-
$this->
|
121 |
-
LiteSpeed_Cache_Log::debug2( 'CDN
|
122 |
}
|
123 |
|
124 |
-
$this->
|
125 |
|
126 |
-
$this->
|
127 |
-
$this->
|
128 |
|
129 |
-
if ( ! empty( $this->
|
130 |
// Hook to srcset
|
131 |
if ( function_exists( 'wp_calculate_image_srcset' ) ) {
|
132 |
add_filter( 'wp_calculate_image_srcset', array( $this, 'srcset' ), 999 ) ;
|
@@ -136,11 +144,11 @@ class LiteSpeed_Cache_CDN
|
|
136 |
add_filter( 'wp_get_attachment_url', array( $this, 'url_img' ), 999 ) ;
|
137 |
}
|
138 |
|
139 |
-
if ( ! empty( $this->
|
140 |
add_filter( 'style_loader_src', array( $this, 'url_css' ), 999 ) ;
|
141 |
}
|
142 |
|
143 |
-
if ( ! empty( $this->
|
144 |
add_filter( 'script_loader_src', array( $this, 'url_js' ), 999 ) ;
|
145 |
}
|
146 |
|
@@ -155,16 +163,16 @@ class LiteSpeed_Cache_CDN
|
|
155 |
private function _append_cdn_mapping( $filetype, $url )
|
156 |
{
|
157 |
// If filetype to url is one to many, make url be an array
|
158 |
-
if ( empty( $this->
|
159 |
-
$this->
|
160 |
}
|
161 |
-
elseif ( is_array( $this->
|
162 |
// Append url to filetype
|
163 |
-
$this->
|
164 |
}
|
165 |
else {
|
166 |
-
// Convert
|
167 |
-
$this->
|
168 |
}
|
169 |
}
|
170 |
|
@@ -199,11 +207,11 @@ class LiteSpeed_Cache_CDN
|
|
199 |
{
|
200 |
$instance = self::get_instance() ;
|
201 |
|
202 |
-
if ( $type == 'css' && ! empty( $instance->
|
203 |
return true ;
|
204 |
}
|
205 |
|
206 |
-
if ( $type == 'js' && ! empty( $instance->
|
207 |
return true ;
|
208 |
}
|
209 |
|
@@ -275,12 +283,12 @@ class LiteSpeed_Cache_CDN
|
|
275 |
LiteSpeed_Cache_Log::debug( 'CDN _finalize' ) ;
|
276 |
|
277 |
// Start replacing img src
|
278 |
-
if ( ! empty( $this->
|
279 |
$this->_replace_img() ;
|
280 |
$this->_replace_inline_css() ;
|
281 |
}
|
282 |
|
283 |
-
if ( ! empty( $this->
|
284 |
$this->_replace_file_types() ;
|
285 |
}
|
286 |
|
@@ -299,7 +307,7 @@ class LiteSpeed_Cache_CDN
|
|
299 |
return ;
|
300 |
}
|
301 |
|
302 |
-
$filetypes = array_keys( $this->
|
303 |
foreach ( $matches[ 2 ] as $k => $url ) {
|
304 |
$url_parsed = parse_url( $url ) ;
|
305 |
if ( empty( $url_parsed[ 'path' ] ) ) {
|
@@ -462,57 +470,55 @@ class LiteSpeed_Cache_CDN
|
|
462 |
*/
|
463 |
public function rewrite( $url, $mapping_kind, $postfix = false )
|
464 |
{
|
465 |
-
LiteSpeed_Cache_Log::debug2( 'CDN
|
466 |
$url_parsed = parse_url( $url ) ;
|
467 |
|
468 |
// Only images under wp-cotnent/wp-includes can be replaced
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
}
|
474 |
}
|
475 |
|
476 |
// Check if is external url
|
477 |
if ( ! empty( $url_parsed[ 'host' ] ) ) {
|
478 |
if ( ! LiteSpeed_Cache_Utility::internal( $url_parsed[ 'host' ] ) && ! $this->_is_ori_url( $url ) ) {
|
479 |
-
LiteSpeed_Cache_Log::debug2( 'CDN
|
480 |
return false ;
|
481 |
}
|
482 |
}
|
483 |
|
484 |
-
if ( $this->
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
}
|
490 |
}
|
491 |
}
|
492 |
|
493 |
// Fill full url before replacement
|
494 |
if ( empty( $url_parsed[ 'host' ] ) ) {
|
495 |
$url = LiteSpeed_Cache_Utility::uri2url( $url ) ;
|
496 |
-
LiteSpeed_Cache_Log::debug2( 'CDN
|
497 |
|
498 |
$url_parsed = parse_url( $url ) ;
|
499 |
}
|
500 |
|
501 |
$scheme = ! empty( $url_parsed[ 'scheme' ] ) ? $url_parsed[ 'scheme' ] . ':' : '' ;
|
502 |
if ( $scheme ) {
|
503 |
-
LiteSpeed_Cache_Log::debug2( 'CDN
|
504 |
}
|
505 |
|
506 |
// Find the mapping url to be replaced to
|
507 |
-
if ( empty( $this->
|
508 |
return false ;
|
509 |
}
|
510 |
if ( $mapping_kind !== LiteSpeed_Cache_Config::ITEM_CDN_MAPPING_FILETYPE ) {
|
511 |
-
$final_url = $this->
|
512 |
}
|
513 |
else {
|
514 |
// select from file type
|
515 |
-
$final_url = $this->
|
516 |
}
|
517 |
|
518 |
// If filetype to url is one to many, need to random one
|
@@ -521,7 +527,7 @@ class LiteSpeed_Cache_CDN
|
|
521 |
}
|
522 |
|
523 |
// Now lets replace CDN url
|
524 |
-
foreach ( $this->
|
525 |
if ( strpos( $v, '*' ) !== false ) {
|
526 |
$url = preg_replace( '#' . $scheme . $v . '#iU', $final_url, $url ) ;
|
527 |
}
|
@@ -529,7 +535,7 @@ class LiteSpeed_Cache_CDN
|
|
529 |
$url = str_replace( $scheme . $v, $final_url, $url ) ;
|
530 |
}
|
531 |
}
|
532 |
-
LiteSpeed_Cache_Log::debug2( 'CDN
|
533 |
|
534 |
return $url ;
|
535 |
}
|
@@ -546,7 +552,7 @@ class LiteSpeed_Cache_CDN
|
|
546 |
|
547 |
$scheme = ! empty( $url_parsed[ 'scheme' ] ) ? $url_parsed[ 'scheme' ] . ':' : '' ;
|
548 |
|
549 |
-
foreach ( $this->
|
550 |
$needle = $scheme . $v ;
|
551 |
if ( strpos( $v, '*' ) !== false ) {
|
552 |
if( preg_match( '#' . $needle . '#iU', $url ) ) {
|
@@ -597,9 +603,9 @@ class LiteSpeed_Cache_CDN
|
|
597 |
$v = $wp_scripts->registered[ 'jquery' ]->ver ;
|
598 |
}
|
599 |
|
600 |
-
$src = $this->
|
601 |
|
602 |
-
LiteSpeed_Cache_Log::debug2( 'CDN
|
603 |
|
604 |
wp_deregister_script( 'jquery' ) ;
|
605 |
|
18 |
|
19 |
private $content ;
|
20 |
|
21 |
+
private $_cfg_cdn ;
|
22 |
+
private $_cfg_url_ori ;
|
23 |
+
private $_cfg_ori_dir ;
|
24 |
+
private $_cfg_cdn_mapping = array() ;
|
25 |
+
private $_cfg_cdn_exclude ;
|
26 |
+
private $_cfg_cdn_remote_jquery ;
|
27 |
|
28 |
private $cdn_mapping_hosts = array() ;
|
29 |
|
49 |
* This is separate from CDN on/off
|
50 |
* @since 1.5
|
51 |
*/
|
52 |
+
$this->_cfg_cdn_remote_jquery = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_CDN_REMOTE_JQUERY ) ;
|
53 |
+
if ( $this->_cfg_cdn_remote_jquery ) {
|
54 |
add_action( 'init', array( $this, 'load_jquery_remotely' ) ) ;
|
55 |
}
|
56 |
|
57 |
+
$this->_cfg_cdn = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_CDN ) ;
|
58 |
+
if ( ! $this->_cfg_cdn ) {
|
59 |
if ( ! defined( self::BYPASS ) ) {
|
60 |
define( self::BYPASS, true ) ;
|
61 |
}
|
62 |
return ;
|
63 |
}
|
64 |
|
65 |
+
$this->_cfg_url_ori = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_CDN_ORI ) ;
|
66 |
$cfg_cdn_url = get_option( LiteSpeed_Cache_Config::ITEM_CDN_MAPPING, array() ) ;
|
67 |
// Parse cdn mapping data to array( 'filetype' => 'url' )
|
68 |
$mapping_to_check = array(
|
79 |
// Check img/css/js
|
80 |
foreach ( $mapping_to_check as $to_check ) {
|
81 |
if ( $v[ $to_check ] ) {
|
82 |
+
LiteSpeed_Cache_Log::debug2( '[CDN] mapping ' . $to_check . ' -> ' . $this_url ) ;
|
83 |
|
84 |
// If filetype to url is one to many, make url be an array
|
85 |
$this->_append_cdn_mapping( $to_check, $this_url ) ;
|
94 |
$filetypes = array_map( 'trim', explode( "\n", $v[ LiteSpeed_Cache_Config::ITEM_CDN_MAPPING_FILETYPE ] ) ) ;
|
95 |
foreach ( $filetypes as $v2 ) {
|
96 |
if ( $v2 ) {
|
97 |
+
$this->_cfg_cdn_mapping[ LiteSpeed_Cache_Config::ITEM_CDN_MAPPING_FILETYPE ] = true ;
|
98 |
|
99 |
// If filetype to url is one to many, make url be an array
|
100 |
$this->_append_cdn_mapping( $v2, $this_url ) ;
|
104 |
}
|
105 |
}
|
106 |
}
|
107 |
+
LiteSpeed_Cache_Log::debug2( '[CDN] mapping ' . implode( ',', $filetypes ) . ' -> ' . $this_url ) ;
|
108 |
}
|
109 |
}
|
110 |
+
|
111 |
+
if ( ! $this->_cfg_url_ori || ! $this->_cfg_cdn_mapping ) {
|
112 |
if ( ! defined( self::BYPASS ) ) {
|
113 |
define( self::BYPASS, true ) ;
|
114 |
}
|
115 |
return ;
|
116 |
}
|
117 |
|
118 |
+
$this->_cfg_ori_dir = LiteSpeed_Cache_Config::get_instance()->get_item( LiteSpeed_Cache_Config::ITEM_CDN_ORI_DIR ) ;
|
119 |
+
// In case user customized upload path
|
120 |
+
if ( defined( 'UPLOADS' ) ) {
|
121 |
+
$this->_cfg_ori_dir[] = UPLOADS ;
|
122 |
+
}
|
123 |
+
|
124 |
// Check if need preg_replace
|
125 |
+
if ( strpos( $this->_cfg_url_ori, '*' ) !== false ) {
|
126 |
+
LiteSpeed_Cache_Log::debug( '[CDN] wildcard rule in ' . $this->_cfg_url_ori ) ;
|
127 |
+
$this->_cfg_url_ori = preg_quote( $this->_cfg_url_ori, '#' ) ;
|
128 |
+
$this->_cfg_url_ori = str_replace( '\*', '.*', $this->_cfg_url_ori ) ;
|
129 |
+
LiteSpeed_Cache_Log::debug2( '[CDN] translated rule is ' . $this->_cfg_url_ori ) ;
|
130 |
}
|
131 |
|
132 |
+
$this->_cfg_url_ori = explode( ',', $this->_cfg_url_ori ) ;
|
133 |
|
134 |
+
$this->_cfg_cdn_exclude = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_CDN_EXCLUDE ) ;
|
135 |
+
$this->_cfg_cdn_exclude = $this->_cfg_cdn_exclude ? explode( "\n", $this->_cfg_cdn_exclude ) : array() ;// todo: convert to cfg->get_item()
|
136 |
|
137 |
+
if ( ! empty( $this->_cfg_cdn_mapping[ LiteSpeed_Cache_Config::ITEM_CDN_MAPPING_INC_IMG ] ) ) {
|
138 |
// Hook to srcset
|
139 |
if ( function_exists( 'wp_calculate_image_srcset' ) ) {
|
140 |
add_filter( 'wp_calculate_image_srcset', array( $this, 'srcset' ), 999 ) ;
|
144 |
add_filter( 'wp_get_attachment_url', array( $this, 'url_img' ), 999 ) ;
|
145 |
}
|
146 |
|
147 |
+
if ( ! empty( $this->_cfg_cdn_mapping[ LiteSpeed_Cache_Config::ITEM_CDN_MAPPING_INC_CSS ] ) ) {
|
148 |
add_filter( 'style_loader_src', array( $this, 'url_css' ), 999 ) ;
|
149 |
}
|
150 |
|
151 |
+
if ( ! empty( $this->_cfg_cdn_mapping[ LiteSpeed_Cache_Config::ITEM_CDN_MAPPING_INC_JS ] ) ) {
|
152 |
add_filter( 'script_loader_src', array( $this, 'url_js' ), 999 ) ;
|
153 |
}
|
154 |
|
163 |
private function _append_cdn_mapping( $filetype, $url )
|
164 |
{
|
165 |
// If filetype to url is one to many, make url be an array
|
166 |
+
if ( empty( $this->_cfg_cdn_mapping[ $filetype ] ) ) {
|
167 |
+
$this->_cfg_cdn_mapping[ $filetype ] = $url ;
|
168 |
}
|
169 |
+
elseif ( is_array( $this->_cfg_cdn_mapping[ $filetype ] ) ) {
|
170 |
// Append url to filetype
|
171 |
+
$this->_cfg_cdn_mapping[ $filetype ][] = $url ;
|
172 |
}
|
173 |
else {
|
174 |
+
// Convert _cfg_cdn_mapping from string to array
|
175 |
+
$this->_cfg_cdn_mapping[ $filetype ] = array( $this->_cfg_cdn_mapping[ $filetype ], $url ) ;
|
176 |
}
|
177 |
}
|
178 |
|
207 |
{
|
208 |
$instance = self::get_instance() ;
|
209 |
|
210 |
+
if ( $type == 'css' && ! empty( $instance->_cfg_cdn_mapping[ LiteSpeed_Cache_Config::ITEM_CDN_MAPPING_INC_CSS ] ) ) {
|
211 |
return true ;
|
212 |
}
|
213 |
|
214 |
+
if ( $type == 'js' && ! empty( $instance->_cfg_cdn_mapping[ LiteSpeed_Cache_Config::ITEM_CDN_MAPPING_INC_JS ] ) ) {
|
215 |
return true ;
|
216 |
}
|
217 |
|
283 |
LiteSpeed_Cache_Log::debug( 'CDN _finalize' ) ;
|
284 |
|
285 |
// Start replacing img src
|
286 |
+
if ( ! empty( $this->_cfg_cdn_mapping[ LiteSpeed_Cache_Config::ITEM_CDN_MAPPING_INC_IMG ] ) ) {
|
287 |
$this->_replace_img() ;
|
288 |
$this->_replace_inline_css() ;
|
289 |
}
|
290 |
|
291 |
+
if ( ! empty( $this->_cfg_cdn_mapping[ LiteSpeed_Cache_Config::ITEM_CDN_MAPPING_FILETYPE ] ) ) {
|
292 |
$this->_replace_file_types() ;
|
293 |
}
|
294 |
|
307 |
return ;
|
308 |
}
|
309 |
|
310 |
+
$filetypes = array_keys( $this->_cfg_cdn_mapping ) ;
|
311 |
foreach ( $matches[ 2 ] as $k => $url ) {
|
312 |
$url_parsed = parse_url( $url ) ;
|
313 |
if ( empty( $url_parsed[ 'path' ] ) ) {
|
470 |
*/
|
471 |
public function rewrite( $url, $mapping_kind, $postfix = false )
|
472 |
{
|
473 |
+
LiteSpeed_Cache_Log::debug2( '[CDN] try rewriting ' . $url ) ;
|
474 |
$url_parsed = parse_url( $url ) ;
|
475 |
|
476 |
// Only images under wp-cotnent/wp-includes can be replaced
|
477 |
+
$is_internal_folder = LiteSpeed_Cache_Utility::str_hit_array( $url_parsed[ 'path' ], $this->_cfg_ori_dir ) ;
|
478 |
+
if ( ! $is_internal_folder ) {
|
479 |
+
LiteSpeed_Cache_Log::debug2( '[CDN] rewriting failed: path not match: ' . LSCWP_CONTENT_FOLDER ) ;
|
480 |
+
return false ;
|
|
|
481 |
}
|
482 |
|
483 |
// Check if is external url
|
484 |
if ( ! empty( $url_parsed[ 'host' ] ) ) {
|
485 |
if ( ! LiteSpeed_Cache_Utility::internal( $url_parsed[ 'host' ] ) && ! $this->_is_ori_url( $url ) ) {
|
486 |
+
LiteSpeed_Cache_Log::debug2( '[CDN] rewriting failed: host not internal' ) ;
|
487 |
return false ;
|
488 |
}
|
489 |
}
|
490 |
|
491 |
+
if ( $this->_cfg_cdn_exclude ) {
|
492 |
+
$exclude = LiteSpeed_Cache_Utility::str_hit_array( $url, $this->_cfg_cdn_exclude ) ;
|
493 |
+
if ( $exclude ) {
|
494 |
+
LiteSpeed_Cache_Log::debug2( '[CDN] Abort excludes ' . $exclude ) ;
|
495 |
+
return false ;
|
|
|
496 |
}
|
497 |
}
|
498 |
|
499 |
// Fill full url before replacement
|
500 |
if ( empty( $url_parsed[ 'host' ] ) ) {
|
501 |
$url = LiteSpeed_Cache_Utility::uri2url( $url ) ;
|
502 |
+
LiteSpeed_Cache_Log::debug2( '[CDN] fill before rewritten: ' . $url ) ;
|
503 |
|
504 |
$url_parsed = parse_url( $url ) ;
|
505 |
}
|
506 |
|
507 |
$scheme = ! empty( $url_parsed[ 'scheme' ] ) ? $url_parsed[ 'scheme' ] . ':' : '' ;
|
508 |
if ( $scheme ) {
|
509 |
+
LiteSpeed_Cache_Log::debug2( '[CDN] scheme from url: ' . $scheme ) ;
|
510 |
}
|
511 |
|
512 |
// Find the mapping url to be replaced to
|
513 |
+
if ( empty( $this->_cfg_cdn_mapping[ $mapping_kind ] ) ) {
|
514 |
return false ;
|
515 |
}
|
516 |
if ( $mapping_kind !== LiteSpeed_Cache_Config::ITEM_CDN_MAPPING_FILETYPE ) {
|
517 |
+
$final_url = $this->_cfg_cdn_mapping[ $mapping_kind ] ;
|
518 |
}
|
519 |
else {
|
520 |
// select from file type
|
521 |
+
$final_url = $this->_cfg_cdn_mapping[ $postfix ] ;
|
522 |
}
|
523 |
|
524 |
// If filetype to url is one to many, need to random one
|
527 |
}
|
528 |
|
529 |
// Now lets replace CDN url
|
530 |
+
foreach ( $this->_cfg_url_ori as $v ) {
|
531 |
if ( strpos( $v, '*' ) !== false ) {
|
532 |
$url = preg_replace( '#' . $scheme . $v . '#iU', $final_url, $url ) ;
|
533 |
}
|
535 |
$url = str_replace( $scheme . $v, $final_url, $url ) ;
|
536 |
}
|
537 |
}
|
538 |
+
LiteSpeed_Cache_Log::debug2( '[CDN] after rewritten: ' . $url ) ;
|
539 |
|
540 |
return $url ;
|
541 |
}
|
552 |
|
553 |
$scheme = ! empty( $url_parsed[ 'scheme' ] ) ? $url_parsed[ 'scheme' ] . ':' : '' ;
|
554 |
|
555 |
+
foreach ( $this->_cfg_url_ori as $v ) {
|
556 |
$needle = $scheme . $v ;
|
557 |
if ( strpos( $v, '*' ) !== false ) {
|
558 |
if( preg_match( '#' . $needle . '#iU', $url ) ) {
|
603 |
$v = $wp_scripts->registered[ 'jquery' ]->ver ;
|
604 |
}
|
605 |
|
606 |
+
$src = $this->_cfg_cdn_remote_jquery === LiteSpeed_Cache_Config::VAL_ON ? "//ajax.googleapis.com/ajax/libs/jquery/$v/jquery.min.js" : "//cdnjs.cloudflare.com/ajax/libs/jquery/$v/jquery.min.js" ;
|
607 |
|
608 |
+
LiteSpeed_Cache_Log::debug2( '[CDN] load_jquery_remotely: ' . $src ) ;
|
609 |
|
610 |
wp_deregister_script( 'jquery' ) ;
|
611 |
|
inc/config.class.php
CHANGED
@@ -32,6 +32,8 @@ class LiteSpeed_Cache_Config
|
|
32 |
const ITEM_OBJECT_GLOBAL_GROUPS = 'litespeed-object_global_groups' ;
|
33 |
const ITEM_OBJECT_NON_PERSISTENT_GROUPS = 'litespeed-object_non_persistent_groups' ;
|
34 |
const ITEM_CRWL_AS_UIDS = 'litespeed-crawler-as-uids' ;
|
|
|
|
|
35 |
|
36 |
const ITEM_SETTING_MODE = 'litespeed-setting-mode' ;
|
37 |
const ITEM_CRAWLER_HASH = 'litespeed-crawler-hash' ;
|
@@ -247,13 +249,13 @@ class LiteSpeed_Cache_Config
|
|
247 |
}
|
248 |
|
249 |
// Vary group settings
|
250 |
-
$this->vary_groups = (
|
251 |
|
252 |
// Exclude optimization role setting
|
253 |
-
$this->exclude_optimization_roles =
|
254 |
|
255 |
// Exclude cache role setting
|
256 |
-
$this->exclude_cache_roles =
|
257 |
|
258 |
// Set security key if not initialized yet
|
259 |
if ( isset( $this->options[ self::HASH ] ) && empty( $this->options[ self::HASH ] ) ) {
|
@@ -262,6 +264,37 @@ class LiteSpeed_Cache_Config
|
|
262 |
|
263 |
}
|
264 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
/**
|
266 |
* Define `LSCACHE_ADV_CACHE` based on options setting
|
267 |
*
|
@@ -440,9 +473,8 @@ class LiteSpeed_Cache_Config
|
|
440 |
}
|
441 |
|
442 |
$instance = self::get_instance() ;
|
443 |
-
$list = $instance->
|
444 |
|
445 |
-
$list = explode( "\n", $list ) ;
|
446 |
$list[] = $_SERVER[ 'HTTP_REFERER' ] ;
|
447 |
$list = array_map( 'LiteSpeed_Cache_Utility::make_relative', $list ) ;// Remove domain
|
448 |
$list = array_unique( $list ) ;
|
@@ -765,6 +797,26 @@ class LiteSpeed_Cache_Config
|
|
765 |
return $default_site_options ;
|
766 |
}
|
767 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
768 |
/**
|
769 |
* Get default item val
|
770 |
*
|
@@ -780,6 +832,12 @@ class LiteSpeed_Cache_Config
|
|
780 |
case self::ITEM_OBJECT_NON_PERSISTENT_GROUPS :
|
781 |
return "comment\ncounts\nplugins" ;
|
782 |
|
|
|
|
|
|
|
|
|
|
|
|
|
783 |
default :
|
784 |
break ;
|
785 |
}
|
32 |
const ITEM_OBJECT_GLOBAL_GROUPS = 'litespeed-object_global_groups' ;
|
33 |
const ITEM_OBJECT_NON_PERSISTENT_GROUPS = 'litespeed-object_non_persistent_groups' ;
|
34 |
const ITEM_CRWL_AS_UIDS = 'litespeed-crawler-as-uids' ;
|
35 |
+
const ITEM_ADV_PURGE_ALL_HOOKS = 'litespeed-adv-purge_all_hooks' ;
|
36 |
+
const ITEM_CDN_ORI_DIR = 'litespeed-cdn-ori_dir' ;
|
37 |
|
38 |
const ITEM_SETTING_MODE = 'litespeed-setting-mode' ;
|
39 |
const ITEM_CRAWLER_HASH = 'litespeed-crawler-hash' ;
|
249 |
}
|
250 |
|
251 |
// Vary group settings
|
252 |
+
$this->vary_groups = $this->get_item( self::VARY_GROUP ) ;
|
253 |
|
254 |
// Exclude optimization role setting
|
255 |
+
$this->exclude_optimization_roles = $this->get_item( self::EXCLUDE_OPTIMIZATION_ROLES ) ;
|
256 |
|
257 |
// Exclude cache role setting
|
258 |
+
$this->exclude_cache_roles = $this->get_item( self::EXCLUDE_CACHE_ROLES ) ;
|
259 |
|
260 |
// Set security key if not initialized yet
|
261 |
if ( isset( $this->options[ self::HASH ] ) && empty( $this->options[ self::HASH ] ) ) {
|
264 |
|
265 |
}
|
266 |
|
267 |
+
/**
|
268 |
+
* Get the items in wp_options that need for backup
|
269 |
+
*
|
270 |
+
* @since 2.2.1
|
271 |
+
* @access public
|
272 |
+
*/
|
273 |
+
public function stored_items()
|
274 |
+
{
|
275 |
+
return array(
|
276 |
+
self::OPTION_NAME,
|
277 |
+
self::VARY_GROUP,
|
278 |
+
self::EXCLUDE_OPTIMIZATION_ROLES,
|
279 |
+
self::EXCLUDE_CACHE_ROLES,
|
280 |
+
self::ITEM_OPTM_CSS,
|
281 |
+
self::ITEM_OPTM_JS_DEFER_EXC,
|
282 |
+
self::ITEM_MEDIA_LAZY_IMG_EXC,
|
283 |
+
self::ITEM_IMG_OPTM_NEED_PULL,
|
284 |
+
self::ITEM_ENV_REF,
|
285 |
+
self::ITEM_CACHE_DROP_QS,
|
286 |
+
self::ITEM_CDN_MAPPING,
|
287 |
+
self::ITEM_DNS_PREFETCH,
|
288 |
+
self::ITEM_CLOUDFLARE_STATUS,
|
289 |
+
self::ITEM_LOG_IGNORE_FILTERS,
|
290 |
+
self::ITEM_LOG_IGNORE_PART_FILTERS,
|
291 |
+
self::ITEM_OBJECT_GLOBAL_GROUPS,
|
292 |
+
self::ITEM_OBJECT_NON_PERSISTENT_GROUPS,
|
293 |
+
self::ITEM_CRWL_AS_UIDS,
|
294 |
+
self::ITEM_ADV_PURGE_ALL_HOOKS,
|
295 |
+
) ;
|
296 |
+
}
|
297 |
+
|
298 |
/**
|
299 |
* Define `LSCACHE_ADV_CACHE` based on options setting
|
300 |
*
|
473 |
}
|
474 |
|
475 |
$instance = self::get_instance() ;
|
476 |
+
$list = $instance->get_item( $id ) ;
|
477 |
|
|
|
478 |
$list[] = $_SERVER[ 'HTTP_REFERER' ] ;
|
479 |
$list = array_map( 'LiteSpeed_Cache_Utility::make_relative', $list ) ;// Remove domain
|
480 |
$list = array_unique( $list ) ;
|
797 |
return $default_site_options ;
|
798 |
}
|
799 |
|
800 |
+
/**
|
801 |
+
* Get item val
|
802 |
+
*
|
803 |
+
* @since 2.2.1
|
804 |
+
* @access public
|
805 |
+
*/
|
806 |
+
public function get_item( $k, $return_string = false )
|
807 |
+
{
|
808 |
+
$val = get_option( $k, $this->default_item( $k ) ) ;
|
809 |
+
|
810 |
+
if ( ! $return_string && ! is_array( $val ) ) {
|
811 |
+
$val = $val ? explode( "\n", $val ) : array() ;
|
812 |
+
}
|
813 |
+
elseif ( $return_string && is_array( $val ) ) {
|
814 |
+
$val = implode( "\n", $val ) ;
|
815 |
+
}
|
816 |
+
|
817 |
+
return $val ;
|
818 |
+
}
|
819 |
+
|
820 |
/**
|
821 |
* Get default item val
|
822 |
*
|
832 |
case self::ITEM_OBJECT_NON_PERSISTENT_GROUPS :
|
833 |
return "comment\ncounts\nplugins" ;
|
834 |
|
835 |
+
case self::ITEM_ADV_PURGE_ALL_HOOKS :
|
836 |
+
return "switch_theme\nwp_create_nav_menu\nwp_update_nav_menu\nwp_delete_nav_menu\ncreate_term\nedit_terms\ndelete_term\nadd_link\nedit_link\ndelete_link" ;
|
837 |
+
|
838 |
+
case self::ITEM_CDN_ORI_DIR :
|
839 |
+
return LSCWP_CONTENT_FOLDER . "\nwp-includes\n/min/" ;
|
840 |
+
|
841 |
default :
|
842 |
break ;
|
843 |
}
|
inc/import.class.php
CHANGED
@@ -28,26 +28,7 @@ class LiteSpeed_Cache_Import
|
|
28 |
{
|
29 |
LiteSpeed_Cache_Log::debug( 'Import init' ) ;
|
30 |
|
31 |
-
$this->_cfg_items =
|
32 |
-
LiteSpeed_Cache_Config::OPTION_NAME,
|
33 |
-
LiteSpeed_Cache_Config::VARY_GROUP,
|
34 |
-
LiteSpeed_Cache_Config::EXCLUDE_OPTIMIZATION_ROLES,
|
35 |
-
LiteSpeed_Cache_Config::EXCLUDE_CACHE_ROLES,
|
36 |
-
LiteSpeed_Cache_Config::ITEM_OPTM_CSS,
|
37 |
-
LiteSpeed_Cache_Config::ITEM_OPTM_JS_DEFER_EXC,
|
38 |
-
LiteSpeed_Cache_Config::ITEM_MEDIA_LAZY_IMG_EXC,
|
39 |
-
LiteSpeed_Cache_Config::ITEM_IMG_OPTM_NEED_PULL,
|
40 |
-
LiteSpeed_Cache_Config::ITEM_ENV_REF,
|
41 |
-
LiteSpeed_Cache_Config::ITEM_CACHE_DROP_QS,
|
42 |
-
LiteSpeed_Cache_Config::ITEM_CDN_MAPPING,
|
43 |
-
LiteSpeed_Cache_Config::ITEM_DNS_PREFETCH,
|
44 |
-
LiteSpeed_Cache_Config::ITEM_CLOUDFLARE_STATUS,
|
45 |
-
LiteSpeed_Cache_Config::ITEM_LOG_IGNORE_FILTERS,
|
46 |
-
LiteSpeed_Cache_Config::ITEM_LOG_IGNORE_PART_FILTERS,
|
47 |
-
LiteSpeed_Cache_Config::ITEM_OBJECT_GLOBAL_GROUPS,
|
48 |
-
LiteSpeed_Cache_Config::ITEM_OBJECT_NON_PERSISTENT_GROUPS,
|
49 |
-
LiteSpeed_Cache_Config::ITEM_CRWL_AS_UIDS,
|
50 |
-
) ;
|
51 |
}
|
52 |
|
53 |
/**
|
28 |
{
|
29 |
LiteSpeed_Cache_Log::debug( 'Import init' ) ;
|
30 |
|
31 |
+
$this->_cfg_items = LiteSpeed_Cache_Config::get_instance()->stored_items() ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
}
|
33 |
|
34 |
/**
|
inc/litespeed-cache.class.php
CHANGED
@@ -19,7 +19,7 @@ class LiteSpeed_Cache
|
|
19 |
private static $_instance ;
|
20 |
|
21 |
const PLUGIN_NAME = 'litespeed-cache' ;
|
22 |
-
const PLUGIN_VERSION = '2.2.
|
23 |
|
24 |
const PAGE_EDIT_HTACCESS = 'lscache-edit-htaccess' ;
|
25 |
|
@@ -97,13 +97,6 @@ class LiteSpeed_Cache
|
|
97 |
define( 'LITESPEED_DISABLE_ALL', true ) ;
|
98 |
}
|
99 |
|
100 |
-
/**
|
101 |
-
* This needs to be before activation because admin-rules.class.php need const `LSCWP_CONTENT_FOLDER`
|
102 |
-
* @since 1.9.1 Moved up
|
103 |
-
*/
|
104 |
-
define( 'LSCWP_CONTENT_FOLDER', str_replace( home_url( '/' ), '', WP_CONTENT_URL ) ) ; // `wp-content`
|
105 |
-
define( 'LSWCP_PLUGIN_URL', plugin_dir_url( dirname( __FILE__ ) ) ) ;// Full URL path '//example.com/wp-content/plugins/litespeed-cache/'
|
106 |
-
|
107 |
// Register plugin activate/deactivate/uninstall hooks
|
108 |
// NOTE: this can't be moved under after_setup_theme, otherwise activation will be bypassed somehow
|
109 |
if( is_admin() || defined( 'LITESPEED_CLI' ) ) {
|
19 |
private static $_instance ;
|
20 |
|
21 |
const PLUGIN_NAME = 'litespeed-cache' ;
|
22 |
+
const PLUGIN_VERSION = '2.2.1' ;
|
23 |
|
24 |
const PAGE_EDIT_HTACCESS = 'lscache-edit-htaccess' ;
|
25 |
|
97 |
define( 'LITESPEED_DISABLE_ALL', true ) ;
|
98 |
}
|
99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
// Register plugin activate/deactivate/uninstall hooks
|
101 |
// NOTE: this can't be moved under after_setup_theme, otherwise activation will be bypassed somehow
|
102 |
if( is_admin() || defined( 'LITESPEED_CLI' ) ) {
|
inc/media.class.php
CHANGED
@@ -518,6 +518,22 @@ class LiteSpeed_Cache_Media
|
|
518 |
) ;
|
519 |
$this->content = str_replace( $matches[ 0 ][ $k ], $html_snippet, $this->content ) ;
|
520 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
521 |
}
|
522 |
|
523 |
/**
|
518 |
) ;
|
519 |
$this->content = str_replace( $matches[ 0 ][ $k ], $html_snippet, $this->content ) ;
|
520 |
}
|
521 |
+
|
522 |
+
// Replace background-image
|
523 |
+
preg_match_all( '#background\-image:(\s*)url\((.*)\)#iU', $this->content, $matches ) ;
|
524 |
+
foreach ( $matches[ 2 ] as $k => $url ) {
|
525 |
+
// Check if is a DATA-URI
|
526 |
+
if ( strpos( $url, 'data:image' ) !== false ) {
|
527 |
+
continue ;
|
528 |
+
}
|
529 |
+
|
530 |
+
if ( ! $url2 = $this->_replace_webp( $url ) ) {
|
531 |
+
continue ;
|
532 |
+
}
|
533 |
+
|
534 |
+
$html_snippet = sprintf( 'background-image:%1$surl(%2$s)', $matches[ 1 ][ $k ], $url2 ) ;
|
535 |
+
$this->content = str_replace( $matches[ 0 ][ $k ], $html_snippet, $this->content ) ;
|
536 |
+
}
|
537 |
}
|
538 |
|
539 |
/**
|
inc/object.class.php
CHANGED
@@ -46,6 +46,8 @@ class LiteSpeed_Cache_Object
|
|
46 |
/**
|
47 |
* Init
|
48 |
*
|
|
|
|
|
49 |
* @since 1.8
|
50 |
* @access private
|
51 |
*/
|
46 |
/**
|
47 |
* Init
|
48 |
*
|
49 |
+
* NOTE: this class may be included without initialized LiteSpeed_Cache core
|
50 |
+
*
|
51 |
* @since 1.8
|
52 |
* @access private
|
53 |
*/
|
inc/optimize.class.php
CHANGED
@@ -224,7 +224,7 @@ class LiteSpeed_Cache_Optimize
|
|
224 |
return ;
|
225 |
}
|
226 |
|
227 |
-
LiteSpeed_Cache_Log::
|
228 |
|
229 |
// Proceed css/js file generation
|
230 |
define( 'LITESPEED_MIN_FILE', true ) ;
|
@@ -249,12 +249,12 @@ class LiteSpeed_Cache_Optimize
|
|
249 |
|
250 |
// Generate static file
|
251 |
Litespeed_File::save( $static_file, $content, true ) ;
|
252 |
-
LiteSpeed_Cache_Log::
|
253 |
|
254 |
}
|
255 |
else {
|
256 |
// Load file from file based cache if not expired
|
257 |
-
LiteSpeed_Cache_Log::
|
258 |
$content = Litespeed_File::read( $static_file ) ;
|
259 |
}
|
260 |
|
@@ -941,7 +941,7 @@ class LiteSpeed_Cache_Optimize
|
|
941 |
// Generate static file
|
942 |
Litespeed_File::save( $static_file, $content, true ) ;
|
943 |
|
944 |
-
LiteSpeed_Cache_Log::
|
945 |
|
946 |
}
|
947 |
|
224 |
return ;
|
225 |
}
|
226 |
|
227 |
+
LiteSpeed_Cache_Log::debug2( '[Optm] start minifying file' ) ;
|
228 |
|
229 |
// Proceed css/js file generation
|
230 |
define( 'LITESPEED_MIN_FILE', true ) ;
|
249 |
|
250 |
// Generate static file
|
251 |
Litespeed_File::save( $static_file, $content, true ) ;
|
252 |
+
LiteSpeed_Cache_Log::debug2( '[Optm] Saved cache to file [path] ' . $static_file ) ;
|
253 |
|
254 |
}
|
255 |
else {
|
256 |
// Load file from file based cache if not expired
|
257 |
+
LiteSpeed_Cache_Log::debug2( '[Optm] Static file available' ) ;
|
258 |
$content = Litespeed_File::read( $static_file ) ;
|
259 |
}
|
260 |
|
941 |
// Generate static file
|
942 |
Litespeed_File::save( $static_file, $content, true ) ;
|
943 |
|
944 |
+
LiteSpeed_Cache_Log::debug2( '[Optm] Saved static file [path] ' . $static_file ) ;
|
945 |
|
946 |
}
|
947 |
|
inc/optimizer.class.php
CHANGED
@@ -122,7 +122,7 @@ class LiteSpeed_Cache_Optimizer
|
|
122 |
$content = $this->_remove_comment( $content, $file_type ) ;
|
123 |
}
|
124 |
|
125 |
-
LiteSpeed_Cache_Log::
|
126 |
|
127 |
return $content ;
|
128 |
}
|
@@ -137,7 +137,7 @@ class LiteSpeed_Cache_Optimizer
|
|
137 |
{
|
138 |
$con = array() ;
|
139 |
foreach ( $files as $real_path ) {
|
140 |
-
LiteSpeed_Cache_Log::
|
141 |
$data = Litespeed_File::read( $real_path ) ;
|
142 |
|
143 |
$data = preg_replace( '/@charset[^;]+;\\s*/', '', $data ) ;
|
122 |
$content = $this->_remove_comment( $content, $file_type ) ;
|
123 |
}
|
124 |
|
125 |
+
LiteSpeed_Cache_Log::debug2( '[Optmer] Generated content ' . $file_type ) ;
|
126 |
|
127 |
return $content ;
|
128 |
}
|
137 |
{
|
138 |
$con = array() ;
|
139 |
foreach ( $files as $real_path ) {
|
140 |
+
LiteSpeed_Cache_Log::debug2( '[Optmer] [real_path] ' . $real_path ) ;
|
141 |
$data = Litespeed_File::read( $real_path ) ;
|
142 |
|
143 |
$data = preg_replace( '/@charset[^;]+;\\s*/', '', $data ) ;
|
inc/utility.class.php
CHANGED
@@ -154,6 +154,10 @@ class LiteSpeed_Cache_Utility
|
|
154 |
public static function str_hit_array( $needle, $haystack )
|
155 |
{
|
156 |
foreach( $haystack as $item ) {
|
|
|
|
|
|
|
|
|
157 |
if ( substr( $item, -1 ) === '$' ) {
|
158 |
// do exact match
|
159 |
if ( substr( $item, 0, -1 ) === $needle ) {
|
154 |
public static function str_hit_array( $needle, $haystack )
|
155 |
{
|
156 |
foreach( $haystack as $item ) {
|
157 |
+
if ( ! $item ) {
|
158 |
+
continue ;
|
159 |
+
}
|
160 |
+
|
161 |
if ( substr( $item, -1 ) === '$' ) {
|
162 |
// do exact match
|
163 |
if ( substr( $item, 0, -1 ) === $needle ) {
|
includes/litespeed-cache-cdn.class.php
CHANGED
@@ -18,11 +18,12 @@ class LiteSpeed_Cache_CDN
|
|
18 |
|
19 |
private $content ;
|
20 |
|
21 |
-
private $
|
22 |
-
private $
|
23 |
-
private $
|
24 |
-
private $
|
25 |
-
private $
|
|
|
26 |
|
27 |
private $cdn_mapping_hosts = array() ;
|
28 |
|
@@ -48,20 +49,20 @@ class LiteSpeed_Cache_CDN
|
|
48 |
* This is separate from CDN on/off
|
49 |
* @since 1.5
|
50 |
*/
|
51 |
-
$this->
|
52 |
-
if ( $this->
|
53 |
add_action( 'init', array( $this, 'load_jquery_remotely' ) ) ;
|
54 |
}
|
55 |
|
56 |
-
$this->
|
57 |
-
if ( ! $this->
|
58 |
if ( ! defined( self::BYPASS ) ) {
|
59 |
define( self::BYPASS, true ) ;
|
60 |
}
|
61 |
return ;
|
62 |
}
|
63 |
|
64 |
-
$this->
|
65 |
$cfg_cdn_url = get_option( LiteSpeed_Cache_Config::ITEM_CDN_MAPPING, array() ) ;
|
66 |
// Parse cdn mapping data to array( 'filetype' => 'url' )
|
67 |
$mapping_to_check = array(
|
@@ -78,7 +79,7 @@ class LiteSpeed_Cache_CDN
|
|
78 |
// Check img/css/js
|
79 |
foreach ( $mapping_to_check as $to_check ) {
|
80 |
if ( $v[ $to_check ] ) {
|
81 |
-
LiteSpeed_Cache_Log::debug2( 'CDN
|
82 |
|
83 |
// If filetype to url is one to many, make url be an array
|
84 |
$this->_append_cdn_mapping( $to_check, $this_url ) ;
|
@@ -93,7 +94,7 @@ class LiteSpeed_Cache_CDN
|
|
93 |
$filetypes = array_map( 'trim', explode( "\n", $v[ LiteSpeed_Cache_Config::ITEM_CDN_MAPPING_FILETYPE ] ) ) ;
|
94 |
foreach ( $filetypes as $v2 ) {
|
95 |
if ( $v2 ) {
|
96 |
-
$this->
|
97 |
|
98 |
// If filetype to url is one to many, make url be an array
|
99 |
$this->_append_cdn_mapping( $v2, $this_url ) ;
|
@@ -103,30 +104,37 @@ class LiteSpeed_Cache_CDN
|
|
103 |
}
|
104 |
}
|
105 |
}
|
106 |
-
LiteSpeed_Cache_Log::debug2( 'CDN
|
107 |
}
|
108 |
}
|
109 |
-
|
|
|
110 |
if ( ! defined( self::BYPASS ) ) {
|
111 |
define( self::BYPASS, true ) ;
|
112 |
}
|
113 |
return ;
|
114 |
}
|
115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
// Check if need preg_replace
|
117 |
-
if ( strpos( $this->
|
118 |
-
LiteSpeed_Cache_Log::debug( 'CDN
|
119 |
-
$this->
|
120 |
-
$this->
|
121 |
-
LiteSpeed_Cache_Log::debug2( 'CDN
|
122 |
}
|
123 |
|
124 |
-
$this->
|
125 |
|
126 |
-
$this->
|
127 |
-
$this->
|
128 |
|
129 |
-
if ( ! empty( $this->
|
130 |
// Hook to srcset
|
131 |
if ( function_exists( 'wp_calculate_image_srcset' ) ) {
|
132 |
add_filter( 'wp_calculate_image_srcset', array( $this, 'srcset' ), 999 ) ;
|
@@ -136,11 +144,11 @@ class LiteSpeed_Cache_CDN
|
|
136 |
add_filter( 'wp_get_attachment_url', array( $this, 'url_img' ), 999 ) ;
|
137 |
}
|
138 |
|
139 |
-
if ( ! empty( $this->
|
140 |
add_filter( 'style_loader_src', array( $this, 'url_css' ), 999 ) ;
|
141 |
}
|
142 |
|
143 |
-
if ( ! empty( $this->
|
144 |
add_filter( 'script_loader_src', array( $this, 'url_js' ), 999 ) ;
|
145 |
}
|
146 |
|
@@ -155,16 +163,16 @@ class LiteSpeed_Cache_CDN
|
|
155 |
private function _append_cdn_mapping( $filetype, $url )
|
156 |
{
|
157 |
// If filetype to url is one to many, make url be an array
|
158 |
-
if ( empty( $this->
|
159 |
-
$this->
|
160 |
}
|
161 |
-
elseif ( is_array( $this->
|
162 |
// Append url to filetype
|
163 |
-
$this->
|
164 |
}
|
165 |
else {
|
166 |
-
// Convert
|
167 |
-
$this->
|
168 |
}
|
169 |
}
|
170 |
|
@@ -199,11 +207,11 @@ class LiteSpeed_Cache_CDN
|
|
199 |
{
|
200 |
$instance = self::get_instance() ;
|
201 |
|
202 |
-
if ( $type == 'css' && ! empty( $instance->
|
203 |
return true ;
|
204 |
}
|
205 |
|
206 |
-
if ( $type == 'js' && ! empty( $instance->
|
207 |
return true ;
|
208 |
}
|
209 |
|
@@ -275,12 +283,12 @@ class LiteSpeed_Cache_CDN
|
|
275 |
LiteSpeed_Cache_Log::debug( 'CDN _finalize' ) ;
|
276 |
|
277 |
// Start replacing img src
|
278 |
-
if ( ! empty( $this->
|
279 |
$this->_replace_img() ;
|
280 |
$this->_replace_inline_css() ;
|
281 |
}
|
282 |
|
283 |
-
if ( ! empty( $this->
|
284 |
$this->_replace_file_types() ;
|
285 |
}
|
286 |
|
@@ -299,7 +307,7 @@ class LiteSpeed_Cache_CDN
|
|
299 |
return ;
|
300 |
}
|
301 |
|
302 |
-
$filetypes = array_keys( $this->
|
303 |
foreach ( $matches[ 2 ] as $k => $url ) {
|
304 |
$url_parsed = parse_url( $url ) ;
|
305 |
if ( empty( $url_parsed[ 'path' ] ) ) {
|
@@ -462,57 +470,55 @@ class LiteSpeed_Cache_CDN
|
|
462 |
*/
|
463 |
public function rewrite( $url, $mapping_kind, $postfix = false )
|
464 |
{
|
465 |
-
LiteSpeed_Cache_Log::debug2( 'CDN
|
466 |
$url_parsed = parse_url( $url ) ;
|
467 |
|
468 |
// Only images under wp-cotnent/wp-includes can be replaced
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
}
|
474 |
}
|
475 |
|
476 |
// Check if is external url
|
477 |
if ( ! empty( $url_parsed[ 'host' ] ) ) {
|
478 |
if ( ! LiteSpeed_Cache_Utility::internal( $url_parsed[ 'host' ] ) && ! $this->_is_ori_url( $url ) ) {
|
479 |
-
LiteSpeed_Cache_Log::debug2( 'CDN
|
480 |
return false ;
|
481 |
}
|
482 |
}
|
483 |
|
484 |
-
if ( $this->
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
}
|
490 |
}
|
491 |
}
|
492 |
|
493 |
// Fill full url before replacement
|
494 |
if ( empty( $url_parsed[ 'host' ] ) ) {
|
495 |
$url = LiteSpeed_Cache_Utility::uri2url( $url ) ;
|
496 |
-
LiteSpeed_Cache_Log::debug2( 'CDN
|
497 |
|
498 |
$url_parsed = parse_url( $url ) ;
|
499 |
}
|
500 |
|
501 |
$scheme = ! empty( $url_parsed[ 'scheme' ] ) ? $url_parsed[ 'scheme' ] . ':' : '' ;
|
502 |
if ( $scheme ) {
|
503 |
-
LiteSpeed_Cache_Log::debug2( 'CDN
|
504 |
}
|
505 |
|
506 |
// Find the mapping url to be replaced to
|
507 |
-
if ( empty( $this->
|
508 |
return false ;
|
509 |
}
|
510 |
if ( $mapping_kind !== LiteSpeed_Cache_Config::ITEM_CDN_MAPPING_FILETYPE ) {
|
511 |
-
$final_url = $this->
|
512 |
}
|
513 |
else {
|
514 |
// select from file type
|
515 |
-
$final_url = $this->
|
516 |
}
|
517 |
|
518 |
// If filetype to url is one to many, need to random one
|
@@ -521,7 +527,7 @@ class LiteSpeed_Cache_CDN
|
|
521 |
}
|
522 |
|
523 |
// Now lets replace CDN url
|
524 |
-
foreach ( $this->
|
525 |
if ( strpos( $v, '*' ) !== false ) {
|
526 |
$url = preg_replace( '#' . $scheme . $v . '#iU', $final_url, $url ) ;
|
527 |
}
|
@@ -529,7 +535,7 @@ class LiteSpeed_Cache_CDN
|
|
529 |
$url = str_replace( $scheme . $v, $final_url, $url ) ;
|
530 |
}
|
531 |
}
|
532 |
-
LiteSpeed_Cache_Log::debug2( 'CDN
|
533 |
|
534 |
return $url ;
|
535 |
}
|
@@ -546,7 +552,7 @@ class LiteSpeed_Cache_CDN
|
|
546 |
|
547 |
$scheme = ! empty( $url_parsed[ 'scheme' ] ) ? $url_parsed[ 'scheme' ] . ':' : '' ;
|
548 |
|
549 |
-
foreach ( $this->
|
550 |
$needle = $scheme . $v ;
|
551 |
if ( strpos( $v, '*' ) !== false ) {
|
552 |
if( preg_match( '#' . $needle . '#iU', $url ) ) {
|
@@ -597,9 +603,9 @@ class LiteSpeed_Cache_CDN
|
|
597 |
$v = $wp_scripts->registered[ 'jquery' ]->ver ;
|
598 |
}
|
599 |
|
600 |
-
$src = $this->
|
601 |
|
602 |
-
LiteSpeed_Cache_Log::debug2( 'CDN
|
603 |
|
604 |
wp_deregister_script( 'jquery' ) ;
|
605 |
|
18 |
|
19 |
private $content ;
|
20 |
|
21 |
+
private $_cfg_cdn ;
|
22 |
+
private $_cfg_url_ori ;
|
23 |
+
private $_cfg_ori_dir ;
|
24 |
+
private $_cfg_cdn_mapping = array() ;
|
25 |
+
private $_cfg_cdn_exclude ;
|
26 |
+
private $_cfg_cdn_remote_jquery ;
|
27 |
|
28 |
private $cdn_mapping_hosts = array() ;
|
29 |
|
49 |
* This is separate from CDN on/off
|
50 |
* @since 1.5
|
51 |
*/
|
52 |
+
$this->_cfg_cdn_remote_jquery = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_CDN_REMOTE_JQUERY ) ;
|
53 |
+
if ( $this->_cfg_cdn_remote_jquery ) {
|
54 |
add_action( 'init', array( $this, 'load_jquery_remotely' ) ) ;
|
55 |
}
|
56 |
|
57 |
+
$this->_cfg_cdn = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_CDN ) ;
|
58 |
+
if ( ! $this->_cfg_cdn ) {
|
59 |
if ( ! defined( self::BYPASS ) ) {
|
60 |
define( self::BYPASS, true ) ;
|
61 |
}
|
62 |
return ;
|
63 |
}
|
64 |
|
65 |
+
$this->_cfg_url_ori = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_CDN_ORI ) ;
|
66 |
$cfg_cdn_url = get_option( LiteSpeed_Cache_Config::ITEM_CDN_MAPPING, array() ) ;
|
67 |
// Parse cdn mapping data to array( 'filetype' => 'url' )
|
68 |
$mapping_to_check = array(
|
79 |
// Check img/css/js
|
80 |
foreach ( $mapping_to_check as $to_check ) {
|
81 |
if ( $v[ $to_check ] ) {
|
82 |
+
LiteSpeed_Cache_Log::debug2( '[CDN] mapping ' . $to_check . ' -> ' . $this_url ) ;
|
83 |
|
84 |
// If filetype to url is one to many, make url be an array
|
85 |
$this->_append_cdn_mapping( $to_check, $this_url ) ;
|
94 |
$filetypes = array_map( 'trim', explode( "\n", $v[ LiteSpeed_Cache_Config::ITEM_CDN_MAPPING_FILETYPE ] ) ) ;
|
95 |
foreach ( $filetypes as $v2 ) {
|
96 |
if ( $v2 ) {
|
97 |
+
$this->_cfg_cdn_mapping[ LiteSpeed_Cache_Config::ITEM_CDN_MAPPING_FILETYPE ] = true ;
|
98 |
|
99 |
// If filetype to url is one to many, make url be an array
|
100 |
$this->_append_cdn_mapping( $v2, $this_url ) ;
|
104 |
}
|
105 |
}
|
106 |
}
|
107 |
+
LiteSpeed_Cache_Log::debug2( '[CDN] mapping ' . implode( ',', $filetypes ) . ' -> ' . $this_url ) ;
|
108 |
}
|
109 |
}
|
110 |
+
|
111 |
+
if ( ! $this->_cfg_url_ori || ! $this->_cfg_cdn_mapping ) {
|
112 |
if ( ! defined( self::BYPASS ) ) {
|
113 |
define( self::BYPASS, true ) ;
|
114 |
}
|
115 |
return ;
|
116 |
}
|
117 |
|
118 |
+
$this->_cfg_ori_dir = LiteSpeed_Cache_Config::get_instance()->get_item( LiteSpeed_Cache_Config::ITEM_CDN_ORI_DIR ) ;
|
119 |
+
// In case user customized upload path
|
120 |
+
if ( defined( 'UPLOADS' ) ) {
|
121 |
+
$this->_cfg_ori_dir[] = UPLOADS ;
|
122 |
+
}
|
123 |
+
|
124 |
// Check if need preg_replace
|
125 |
+
if ( strpos( $this->_cfg_url_ori, '*' ) !== false ) {
|
126 |
+
LiteSpeed_Cache_Log::debug( '[CDN] wildcard rule in ' . $this->_cfg_url_ori ) ;
|
127 |
+
$this->_cfg_url_ori = preg_quote( $this->_cfg_url_ori, '#' ) ;
|
128 |
+
$this->_cfg_url_ori = str_replace( '\*', '.*', $this->_cfg_url_ori ) ;
|
129 |
+
LiteSpeed_Cache_Log::debug2( '[CDN] translated rule is ' . $this->_cfg_url_ori ) ;
|
130 |
}
|
131 |
|
132 |
+
$this->_cfg_url_ori = explode( ',', $this->_cfg_url_ori ) ;
|
133 |
|
134 |
+
$this->_cfg_cdn_exclude = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_CDN_EXCLUDE ) ;
|
135 |
+
$this->_cfg_cdn_exclude = $this->_cfg_cdn_exclude ? explode( "\n", $this->_cfg_cdn_exclude ) : array() ;// todo: convert to cfg->get_item()
|
136 |
|
137 |
+
if ( ! empty( $this->_cfg_cdn_mapping[ LiteSpeed_Cache_Config::ITEM_CDN_MAPPING_INC_IMG ] ) ) {
|
138 |
// Hook to srcset
|
139 |
if ( function_exists( 'wp_calculate_image_srcset' ) ) {
|
140 |
add_filter( 'wp_calculate_image_srcset', array( $this, 'srcset' ), 999 ) ;
|
144 |
add_filter( 'wp_get_attachment_url', array( $this, 'url_img' ), 999 ) ;
|
145 |
}
|
146 |
|
147 |
+
if ( ! empty( $this->_cfg_cdn_mapping[ LiteSpeed_Cache_Config::ITEM_CDN_MAPPING_INC_CSS ] ) ) {
|
148 |
add_filter( 'style_loader_src', array( $this, 'url_css' ), 999 ) ;
|
149 |
}
|
150 |
|
151 |
+
if ( ! empty( $this->_cfg_cdn_mapping[ LiteSpeed_Cache_Config::ITEM_CDN_MAPPING_INC_JS ] ) ) {
|
152 |
add_filter( 'script_loader_src', array( $this, 'url_js' ), 999 ) ;
|
153 |
}
|
154 |
|
163 |
private function _append_cdn_mapping( $filetype, $url )
|
164 |
{
|
165 |
// If filetype to url is one to many, make url be an array
|
166 |
+
if ( empty( $this->_cfg_cdn_mapping[ $filetype ] ) ) {
|
167 |
+
$this->_cfg_cdn_mapping[ $filetype ] = $url ;
|
168 |
}
|
169 |
+
elseif ( is_array( $this->_cfg_cdn_mapping[ $filetype ] ) ) {
|
170 |
// Append url to filetype
|
171 |
+
$this->_cfg_cdn_mapping[ $filetype ][] = $url ;
|
172 |
}
|
173 |
else {
|
174 |
+
// Convert _cfg_cdn_mapping from string to array
|
175 |
+
$this->_cfg_cdn_mapping[ $filetype ] = array( $this->_cfg_cdn_mapping[ $filetype ], $url ) ;
|
176 |
}
|
177 |
}
|
178 |
|
207 |
{
|
208 |
$instance = self::get_instance() ;
|
209 |
|
210 |
+
if ( $type == 'css' && ! empty( $instance->_cfg_cdn_mapping[ LiteSpeed_Cache_Config::ITEM_CDN_MAPPING_INC_CSS ] ) ) {
|
211 |
return true ;
|
212 |
}
|
213 |
|
214 |
+
if ( $type == 'js' && ! empty( $instance->_cfg_cdn_mapping[ LiteSpeed_Cache_Config::ITEM_CDN_MAPPING_INC_JS ] ) ) {
|
215 |
return true ;
|
216 |
}
|
217 |
|
283 |
LiteSpeed_Cache_Log::debug( 'CDN _finalize' ) ;
|
284 |
|
285 |
// Start replacing img src
|
286 |
+
if ( ! empty( $this->_cfg_cdn_mapping[ LiteSpeed_Cache_Config::ITEM_CDN_MAPPING_INC_IMG ] ) ) {
|
287 |
$this->_replace_img() ;
|
288 |
$this->_replace_inline_css() ;
|
289 |
}
|
290 |
|
291 |
+
if ( ! empty( $this->_cfg_cdn_mapping[ LiteSpeed_Cache_Config::ITEM_CDN_MAPPING_FILETYPE ] ) ) {
|
292 |
$this->_replace_file_types() ;
|
293 |
}
|
294 |
|
307 |
return ;
|
308 |
}
|
309 |
|
310 |
+
$filetypes = array_keys( $this->_cfg_cdn_mapping ) ;
|
311 |
foreach ( $matches[ 2 ] as $k => $url ) {
|
312 |
$url_parsed = parse_url( $url ) ;
|
313 |
if ( empty( $url_parsed[ 'path' ] ) ) {
|
470 |
*/
|
471 |
public function rewrite( $url, $mapping_kind, $postfix = false )
|
472 |
{
|
473 |
+
LiteSpeed_Cache_Log::debug2( '[CDN] try rewriting ' . $url ) ;
|
474 |
$url_parsed = parse_url( $url ) ;
|
475 |
|
476 |
// Only images under wp-cotnent/wp-includes can be replaced
|
477 |
+
$is_internal_folder = LiteSpeed_Cache_Utility::str_hit_array( $url_parsed[ 'path' ], $this->_cfg_ori_dir ) ;
|
478 |
+
if ( ! $is_internal_folder ) {
|
479 |
+
LiteSpeed_Cache_Log::debug2( '[CDN] rewriting failed: path not match: ' . LSCWP_CONTENT_FOLDER ) ;
|
480 |
+
return false ;
|
|
|
481 |
}
|
482 |
|
483 |
// Check if is external url
|
484 |
if ( ! empty( $url_parsed[ 'host' ] ) ) {
|
485 |
if ( ! LiteSpeed_Cache_Utility::internal( $url_parsed[ 'host' ] ) && ! $this->_is_ori_url( $url ) ) {
|
486 |
+
LiteSpeed_Cache_Log::debug2( '[CDN] rewriting failed: host not internal' ) ;
|
487 |
return false ;
|
488 |
}
|
489 |
}
|
490 |
|
491 |
+
if ( $this->_cfg_cdn_exclude ) {
|
492 |
+
$exclude = LiteSpeed_Cache_Utility::str_hit_array( $url, $this->_cfg_cdn_exclude ) ;
|
493 |
+
if ( $exclude ) {
|
494 |
+
LiteSpeed_Cache_Log::debug2( '[CDN] Abort excludes ' . $exclude ) ;
|
495 |
+
return false ;
|
|
|
496 |
}
|
497 |
}
|
498 |
|
499 |
// Fill full url before replacement
|
500 |
if ( empty( $url_parsed[ 'host' ] ) ) {
|
501 |
$url = LiteSpeed_Cache_Utility::uri2url( $url ) ;
|
502 |
+
LiteSpeed_Cache_Log::debug2( '[CDN] fill before rewritten: ' . $url ) ;
|
503 |
|
504 |
$url_parsed = parse_url( $url ) ;
|
505 |
}
|
506 |
|
507 |
$scheme = ! empty( $url_parsed[ 'scheme' ] ) ? $url_parsed[ 'scheme' ] . ':' : '' ;
|
508 |
if ( $scheme ) {
|
509 |
+
LiteSpeed_Cache_Log::debug2( '[CDN] scheme from url: ' . $scheme ) ;
|
510 |
}
|
511 |
|
512 |
// Find the mapping url to be replaced to
|
513 |
+
if ( empty( $this->_cfg_cdn_mapping[ $mapping_kind ] ) ) {
|
514 |
return false ;
|
515 |
}
|
516 |
if ( $mapping_kind !== LiteSpeed_Cache_Config::ITEM_CDN_MAPPING_FILETYPE ) {
|
517 |
+
$final_url = $this->_cfg_cdn_mapping[ $mapping_kind ] ;
|
518 |
}
|
519 |
else {
|
520 |
// select from file type
|
521 |
+
$final_url = $this->_cfg_cdn_mapping[ $postfix ] ;
|
522 |
}
|
523 |
|
524 |
// If filetype to url is one to many, need to random one
|
527 |
}
|
528 |
|
529 |
// Now lets replace CDN url
|
530 |
+
foreach ( $this->_cfg_url_ori as $v ) {
|
531 |
if ( strpos( $v, '*' ) !== false ) {
|
532 |
$url = preg_replace( '#' . $scheme . $v . '#iU', $final_url, $url ) ;
|
533 |
}
|
535 |
$url = str_replace( $scheme . $v, $final_url, $url ) ;
|
536 |
}
|
537 |
}
|
538 |
+
LiteSpeed_Cache_Log::debug2( '[CDN] after rewritten: ' . $url ) ;
|
539 |
|
540 |
return $url ;
|
541 |
}
|
552 |
|
553 |
$scheme = ! empty( $url_parsed[ 'scheme' ] ) ? $url_parsed[ 'scheme' ] . ':' : '' ;
|
554 |
|
555 |
+
foreach ( $this->_cfg_url_ori as $v ) {
|
556 |
$needle = $scheme . $v ;
|
557 |
if ( strpos( $v, '*' ) !== false ) {
|
558 |
if( preg_match( '#' . $needle . '#iU', $url ) ) {
|
603 |
$v = $wp_scripts->registered[ 'jquery' ]->ver ;
|
604 |
}
|
605 |
|
606 |
+
$src = $this->_cfg_cdn_remote_jquery === LiteSpeed_Cache_Config::VAL_ON ? "//ajax.googleapis.com/ajax/libs/jquery/$v/jquery.min.js" : "//cdnjs.cloudflare.com/ajax/libs/jquery/$v/jquery.min.js" ;
|
607 |
|
608 |
+
LiteSpeed_Cache_Log::debug2( '[CDN] load_jquery_remotely: ' . $src ) ;
|
609 |
|
610 |
wp_deregister_script( 'jquery' ) ;
|
611 |
|
includes/litespeed-cache-config.class.php
CHANGED
@@ -32,6 +32,8 @@ class LiteSpeed_Cache_Config
|
|
32 |
const ITEM_OBJECT_GLOBAL_GROUPS = 'litespeed-object_global_groups' ;
|
33 |
const ITEM_OBJECT_NON_PERSISTENT_GROUPS = 'litespeed-object_non_persistent_groups' ;
|
34 |
const ITEM_CRWL_AS_UIDS = 'litespeed-crawler-as-uids' ;
|
|
|
|
|
35 |
|
36 |
const ITEM_SETTING_MODE = 'litespeed-setting-mode' ;
|
37 |
const ITEM_CRAWLER_HASH = 'litespeed-crawler-hash' ;
|
@@ -247,13 +249,13 @@ class LiteSpeed_Cache_Config
|
|
247 |
}
|
248 |
|
249 |
// Vary group settings
|
250 |
-
$this->vary_groups = (
|
251 |
|
252 |
// Exclude optimization role setting
|
253 |
-
$this->exclude_optimization_roles =
|
254 |
|
255 |
// Exclude cache role setting
|
256 |
-
$this->exclude_cache_roles =
|
257 |
|
258 |
// Set security key if not initialized yet
|
259 |
if ( isset( $this->options[ self::HASH ] ) && empty( $this->options[ self::HASH ] ) ) {
|
@@ -262,6 +264,37 @@ class LiteSpeed_Cache_Config
|
|
262 |
|
263 |
}
|
264 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
/**
|
266 |
* Define `LSCACHE_ADV_CACHE` based on options setting
|
267 |
*
|
@@ -440,9 +473,8 @@ class LiteSpeed_Cache_Config
|
|
440 |
}
|
441 |
|
442 |
$instance = self::get_instance() ;
|
443 |
-
$list = $instance->
|
444 |
|
445 |
-
$list = explode( "\n", $list ) ;
|
446 |
$list[] = $_SERVER[ 'HTTP_REFERER' ] ;
|
447 |
$list = array_map( 'LiteSpeed_Cache_Utility::make_relative', $list ) ;// Remove domain
|
448 |
$list = array_unique( $list ) ;
|
@@ -765,6 +797,26 @@ class LiteSpeed_Cache_Config
|
|
765 |
return $default_site_options ;
|
766 |
}
|
767 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
768 |
/**
|
769 |
* Get default item val
|
770 |
*
|
@@ -780,6 +832,12 @@ class LiteSpeed_Cache_Config
|
|
780 |
case self::ITEM_OBJECT_NON_PERSISTENT_GROUPS :
|
781 |
return "comment\ncounts\nplugins" ;
|
782 |
|
|
|
|
|
|
|
|
|
|
|
|
|
783 |
default :
|
784 |
break ;
|
785 |
}
|
32 |
const ITEM_OBJECT_GLOBAL_GROUPS = 'litespeed-object_global_groups' ;
|
33 |
const ITEM_OBJECT_NON_PERSISTENT_GROUPS = 'litespeed-object_non_persistent_groups' ;
|
34 |
const ITEM_CRWL_AS_UIDS = 'litespeed-crawler-as-uids' ;
|
35 |
+
const ITEM_ADV_PURGE_ALL_HOOKS = 'litespeed-adv-purge_all_hooks' ;
|
36 |
+
const ITEM_CDN_ORI_DIR = 'litespeed-cdn-ori_dir' ;
|
37 |
|
38 |
const ITEM_SETTING_MODE = 'litespeed-setting-mode' ;
|
39 |
const ITEM_CRAWLER_HASH = 'litespeed-crawler-hash' ;
|
249 |
}
|
250 |
|
251 |
// Vary group settings
|
252 |
+
$this->vary_groups = $this->get_item( self::VARY_GROUP ) ;
|
253 |
|
254 |
// Exclude optimization role setting
|
255 |
+
$this->exclude_optimization_roles = $this->get_item( self::EXCLUDE_OPTIMIZATION_ROLES ) ;
|
256 |
|
257 |
// Exclude cache role setting
|
258 |
+
$this->exclude_cache_roles = $this->get_item( self::EXCLUDE_CACHE_ROLES ) ;
|
259 |
|
260 |
// Set security key if not initialized yet
|
261 |
if ( isset( $this->options[ self::HASH ] ) && empty( $this->options[ self::HASH ] ) ) {
|
264 |
|
265 |
}
|
266 |
|
267 |
+
/**
|
268 |
+
* Get the items in wp_options that need for backup
|
269 |
+
*
|
270 |
+
* @since 2.2.1
|
271 |
+
* @access public
|
272 |
+
*/
|
273 |
+
public function stored_items()
|
274 |
+
{
|
275 |
+
return array(
|
276 |
+
self::OPTION_NAME,
|
277 |
+
self::VARY_GROUP,
|
278 |
+
self::EXCLUDE_OPTIMIZATION_ROLES,
|
279 |
+
self::EXCLUDE_CACHE_ROLES,
|
280 |
+
self::ITEM_OPTM_CSS,
|
281 |
+
self::ITEM_OPTM_JS_DEFER_EXC,
|
282 |
+
self::ITEM_MEDIA_LAZY_IMG_EXC,
|
283 |
+
self::ITEM_IMG_OPTM_NEED_PULL,
|
284 |
+
self::ITEM_ENV_REF,
|
285 |
+
self::ITEM_CACHE_DROP_QS,
|
286 |
+
self::ITEM_CDN_MAPPING,
|
287 |
+
self::ITEM_DNS_PREFETCH,
|
288 |
+
self::ITEM_CLOUDFLARE_STATUS,
|
289 |
+
self::ITEM_LOG_IGNORE_FILTERS,
|
290 |
+
self::ITEM_LOG_IGNORE_PART_FILTERS,
|
291 |
+
self::ITEM_OBJECT_GLOBAL_GROUPS,
|
292 |
+
self::ITEM_OBJECT_NON_PERSISTENT_GROUPS,
|
293 |
+
self::ITEM_CRWL_AS_UIDS,
|
294 |
+
self::ITEM_ADV_PURGE_ALL_HOOKS,
|
295 |
+
) ;
|
296 |
+
}
|
297 |
+
|
298 |
/**
|
299 |
* Define `LSCACHE_ADV_CACHE` based on options setting
|
300 |
*
|
473 |
}
|
474 |
|
475 |
$instance = self::get_instance() ;
|
476 |
+
$list = $instance->get_item( $id ) ;
|
477 |
|
|
|
478 |
$list[] = $_SERVER[ 'HTTP_REFERER' ] ;
|
479 |
$list = array_map( 'LiteSpeed_Cache_Utility::make_relative', $list ) ;// Remove domain
|
480 |
$list = array_unique( $list ) ;
|
797 |
return $default_site_options ;
|
798 |
}
|
799 |
|
800 |
+
/**
|
801 |
+
* Get item val
|
802 |
+
*
|
803 |
+
* @since 2.2.1
|
804 |
+
* @access public
|
805 |
+
*/
|
806 |
+
public function get_item( $k, $return_string = false )
|
807 |
+
{
|
808 |
+
$val = get_option( $k, $this->default_item( $k ) ) ;
|
809 |
+
|
810 |
+
if ( ! $return_string && ! is_array( $val ) ) {
|
811 |
+
$val = $val ? explode( "\n", $val ) : array() ;
|
812 |
+
}
|
813 |
+
elseif ( $return_string && is_array( $val ) ) {
|
814 |
+
$val = implode( "\n", $val ) ;
|
815 |
+
}
|
816 |
+
|
817 |
+
return $val ;
|
818 |
+
}
|
819 |
+
|
820 |
/**
|
821 |
* Get default item val
|
822 |
*
|
832 |
case self::ITEM_OBJECT_NON_PERSISTENT_GROUPS :
|
833 |
return "comment\ncounts\nplugins" ;
|
834 |
|
835 |
+
case self::ITEM_ADV_PURGE_ALL_HOOKS :
|
836 |
+
return "switch_theme\nwp_create_nav_menu\nwp_update_nav_menu\nwp_delete_nav_menu\ncreate_term\nedit_terms\ndelete_term\nadd_link\nedit_link\ndelete_link" ;
|
837 |
+
|
838 |
+
case self::ITEM_CDN_ORI_DIR :
|
839 |
+
return LSCWP_CONTENT_FOLDER . "\nwp-includes\n/min/" ;
|
840 |
+
|
841 |
default :
|
842 |
break ;
|
843 |
}
|
includes/litespeed-cache-optimize.class.php
CHANGED
@@ -224,7 +224,7 @@ class LiteSpeed_Cache_Optimize
|
|
224 |
return ;
|
225 |
}
|
226 |
|
227 |
-
LiteSpeed_Cache_Log::
|
228 |
|
229 |
// Proceed css/js file generation
|
230 |
define( 'LITESPEED_MIN_FILE', true ) ;
|
@@ -249,12 +249,12 @@ class LiteSpeed_Cache_Optimize
|
|
249 |
|
250 |
// Generate static file
|
251 |
Litespeed_File::save( $static_file, $content, true ) ;
|
252 |
-
LiteSpeed_Cache_Log::
|
253 |
|
254 |
}
|
255 |
else {
|
256 |
// Load file from file based cache if not expired
|
257 |
-
LiteSpeed_Cache_Log::
|
258 |
$content = Litespeed_File::read( $static_file ) ;
|
259 |
}
|
260 |
|
@@ -941,7 +941,7 @@ class LiteSpeed_Cache_Optimize
|
|
941 |
// Generate static file
|
942 |
Litespeed_File::save( $static_file, $content, true ) ;
|
943 |
|
944 |
-
LiteSpeed_Cache_Log::
|
945 |
|
946 |
}
|
947 |
|
224 |
return ;
|
225 |
}
|
226 |
|
227 |
+
LiteSpeed_Cache_Log::debug2( '[Optm] start minifying file' ) ;
|
228 |
|
229 |
// Proceed css/js file generation
|
230 |
define( 'LITESPEED_MIN_FILE', true ) ;
|
249 |
|
250 |
// Generate static file
|
251 |
Litespeed_File::save( $static_file, $content, true ) ;
|
252 |
+
LiteSpeed_Cache_Log::debug2( '[Optm] Saved cache to file [path] ' . $static_file ) ;
|
253 |
|
254 |
}
|
255 |
else {
|
256 |
// Load file from file based cache if not expired
|
257 |
+
LiteSpeed_Cache_Log::debug2( '[Optm] Static file available' ) ;
|
258 |
$content = Litespeed_File::read( $static_file ) ;
|
259 |
}
|
260 |
|
941 |
// Generate static file
|
942 |
Litespeed_File::save( $static_file, $content, true ) ;
|
943 |
|
944 |
+
LiteSpeed_Cache_Log::debug2( '[Optm] Saved static file [path] ' . $static_file ) ;
|
945 |
|
946 |
}
|
947 |
|
includes/litespeed-cache-utility.class.php
CHANGED
@@ -154,6 +154,10 @@ class LiteSpeed_Cache_Utility
|
|
154 |
public static function str_hit_array( $needle, $haystack )
|
155 |
{
|
156 |
foreach( $haystack as $item ) {
|
|
|
|
|
|
|
|
|
157 |
if ( substr( $item, -1 ) === '$' ) {
|
158 |
// do exact match
|
159 |
if ( substr( $item, 0, -1 ) === $needle ) {
|
154 |
public static function str_hit_array( $needle, $haystack )
|
155 |
{
|
156 |
foreach( $haystack as $item ) {
|
157 |
+
if ( ! $item ) {
|
158 |
+
continue ;
|
159 |
+
}
|
160 |
+
|
161 |
if ( substr( $item, -1 ) === '$' ) {
|
162 |
// do exact match
|
163 |
if ( substr( $item, 0, -1 ) === $needle ) {
|
includes/litespeed-cache.class.php
CHANGED
@@ -19,7 +19,7 @@ class LiteSpeed_Cache
|
|
19 |
private static $_instance ;
|
20 |
|
21 |
const PLUGIN_NAME = 'litespeed-cache' ;
|
22 |
-
const PLUGIN_VERSION = '2.2.
|
23 |
|
24 |
const PAGE_EDIT_HTACCESS = 'lscache-edit-htaccess' ;
|
25 |
|
@@ -97,13 +97,6 @@ class LiteSpeed_Cache
|
|
97 |
define( 'LITESPEED_DISABLE_ALL', true ) ;
|
98 |
}
|
99 |
|
100 |
-
/**
|
101 |
-
* This needs to be before activation because admin-rules.class.php need const `LSCWP_CONTENT_FOLDER`
|
102 |
-
* @since 1.9.1 Moved up
|
103 |
-
*/
|
104 |
-
define( 'LSCWP_CONTENT_FOLDER', str_replace( home_url( '/' ), '', WP_CONTENT_URL ) ) ; // `wp-content`
|
105 |
-
define( 'LSWCP_PLUGIN_URL', plugin_dir_url( dirname( __FILE__ ) ) ) ;// Full URL path '//example.com/wp-content/plugins/litespeed-cache/'
|
106 |
-
|
107 |
// Register plugin activate/deactivate/uninstall hooks
|
108 |
// NOTE: this can't be moved under after_setup_theme, otherwise activation will be bypassed somehow
|
109 |
if( is_admin() || defined( 'LITESPEED_CLI' ) ) {
|
19 |
private static $_instance ;
|
20 |
|
21 |
const PLUGIN_NAME = 'litespeed-cache' ;
|
22 |
+
const PLUGIN_VERSION = '2.2.1' ;
|
23 |
|
24 |
const PAGE_EDIT_HTACCESS = 'lscache-edit-htaccess' ;
|
25 |
|
97 |
define( 'LITESPEED_DISABLE_ALL', true ) ;
|
98 |
}
|
99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
// Register plugin activate/deactivate/uninstall hooks
|
101 |
// NOTE: this can't be moved under after_setup_theme, otherwise activation will be bypassed somehow
|
102 |
if( is_admin() || defined( 'LITESPEED_CLI' ) ) {
|
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: WordPress plugin to connect to LSCache on LiteSpeed Web Server.
|
18 |
-
* Version: 2.2.
|
19 |
* Author: LiteSpeed Technologies
|
20 |
* Author URI: https://www.litespeedtech.com
|
21 |
* License: GPLv3
|
@@ -52,6 +52,15 @@ if ( class_exists( 'LiteSpeed_Cache' ) || defined( 'LSCWP_DIR' ) ) {
|
|
52 |
! defined( 'LSCWP_DIR' ) && define( 'LSCWP_DIR', dirname( __FILE__ ) . '/' ) ;// Full absolute path '/usr/local/lsws/***/wp-content/plugins/litespeed-cache/' or MU
|
53 |
! defined( 'LSCWP_BASENAME' ) && define( 'LSCWP_BASENAME', 'litespeed-cache/litespeed-cache.php' ) ;//LSCWP_BASENAME='litespeed-cache/litespeed-cache.php'
|
54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
! defined( 'LITESPEED_TIME_OFFSET' ) && define( 'LITESPEED_TIME_OFFSET', get_option( 'gmt_offset' ) * 60 * 60 ) ;
|
56 |
|
57 |
// Placeholder for lazyload img
|
15 |
* Plugin Name: LiteSpeed Cache
|
16 |
* Plugin URI: https://www.litespeedtech.com/products/cache-plugins/wordpress-acceleration
|
17 |
* Description: WordPress plugin to connect to LSCache on LiteSpeed Web Server.
|
18 |
+
* Version: 2.2.1
|
19 |
* Author: LiteSpeed Technologies
|
20 |
* Author URI: https://www.litespeedtech.com
|
21 |
* License: GPLv3
|
52 |
! defined( 'LSCWP_DIR' ) && define( 'LSCWP_DIR', dirname( __FILE__ ) . '/' ) ;// Full absolute path '/usr/local/lsws/***/wp-content/plugins/litespeed-cache/' or MU
|
53 |
! defined( 'LSCWP_BASENAME' ) && define( 'LSCWP_BASENAME', 'litespeed-cache/litespeed-cache.php' ) ;//LSCWP_BASENAME='litespeed-cache/litespeed-cache.php'
|
54 |
|
55 |
+
/**
|
56 |
+
* This needs to be before activation because admin-rules.class.php need const `LSCWP_CONTENT_FOLDER`
|
57 |
+
* This also needs to be before cfg.cls init because default cdn_included_dir needs `LSCWP_CONTENT_FOLDER`
|
58 |
+
* @since 1.9.1 Moved up
|
59 |
+
* @since 2.2.1 Moved up from core.cls
|
60 |
+
*/
|
61 |
+
define( 'LSCWP_CONTENT_FOLDER', str_replace( home_url( '/' ), '', WP_CONTENT_URL ) ) ; // `wp-content`
|
62 |
+
define( 'LSWCP_PLUGIN_URL', plugin_dir_url( __FILE__ ) ) ;// Full URL path '//example.com/wp-content/plugins/litespeed-cache/'
|
63 |
+
|
64 |
! defined( 'LITESPEED_TIME_OFFSET' ) && define( 'LITESPEED_TIME_OFFSET', get_option( 'gmt_offset' ) * 60 * 60 ) ;
|
65 |
|
66 |
// Placeholder for lazyload img
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: LiteSpeedTech
|
3 |
Tags: cache, wp-cache, litespeed, super cache, http2, total cache, optimize, object cache, redis, memcached, lazy load, database cleaner
|
4 |
Requires at least: 4.0
|
5 |
-
Tested up to: 4.9.
|
6 |
-
Stable tag: 2.2.
|
7 |
License: GPLv3
|
8 |
License URI: http://www.gnu.org/licenses/gpl.html
|
9 |
|
@@ -87,6 +87,7 @@ LSCWP supports WordPress Multisite and is compatible with most popular plugins,
|
|
87 |
* [View detailed documentation on our wiki](https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:cache:lscwp).
|
88 |
* [Read WordPress Wednesday tutorials on our blog](http://blog.litespeedtech.com/tag/wordpress-wednesday).
|
89 |
* [Help translate LSCWP](https://translate.wordpress.org/projects/wp-plugins/litespeed-cache).
|
|
|
90 |
|
91 |
== Installation ==
|
92 |
|
@@ -252,13 +253,21 @@ Click on the `Advanced View` link at the top of the page, and several more tabs
|
|
252 |
|
253 |
== Changelog ==
|
254 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
= 2.2.0.2 - Apr 3 2018 =
|
256 |
-
* [HOTFIX] Fixed the PHP warning
|
257 |
|
258 |
= 2.2.0.1 - Apr 3 2018 =
|
259 |
* [HOTFIX] Object parameter will no longer cause warnings to be logged for Purge and Cache classes. (@kelltech @khrifat)
|
260 |
* [UPDATE] Removed duplicated del_file func from Object Cache class.
|
261 |
-
* [BUGFIX] CLI no longer shows 400 error upon successful result.
|
262 |
|
263 |
= 2.2 - Apr 2 2018 =
|
264 |
* [NEW FEATURE] <strong>Debug</strong> Disable All Features setting in Debug tab. (@monarobase)
|
2 |
Contributors: LiteSpeedTech
|
3 |
Tags: cache, wp-cache, litespeed, super cache, http2, total cache, optimize, object cache, redis, memcached, lazy load, database cleaner
|
4 |
Requires at least: 4.0
|
5 |
+
Tested up to: 4.9.5
|
6 |
+
Stable tag: 2.2.1
|
7 |
License: GPLv3
|
8 |
License URI: http://www.gnu.org/licenses/gpl.html
|
9 |
|
87 |
* [View detailed documentation on our wiki](https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:cache:lscwp).
|
88 |
* [Read WordPress Wednesday tutorials on our blog](http://blog.litespeedtech.com/tag/wordpress-wednesday).
|
89 |
* [Help translate LSCWP](https://translate.wordpress.org/projects/wp-plugins/litespeed-cache).
|
90 |
+
* [LSCWP GitHub Repo](https://github.com/litespeedtech/lscache_wp).
|
91 |
|
92 |
== Installation ==
|
93 |
|
253 |
|
254 |
== Changelog ==
|
255 |
|
256 |
+
= 2.2.1 - Apr 10 2018 =
|
257 |
+
* [NEW FEATURE] Included Directories setting in CDN tab. (@Dave)
|
258 |
+
* [NEW FEATURE] Purge All Hooks setting in Advanced tab.
|
259 |
+
* [UPDATE] Added background-image WebP replacement support. (@vengen)
|
260 |
+
* [UPDATE] Show recommended values for textarea items in settings.
|
261 |
+
* [UPDATE] Moved CSS/JS optimizer log to Advanced level.
|
262 |
+
* [INTEGRATION] Added WebP support for Avada Fusion Sliders. (@vengen)
|
263 |
+
|
264 |
= 2.2.0.2 - Apr 3 2018 =
|
265 |
+
* [HOTFIX] <strong>Object Cache</strong> Fixed the PHP warning caused by previous improvement to Object Cache.
|
266 |
|
267 |
= 2.2.0.1 - Apr 3 2018 =
|
268 |
* [HOTFIX] Object parameter will no longer cause warnings to be logged for Purge and Cache classes. (@kelltech @khrifat)
|
269 |
* [UPDATE] Removed duplicated del_file func from Object Cache class.
|
270 |
+
* [BUGFIX] `CLI` no longer shows 400 error upon successful result.
|
271 |
|
272 |
= 2.2 - Apr 2 2018 =
|
273 |
* [NEW FEATURE] <strong>Debug</strong> Disable All Features setting in Debug tab. (@monarobase)
|