Introduce a function, wp_attachment_is( $type, $post = 0 ), to collapse the logic for determining whether an attachment is an image, audio, or video.

This is admittedly a first pass. There needs to be a generic handler for when any other type is passed, but for now it accepts the whitelist.

See #25275.


git-svn-id: https://develop.svn.wordpress.org/trunk@31645 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2015-03-06 20:25:09 +00:00
parent ff67402710
commit 42bcec5061
7 changed files with 57 additions and 29 deletions
+2 -2
View File
@@ -127,10 +127,10 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
if ( $image_meta )
$metadata['image_meta'] = $image_meta;
} elseif ( preg_match( '#^video/#', get_post_mime_type( $attachment ) ) ) {
} elseif ( wp_attachment_is( 'video', $attachment ) ) {
$metadata = wp_read_video_metadata( $file );
$support = current_theme_supports( 'post-thumbnails', 'attachment:video' ) || post_type_supports( 'attachment:video', 'thumbnail' );
} elseif ( preg_match( '#^audio/#', get_post_mime_type( $attachment ) ) ) {
} elseif ( wp_attachment_is( 'audio', $attachment ) ) {
$metadata = wp_read_audio_metadata( $file );
$support = current_theme_supports( 'post-thumbnails', 'attachment:audio' ) || post_type_supports( 'attachment:audio', 'thumbnail' );
}