Skip to content

Commit

Permalink
Simplify CF zone code to only remove www. from hostname
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
comzeradd committed Dec 2, 2024
1 parent 9772109 commit 645fa11
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/Commands/SaveCloudflareKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]);
Expand Down

0 comments on commit 645fa11

Please sign in to comment.