You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/Site_Command.php
+99-3Lines changed: 99 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -522,8 +522,15 @@ public function get( $args, $assoc_args ) {
522
522
*
523
523
* ## OPTIONS
524
524
*
525
-
* --slug=<slug>
525
+
* [--slug=<slug>]
526
526
* : Path for the new site. Subdomain on subdomain installs, directory on subdirectory installs.
527
+
* Required if --site-url is not provided.
528
+
*
529
+
* [--site-url=<url>]
530
+
* : Full URL for the new site. Use this to specify a custom domain instead of the auto-generated one.
531
+
* For subdomain installs, this allows you to use a different base domain (e.g., 'http://site.example.com' instead of 'http://site.main.example.com').
532
+
* For subdirectory installs, this allows you to use a different path.
533
+
* If provided, --slug is optional and will be derived from the URL. If both --slug and --site-url are provided, --slug will be used as the base for internal operations (like user creation), while the domain/path from --site-url will be used for the actual site URL.
527
534
*
528
535
* [--title=<title>]
529
536
* : Title of the new site. Default: prettified slug.
@@ -542,8 +549,17 @@ public function get( $args, $assoc_args ) {
542
549
*
543
550
* ## EXAMPLES
544
551
*
552
+
* # Create a site with auto-generated domain
545
553
* $ wp site create --slug=example
546
554
* Success: Site 3 created: http://www.example.com/example/
555
+
*
556
+
* # Create a site with a custom domain (subdomain multisite)
557
+
* $ wp site create --site-url=http://site.example.com
558
+
* Success: Site 4 created: http://site.example.com/
559
+
*
560
+
* # Create a site with a custom subdirectory (subdirectory multisite)
561
+
* $ wp site create --site-url=http://example.com/custom/path/
562
+
* Success: Site 5 created: http://example.com/custom/path/
547
563
*/
548
564
publicfunctioncreate( $args, $assoc_args ) {
549
565
if ( ! is_multisite() ) {
@@ -552,7 +568,72 @@ public function create( $args, $assoc_args ) {
552
568
553
569
global$wpdb, $current_site;
554
570
555
-
$base = $assoc_args['slug'];
571
+
// Check if either slug or site-url is provided
572
+
$has_slug = isset( $assoc_args['slug'] );
573
+
$has_site_url = isset( $assoc_args['site-url'] );
574
+
575
+
if ( ! $has_slug && ! $has_site_url ) {
576
+
WP_CLI::error( 'Either --slug or --site-url must be provided.' );
577
+
}
578
+
579
+
// If site URL is provided, parse it to get domain and path
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
+
}
699
+
}
700
+
} elseif ( is_subdomain_install() ) {
701
+
// No custom site URL, use the slug to generate the domain/path for subdomain install.
0 commit comments