From 645fa119ee06f2fca3dc6e47b8bb5d0b58bca7a0 Mon Sep 17 00:00:00 2001 From: Nikos Roussos Date: Thu, 28 Nov 2024 11:40:39 +0200 Subject: [PATCH] Simplify CF zone code to only remove www. from hostname We made a change to accommodate for domains with more parts (like `.org.au`), but that broke `ummah4earth.org` because they don't have `www` in their hostname. Since we practically only want to remove `www`, this simplifies that part of the code to avoid complicated conditional logic for all use cases. --- src/Commands/SaveCloudflareKey.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Commands/SaveCloudflareKey.php b/src/Commands/SaveCloudflareKey.php index 862f3224fb..d0de522831 100644 --- a/src/Commands/SaveCloudflareKey.php +++ b/src/Commands/SaveCloudflareKey.php @@ -49,10 +49,8 @@ public static function execute(?array $args, ?array $assoc_args): void WP_CLI::error('CLOUDFLARE_API_KEY constant is not set.'); } - // Keep last two parts of the hostname, or three in special cases like .org.au. - $domain_parts = explode('.', $hostname); - $slice = count($domain_parts) - 1; - $root_domain = implode('.', array_slice($domain_parts, - $slice)); + // Remove www from the hostname, since Cloudflare needs the apex domain. + $root_domain = str_replace('www.', '', $hostname); update_option('cloudflare_api_key', CLOUDFLARE_API_KEY); update_option('automatic_platform_optimization', [ 'value' => 1 ]);