Skip to content

Commit 3f7c916

Browse files
authored
Merge pull request #444 from shawnhooper/441-delete-site-by-slug
2 parents 684d4d1 + 342167f commit 3f7c916

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

features/site.feature

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,29 @@ Feature: Manage sites in a multisite installation
120120
When I try the previous command again
121121
Then the return code should be 1
122122

123+
When I run `wp site create --slug=42`
124+
Then STDOUT should contain:
125+
"""
126+
Success: Site 3 created: http
127+
"""
128+
And STDOUT should contain:
129+
"""
130+
://example.com/42/
131+
"""
132+
133+
When I run `wp site delete --slug=42 --yes`
134+
Then STDOUT should contain:
135+
"""
136+
://example.com/42/' was deleted.
137+
"""
138+
139+
When I try the previous command again
140+
Then STDERR should contain:
141+
"""
142+
Site with slug '42' does not exist.
143+
"""
144+
And the return code should be 1
145+
123146
Scenario: Get site info
124147
Given a WP multisite install
125148

src/Site_Command.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,11 @@ public function delete( $args, $assoc_args ) {
332332
}
333333

334334
if ( isset( $assoc_args['slug'] ) ) {
335-
$blog = get_blog_details( trim( $assoc_args['slug'], '/' ) );
335+
$blog_id = get_id_from_blogname( $assoc_args['slug'] );
336+
if ( null === $blog_id ) {
337+
WP_CLI::error( "Site with slug '{$assoc_args['slug']}' does not exist." );
338+
}
339+
$blog = get_blog_details( $blog_id );
336340
} else {
337341
if ( empty( $args ) ) {
338342
WP_CLI::error( 'Need to specify a blog id.' );

0 commit comments

Comments
 (0)