Make WordPress Core

Ticket #25275: 25275.diff

File 25275.diff, 7.1 KB (added by wonderboymusic, 10 years ago)
  • src/wp-admin/edit-form-advanced.php

     
    5252
    5353$thumbnail_support = current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' );
    5454if ( ! $thumbnail_support && 'attachment' === $post_type && $post->post_mime_type ) {
    55         if ( 0 === strpos( $post->post_mime_type, 'audio/' ) ) {
     55        if ( wp_attachment_is_audio( $post ) ) {
    5656                $thumbnail_support = post_type_supports( 'attachment:audio', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:audio' );
    57         } elseif ( 0 === strpos( $post->post_mime_type, 'video/' ) ) {
     57        } elseif ( wp_attachment_is_video( $post ) ) {
    5858                $thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:video' );
    5959        }
    6060}
     
    178178        add_meta_box( 'submitdiv', __('Save'), 'attachment_submit_meta_box', null, 'side', 'core' );
    179179        add_action( 'edit_form_after_title', 'edit_form_image_editor' );
    180180
    181         if ( 0 === strpos( $post->post_mime_type, 'audio/' ) ) {
     181        if ( wp_attachment_is_audio( $post ) ) {
    182182                add_meta_box( 'attachment-id3', __( 'Metadata' ), 'attachment_id3_data_meta_box', null, 'normal', 'core' );
    183183        }
    184184} else {
  • src/wp-admin/includes/ajax-actions.php

     
    22872287                }
    22882288        }
    22892289
    2290         if ( 0 === strpos( $post['post_mime_type'], 'audio/' ) ) {
     2290        if ( wp_attachment_is_audio( $post['ID'] ) ) {
    22912291                $changed = false;
    22922292                $id3data = wp_get_attachment_metadata( $post['ID'] );
    22932293                if ( ! is_array( $id3data ) ) {
     
    24452445                $caption = isset( $attachment['post_excerpt'] ) ? $attachment['post_excerpt'] : '';
    24462446                $title = ''; // We no longer insert title tags into <img> tags, as they are redundant.
    24472447                $html = get_image_send_to_editor( $id, $caption, $title, $align, $url, (bool) $rel, $size, $alt );
    2448         } elseif ( 'video' === substr( $post->post_mime_type, 0, 5 ) || 'audio' === substr( $post->post_mime_type, 0, 5 )  ) {
     2448        } elseif ( wp_attachment_is_video( $post ) || wp_attachment_is_audio( $post )  ) {
    24492449                $html = stripslashes_deep( $_POST['html'] );
    24502450        }
    24512451
  • src/wp-admin/includes/image.php

     
    130130        } elseif ( preg_match( '#^video/#', get_post_mime_type( $attachment ) ) ) {
    131131                $metadata = wp_read_video_metadata( $file );
    132132                $support = current_theme_supports( 'post-thumbnails', 'attachment:video' ) || post_type_supports( 'attachment:video', 'thumbnail' );
    133         } elseif ( preg_match( '#^audio/#', get_post_mime_type( $attachment ) ) ) {
     133        } elseif ( wp_attachment_is_audio( $attachment ) ) {
    134134                $metadata = wp_read_audio_metadata( $file );
    135135                $support = current_theme_supports( 'post-thumbnails', 'attachment:audio' ) || post_type_supports( 'attachment:audio', 'thumbnail' );
    136136        }
  • src/wp-admin/includes/media.php

     
    26532653                        <?php if ( $open ) wp_image_editor( $attachment_id ); ?>
    26542654                </div>
    26552655        <?php
    2656         elseif ( $attachment_id && 0 === strpos( $post->post_mime_type, 'audio/' ) ):
     2656        elseif ( $attachment_id && wp_attachment_is_audio( $post ) ):
    26572657
    26582658                wp_maybe_generate_attachment_metadata( $post );
    26592659
    26602660                echo wp_audio_shortcode( array( 'src' => $att_url ) );
    26612661
    2662         elseif ( $attachment_id && 0 === strpos( $post->post_mime_type, 'video/' ) ):
     2662        elseif ( $attachment_id && wp_attachment_is_video( $post ) ):
    26632663
    26642664                wp_maybe_generate_attachment_metadata( $post );
    26652665
  • src/wp-includes/media.php

     
    29762976
    29772977                $thumbnail_support = current_theme_supports( 'post-thumbnails', $post->post_type ) && post_type_supports( $post->post_type, 'thumbnail' );
    29782978                if ( ! $thumbnail_support && 'attachment' === $post->post_type && $post->post_mime_type ) {
    2979                         if ( 0 === strpos( $post->post_mime_type, 'audio/' ) ) {
     2979                        if ( wp_attachment_is_audio( $post ) ) {
    29802980                                $thumbnail_support = post_type_supports( 'attachment:audio', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:audio' );
    2981                         } elseif ( 0 === strpos( $post->post_mime_type, 'video/' ) ) {
     2981                        } elseif ( wp_attachment_is_video( $post ) ) {
    29822982                                $thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:video' );
    29832983                        }
    29842984                }
  • src/wp-includes/post-template.php

     
    15501550        if ( empty($post->post_type) || $post->post_type != 'attachment' )
    15511551                return $content;
    15521552
    1553         if ( 0 === strpos( $post->post_mime_type, 'video' ) ) {
     1553        if ( wp_attachment_is_video( $post ) ) {
    15541554                $meta = wp_get_attachment_metadata( get_the_ID() );
    15551555                $atts = array( 'src' => wp_get_attachment_url() );
    15561556                if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) {
     
    15611561                        $atts['poster'] = wp_get_attachment_url( get_post_thumbnail_id() );
    15621562                }
    15631563                $p = wp_video_shortcode( $atts );
    1564         } elseif ( 0 === strpos( $post->post_mime_type, 'audio' ) ) {
     1564        } elseif ( wp_attachment_is_audio( $post ) ) {
    15651565                $p = wp_audio_shortcode( array( 'src' => wp_get_attachment_url() ) );
    15661566        } else {
    15671567                $p = '<p class="attachment">';
  • src/wp-includes/post.php

     
    50885088}
    50895089
    50905090/**
     5091 * Determine if an attachment is an audio file
     5092 *
     5093 * @since 4.2.0
     5094 *
     5095 * @param int|WP_Post $post
     5096 * @return bool
     5097 */
     5098function wp_attachment_is_audio( $post ) {
     5099        if ( ! $post = get_post( $post ) || ! $file = get_attached_file( $post->ID ) ) {
     5100                return false;
     5101        }
     5102
     5103        return ( 0 == strpos( $post->post_mime_type, 'audio/' ) ||
     5104                (
     5105                        $ext = wp_check_filetype( $file ) && $ext['ext'] &&
     5106                        'import' == $post->post_mime_type &&
     5107                        in_array( $ext['ext'], wp_get_audio_extensions() )
     5108                )
     5109        );
     5110}
     5111
     5112/**
     5113 * Determine if an attachment is a video
     5114 *
     5115 * @since 4.2.0
     5116 *
     5117 * @param int|WP_Post $post
     5118 * @return bool
     5119 */
     5120function wp_attachment_is_video( $post ) {
     5121        if ( ! $post = get_post( $post ) || ! $file = get_attached_file( $post->ID ) ) {
     5122                return false;
     5123        }
     5124
     5125        return ( 0 == strpos( $post->post_mime_type, 'video/' ) ||
     5126                (
     5127                        $ext = wp_check_filetype( $file ) && $ext['ext'] &&
     5128                        'import' == $post->post_mime_type &&
     5129                        in_array( $ext['ext'], wp_get_video_extensions() )
     5130                )
     5131        );
     5132}
     5133
     5134/**
    50915135 * Retrieve the icon for a MIME type.
    50925136 *
    50935137 * @since 2.1.0