Cloudflare - Version 3.3.3

Version Description

  • 2019-3-6 =

Fixed

  • Bug in Hooks.php causing errors in PHP 7+
  • Bug preventing Autoptimize plugin's optimized asset urls from being used when present and when Cloudflare HTTP/2 Push was enabled
Download this release

Release Info

Developer zackproser
Plugin Icon 128x128 Cloudflare
Version 3.3.3
Comparing to
See all releases

Code changes from version 3.3.2 to 3.3.3

CONTRIBUTING.md CHANGED
@@ -21,7 +21,7 @@ Cloudflare has multiple plugins using shared codebases.
21
 
22
  [WordPress](https://github.com/cloudflare/Cloudflare-WordPress), [CPanel](https://github.com/cloudflare/CloudFlare-CPanel), [Magento](https://github.com/cloudflare/CloudFlare-Magento) are the main repositories of the plugins. Every plugin has a config.js file which allows them to control the frontend of the plugin.
23
 
24
- Below are Cloudflare maintained repositories the plugins depend on.
25
 
26
  * [cloudflare-frontend](https://github.com/cloudflare/CloudFlare-FrontEnd) is a generic frontend used in plugins. You can add/remove cards simply by editing [config](https://github.com/cloudflare/CloudFlare-FrontEnd/blob/master/config.js) file.
27
  * [cf-ui](https://github.com/cloudflare/cf-ui) is a Cloudflare UI Framework where cloudflare-frontend is using.
@@ -29,6 +29,10 @@ Below are Cloudflare maintained repositories the plugins depend on.
29
  * [cf-ip-rewrite](https://github.com/cloudflare/cf-ip-rewrite) allows to rewrite Cloudflare IP's in Application level.
30
  * [mod_cloudflare](https://github.com/cloudflare/mod_cloudflare) allows Apache to rewrite Cloudflare IP's with user IP's. It is not used in plugins itself but it maybe be a better alternative then `cf-ip-rewrite`.
31
 
 
 
 
 
32
  ## WordPress Plugin Specific Details
33
 
34
  Cloudflare WordPress Plugin uses PHPUnit for testing. WordPress specific function are mocked inside [WordPressWrapper](https://github.com/cloudflare/Cloudflare-WordPress/blob/master/src/WordPress/WordPressWrapper.php) class. Everything under `src/` directory should have unit test written.
@@ -45,4 +49,4 @@ Each plugin may use different Frontend [versions]((https://github.com/cloudflare
45
 
46
  ## Translations
47
 
48
- The plugins use a common language file which is located [here](https://github.com/cloudflare/CloudFlare-FrontEnd/tree/master/lang). English translation is always up to date where as other translations are not. If you have any issues or questions regarding with translations feel free to open an [issue](https://github.com/cloudflare/CloudFlare-FrontEnd/issues).
21
 
22
  [WordPress](https://github.com/cloudflare/Cloudflare-WordPress), [CPanel](https://github.com/cloudflare/CloudFlare-CPanel), [Magento](https://github.com/cloudflare/CloudFlare-Magento) are the main repositories of the plugins. Every plugin has a config.js file which allows them to control the frontend of the plugin.
23
 
24
+ Below are Cloudflare maintained repositories the plugins depend on.
25
 
26
  * [cloudflare-frontend](https://github.com/cloudflare/CloudFlare-FrontEnd) is a generic frontend used in plugins. You can add/remove cards simply by editing [config](https://github.com/cloudflare/CloudFlare-FrontEnd/blob/master/config.js) file.
27
  * [cf-ui](https://github.com/cloudflare/cf-ui) is a Cloudflare UI Framework where cloudflare-frontend is using.
29
  * [cf-ip-rewrite](https://github.com/cloudflare/cf-ip-rewrite) allows to rewrite Cloudflare IP's in Application level.
30
  * [mod_cloudflare](https://github.com/cloudflare/mod_cloudflare) allows Apache to rewrite Cloudflare IP's with user IP's. It is not used in plugins itself but it maybe be a better alternative then `cf-ip-rewrite`.
31
 
32
+ ### Dependency Graph
33
+
34
+ ![](https://i.imgur.com/oXEKYVd.png)
35
+
36
  ## WordPress Plugin Specific Details
37
 
38
  Cloudflare WordPress Plugin uses PHPUnit for testing. WordPress specific function are mocked inside [WordPressWrapper](https://github.com/cloudflare/Cloudflare-WordPress/blob/master/src/WordPress/WordPressWrapper.php) class. Everything under `src/` directory should have unit test written.
49
 
50
  ## Translations
51
 
52
+ The plugins use a common language file which is located [here](https://github.com/cloudflare/CloudFlare-FrontEnd/tree/master/lang). English translation is always up to date where as other translations are not. If you have any issues or questions regarding with translations feel free to open an [issue](https://github.com/cloudflare/CloudFlare-FrontEnd/issues).
cloudflare.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Cloudflare
4
  Plugin URI: https://blog.cloudflare.com/new-wordpress-plugin/
5
  Description: Cloudflare speeds up and protects your WordPress site.
6
- Version: 3.3.2
7
  Author: John Wineman, Furkan Yilmaz, Junade Ali (Cloudflare Team)
8
  License: BSD-3-Clause
9
  */
3
  Plugin Name: Cloudflare
4
  Plugin URI: https://blog.cloudflare.com/new-wordpress-plugin/
5
  Description: Cloudflare speeds up and protects your WordPress site.
6
+ Version: 3.3.3
7
  Author: John Wineman, Furkan Yilmaz, Junade Ali (Cloudflare Team)
8
  License: BSD-3-Clause
9
  */
composer.json CHANGED
@@ -21,7 +21,7 @@
21
  "simplyadmire/composer-plugins": "@dev"
22
  },
23
  "scripts": {
24
- "format": "php vendor/squizlabs/php_codesniffer/scripts/phpcs -n --standard=phpcs.xml",
25
  "test": "php vendor/phpunit/phpunit/phpunit",
26
  "post-install-cmd": "@php-compatibility-install",
27
  "post-update-cmd": "@php-compatibility-install",
@@ -30,5 +30,5 @@
30
  "_comment": [
31
  "php-compatibility-install comes from https://github.com/wimg/PHPCompatibility/issues/102#issuecomment-255778195"
32
  ],
33
- "version": "3.3.2"
34
  }
21
  "simplyadmire/composer-plugins": "@dev"
22
  },
23
  "scripts": {
24
+ "format": "php vendor/squizlabs/php_codesniffer/scripts/phpcs -d date.timezone=UTC -n --standard=phpcs.xml",
25
  "test": "php vendor/phpunit/phpunit/phpunit",
26
  "post-install-cmd": "@php-compatibility-install",
27
  "post-update-cmd": "@php-compatibility-install",
30
  "_comment": [
31
  "php-compatibility-install comes from https://github.com/wimg/PHPCompatibility/issues/102#issuecomment-255778195"
32
  ],
33
+ "version": "3.3.3"
34
  }
config.js CHANGED
@@ -25,5 +25,5 @@
25
  },
26
  "locale": "en",
27
  "integrationName": "wordpress",
28
- "version": "3.3.2"
29
  }
25
  },
26
  "locale": "en",
27
  "integrationName": "wordpress",
28
+ "version": "3.3.3"
29
  }
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === Cloudflare ===
2
- Contributors: jwineman, furkan811, icyapril, manatarms
3
  Tags: cloudflare, seo, ssl, ddos, speed, security, cdn, performance, free
4
  Requires at least: 3.4
5
  Tested up to: 4.9.1
6
- Stable tag: 3.3.2
7
  License: BSD-3-Clause
8
 
9
  All of Cloudflare’s performance and security benefits in a simple one-click install of recommended settings specifically developed for WordPress.
@@ -83,11 +83,18 @@ Yes, Cloudflare works with, and helps speed up your site even more, if you have
83
 
84
  == Changelog ==
85
 
 
 
 
 
 
 
 
86
  = 3.3.2 - 2017-12-12 =
87
 
88
  *Fixed*
89
 
90
- * Bug in cf-ip-rewrite
91
 
92
  *Added*
93
 
@@ -115,7 +122,7 @@ Yes, Cloudflare works with, and helps speed up your site even more, if you have
115
 
116
  *Fixed*
117
 
118
- * Bug where domains which had capital letters not working.
119
  * Bug where Automatic Cache Purge couldn't purge front page.
120
  * Bug related to work with IWP.
121
  * Bug where if PHP is compiled with ipv6-disable flag, it crashed the site.
1
  === Cloudflare ===
2
+ Contributors: jwineman, furkan811, icyapril, manatarms, zproser
3
  Tags: cloudflare, seo, ssl, ddos, speed, security, cdn, performance, free
4
  Requires at least: 3.4
5
  Tested up to: 4.9.1
6
+ Stable tag: 3.3.3
7
  License: BSD-3-Clause
8
 
9
  All of Cloudflare’s performance and security benefits in a simple one-click install of recommended settings specifically developed for WordPress.
83
 
84
  == Changelog ==
85
 
86
+ = 3.3.3 - 2019-3-6 =
87
+
88
+ *Fixed*
89
+
90
+ * Bug in Hooks.php causing errors in PHP 7+
91
+ * Bug preventing Autoptimize plugin's optimized asset urls from being used when present and when Cloudflare HTTP/2 Push was enabled
92
+
93
  = 3.3.2 - 2017-12-12 =
94
 
95
  *Fixed*
96
 
97
+ * Bug in cf-ip-rewrite
98
 
99
  *Added*
100
 
122
 
123
  *Fixed*
124
 
125
+ * Bug where domains which had capital letters not working.
126
  * Bug where Automatic Cache Purge couldn't purge front page.
127
  * Bug related to work with IWP.
128
  * Bug where if PHP is compiled with ipv6-disable flag, it crashed the site.
src/WordPress/HTTP2ServerPush.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
 
3
- // TODO:
4
  // Get rid of $GLOBALS and use static variables
5
  // Make class functions non-static
6
  // Add debug logs. Need dependency injection of logger to this class
@@ -23,9 +23,25 @@ class HTTP2ServerPush
23
  {
24
  self::$initiated = true;
25
 
 
 
 
26
  add_action('wp_head', array('\CF\WordPress\HTTP2ServerPush', 'http2ResourceHints'), 99, 1);
27
- add_filter('script_loader_src', array('\CF\WordPress\HTTP2ServerPush', 'http2LinkPreloadHeader'), 99, 1);
28
- add_filter('style_loader_src', array('\CF\WordPress\HTTP2ServerPush', 'http2LinkPreloadHeader'), 99, 1);
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  }
30
 
31
  public static function http2LinkPreloadHeader($src)
@@ -37,7 +53,7 @@ class HTTP2ServerPush
37
  $newHeader = sprintf(
38
  'Link: <%s>; rel=preload; as=%s',
39
  esc_url(self::http2LinkUrlToRelativePath($preload_src)),
40
- sanitize_html_class(self::http2LinkResourceHintAs(current_filter()))
41
  );
42
 
43
  // If the current header size is larger than 3KB (3072 bytes)
@@ -55,7 +71,7 @@ class HTTP2ServerPush
55
 
56
  header($newHeader, false);
57
 
58
- $GLOBALS['http2_'.self::http2LinkResourceHintAs(current_filter()).'_srcs'][] = self::http2LinkUrlToRelativePath($preload_src);
59
  }
60
  }
61
 
@@ -68,10 +84,12 @@ class HTTP2ServerPush
68
  */
69
  public static function http2ResourceHints()
70
  {
 
71
  $resource_types = array('script', 'style');
72
  array_walk($resource_types, function ($resource_type) {
73
- if (is_array($GLOBALS["http2_{$resource_type}_srcs"])) {
74
- array_walk($GLOBALS["http2_{$resource_type}_srcs"], function ($src) use ($resource_type) {
 
75
  printf('<link rel="preload" href="%s" as="%s">', esc_url($src), esc_html($resource_type));
76
  });
77
  }
@@ -97,8 +115,24 @@ class HTTP2ServerPush
97
  *
98
  * @return string 'style' or 'script'
99
  */
100
- public static function http2LinkResourceHintAs($current_hook)
101
  {
102
- return 'style_loader_src' === $current_hook ? 'style' : 'script';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  }
104
  }
1
  <?php
2
 
3
+ // TODO:
4
  // Get rid of $GLOBALS and use static variables
5
  // Make class functions non-static
6
  // Add debug logs. Need dependency injection of logger to this class
23
  {
24
  self::$initiated = true;
25
 
26
+ $autoptimize_js_enabled = (get_option('autoptimize_js') && get_option('autoptimize_js') === 'on');
27
+ $autoptimize_css_enabled = (get_option('autoptimize_css') && get_option('autoptimize_css') === 'on');
28
+
29
  add_action('wp_head', array('\CF\WordPress\HTTP2ServerPush', 'http2ResourceHints'), 99, 1);
30
+
31
+ // If Autoptimize exists, prefer the optimized assets it emits over usual WordPress enqueued scripts
32
+ if (class_exists('autoptimizeMain')) {
33
+ add_filter('autoptimize_filter_cache_getname', array('\CF\WordPress\HTTP2ServerPush', 'http2LinkPreloadHeader'), 99, 1);
34
+ if (!$autoptimize_js_enabled) {
35
+ add_filter('script_loader_src', array('\CF\WordPress\HTTP2ServerPush', 'http2LinkPreloadHeader'), 99, 1);
36
+ }
37
+ if (!$autoptimize_css_enabled) {
38
+ add_filter('style_loader_src', array('\CF\WordPress\HTTP2ServerPush', 'http2LinkPreloadHeader'), 99, 1);
39
+ }
40
+ } else {
41
+ // Autoptimize plugin is not activated, so fallback to the usual WordPress script and style queues
42
+ add_filter('script_loader_src', array('\CF\WordPress\HTTP2ServerPush', 'http2LinkPreloadHeader'), 99, 1);
43
+ add_filter('style_loader_src', array('\CF\WordPress\HTTP2ServerPush', 'http2LinkPreloadHeader'), 99, 1);
44
+ }
45
  }
46
 
47
  public static function http2LinkPreloadHeader($src)
53
  $newHeader = sprintf(
54
  'Link: <%s>; rel=preload; as=%s',
55
  esc_url(self::http2LinkUrlToRelativePath($preload_src)),
56
+ sanitize_html_class(self::http2LinkResourceHintAs(current_filter(), $preload_src))
57
  );
58
 
59
  // If the current header size is larger than 3KB (3072 bytes)
71
 
72
  header($newHeader, false);
73
 
74
+ $GLOBALS['http2_'.self::http2LinkResourceHintAs(current_filter(), $preload_src).'_srcs'][] = self::http2LinkUrlToRelativePath($preload_src);
75
  }
76
  }
77
 
84
  */
85
  public static function http2ResourceHints()
86
  {
87
+
88
  $resource_types = array('script', 'style');
89
  array_walk($resource_types, function ($resource_type) {
90
+ $key = "http2_{$resource_type}_srcs";
91
+ if (isset($GLOBALS[$key]) && is_array($GLOBALS[$key])) {
92
+ array_walk($GLOBALS[$key], function ($src) use ($resource_type) {
93
  printf('<link rel="preload" href="%s" as="%s">', esc_url($src), esc_html($resource_type));
94
  });
95
  }
115
  *
116
  * @return string 'style' or 'script'
117
  */
118
+ public static function http2LinkResourceHintAs($current_hook, $src)
119
  {
120
+
121
+ switch ($current_hook) {
122
+ case 'style_loader_src':
123
+ return 'style';
124
+ case 'script_loader_src':
125
+ return 'script';
126
+ case 'autoptimize_filter_cache_getname':
127
+ $ext = pathinfo($src, PATHINFO_EXTENSION);
128
+ if ($ext === 'js') {
129
+ return 'script';
130
+ } else if ($ext === 'css') {
131
+ return 'style';
132
+ }
133
+ return '';
134
+ default:
135
+ return '';
136
+ }
137
  }
138
  }
src/WordPress/Hooks.php CHANGED
@@ -111,8 +111,9 @@ class Hooks
111
  {
112
  if ($this->isPluginSpecificCacheEnabled()) {
113
  $wpDomainList = $this->integrationAPI->getDomainList();
114
- $wpDomain = $wpDomainList[0];
115
- if (count($wpDomain) > 0) {
 
116
  $zoneTag = $this->api->getZoneTag($wpDomain);
117
 
118
  if (isset($zoneTag)) {
@@ -129,10 +130,10 @@ class Hooks
129
  {
130
  if ($this->isPluginSpecificCacheEnabled()) {
131
  $wpDomainList = $this->integrationAPI->getDomainList();
132
- $wpDomain = $wpDomainList[0];
133
- if (count($wpDomain) <= 0) {
134
  return;
135
  }
 
136
 
137
  $validPostStatus = array('publish', 'trash');
138
  $thisPostStatus = get_post_status($postId);
111
  {
112
  if ($this->isPluginSpecificCacheEnabled()) {
113
  $wpDomainList = $this->integrationAPI->getDomainList();
114
+ if (count($wpDomainList) > 0) {
115
+ $wpDomain = $wpDomainList[0];
116
+
117
  $zoneTag = $this->api->getZoneTag($wpDomain);
118
 
119
  if (isset($zoneTag)) {
130
  {
131
  if ($this->isPluginSpecificCacheEnabled()) {
132
  $wpDomainList = $this->integrationAPI->getDomainList();
133
+ if (count($wpDomainList) <= 0) {
 
134
  return;
135
  }
136
+ $wpDomain = $wpDomainList[0];
137
 
138
  $validPostStatus = array('publish', 'trash');
139
  $thisPostStatus = get_post_status($postId);
src/WordPress/WordPressAPI.php CHANGED
@@ -84,13 +84,13 @@ class WordPressAPI implements IntegrationAPIInterface
84
  *
85
  * @param null $userId
86
  *
87
- * @return mixed
88
  */
89
  public function getDomainList($userId = null)
90
  {
91
  $cachedDomainName = $this->dataStore->getDomainNameCache();
92
  if (empty($cachedDomainName)) {
93
- return;
94
  }
95
 
96
  return array($cachedDomainName);
84
  *
85
  * @param null $userId
86
  *
87
+ * @return array
88
  */
89
  public function getDomainList($userId = null)
90
  {
91
  $cachedDomainName = $this->dataStore->getDomainNameCache();
92
  if (empty($cachedDomainName)) {
93
+ return array();
94
  }
95
 
96
  return array($cachedDomainName);