Skip to content

Commit 2251e52

Browse files
Copilotswissspidy
andcommitted
Use Utils\pluralize() in get_image_sizes_description() instead of manual plural_noun parameter
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 741d4d5 commit 2251e52

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

src/Media_Command.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function regenerate( $args, $assoc_args = array() ) {
152152
WP_CLI::confirm(
153153
sprintf(
154154
'Do you really want to regenerate the %s for all images?',
155-
$this->get_image_sizes_description( $image_sizes, 'image size', 'image sizes' )
155+
$this->get_image_sizes_description( $image_sizes, 'image size' )
156156
),
157157
$assoc_args
158158
);
@@ -696,20 +696,15 @@ private function make_copy( $path ) {
696696
* Returns a human-readable description for one or more image size names.
697697
*
698698
* @param string[] $sizes The size names.
699-
* @param string $singular_noun Noun to use when exactly one size is given (e.g. 'thumbnail').
700-
* @param string $plural_noun Noun to use when more than one size is given (e.g. 'thumbnails').
699+
* @param string $noun Noun in singular form (e.g. 'thumbnail'); pluralized automatically.
701700
* @param string $default_if_empty String to return when $sizes is empty.
702701
* @return string
703702
*/
704-
private function get_image_sizes_description( array $sizes, $singular_noun, $plural_noun, $default_if_empty = '' ) {
705-
$count = count( $sizes );
706-
if ( 0 === $count ) {
703+
private function get_image_sizes_description( array $sizes, $noun, $default_if_empty = '' ) {
704+
if ( empty( $sizes ) ) {
707705
return $default_if_empty;
708706
}
709-
if ( 1 === $count ) {
710-
return sprintf( '"%s" %s', reset( $sizes ), $singular_noun );
711-
}
712-
return sprintf( '"%s" %s', implode( '", "', $sizes ), $plural_noun );
707+
return sprintf( '"%s" %s', implode( '", "', $sizes ), Utils\pluralize( $noun, count( $sizes ) ) );
713708
}
714709

715710
/**
@@ -743,7 +738,7 @@ private function process_regeneration( $id, $skip_delete, $only_missing, $delete
743738
} else {
744739
$att_desc = sprintf( '"%1$s" (ID %2$d)', $title, $id );
745740
}
746-
$thumbnail_desc = $this->get_image_sizes_description( $image_sizes, 'thumbnail', 'thumbnails', 'thumbnail' );
741+
$thumbnail_desc = $this->get_image_sizes_description( $image_sizes, 'thumbnail', 'thumbnail' );
747742

748743
$fullsizepath = $this->get_attached_file( $id );
749744

@@ -817,7 +812,7 @@ private function process_regeneration( $id, $skip_delete, $only_missing, $delete
817812
if ( $image_sizes ) {
818813
$regenerated_sizes = $this->update_attachment_metadata_for_image_size( $id, $metadata, $image_sizes, $original_meta );
819814
if ( $regenerated_sizes ) {
820-
WP_CLI::log( "$progress Regenerated {$this->get_image_sizes_description( $regenerated_sizes, 'thumbnail', 'thumbnails' )} for $att_desc." );
815+
WP_CLI::log( "$progress Regenerated {$this->get_image_sizes_description( $regenerated_sizes, 'thumbnail' )} for $att_desc." );
821816
} else {
822817
WP_CLI::log( "$progress No $thumbnail_desc regeneration needed for $att_desc." );
823818
}

0 commit comments

Comments
 (0)