Skip to content

Commit fe2c33b

Browse files
committed
Make string usage consistent
1 parent e9a2bbd commit fe2c33b

11 files changed

+65
-62
lines changed

src/Comment_Command.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function ( $params ) {
7272
$post_id = $params['comment_post_ID'];
7373
$post = get_post( $post_id );
7474
if ( ! $post ) {
75-
return new WP_Error( 'no_post', "Can't find post $post_id." );
75+
return new WP_Error( 'no_post', "Can't find post {$post_id}." );
7676
}
7777
} else {
7878
// Make sure it's set for older WP versions else get undefined PHP notice.
@@ -355,7 +355,7 @@ public function list_( $args, $assoc_args ) {
355355
if ( $comment ) {
356356
$comments[] = $comment;
357357
} else {
358-
WP_CLI::warning( sprintf( 'Invalid comment %s.', $comment_id ) );
358+
WP_CLI::warning( "Invalid comment {$comment_id}." );
359359
}
360360
}
361361
} else {
@@ -414,25 +414,25 @@ function ( $comment_id, $assoc_args ) {
414414
$result = wp_delete_comment( $comment_id, $force );
415415

416416
if ( ! $result ) {
417-
return [ 'error', "Failed deleting comment $comment_id." ];
417+
return [ 'error', "Failed deleting comment {$comment_id}." ];
418418
}
419419

420420
$verb = ( $force || 'trash' === $status ) ? 'Deleted' : 'Trashed';
421-
return [ 'success', "$verb comment $comment_id." ];
421+
return [ 'success', "{$verb} comment {$comment_id}." ];
422422
}
423423
);
424424
}
425425

426426
private function call( $args, $status, $success, $failure ) {
427427
$comment_id = absint( $args );
428428

429-
$func = sprintf( 'wp_%s_comment', $status );
429+
$func = "wp_{$status}_comment";
430430

431431
if ( ! $func( $comment_id ) ) {
432-
WP_CLI::error( "$failure comment $comment_id." );
432+
WP_CLI::error( "{$failure} comment {$comment_id}." );
433433
}
434434

435-
WP_CLI::success( "$success comment $comment_id." );
435+
WP_CLI::success( "{$success} comment {$comment_id}." );
436436
}
437437

438438
private function set_status( $args, $status, $success ) {
@@ -444,7 +444,7 @@ private function set_status( $args, $status, $success ) {
444444
WP_CLI::error( $result );
445445
}
446446

447-
WP_CLI::success( "$success comment $comment->comment_ID." );
447+
WP_CLI::success( "{$success} comment {$comment->comment_ID}." );
448448
}
449449

450450
/**
@@ -645,9 +645,9 @@ public function recount( $args ) {
645645
wp_update_comment_count( $id );
646646
$post = get_post( $id );
647647
if ( $post ) {
648-
WP_CLI::log( sprintf( 'Updated post %d comment count to %d.', $post->ID, $post->comment_count ) );
648+
WP_CLI::log( "Updated post {$post->ID} comment count to {$post->comment_count}." );
649649
} else {
650-
WP_CLI::warning( sprintf( "Post %d doesn't exist.", $post->ID ) );
650+
WP_CLI::warning( "Post {$post->ID} doesn't exist." );
651651
}
652652
}
653653
}
@@ -672,7 +672,7 @@ public function status( $args, $assoc_args ) {
672672
$status = wp_get_comment_status( $comment_id );
673673

674674
if ( false === $status ) {
675-
WP_CLI::error( "Could not check status of comment $comment_id." );
675+
WP_CLI::error( "Could not check status of comment {$comment_id}." );
676676
} else {
677677
WP_CLI::line( $status );
678678
}
@@ -696,7 +696,7 @@ public function status( $args, $assoc_args ) {
696696
*/
697697
public function exists( $args ) {
698698
if ( $this->fetcher->get( $args[0] ) ) {
699-
WP_CLI::success( "Comment with ID $args[0] exists." );
699+
WP_CLI::success( "Comment with ID {$args[0]} exists." );
700700
}
701701
}
702702
}

src/Menu_Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function create( $args, $assoc_args ) {
7373
if ( Utils\get_flag_value( $assoc_args, 'porcelain' ) ) {
7474
WP_CLI::line( $menu_id );
7575
} else {
76-
WP_CLI::success( "Created menu $menu_id." );
76+
WP_CLI::success( "Created menu {$menu_id}." );
7777
}
7878
}
7979
}

src/Menu_Location_Command.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,20 @@ public function assign( $args, $assoc_args ) {
114114

115115
$menu_obj = wp_get_nav_menu_object( $menu );
116116
if ( ! $menu_obj ) {
117-
WP_CLI::error( "Invalid menu $menu." );
117+
WP_CLI::error( "Invalid menu {$menu}." );
118118
}
119119

120120
$locations = get_registered_nav_menus();
121121
if ( ! array_key_exists( $location, $locations ) ) {
122-
WP_CLI::error( "Invalid location $location." );
122+
WP_CLI::error( "Invalid location {$location}." );
123123
}
124124

125125
$locations = get_nav_menu_locations();
126126
$locations[ $location ] = $menu_obj->term_id;
127127

128128
set_theme_mod( 'nav_menu_locations', $locations );
129129

130-
WP_CLI::success( "Assigned location $location to menu $menu." );
130+
WP_CLI::success( "Assigned location {$location} to menu {$menu}." );
131131
}
132132

133133
/**

src/Post_Command.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ public function generate( $args, $assoc_args ) {
749749
}
750750

751751
if ( ! post_type_exists( $post_type ) ) {
752-
WP_CLI::error( sprintf( "'%s' is not a registered post type.", $post_type ) );
752+
WP_CLI::error( "'{$post_type}' is not a registered post type." );
753753
}
754754

755755
if ( $post_author ) {
@@ -804,11 +804,11 @@ public function generate( $args, $assoc_args ) {
804804

805805
$args = [
806806
'post_type' => $post_type,
807-
'post_title' => ! empty( $post_title ) && $i === $total ? "$label" : "$label $i",
807+
'post_title' => ! empty( $post_title ) && $i === $total ? $label : "{$label} {$i}",
808808
'post_status' => $post_status,
809809
'post_author' => $post_author,
810810
'post_parent' => $current_parent,
811-
'post_name' => ! empty( $post_title ) ? sanitize_title( $post_title . ( $i === $total ) ? '' : '-$i' ) : "post-$i",
811+
'post_name' => ! empty( $post_title ) ? sanitize_title( $post_title . ( $i === $total ? '' : "-{$i}" ) ) : "post-{$i}",
812812
'post_date' => $post_date,
813813
'post_date_gmt' => $post_date_gmt,
814814
'post_content' => $post_content,
@@ -856,7 +856,7 @@ private function read_from_file_or_stdin( $arg ) {
856856
if ( '-' !== $arg ) {
857857
$readfile = $arg;
858858
if ( ! file_exists( $readfile ) || ! is_file( $readfile ) ) {
859-
WP_CLI::error( "Unable to read content from '$readfile'." );
859+
WP_CLI::error( "Unable to read content from '{$readfile}'." );
860860
}
861861
} else {
862862
$readfile = 'php://stdin';
@@ -882,7 +882,7 @@ private function get_category_ids( $arg ) {
882882
$category_id = category_exists( $post_category );
883883
}
884884
if ( ! $category_id ) {
885-
WP_CLI::error( "No such post category '$post_category'." );
885+
WP_CLI::error( "No such post category '{$post_category}'." );
886886
}
887887
$category_ids[] = $category_id;
888888
}

src/Site_Command.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,11 @@ public function delete( $args, $assoc_args ) {
317317

318318
$site_url = trailingslashit( $blog->siteurl );
319319

320-
WP_CLI::confirm( "Are you sure you want to delete the '$site_url' site?", $assoc_args );
320+
WP_CLI::confirm( "Are you sure you want to delete the '{$site_url}' site?", $assoc_args );
321321

322322
wpmu_delete_blog( $blog->blog_id, ! Utils\get_flag_value( $assoc_args, 'keep-tables' ) );
323323

324-
WP_CLI::success( "The site at '$site_url' was deleted." );
324+
WP_CLI::success( "The site at '{$site_url}' was deleted." );
325325
}
326326

327327
/**
@@ -368,7 +368,7 @@ public function create( $args, $assoc_args ) {
368368
if ( ! empty( $assoc_args['network_id'] ) ) {
369369
$network = $this->get_network( $assoc_args['network_id'] );
370370
if ( false === $network ) {
371-
WP_CLI::error( sprintf( 'Network with id %d does not exist.', $assoc_args['network_id'] ) );
371+
WP_CLI::error( "Network with id {$assoc_args['network_id']} does not exist." );
372372
}
373373
} else {
374374
$network = $current_site;
@@ -442,7 +442,7 @@ public function create( $args, $assoc_args ) {
442442
WP_CLI::line( $id );
443443
} else {
444444
$site_url = trailingslashit( get_site_url( $id ) );
445-
WP_CLI::success( "Site $id created: $site_url" );
445+
WP_CLI::success( "Site {$id} created: {$site_url}" );
446446
}
447447
}
448448

src/Site_Option_Command.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ public function add( $args, $assoc_args ) {
9797
$value = WP_CLI::read_value( $value, $assoc_args );
9898

9999
if ( ! add_site_option( $key, $value ) ) {
100-
WP_CLI::error( "Could not add site option '$key'. Does it already exist?" );
100+
WP_CLI::error( "Could not add site option '{$key}'. Does it already exist?" );
101101
} else {
102-
WP_CLI::success( "Added '$key' site option." );
102+
WP_CLI::success( "Added '{$key}' site option." );
103103
}
104104
}
105105

@@ -244,12 +244,12 @@ public function update( $args, $assoc_args ) {
244244
$old_value = sanitize_option( $key, get_site_option( $key ) );
245245

246246
if ( $value === $old_value ) {
247-
WP_CLI::success( "Value passed for '$key' site option is unchanged." );
247+
WP_CLI::success( "Value passed for '{$key}' site option is unchanged." );
248248
} else {
249249
if ( update_site_option( $key, $value ) ) {
250-
WP_CLI::success( "Updated '$key' site option." );
250+
WP_CLI::success( "Updated '{$key}' site option." );
251251
} else {
252-
WP_CLI::error( "Could not update site option '$key'." );
252+
WP_CLI::error( "Could not update site option '{$key}'." );
253253
}
254254
}
255255
}
@@ -271,9 +271,9 @@ public function delete( $args ) {
271271
list( $key ) = $args;
272272

273273
if ( ! delete_site_option( $key ) ) {
274-
WP_CLI::error( "Could not delete '$key' site option. Does it exist?" );
274+
WP_CLI::error( "Could not delete '{$key}' site option. Does it exist?" );
275275
} else {
276-
WP_CLI::success( "Deleted '$key' site option." );
276+
WP_CLI::success( "Deleted '{$key}' site option." );
277277
}
278278
}
279279

@@ -400,12 +400,12 @@ function( $key ) {
400400
$patched_value = sanitize_option( $key, $traverser->value() );
401401

402402
if ( $patched_value === $old_value ) {
403-
WP_CLI::success( "Value passed for '$key' site option is unchanged." );
403+
WP_CLI::success( "Value passed for '{$key}' site option is unchanged." );
404404
} else {
405405
if ( update_site_option( $key, $patched_value ) ) {
406-
WP_CLI::success( "Updated '$key' site option." );
406+
WP_CLI::success( "Updated '{$key}' site option." );
407407
} else {
408-
WP_CLI::error( "Could not update site option '$key'." );
408+
WP_CLI::error( "Could not update site option '{$key}'." );
409409
}
410410
}
411411
}

src/Term_Command.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class Term_Command extends WP_CLI_Command {
121121
public function list_( $args, $assoc_args ) {
122122
foreach ( $args as $taxonomy ) {
123123
if ( ! taxonomy_exists( $taxonomy ) ) {
124-
WP_CLI::error( "Taxonomy $taxonomy doesn't exist." );
124+
WP_CLI::error( "Taxonomy {$taxonomy} doesn't exist." );
125125
}
126126
}
127127

@@ -146,7 +146,7 @@ public function list_( $args, $assoc_args ) {
146146
if ( $term && ! is_wp_error( $term ) ) {
147147
$terms[] = $term;
148148
} else {
149-
WP_CLI::warning( sprintf( 'Invalid term %s.', $term_id ) );
149+
WP_CLI::warning( "Invalid term {$term_id}." );
150150
}
151151
}
152152
} else {
@@ -229,7 +229,7 @@ public function create( $args, $assoc_args ) {
229229
if ( $porcelain ) {
230230
WP_CLI::line( $result['term_id'] );
231231
} else {
232-
WP_CLI::success( sprintf( 'Created %s %d.', $taxonomy, $result['term_id'] ) );
232+
WP_CLI::success( "Created {$taxonomy} {$result['term_id']}." );
233233
}
234234
}
235235
}
@@ -440,7 +440,7 @@ public function delete( $args, $assoc_args ) {
440440

441441
// If term not found, then show error message and skip the iteration.
442442
if ( ! $term ) {
443-
WP_CLI::warning( sprintf( "%s %s doesn't exist.", $taxonomy, $term_id ) );
443+
WP_CLI::warning( "{$taxonomy} {$term_id} doesn't exist." );
444444
continue;
445445
}
446446

@@ -455,10 +455,10 @@ public function delete( $args, $assoc_args ) {
455455
WP_CLI::warning( $result );
456456
$errors++;
457457
} elseif ( $result ) {
458-
WP_CLI::log( sprintf( 'Deleted %s %d.', $taxonomy, $term_id ) );
458+
WP_CLI::log( "Deleted {$taxonomy} {$term_id}." );
459459
$successes++;
460460
} else {
461-
WP_CLI::warning( sprintf( "%s %s doesn't exist.", $taxonomy, $term_id ) );
461+
WP_CLI::warning( "{$taxonomy} {$term_id} doesn't exist." );
462462
}
463463
}
464464
Utils\report_batch_operation_results( 'term', 'delete', count( $args ), $successes, $errors );
@@ -522,7 +522,7 @@ public function generate( $args, $assoc_args ) {
522522
$max_depth = $final_args['max_depth'];
523523

524524
if ( ! taxonomy_exists( $taxonomy ) ) {
525-
WP_CLI::error( sprintf( "'%s' is not a registered taxonomy.", $taxonomy ) );
525+
WP_CLI::error( "'{$taxonomy}' is not a registered taxonomy." );
526526
}
527527

528528
$label = get_taxonomy( $taxonomy )->labels->singular_name;
@@ -565,10 +565,10 @@ public function generate( $args, $assoc_args ) {
565565

566566
$args = [
567567
'parent' => $current_parent,
568-
'slug' => $slug . "-$i",
568+
'slug' => $slug . "-{$i}",
569569
];
570570

571-
$name = "$label $i";
571+
$name = "{$label} {$i}";
572572
$term = wp_insert_term( $name, $taxonomy, $args );
573573
if ( is_wp_error( $term ) ) {
574574
WP_CLI::warning( $term );
@@ -630,15 +630,15 @@ public function recount( $args ) {
630630
foreach ( $args as $taxonomy ) {
631631

632632
if ( ! taxonomy_exists( $taxonomy ) ) {
633-
WP_CLI::warning( sprintf( 'Taxonomy %s does not exist.', $taxonomy ) );
633+
WP_CLI::warning( "Taxonomy {$taxonomy} does not exist." );
634634
} else {
635635

636636
$terms = get_terms( $taxonomy, [ 'hide_empty' => false ] );
637637
$term_taxonomy_ids = wp_list_pluck( $terms, 'term_taxonomy_id' );
638638

639639
wp_update_term_count( $term_taxonomy_ids, $taxonomy );
640640

641-
WP_CLI::success( sprintf( 'Updated %s term count.', $taxonomy ) );
641+
WP_CLI::success( "Updated {$taxonomy} term count." );
642642
}
643643
}
644644
}

0 commit comments

Comments
 (0)