Skip to content

Commit c969927

Browse files
authored
Update src/Site_Command.php
1 parent c3d2fa3 commit c969927

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/Site_Command.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -616,22 +616,16 @@ public function create( $args, $assoc_args ) {
616616
// Sanitize and lowercase the derived base
617617
$base = strtolower( $base );
618618
} else {
619-
// For subdirectory installs, use the path as the base
620-
$base = trim( $custom_path, '/' );
621-
// Use the last part of the path if there are multiple segments
622-
if ( ! empty( $base ) ) {
623-
$path_parts = explode( '/', $base );
624-
$last_part = array_pop( $path_parts );
625-
if ( null !== $last_part && '' !== $last_part ) {
626-
$base = $last_part;
627-
}
628-
}
629-
// If base is empty (root path), require explicit slug
619+
// For subdirectory installs, derive slug from the last part of the path.
620+
$path_parts = array_filter( explode( '/', trim( $custom_path, '/' ) ) );
621+
$base = (string) array_pop( $path_parts );
622+
623+
// If base is empty (root path), require explicit slug.
630624
if ( empty( $base ) ) {
631625
WP_CLI::error( 'Could not derive a valid slug from the URL path. Please provide --slug explicitly.' );
632626
}
633627

634-
// Sanitize and lowercase the derived base
628+
// Sanitize and lowercase the derived base.
635629
$base = strtolower( $base );
636630
}
637631
} else {

0 commit comments

Comments
 (0)