Version Description
- Update URL matcher in rewriter (#25)
- Update settings conversion (#26)
- Add
cdn_enabler_exclude_admin
,cdn_enabler_contents_before_rewrite
, andcdn_enabler_contents_after_rewrite
filter hooks (#27) - Fix configuration validation for installations in a subdirectory (#27)
- Remove
cdn_enabler_page_contents_before_rewrite
filter hook in favor of replacement (#27)
Download this release
Release Info
Developer | keycdn |
Plugin | CDN Enabler – WordPress CDN Plugin |
Version | 2.0.1 |
Comparing to | |
See all releases |
Code changes from version 2.0.0 to 2.0.1
- cdn-enabler.php +3 -4
- inc/cdn_enabler.class.php +12 -5
- inc/cdn_enabler_engine.class.php +39 -20
- readme.txt +7 -0
cdn-enabler.php
CHANGED
@@ -6,7 +6,7 @@ Description: Simple and fast WordPress content delivery network (CDN) integratio
|
|
6 |
Author: KeyCDN
|
7 |
Author URI: https://www.keycdn.com
|
8 |
License: GPLv2 or later
|
9 |
-
Version: 2.0.
|
10 |
*/
|
11 |
|
12 |
/*
|
@@ -32,12 +32,12 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
32 |
}
|
33 |
|
34 |
// constants
|
35 |
-
define( 'CDN_ENABLER_VERSION', '2.0.
|
36 |
define( 'CDN_ENABLER_MIN_PHP', '5.6' );
|
37 |
define( 'CDN_ENABLER_MIN_WP', '5.1' );
|
38 |
define( 'CDN_ENABLER_FILE', __FILE__ );
|
39 |
define( 'CDN_ENABLER_BASE', plugin_basename( __FILE__ ) );
|
40 |
-
define( 'CDN_ENABLER_DIR',
|
41 |
|
42 |
// hooks
|
43 |
add_action( 'plugins_loaded', array( 'CDN_Enabler', 'init' ) );
|
@@ -58,7 +58,6 @@ function cdn_enabler_autoload( $class_name ) {
|
|
58 |
}
|
59 |
}
|
60 |
|
61 |
-
|
62 |
// load WP-CLI command
|
63 |
if ( defined( 'WP_CLI' ) && WP_CLI && class_exists( 'WP_CLI' ) ) {
|
64 |
require_once CDN_ENABLER_DIR . '/inc/cdn_enabler_cli.class.php';
|
6 |
Author: KeyCDN
|
7 |
Author URI: https://www.keycdn.com
|
8 |
License: GPLv2 or later
|
9 |
+
Version: 2.0.1
|
10 |
*/
|
11 |
|
12 |
/*
|
32 |
}
|
33 |
|
34 |
// constants
|
35 |
+
define( 'CDN_ENABLER_VERSION', '2.0.1' );
|
36 |
define( 'CDN_ENABLER_MIN_PHP', '5.6' );
|
37 |
define( 'CDN_ENABLER_MIN_WP', '5.1' );
|
38 |
define( 'CDN_ENABLER_FILE', __FILE__ );
|
39 |
define( 'CDN_ENABLER_BASE', plugin_basename( __FILE__ ) );
|
40 |
+
define( 'CDN_ENABLER_DIR', __DIR__ );
|
41 |
|
42 |
// hooks
|
43 |
add_action( 'plugins_loaded', array( 'CDN_Enabler', 'init' ) );
|
58 |
}
|
59 |
}
|
60 |
|
|
|
61 |
// load WP-CLI command
|
62 |
if ( defined( 'WP_CLI' ) && WP_CLI && class_exists( 'WP_CLI' ) ) {
|
63 |
require_once CDN_ENABLER_DIR . '/inc/cdn_enabler_cli.class.php';
|
inc/cdn_enabler.class.php
CHANGED
@@ -342,7 +342,7 @@ final class CDN_Enabler {
|
|
342 |
* convert settings to new structure
|
343 |
*
|
344 |
* @since 2.0.0
|
345 |
-
* @change 2.0.
|
346 |
*
|
347 |
* @param array $settings settings
|
348 |
* @return array $settings converted settings if applicable, unchanged otherwise
|
@@ -355,6 +355,11 @@ final class CDN_Enabler {
|
|
355 |
return $settings;
|
356 |
}
|
357 |
|
|
|
|
|
|
|
|
|
|
|
358 |
// reformatted settings
|
359 |
if ( isset( $settings['excludes'] ) && is_string( $settings['excludes'] ) ) {
|
360 |
$settings['excludes'] = str_replace( ',', PHP_EOL, $settings['excludes'] );
|
@@ -868,7 +873,7 @@ final class CDN_Enabler {
|
|
868 |
* validate configuration
|
869 |
*
|
870 |
* @since 2.0.0
|
871 |
-
* @change 2.0.
|
872 |
*
|
873 |
* @param array $validated_settings validated settings
|
874 |
* @return array $validated_settings validated settings
|
@@ -880,12 +885,14 @@ final class CDN_Enabler {
|
|
880 |
return $validated_settings;
|
881 |
}
|
882 |
|
883 |
-
// get validation
|
884 |
-
|
|
|
|
|
885 |
|
886 |
// validation request
|
887 |
$response = wp_remote_get(
|
888 |
-
$
|
889 |
array(
|
890 |
'method' => 'HEAD',
|
891 |
'timeout' => 15,
|
342 |
* convert settings to new structure
|
343 |
*
|
344 |
* @since 2.0.0
|
345 |
+
* @change 2.0.1
|
346 |
*
|
347 |
* @param array $settings settings
|
348 |
* @return array $settings converted settings if applicable, unchanged otherwise
|
355 |
return $settings;
|
356 |
}
|
357 |
|
358 |
+
// updated settings
|
359 |
+
if ( isset( $settings['url'] ) && is_string( $settings['url'] ) && substr_count( $settings['url'], '/' ) > 2 ) {
|
360 |
+
$settings['url'] = '';
|
361 |
+
}
|
362 |
+
|
363 |
// reformatted settings
|
364 |
if ( isset( $settings['excludes'] ) && is_string( $settings['excludes'] ) ) {
|
365 |
$settings['excludes'] = str_replace( ',', PHP_EOL, $settings['excludes'] );
|
873 |
* validate configuration
|
874 |
*
|
875 |
* @since 2.0.0
|
876 |
+
* @change 2.0.1
|
877 |
*
|
878 |
* @param array $validated_settings validated settings
|
879 |
* @return array $validated_settings validated settings
|
885 |
return $validated_settings;
|
886 |
}
|
887 |
|
888 |
+
// get validation request URL
|
889 |
+
CDN_Enabler_Engine::$settings['cdn_hostname'] = $validated_settings['cdn_hostname'];
|
890 |
+
CDN_Enabler_Engine::$settings['included_file_extensions'] = '.css';
|
891 |
+
$validation_request_url = CDN_Enabler_Engine::rewriter( plugins_url( 'css/settings.min.css', CDN_ENABLER_FILE ) );
|
892 |
|
893 |
// validation request
|
894 |
$response = wp_remote_get(
|
895 |
+
$validation_request_url,
|
896 |
array(
|
897 |
'method' => 'HEAD',
|
898 |
'timeout' => 15,
|
inc/cdn_enabler_engine.class.php
CHANGED
@@ -68,28 +68,26 @@ final class CDN_Enabler_Engine {
|
|
68 |
|
69 |
|
70 |
/**
|
71 |
-
* end output buffering and rewrite
|
72 |
*
|
73 |
* @since 2.0.0
|
74 |
-
* @change 2.0.
|
75 |
*
|
76 |
-
* @param string $
|
77 |
-
* @param integer $phase
|
78 |
-
* @return string $
|
79 |
*/
|
80 |
|
81 |
-
private static function end_buffering( $
|
82 |
|
83 |
if ( $phase & PHP_OUTPUT_HANDLER_FINAL || $phase & PHP_OUTPUT_HANDLER_END ) {
|
84 |
if ( self::bypass_rewrite() ) {
|
85 |
-
return $
|
86 |
}
|
87 |
|
88 |
-
$
|
89 |
-
|
90 |
-
$page_contents = self::rewriter( $page_contents );
|
91 |
|
92 |
-
return $
|
93 |
}
|
94 |
}
|
95 |
|
@@ -121,11 +119,30 @@ final class CDN_Enabler_Engine {
|
|
121 |
}
|
122 |
|
123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
/**
|
125 |
* check if rewrite should be bypassed
|
126 |
*
|
127 |
* @since 2.0.0
|
128 |
-
* @change 2.0.
|
129 |
*
|
130 |
* @return boolean true if rewrite should be bypassed, false otherwise
|
131 |
*/
|
@@ -143,7 +160,7 @@ final class CDN_Enabler_Engine {
|
|
143 |
}
|
144 |
|
145 |
// check conditional tags
|
146 |
-
if ( is_admin() || is_trackback() || is_robots() || is_preview() ) {
|
147 |
return true;
|
148 |
}
|
149 |
|
@@ -157,7 +174,7 @@ final class CDN_Enabler_Engine {
|
|
157 |
* @since 0.0.1
|
158 |
* @change 2.0.0
|
159 |
*
|
160 |
-
* @param array $matches pattern matches from parsed
|
161 |
* @return string $file_url rewritten file URL if applicable, unchanged otherwise
|
162 |
*/
|
163 |
|
@@ -198,13 +215,13 @@ final class CDN_Enabler_Engine {
|
|
198 |
|
199 |
|
200 |
/**
|
201 |
-
* rewrite
|
202 |
*
|
203 |
* @since 0.0.1
|
204 |
-
* @change 2.0.
|
205 |
*
|
206 |
-
* @param string $contents contents
|
207 |
-
* @return string $contents|$rewritten_contents rewritten
|
208 |
*/
|
209 |
|
210 |
public static function rewriter( $contents ) {
|
@@ -214,11 +231,13 @@ final class CDN_Enabler_Engine {
|
|
214 |
return $contents;
|
215 |
}
|
216 |
|
|
|
|
|
217 |
$included_file_extensions_regex = quotemeta( implode( '|', explode( PHP_EOL, self::$settings['included_file_extensions'] ) ) );
|
218 |
|
219 |
-
$urls_regex = '#[^\"\'\s
|
220 |
|
221 |
-
$rewritten_contents = preg_replace_callback( $urls_regex, 'self::rewrite_url', $contents );
|
222 |
|
223 |
return $rewritten_contents;
|
224 |
}
|
68 |
|
69 |
|
70 |
/**
|
71 |
+
* end output buffering and rewrite contents if applicable
|
72 |
*
|
73 |
* @since 2.0.0
|
74 |
+
* @change 2.0.1
|
75 |
*
|
76 |
+
* @param string $contents contents from the output buffer
|
77 |
+
* @param integer $phase bitmask of PHP_OUTPUT_HANDLER_* constants
|
78 |
+
* @return string $contents|$rewritten_contents rewritten contents if applicable, unchanged otherwise
|
79 |
*/
|
80 |
|
81 |
+
private static function end_buffering( $contents, $phase ) {
|
82 |
|
83 |
if ( $phase & PHP_OUTPUT_HANDLER_FINAL || $phase & PHP_OUTPUT_HANDLER_END ) {
|
84 |
if ( self::bypass_rewrite() ) {
|
85 |
+
return $contents;
|
86 |
}
|
87 |
|
88 |
+
$rewritten_contents = self::rewriter( $contents );
|
|
|
|
|
89 |
|
90 |
+
return $rewritten_contents;
|
91 |
}
|
92 |
}
|
93 |
|
119 |
}
|
120 |
|
121 |
|
122 |
+
/**
|
123 |
+
* check if administrative interface page
|
124 |
+
*
|
125 |
+
* @since 2.0.1
|
126 |
+
* @change 2.0.1
|
127 |
+
*
|
128 |
+
* @return boolean true if administrative interface page, false otherwise
|
129 |
+
*/
|
130 |
+
|
131 |
+
private static function is_admin() {
|
132 |
+
|
133 |
+
if ( apply_filters( 'cdn_enabler_exclude_admin', is_admin() ) ) {
|
134 |
+
return true;
|
135 |
+
}
|
136 |
+
|
137 |
+
return false;
|
138 |
+
}
|
139 |
+
|
140 |
+
|
141 |
/**
|
142 |
* check if rewrite should be bypassed
|
143 |
*
|
144 |
* @since 2.0.0
|
145 |
+
* @change 2.0.1
|
146 |
*
|
147 |
* @return boolean true if rewrite should be bypassed, false otherwise
|
148 |
*/
|
160 |
}
|
161 |
|
162 |
// check conditional tags
|
163 |
+
if ( self::is_admin() || is_trackback() || is_robots() || is_preview() ) {
|
164 |
return true;
|
165 |
}
|
166 |
|
174 |
* @since 0.0.1
|
175 |
* @change 2.0.0
|
176 |
*
|
177 |
+
* @param array $matches pattern matches from parsed contents
|
178 |
* @return string $file_url rewritten file URL if applicable, unchanged otherwise
|
179 |
*/
|
180 |
|
215 |
|
216 |
|
217 |
/**
|
218 |
+
* rewrite contents
|
219 |
*
|
220 |
* @since 0.0.1
|
221 |
+
* @change 2.0.1
|
222 |
*
|
223 |
+
* @param string $contents contents to parse
|
224 |
+
* @return string $contents|$rewritten_contents rewritten contents if applicable, unchanged otherwise
|
225 |
*/
|
226 |
|
227 |
public static function rewriter( $contents ) {
|
231 |
return $contents;
|
232 |
}
|
233 |
|
234 |
+
$contents = apply_filters( 'cdn_enabler_contents_before_rewrite', $contents );
|
235 |
+
|
236 |
$included_file_extensions_regex = quotemeta( implode( '|', explode( PHP_EOL, self::$settings['included_file_extensions'] ) ) );
|
237 |
|
238 |
+
$urls_regex = '#(?:(?:[\"\'\s=>,]|url\()\K|^)[^\"\'\s(=>,]+(' . $included_file_extensions_regex . ')(\?[^?\\\"\'\s)>,]+)?(?:(?=\/?[?\\\"\'\s)>,])|$)#i';
|
239 |
|
240 |
+
$rewritten_contents = apply_filters( 'cdn_enabler_contents_after_rewrite', preg_replace_callback( $urls_regex, 'self::rewrite_url', $contents ) );
|
241 |
|
242 |
return $rewritten_contents;
|
243 |
}
|
readme.txt
CHANGED
@@ -47,6 +47,13 @@ CDN Enabler captures page contents and rewrites URLs to be served by the designa
|
|
47 |
|
48 |
== Changelog ==
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
= 2.0.0 =
|
51 |
* Update output buffer timing to start earlier on the `setup_theme` hook instead of the `template_redirect` hook (#23)
|
52 |
* Update settings (#23)
|
47 |
|
48 |
== Changelog ==
|
49 |
|
50 |
+
= 2.0.1 =
|
51 |
+
* Update URL matcher in rewriter (#25)
|
52 |
+
* Update settings conversion (#26)
|
53 |
+
* Add `cdn_enabler_exclude_admin`, `cdn_enabler_contents_before_rewrite`, and `cdn_enabler_contents_after_rewrite` filter hooks (#27)
|
54 |
+
* Fix configuration validation for installations in a subdirectory (#27)
|
55 |
+
* Remove `cdn_enabler_page_contents_before_rewrite` filter hook in favor of replacement (#27)
|
56 |
+
|
57 |
= 2.0.0 =
|
58 |
* Update output buffer timing to start earlier on the `setup_theme` hook instead of the `template_redirect` hook (#23)
|
59 |
* Update settings (#23)
|