diff --git a/cloudflare.php b/cloudflare.php index 1ce0457c..70013d16 100644 --- a/cloudflare.php +++ b/cloudflare.php @@ -11,6 +11,11 @@ // 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']); +// 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 279868d0..67d0d7eb 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') && CLOUDFLARE_API_KEY !== '') { + return CLOUDFLARE_API_KEY; + } + return $this->get(self::API_KEY); } @@ -79,6 +87,10 @@ public function getHostAPIUserKey() */ public function getDomainNameCache() { + if (defined('CLOUDFLARE_DOMAIN_NAME') && CLOUDFLARE_DOMAIN_NAME !== '') { + return CLOUDFLARE_DOMAIN_NAME; + } + $cachedDomainName = $this->get(self::CACHED_DOMAIN_NAME); if (empty($cachedDomainName)) { return; @@ -92,6 +104,10 @@ public function getDomainNameCache() */ public function setDomainNameCache($domainName) { + if (defined('CLOUDFLARE_DOMAIN_NAME') && CLOUDFLARE_DOMAIN_NAME !== '') { + return; + } + return $this->set(self::CACHED_DOMAIN_NAME, $domainName); } @@ -100,6 +116,10 @@ public function setDomainNameCache($domainName) */ public function getCloudFlareEmail() { + if (defined('CLOUDFLARE_EMAIL') && CLOUDFLARE_EMAIL !== '') { + return CLOUDFLARE_EMAIL; + } + return $this->get(self::EMAIL); }