Make WordPress Core

Ticket #25275: post.diff

File post.diff, 1.5 KB (added by danielpataki, 12 years ago)

Final version of diff to add audio and video checking to attachments in post.php

  • .php

    old new  
    42794279}
    42804280
    42814281/**
     4282 * Check if the attachment is an audio file.
     4283 *
     4284 * @since
     4285 *
     4286 * @param int $post_id Attachment ID
     4287 * @return bool
     4288 */
     4289function wp_attachment_is_audio( $post_id = 0 ) {
     4290        $post_id = (int) $post_id;
     4291        if ( !$post = get_post( $post_id ) )
     4292                return false;
     4293
     4294        if ( !$file = get_attached_file( $post->ID ) )
     4295                return false;
     4296
     4297        $ext = preg_match('/\.([^.]+)$/', $file, $matches) ? strtolower($matches[1]) : false;
     4298
     4299        $audio_exts = array( 'mp3', 'm4a', 'wav', 'flac', 'wma', 'ogg' );
     4300
     4301        if ( 'image/' == substr($post->post_mime_type, 0, 6) || $ext && 'import' == $post->post_mime_type && in_array($ext, $audio_exts) )
     4302                return true;
     4303        return false;
     4304}
     4305
     4306/**
     4307 * Check if the attachment is a video file.
     4308 *
     4309 * @since
     4310 *
     4311 * @param int $post_id Attachment ID
     4312 * @return bool
     4313 */
     4314function wp_attachment_is_video( $post_id = 0 ) {
     4315        $post_id = (int) $post_id;
     4316        if ( !$post = get_post( $post_id ) )
     4317                return false;
     4318
     4319        if ( !$file = get_attached_file( $post->ID ) )
     4320                return false;
     4321
     4322        $ext = preg_match('/\.([^.]+)$/', $file, $matches) ? strtolower($matches[1]) : false;
     4323
     4324        $video_exts = array( 'wmv', 'mov', 'avi', 'mpg', 'mpeg', 'mkv' );
     4325
     4326        if ( 'image/' == substr($post->post_mime_type, 0, 6) || $ext && 'import' == $post->post_mime_type && in_array($ext, $video_exts) )
     4327                return true;
     4328        return false;
     4329}
     4330
     4331
     4332/**
    42824333 * Retrieve the icon for a MIME type.
    42834334 *
    42844335 * @since 2.1.0