Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/Media_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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
Expand Down Expand Up @@ -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<string, mixed>}|false $metadata
* @param array{sizes?: array<string, mixed>}|false $metadata
* @return string[] The sizes that were actually regenerated.
*/
private function update_attachment_metadata_for_image_size( $id, $new_metadata, $image_sizes, $metadata ) {
Expand Down Expand Up @@ -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.' );
}

Expand All @@ -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
Expand Down