CDN Enabler – WordPress CDN Plugin - Version 2.0.4

Version Description

  • Update configuration validation to include the Site Address (URL) as an HTTP Referer (#42)
  • Update URL matcher in rewriter to match URLs that are in escaped JSON format (#41)
  • Update CDN hostname validation to trim surrounding whitespace characters (#40)
Download this release

Release Info

Developer keycdn
Plugin Icon 128x128 CDN Enabler – WordPress CDN Plugin
Version 2.0.4
Comparing to
See all releases

Code changes from version 2.0.3 to 2.0.4

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.3
10
  */
11
 
12
  /*
@@ -32,7 +32,7 @@ if ( ! defined( 'ABSPATH' ) ) {
32
  }
33
 
34
  // constants
35
- define( 'CDN_ENABLER_VERSION', '2.0.3' );
36
  define( 'CDN_ENABLER_MIN_PHP', '5.6' );
37
  define( 'CDN_ENABLER_MIN_WP', '5.1' );
38
  define( 'CDN_ENABLER_FILE', __FILE__ );
6
  Author: KeyCDN
7
  Author URI: https://www.keycdn.com
8
  License: GPLv2 or later
9
+ Version: 2.0.4
10
  */
11
 
12
  /*
32
  }
33
 
34
  // constants
35
+ define( 'CDN_ENABLER_VERSION', '2.0.4' );
36
  define( 'CDN_ENABLER_MIN_PHP', '5.6' );
37
  define( 'CDN_ENABLER_MIN_WP', '5.1' );
38
  define( 'CDN_ENABLER_FILE', __FILE__ );
inc/cdn_enabler.class.php CHANGED
@@ -14,7 +14,7 @@ final class CDN_Enabler {
14
  /**
15
  * initialize plugin
16
  *
17
- * @since 0.0.1
18
  * @change 2.0.0
19
  */
20
 
@@ -66,7 +66,7 @@ final class CDN_Enabler {
66
  /**
67
  * activation hook
68
  *
69
- * @since 0.0.1
70
  * @change 2.0.0
71
  *
72
  * @param boolean $network_wide network activated
@@ -124,7 +124,7 @@ final class CDN_Enabler {
124
  * add or update backend requirements
125
  *
126
  * @since 2.0.0
127
- * @change 2.0.0
128
  *
129
  * @return array $new_option_value new or current database option value
130
  */
@@ -135,13 +135,13 @@ final class CDN_Enabler {
135
  $old_option_value = get_option( 'cdn_enabler', array() );
136
 
137
  // maybe convert old settings to new settings
138
- $old_option_value = self::convert_settings( $old_option_value );
139
 
140
  // update default system settings
141
- $old_option_value = wp_parse_args( self::get_default_settings( 'system' ), $old_option_value );
142
 
143
  // merge defined settings into default settings
144
- $new_option_value = wp_parse_args( $old_option_value, self::get_default_settings() );
145
 
146
  // validate settings
147
  $new_option_value = self::validate_settings( $new_option_value );
@@ -171,7 +171,7 @@ final class CDN_Enabler {
171
  * enter each site
172
  *
173
  * @since 2.0.0
174
- * @change 2.0.0
175
  *
176
  * @param boolean $network whether or not each site in network
177
  * @param string $callback callback function
@@ -185,14 +185,16 @@ final class CDN_Enabler {
185
 
186
  if ( $network ) {
187
  $blog_ids = self::get_blog_ids();
 
188
  // switch to each site in network
189
  foreach ( $blog_ids as $blog_id ) {
190
  switch_to_blog( $blog_id );
191
- $callback_return[] = (int) call_user_func_array( $callback, $callback_params );
192
  restore_current_blog();
193
  }
194
  } else {
195
- $callback_return[] = (int) call_user_func_array( $callback, $callback_params );
 
196
  }
197
 
198
  return $callback_return;
@@ -239,18 +241,19 @@ final class CDN_Enabler {
239
  * get blog IDs
240
  *
241
  * @since 2.0.0
242
- * @change 2.0.0
243
  *
244
  * @return array $blog_ids blog IDs
245
  */
246
 
247
  private static function get_blog_ids() {
248
 
249
- $blog_ids = array( '1' );
250
 
251
  if ( is_multisite() ) {
252
  global $wpdb;
253
- $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
 
254
  }
255
 
256
  return $blog_ids;
@@ -451,7 +454,7 @@ final class CDN_Enabler {
451
  /**
452
  * add admin bar items
453
  *
454
- * @since 1.0.5
455
  * @change 2.0.0
456
  *
457
  * @param object $wp_admin_bar menu properties
@@ -553,7 +556,7 @@ final class CDN_Enabler {
553
  /**
554
  * process purge cache request
555
  *
556
- * @since 1.0.5
557
  * @change 2.0.3
558
  */
559
 
@@ -729,7 +732,7 @@ final class CDN_Enabler {
729
  /**
730
  * check plugin requirements
731
  *
732
- * @since 0.0.1
733
  * @change 2.0.0
734
  */
735
 
@@ -799,7 +802,7 @@ final class CDN_Enabler {
799
  * validate CDN hostname
800
  *
801
  * @since 2.0.0
802
- * @change 2.0.0
803
  *
804
  * @param string $cdn_hostname CDN hostname
805
  * @return string $validated_cdn_hostname validated CDN hostname
@@ -807,7 +810,7 @@ final class CDN_Enabler {
807
 
808
  private static function validate_cdn_hostname( $cdn_hostname ) {
809
 
810
- $cdn_url = esc_url_raw( $cdn_hostname, array( 'http', 'https' ) );
811
  $validated_cdn_hostname = strtolower( (string) parse_url( $cdn_url, PHP_URL_HOST ) );
812
 
813
  return $validated_cdn_hostname;
@@ -850,19 +853,19 @@ final class CDN_Enabler {
850
 
851
 
852
  /**
853
- * validate Zone ID
854
  *
855
  * @since 2.0.0
856
- * @change 2.0.0
857
  *
858
- * @param string $zone_id Zone ID
859
- * @return integer $validated_zone_id validated Zone ID
860
  */
861
 
862
  private static function validate_zone_id( $zone_id ) {
863
 
864
  $zone_id = sanitize_text_field( $zone_id );
865
- $zone_id = abs( (int) $zone_id );
866
  $validated_zone_id = ( $zone_id === 0 ) ? '' : $zone_id;
867
 
868
  return $validated_zone_id;
@@ -873,7 +876,7 @@ final class CDN_Enabler {
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
@@ -897,6 +900,7 @@ final class CDN_Enabler {
897
  'method' => 'HEAD',
898
  'timeout' => 15,
899
  'httpversion' => '1.1',
 
900
  )
901
  );
902
 
@@ -951,7 +955,7 @@ final class CDN_Enabler {
951
  /**
952
  * validate settings
953
  *
954
- * @since 0.0.1
955
  * @change 2.0.0
956
  *
957
  * @param array $settings user defined settings
@@ -983,7 +987,7 @@ final class CDN_Enabler {
983
  /**
984
  * settings page
985
  *
986
- * @since 0.0.1
987
  * @change 2.0.0
988
  */
989
 
14
  /**
15
  * initialize plugin
16
  *
17
+ * @since 2.0.0
18
  * @change 2.0.0
19
  */
20
 
66
  /**
67
  * activation hook
68
  *
69
+ * @since 2.0.0
70
  * @change 2.0.0
71
  *
72
  * @param boolean $network_wide network activated
124
  * add or update backend requirements
125
  *
126
  * @since 2.0.0
127
+ * @change 2.0.4
128
  *
129
  * @return array $new_option_value new or current database option value
130
  */
135
  $old_option_value = get_option( 'cdn_enabler', array() );
136
 
137
  // maybe convert old settings to new settings
138
+ $new_option_value = self::convert_settings( $old_option_value );
139
 
140
  // update default system settings
141
+ $new_option_value = wp_parse_args( self::get_default_settings( 'system' ), $new_option_value );
142
 
143
  // merge defined settings into default settings
144
+ $new_option_value = wp_parse_args( $new_option_value, self::get_default_settings() );
145
 
146
  // validate settings
147
  $new_option_value = self::validate_settings( $new_option_value );
171
  * enter each site
172
  *
173
  * @since 2.0.0
174
+ * @change 2.0.4
175
  *
176
  * @param boolean $network whether or not each site in network
177
  * @param string $callback callback function
185
 
186
  if ( $network ) {
187
  $blog_ids = self::get_blog_ids();
188
+
189
  // switch to each site in network
190
  foreach ( $blog_ids as $blog_id ) {
191
  switch_to_blog( $blog_id );
192
+ $callback_return[ $blog_id ] = call_user_func_array( $callback, $callback_params );
193
  restore_current_blog();
194
  }
195
  } else {
196
+ $blog_id = 1;
197
+ $callback_return[ $blog_id ] = call_user_func_array( $callback, $callback_params );
198
  }
199
 
200
  return $callback_return;
241
  * get blog IDs
242
  *
243
  * @since 2.0.0
244
+ * @change 2.0.4
245
  *
246
  * @return array $blog_ids blog IDs
247
  */
248
 
249
  private static function get_blog_ids() {
250
 
251
+ $blog_ids = array( 1 );
252
 
253
  if ( is_multisite() ) {
254
  global $wpdb;
255
+
256
+ $blog_ids = array_map( 'absint', $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ) );
257
  }
258
 
259
  return $blog_ids;
454
  /**
455
  * add admin bar items
456
  *
457
+ * @since 2.0.0
458
  * @change 2.0.0
459
  *
460
  * @param object $wp_admin_bar menu properties
556
  /**
557
  * process purge cache request
558
  *
559
+ * @since 2.0.0
560
  * @change 2.0.3
561
  */
562
 
732
  /**
733
  * check plugin requirements
734
  *
735
+ * @since 2.0.0
736
  * @change 2.0.0
737
  */
738
 
802
  * validate CDN hostname
803
  *
804
  * @since 2.0.0
805
+ * @change 2.0.4
806
  *
807
  * @param string $cdn_hostname CDN hostname
808
  * @return string $validated_cdn_hostname validated CDN hostname
810
 
811
  private static function validate_cdn_hostname( $cdn_hostname ) {
812
 
813
+ $cdn_url = esc_url_raw( trim( $cdn_hostname ), array( 'http', 'https' ) );
814
  $validated_cdn_hostname = strtolower( (string) parse_url( $cdn_url, PHP_URL_HOST ) );
815
 
816
  return $validated_cdn_hostname;
853
 
854
 
855
  /**
856
+ * validate KeyCDN Zone ID
857
  *
858
  * @since 2.0.0
859
+ * @change 2.0.4
860
  *
861
+ * @param string $zone_id KeyCDN Zone ID
862
+ * @return integer $validated_zone_id validated KeyCDN Zone ID
863
  */
864
 
865
  private static function validate_zone_id( $zone_id ) {
866
 
867
  $zone_id = sanitize_text_field( $zone_id );
868
+ $zone_id = absint( $zone_id );
869
  $validated_zone_id = ( $zone_id === 0 ) ? '' : $zone_id;
870
 
871
  return $validated_zone_id;
876
  * validate configuration
877
  *
878
  * @since 2.0.0
879
+ * @change 2.0.4
880
  *
881
  * @param array $validated_settings validated settings
882
  * @return array $validated_settings validated settings
900
  'method' => 'HEAD',
901
  'timeout' => 15,
902
  'httpversion' => '1.1',
903
+ 'headers' => array( 'Referer' => home_url() ),
904
  )
905
  );
906
 
955
  /**
956
  * validate settings
957
  *
958
+ * @since 2.0.0
959
  * @change 2.0.0
960
  *
961
  * @param array $settings user defined settings
987
  /**
988
  * settings page
989
  *
990
+ * @since 2.0.0
991
  * @change 2.0.0
992
  */
993
 
inc/cdn_enabler_engine.class.php CHANGED
@@ -171,7 +171,7 @@ final class CDN_Enabler_Engine {
171
  /**
172
  * rewrite URL to use CDN hostname
173
  *
174
- * @since 0.0.1
175
  * @change 2.0.2
176
  *
177
  * @param array $matches pattern matches from parsed contents
@@ -217,8 +217,8 @@ final class CDN_Enabler_Engine {
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
@@ -235,7 +235,7 @@ final class CDN_Enabler_Engine {
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
 
171
  /**
172
  * rewrite URL to use CDN hostname
173
  *
174
+ * @since 2.0.0
175
  * @change 2.0.2
176
  *
177
  * @param array $matches pattern matches from parsed contents
217
  /**
218
  * rewrite contents
219
  *
220
+ * @since 2.0.0
221
+ * @change 2.0.4
222
  *
223
  * @param string $contents contents to parse
224
  * @return string $contents|$rewritten_contents rewritten contents if applicable, unchanged otherwise
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
 
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: keycdn
3
  Tags: cdn, content delivery network, content distribution network
4
  Requires at least: 5.1
5
- Tested up to: 5.7
6
  Requires PHP: 5.6
7
  Stable tag: trunk
8
  License: GPLv2 or later
@@ -22,6 +22,7 @@ CDN Enabler is a simple and easy to use WordPress plugin that rewrites URLs, suc
22
  * Include URLs in the rewrite by file extensions
23
  * Exclude URLs in the rewrite by strings
24
  * WordPress multisite network support
 
25
  * Works perfectly with [Cache Enabler](https://wordpress.org/plugins/cache-enabler/) and the majority of third party plugins
26
 
27
 
@@ -47,6 +48,11 @@ CDN Enabler captures page contents and rewrites URLs to be served by the designa
47
 
48
  == Changelog ==
49
 
 
 
 
 
 
50
  = 2.0.3 =
51
  * Update output buffer handling (#29)
52
  * Fix purge cache request handling (#31)
2
  Contributors: keycdn
3
  Tags: cdn, content delivery network, content distribution network
4
  Requires at least: 5.1
5
+ Tested up to: 5.8
6
  Requires PHP: 5.6
7
  Stable tag: trunk
8
  License: GPLv2 or later
22
  * Include URLs in the rewrite by file extensions
23
  * Exclude URLs in the rewrite by strings
24
  * WordPress multisite network support
25
+ * WordPress REST API support
26
  * Works perfectly with [Cache Enabler](https://wordpress.org/plugins/cache-enabler/) and the majority of third party plugins
27
 
28
 
48
 
49
  == Changelog ==
50
 
51
+ = 2.0.4 =
52
+ * Update configuration validation to include the Site Address (URL) as an HTTP `Referer` (#42)
53
+ * Update URL matcher in rewriter to match URLs that are in escaped JSON format (#41)
54
+ * Update CDN hostname validation to trim surrounding whitespace characters (#40)
55
+
56
  = 2.0.3 =
57
  * Update output buffer handling (#29)
58
  * Fix purge cache request handling (#31)