From 6c62922dce0a749eb95cdcb026a0a74f08cf7df6 Mon Sep 17 00:00:00 2001 From: Joel Escobar Date: Thu, 3 Dec 2020 20:44:34 -0600 Subject: [PATCH 1/3] Add support for configuration via environment vars --- cloudflare.php | 4 ++++ src/WordPress/DataStore.php | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/cloudflare.php b/cloudflare.php index dec1cdf4..cc9ae9d1 100644 --- a/cloudflare.php +++ b/cloudflare.php @@ -10,6 +10,10 @@ // The following constants are available. Add them to wp-config.php to enable. +// To configure Cloudflare credentials via environment vars (defined elsewhere) +// define('CLOUDFLARE_EMAIL', $_ENV['CLOUDFLARE_EMAIL']); +// define('CLOUDFLARE_API_KEY', $_ENV['CLOUDFLARE_API_KEY']); + // To enable HTTP/2 Server Push feature: // define('CLOUDFLARE_HTTP2_SERVER_PUSH_ACTIVE', true); diff --git a/src/WordPress/DataStore.php b/src/WordPress/DataStore.php index 279868d0..dddfa906 100755 --- a/src/WordPress/DataStore.php +++ b/src/WordPress/DataStore.php @@ -39,6 +39,10 @@ public function setWordPressWrapper(WordPressWrapper $wordPressWrapper) */ public function createUserDataStore($client_api_key, $email, $unique_id, $user_key) { + if (defined('CLOUDFLARE_API_KEY') && defined('CLOUDFLARE_EMAIL')) { + return true; + } + // Clear options $this->set(self::API_KEY, ''); $this->set(self::EMAIL, ''); @@ -63,6 +67,10 @@ public function getHostAPIUserUniqueId() */ public function getClientV4APIKey() { + if (defined('CLOUDFLARE_API_KEY')) { + return CLOUDFLARE_API_KEY; + } + return $this->get(self::API_KEY); } @@ -100,6 +108,10 @@ public function setDomainNameCache($domainName) */ public function getCloudFlareEmail() { + if (defined('CLOUDFLARE_EMAIL')) { + return CLOUDFLARE_EMAIL; + } + return $this->get(self::EMAIL); } From 643a916997ea4aa9095c607efdf594bac700ca4c Mon Sep 17 00:00:00 2001 From: Joel Escobar Date: Thu, 3 Dec 2020 21:51:37 -0600 Subject: [PATCH 2/3] Include support for domain configuration via env vars --- cloudflare.php | 1 + src/WordPress/DataStore.php | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/cloudflare.php b/cloudflare.php index cc9ae9d1..a7baeb94 100644 --- a/cloudflare.php +++ b/cloudflare.php @@ -13,6 +13,7 @@ // To configure Cloudflare credentials via environment vars (defined elsewhere) // define('CLOUDFLARE_EMAIL', $_ENV['CLOUDFLARE_EMAIL']); // define('CLOUDFLARE_API_KEY', $_ENV['CLOUDFLARE_API_KEY']); +// define('CLOUDFLARE_DOMAIN_NAME', $_ENV['CLOUDFLARE_DOMAIN_NAME']); // To enable HTTP/2 Server Push feature: // define('CLOUDFLARE_HTTP2_SERVER_PUSH_ACTIVE', true); diff --git a/src/WordPress/DataStore.php b/src/WordPress/DataStore.php index dddfa906..fb9f1da7 100755 --- a/src/WordPress/DataStore.php +++ b/src/WordPress/DataStore.php @@ -87,6 +87,10 @@ public function getHostAPIUserKey() */ public function getDomainNameCache() { + if (defined('CLOUDFLARE_DOMAIN_NAME')) { + return CLOUDFLARE_DOMAIN_NAME; + } + $cachedDomainName = $this->get(self::CACHED_DOMAIN_NAME); if (empty($cachedDomainName)) { return; @@ -100,6 +104,10 @@ public function getDomainNameCache() */ public function setDomainNameCache($domainName) { + if (defined('CLOUDFLARE_DOMAIN_NAME')) { + return; + } + return $this->set(self::CACHED_DOMAIN_NAME, $domainName); } From 0dfcb5f93da3e1a813cbd67376c2334c3124afd8 Mon Sep 17 00:00:00 2001 From: Joel Escobar Date: Thu, 11 Feb 2021 10:28:47 -0600 Subject: [PATCH 3/3] Check that constants are not empty before returning values --- src/WordPress/DataStore.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/WordPress/DataStore.php b/src/WordPress/DataStore.php index fb9f1da7..67d0d7eb 100755 --- a/src/WordPress/DataStore.php +++ b/src/WordPress/DataStore.php @@ -67,7 +67,7 @@ public function getHostAPIUserUniqueId() */ public function getClientV4APIKey() { - if (defined('CLOUDFLARE_API_KEY')) { + if (defined('CLOUDFLARE_API_KEY') && CLOUDFLARE_API_KEY !== '') { return CLOUDFLARE_API_KEY; } @@ -87,7 +87,7 @@ public function getHostAPIUserKey() */ public function getDomainNameCache() { - if (defined('CLOUDFLARE_DOMAIN_NAME')) { + if (defined('CLOUDFLARE_DOMAIN_NAME') && CLOUDFLARE_DOMAIN_NAME !== '') { return CLOUDFLARE_DOMAIN_NAME; } @@ -104,7 +104,7 @@ public function getDomainNameCache() */ public function setDomainNameCache($domainName) { - if (defined('CLOUDFLARE_DOMAIN_NAME')) { + if (defined('CLOUDFLARE_DOMAIN_NAME') && CLOUDFLARE_DOMAIN_NAME !== '') { return; } @@ -116,7 +116,7 @@ public function setDomainNameCache($domainName) */ public function getCloudFlareEmail() { - if (defined('CLOUDFLARE_EMAIL')) { + if (defined('CLOUDFLARE_EMAIL') && CLOUDFLARE_EMAIL !== '') { return CLOUDFLARE_EMAIL; }