Skip to content

Commit be42053

Browse files
Copilotswissspidy
andcommitted
Combine two foreach loops in prune() into a single loop
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 7140614 commit be42053

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

src/Term_Command.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -722,15 +722,13 @@ public function recount( $args ) {
722722
* Success: Pruned 1 of 5 terms.
723723
*/
724724
public function prune( $args, $assoc_args ) {
725+
$dry_run = (bool) Utils\get_flag_value( $assoc_args, 'dry-run', false );
726+
725727
foreach ( $args as $taxonomy ) {
726728
if ( ! taxonomy_exists( $taxonomy ) ) {
727729
WP_CLI::error( "Taxonomy {$taxonomy} doesn't exist." );
728730
}
729-
}
730731

731-
$dry_run = (bool) Utils\get_flag_value( $assoc_args, 'dry-run', false );
732-
733-
foreach ( $args as $taxonomy ) {
734732
$terms = get_terms(
735733
[
736734
'taxonomy' => $taxonomy,
@@ -748,18 +746,15 @@ public function prune( $args, $assoc_args ) {
748746
* @var \WP_Term[] $terms
749747
*/
750748

751-
$total = count( $terms );
752-
$prunable = 0;
753-
$successes = 0;
754-
$errors = 0;
749+
$total = count( $terms );
750+
$successes = 0;
751+
$errors = 0;
755752

756753
foreach ( $terms as $term ) {
757754
if ( $term->count > 1 ) {
758755
continue;
759756
}
760757

761-
++$prunable;
762-
763758
if ( $dry_run ) {
764759
WP_CLI::log( "Would delete {$taxonomy} {$term->term_id}." );
765760
++$successes;

0 commit comments

Comments
 (0)