Skip to content

Commit 886d4d2

Browse files
swissspidyCopilot
andauthored
Update src/Media_Command.php
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 4f6b949 commit 886d4d2

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/Media_Command.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,16 @@ public function replace( $args, $assoc_args = array() ) {
671671

672672
// Generate and update new attachment metadata.
673673
$new_metadata = wp_generate_attachment_metadata( $attachment_id, $new_file_path );
674-
wp_update_attachment_metadata( $attachment_id, $new_metadata );
674+
if ( is_array( $new_metadata ) && ! empty( $new_metadata ) ) {
675+
wp_update_attachment_metadata( $attachment_id, $new_metadata );
676+
} else {
677+
WP_CLI::warning(
678+
sprintf(
679+
"Failed to generate new attachment metadata for attachment ID %d. Existing metadata has been preserved.",
680+
$attachment_id
681+
)
682+
);
683+
}
675684

676685
if ( Utils\get_flag_value( $assoc_args, 'porcelain' ) ) {
677686
WP_CLI::line( (string) $attachment_id );

0 commit comments

Comments
 (0)