Skip to content

Commit 27d502e

Browse files
Copilotswissspidy
andcommitted
Address code review feedback: refactor field casting and improve test reliability
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent ad36514 commit 27d502e

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

features/site.feature

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,14 @@ Feature: Manage sites in a multisite installation
817817
Then STDOUT should be a number
818818
And save STDOUT as {SITE_ID}
819819

820-
When I run `wp site delete $(wp site get http://example.com/deleteme/ --field=blog_id) --yes`
820+
When I run `wp site get http://example.com/deleteme/ --field=blog_id`
821+
Then STDOUT should be:
822+
"""
823+
{SITE_ID}
824+
"""
825+
And save STDOUT as {BLOG_ID}
826+
827+
When I run `wp site delete {BLOG_ID} --yes`
821828
Then STDOUT should contain:
822829
"""
823830
Success: The site at

src/Site_Command.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -500,11 +500,11 @@ public function get( $args, $assoc_args ) {
500500
$site_data['url'] = trailingslashit( get_home_url( $site->blog_id ) );
501501

502502
// Cast numeric fields to int for consistent output
503-
if ( isset( $site_data['blog_id'] ) && is_scalar( $site_data['blog_id'] ) ) {
504-
$site_data['blog_id'] = (int) $site_data['blog_id'];
505-
}
506-
if ( isset( $site_data['site_id'] ) && is_scalar( $site_data['site_id'] ) ) {
507-
$site_data['site_id'] = (int) $site_data['site_id'];
503+
$numeric_fields = [ 'blog_id', 'site_id', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' ];
504+
foreach ( $numeric_fields as $field ) {
505+
if ( isset( $site_data[ $field ] ) && is_scalar( $site_data[ $field ] ) ) {
506+
$site_data[ $field ] = (int) $site_data[ $field ];
507+
}
508508
}
509509

510510
// Set default fields if not specified

0 commit comments

Comments
 (0)