@@ -500,6 +500,9 @@ public function create( $args, $assoc_args ) {
500500 * default: 100
501501 * ---
502502 *
503+ * [--slug=<slug>]
504+ * : Path for the new site. Subdomain on subdomain installs, directory on subdirectory installs.
505+ *
503506 * [--email=<email>]
504507 * : Email for admin user. User will be created if none exists. Assignment to super admin if not included.
505508 *
@@ -535,10 +538,27 @@ public function generate( $args, $assoc_args ) {
535538 'count ' => 100 ,
536539 'email ' => '' ,
537540 'network_id ' => 1 ,
541+ 'slug ' => 'site ' ,
538542 ];
539543
540544 $ assoc_args = array_merge ( $ defaults , $ assoc_args );
541545
546+ // Base.
547+ $ base = $ assoc_args ['slug ' ];
548+ if ( preg_match ( '|^([a-zA-Z0-9-])+$| ' , $ base ) ) {
549+ $ base = strtolower ( $ base );
550+ }
551+
552+ $ is_subdomain_install = is_subdomain_install ();
553+ // If not a subdomain install, make sure the domain isn't a reserved word
554+ if ( ! $ is_subdomain_install ) {
555+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Calling WordPress native hook.
556+ $ subdirectory_reserved_names = apply_filters ( 'subdirectory_reserved_names ' , [ 'page ' , 'comments ' , 'blog ' , 'files ' , 'feed ' ] );
557+ if ( in_array ( $ base , $ subdirectory_reserved_names , true ) ) {
558+ WP_CLI ::error ( 'The following words are reserved and cannot be used as blog names: ' . implode ( ', ' , $ subdirectory_reserved_names ) );
559+ }
560+ }
561+
542562 // Network.
543563 if ( ! empty ( $ assoc_args ['network_id ' ] ) ) {
544564 $ network = $ this ->get_network ( $ assoc_args ['network_id ' ] );
@@ -572,7 +592,7 @@ public function generate( $args, $assoc_args ) {
572592 $ user_id = email_exists ( $ email );
573593 if ( ! $ user_id ) {
574594 $ password = wp_generate_password ( 24 , false );
575- $ user_id = wpmu_create_user ( ' site -admin ' , $ password , $ email );
595+ $ user_id = wpmu_create_user ( $ base . ' -admin ' , $ password , $ email );
576596
577597 if ( false === $ user_id ) {
578598 WP_CLI ::error ( "Can't create user. " );
@@ -581,8 +601,6 @@ public function generate( $args, $assoc_args ) {
581601 }
582602 }
583603
584- $ is_subdomain_install = is_subdomain_install ();
585-
586604 $ format = Utils \get_flag_value ( $ assoc_args , 'format ' , 'progress ' );
587605
588606 $ notify = false ;
@@ -591,18 +609,15 @@ public function generate( $args, $assoc_args ) {
591609 }
592610
593611 for ( $ index = 1 ; $ index <= $ limit ; $ index ++ ) {
594- $ base = 'site ' . $ index ;
595- $ title = 'Site ' . $ index ;
596-
597- $ new_domain = '' ;
598- $ path = '' ;
612+ $ current_base = $ base . $ index ;
613+ $ title = ucfirst ( $ base ) . ' ' . $ index ;
599614
600615 if ( $ is_subdomain_install ) {
601- $ new_domain = $ base . '. ' . preg_replace ( '|^www\.| ' , '' , $ network ->domain );
616+ $ new_domain = $ current_base . '. ' . preg_replace ( '|^www\.| ' , '' , $ network ->domain );
602617 $ path = $ network ->path ;
603618 } else {
604619 $ new_domain = $ network ->domain ;
605- $ path = $ network ->path . $ base . '/ ' ;
620+ $ path = $ network ->path . $ current_base . '/ ' ;
606621 }
607622
608623 $ wpdb ->hide_errors ();
0 commit comments