From 342167f3a4d1dd69c70605c7823797d0c0354dca Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Tue, 14 Nov 2023 15:48:21 -0500 Subject: [PATCH] Fix deleting a site by a slug that is an integer --- features/site.feature | 23 +++++++++++++++++++++++ src/Site_Command.php | 6 +++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/features/site.feature b/features/site.feature index 7f343d42..c27b9b34 100644 --- a/features/site.feature +++ b/features/site.feature @@ -120,6 +120,29 @@ Feature: Manage sites in a multisite installation When I try the previous command again Then the return code should be 1 + When I run `wp site create --slug=42` + Then STDOUT should contain: + """ + Success: Site 3 created: http + """ + And STDOUT should contain: + """ + ://example.com/42/ + """ + + When I run `wp site delete --slug=42 --yes` + Then STDOUT should contain: + """ + ://example.com/42/' was deleted. + """ + + When I try the previous command again + Then STDERR should contain: + """ + Site with slug '42' does not exist. + """ + And the return code should be 1 + Scenario: Get site info Given a WP multisite install diff --git a/src/Site_Command.php b/src/Site_Command.php index a802264f..b06a7909 100644 --- a/src/Site_Command.php +++ b/src/Site_Command.php @@ -332,7 +332,11 @@ public function delete( $args, $assoc_args ) { } if ( isset( $assoc_args['slug'] ) ) { - $blog = get_blog_details( trim( $assoc_args['slug'], '/' ) ); + $blog_id = get_id_from_blogname( $assoc_args['slug'] ); + if ( null === $blog_id ) { + WP_CLI::error( "Site with slug '{$assoc_args['slug']}' does not exist." ); + } + $blog = get_blog_details( $blog_id ); } else { if ( empty( $args ) ) { WP_CLI::error( 'Need to specify a blog id.' );