@@ -500,6 +500,9 @@ public function create( $args, $assoc_args ) {
500
500
* default: 100
501
501
* ---
502
502
*
503
+ * [--slug=<slug>]
504
+ * : Path for the new site. Subdomain on subdomain installs, directory on subdirectory installs.
505
+ *
503
506
* [--email=<email>]
504
507
* : Email for admin user. User will be created if none exists. Assignment to super admin if not included.
505
508
*
@@ -535,10 +538,27 @@ public function generate( $args, $assoc_args ) {
535
538
'count ' => 100 ,
536
539
'email ' => '' ,
537
540
'network_id ' => 1 ,
541
+ 'slug ' => 'site ' ,
538
542
];
539
543
540
544
$ assoc_args = array_merge ( $ defaults , $ assoc_args );
541
545
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
+
542
562
// Network.
543
563
if ( ! empty ( $ assoc_args ['network_id ' ] ) ) {
544
564
$ network = $ this ->get_network ( $ assoc_args ['network_id ' ] );
@@ -572,7 +592,7 @@ public function generate( $args, $assoc_args ) {
572
592
$ user_id = email_exists ( $ email );
573
593
if ( ! $ user_id ) {
574
594
$ 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 );
576
596
577
597
if ( false === $ user_id ) {
578
598
WP_CLI ::error ( "Can't create user. " );
@@ -581,8 +601,6 @@ public function generate( $args, $assoc_args ) {
581
601
}
582
602
}
583
603
584
- $ is_subdomain_install = is_subdomain_install ();
585
-
586
604
$ format = Utils \get_flag_value ( $ assoc_args , 'format ' , 'progress ' );
587
605
588
606
$ notify = false ;
@@ -591,18 +609,15 @@ public function generate( $args, $assoc_args ) {
591
609
}
592
610
593
611
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 ;
599
614
600
615
if ( $ is_subdomain_install ) {
601
- $ new_domain = $ base . '. ' . preg_replace ( '|^www\.| ' , '' , $ network ->domain );
616
+ $ new_domain = $ current_base . '. ' . preg_replace ( '|^www\.| ' , '' , $ network ->domain );
602
617
$ path = $ network ->path ;
603
618
} else {
604
619
$ new_domain = $ network ->domain ;
605
- $ path = $ network ->path . $ base . '/ ' ;
620
+ $ path = $ network ->path . $ current_base . '/ ' ;
606
621
}
607
622
608
623
$ wpdb ->hide_errors ();
0 commit comments