| 1786 | // For audio/video, check for existence of meta_key when $meta is empty |
| 1787 | if ( in_array( $type, array( 'audio', 'video' ) ) && empty( $meta ) ) { |
| 1788 | $_meta = get_post_meta( $attachment->ID ); |
| 1789 | if ( ! array_key_exists( '_wp_attachment_metadata', $_meta ) ) { |
| 1790 | // Regenerate the metadata if the file exists |
| 1791 | $file = get_attached_file( $attachment->ID ); |
| 1792 | $meta = wp_generate_attachment_metadata( $attachment->ID, $file ); |
| 1793 | if ( file_exists( $file ) ) { |
| 1794 | wp_update_attachment_metadata( $attachment->ID, $meta ); |
| 1795 | } |
| 1796 | } |
| 1797 | } |
| 1798 | |