diff --git a/src/Media_Command.php b/src/Media_Command.php index 901c96b3..aab554ae 100644 --- a/src/Media_Command.php +++ b/src/Media_Command.php @@ -198,9 +198,10 @@ public function regenerate( $args, $assoc_args = array() ) { } $images = $this->get_images( $args, $additional_mime_types ); + $posts = $images->posts; $count = $images->post_count; - if ( ! $count ) { + if ( ! $count || ! is_array( $posts ) ) { WP_CLI::warning( 'No images found.' ); return; } @@ -225,7 +226,7 @@ public function regenerate( $args, $assoc_args = array() ) { /** * @var int $post_id */ - foreach ( $images->posts as $post_id ) { + foreach ( $posts as $post_id ) { ++$number; if ( 0 === $number % self::WP_CLEAR_OBJECT_CACHE_INTERVAL ) { // @phpstan-ignore function.deprecated @@ -338,9 +339,10 @@ public function prune( $args, $assoc_args = array() ) { } $images = $this->get_images( $args, $additional_mime_types ); + $posts = $images->posts; $count = $images->post_count; - if ( ! $count ) { + if ( ! $count || ! is_array( $posts ) ) { WP_CLI::warning( 'No images found.' ); return; } @@ -361,7 +363,7 @@ public function prune( $args, $assoc_args = array() ) { /** * @var int $post_id */ - foreach ( $images->posts as $post_id ) { + foreach ( $posts as $post_id ) { ++$number; if ( 0 === $number % self::WP_CLEAR_OBJECT_CACHE_INTERVAL ) { // @phpstan-ignore function.deprecated @@ -1861,7 +1863,7 @@ private function filter_upload_dir( $uploads ) { * @param int $id * @param array $new_metadata * @param string[] $image_sizes - * @param array{sizes: array}|false $metadata + * @param array{sizes?: array}|false $metadata * @return string[] The sizes that were actually regenerated. */ private function update_attachment_metadata_for_image_size( $id, $new_metadata, $image_sizes, $metadata ) { @@ -2054,10 +2056,11 @@ public function fix_orientation( $args, $assoc_args ) { } $images = $this->get_images( $args ); + $posts = $images->posts; $count = $images->post_count; $dry_run = Utils\get_flag_value( $assoc_args, 'dry-run' ); - if ( ! $count ) { + if ( ! $count || ! is_array( $posts ) ) { WP_CLI::error( 'No images found.' ); } @@ -2068,7 +2071,7 @@ public function fix_orientation( $args, $assoc_args ) { /** * @var int $post_id */ - foreach ( $images->posts as $post_id ) { + foreach ( $posts as $post_id ) { ++$number; if ( 0 === $number % self::WP_CLEAR_OBJECT_CACHE_INTERVAL ) { // @phpstan-ignore function.deprecated