File tree Expand file tree Collapse file tree 2 files changed +34
-4
lines changed
Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -163,6 +163,29 @@ Feature: Create a new site on a WP multisite
163163 """
164164 And the return code should be 1
165165
166+ Scenario: Error when numeric-only domain is provided without slug
167+ Given a WP multisite subdomain install
168+
169+ When I try `wp site create --site-url=http://123.example.com`
170+ Then STDERR should be:
171+ """
172+ Error: Could not derive a valid slug from the domain. Please provide --slug explicitly.
173+ """
174+ And the return code should be 1
175+
176+ Scenario: Create site with different domain in subdirectory multisite
177+ Given a WP multisite subdirectory install
178+
179+ When I run `wp site create --site-url=http://custom.example.com/mypath/`
180+ Then STDOUT should contain:
181+ """
182+ Success: Site 2 created:
183+ """
184+ And STDOUT should contain:
185+ """
186+ ://custom.example.com/mypath/
187+ """
188+
166189 Scenario: Preserve existing slug behavior
167190 Given a WP multisite subdomain install
168191
Original file line number Diff line number Diff line change @@ -468,15 +468,22 @@ public function create( $args, $assoc_args ) {
468468 // For subdomain installs, use the first part of the domain as the base
469469 $ domain_parts = explode ( '. ' , $ custom_domain );
470470 $ base = $ domain_parts [0 ];
471+
472+ // Validate that the derived base is suitable for use as a slug
473+ if ( empty ( $ base ) || is_numeric ( $ base ) ) {
474+ WP_CLI ::error ( 'Could not derive a valid slug from the domain. Please provide --slug explicitly. ' );
475+ }
471476 } else {
472477 // For subdirectory installs, use the path as the base
473478 $ base = trim ( $ custom_path , '/ ' );
474479 // Use the last part of the path if there are multiple segments
475- $ path_parts = explode ( '/ ' , $ base );
476- $ base = end ( $ path_parts );
477- // If base is empty (root path), generate a random one
480+ if ( ! empty ( $ base ) ) {
481+ $ path_parts = explode ( '/ ' , $ base );
482+ $ base = $ path_parts [ count ( $ path_parts ) - 1 ];
483+ }
484+ // If base is empty (root path), generate an auto slug
478485 if ( empty ( $ base ) ) {
479- $ base = 'site - ' . wp_generate_password ( 8 , false );
486+ $ base = 'auto - ' . time ( );
480487 }
481488 }
482489 } else {
You can’t perform that action at this time.
0 commit comments