Skip to content

Commit c26c0d1

Browse files
Copilotswissspidy
andcommitted
Simplify conditional logic for domain/path determination
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent c969927 commit c26c0d1

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

src/Site_Command.php

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -684,29 +684,25 @@ public function create( $args, $assoc_args ) {
684684
}
685685
}
686686

687-
if ( is_subdomain_install() ) {
688-
if ( null !== $custom_domain ) {
689-
// Use custom domain if provided via --site-url
690-
$newdomain = $custom_domain;
691-
$path = $custom_path;
692-
} else {
693-
// Use default behavior
694-
$newdomain = $base . '.' . preg_replace( '|^www\.|', '', $current_site->domain );
695-
$path = $current_site->path;
696-
}
697-
} elseif ( null !== $custom_domain ) {
698-
// Use custom domain and path if provided via --site-url
687+
if ( null !== $custom_domain ) {
688+
// A custom site URL was provided.
699689
$newdomain = $custom_domain;
700690
$path = $custom_path;
701691

702-
// Warn if using a different domain in subdirectory install
703-
$network_domain = preg_replace( '|^www\.|', '', $current_site->domain );
704-
$custom_domain_normalized = preg_replace( '|^www\.|', '', $custom_domain );
705-
if ( $custom_domain_normalized !== $network_domain ) {
706-
WP_CLI::warning( 'Using a different domain for a subdirectory multisite install may require additional configuration (such as domain mapping) to work properly.' );
692+
// For subdirectory installs, warn if the domain is different from the network's domain.
693+
if ( ! is_subdomain_install() ) {
694+
$network_domain = preg_replace( '|^www\.|', '', $current_site->domain );
695+
$custom_domain_normalized = preg_replace( '|^www\.|', '', $custom_domain );
696+
if ( $custom_domain_normalized !== $network_domain ) {
697+
WP_CLI::warning( 'Using a different domain for a subdirectory multisite install may require additional configuration (such as domain mapping) to work properly.' );
698+
}
707699
}
700+
} elseif ( is_subdomain_install() ) {
701+
// No custom site URL, use the slug to generate the domain/path for subdomain install.
702+
$newdomain = $base . '.' . preg_replace( '|^www\.|', '', $current_site->domain );
703+
$path = $current_site->path;
708704
} else {
709-
// Use default behavior
705+
// No custom site URL, use the slug to generate the domain/path for subdirectory install.
710706
$newdomain = $current_site->domain;
711707
$path = $current_site->path . $base . '/';
712708
}

0 commit comments

Comments
 (0)