Make WordPress Core

Ticket #25275: 25275.2.diff

File 25275.2.diff, 8.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

     
    22902290                }
    22912291        }
    22922292
    2293         if ( 0 === strpos( $post['post_mime_type'], 'audio/' ) ) {
     2293        if ( wp_attachment_is( 'audio', $post['ID'] ) ) {
    22942294                $changed = false;
    22952295                $id3data = wp_get_attachment_metadata( $post['ID'] );
    22962296                if ( ! is_array( $id3data ) ) {
     
    24482448                $caption = isset( $attachment['post_excerpt'] ) ? $attachment['post_excerpt'] : '';
    24492449                $title = ''; // We no longer insert title tags into <img> tags, as they are redundant.
    24502450                $html = get_image_send_to_editor( $id, $caption, $title, $align, $url, (bool) $rel, $size, $alt );
    2451         } elseif ( 'video' === substr( $post->post_mime_type, 0, 5 ) || 'audio' === substr( $post->post_mime_type, 0, 5 )  ) {
     2451        } elseif ( wp_attachment_is( 'video', $post ) || wp_attachment_is( 'audio', $post )  ) {
    24522452                $html = stripslashes_deep( $_POST['html'] );
    24532453        }
    24542454
  • src/wp-admin/includes/image.php

     
    127127                if ( $image_meta )
    128128                        $metadata['image_meta'] = $image_meta;
    129129
    130         } elseif ( preg_match( '#^video/#', get_post_mime_type( $attachment ) ) ) {
     130        } elseif ( wp_attachment_is( 'video', $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

     
    50715071}
    50725072
    50735073/**
    5074  * Check if the attachment is an image.
     5074 * Verfify the attachment as being of a specific type
    50755075 *
    5076  * @since 2.1.0
    5077  *
    5078  * @param int $post_id Optional. Attachment ID. Default 0.
    5079  * @return bool Whether the attachment is an image.
     5076 * @param string      $type    Type: image, audio, or video.
     5077 * @param int|WP_Post $post_id Optional. Default 0.
     5078 * @return bool
    50805079 */
    5081 function wp_attachment_is_image( $post_id = 0 ) {
    5082         $post_id = (int) $post_id;
    5083         if ( !$post = get_post( $post_id ) )
     5080function wp_attachment_is( $type, $post_id = 0 ) {
     5081        if ( ! $post = get_post( $post_id ) ) {
    50845082                return false;
     5083        }
    50855084
    5086         if ( !$file = get_attached_file( $post->ID ) )
     5085        if ( ! $file = get_attached_file( $post->ID ) ) {
    50875086                return false;
     5087        }
    50885088
    5089         $ext = preg_match('/\.([^.]+)$/', $file, $matches) ? strtolower($matches[1]) : false;
     5089        if ( 0 === strpos( $post->post_mime_type, $type . '/' ) ) {
     5090                return true;
     5091        }
    50905092
    5091         $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' );
     5093        $check = wp_check_filetype( $file );
     5094        if ( empty( $check['ext'] ) || 'import' !== $post->post_mime_type ) {
     5095                return false;
     5096        }
     5097        $ext = $check['ext'];
    50925098
    5093         if ( 'image/' == substr($post->post_mime_type, 0, 6) || $ext && 'import' == $post->post_mime_type && in_array($ext, $image_exts) )
    5094                 return true;
     5099        switch ( $type ) {
     5100        case 'image':
     5101                $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' );
     5102                return in_array( $ext, $image_exts );
     5103
     5104        case 'audio':
     5105                return in_array( $ext, wp_get_audio_extensions() );
     5106
     5107        case 'video':
     5108                return in_array( $ext, wp_get_video_extensions() );
     5109        }
     5110
    50955111        return false;
    50965112}
    50975113
    50985114/**
     5115 * Check if the attachment is an image.
     5116 *
     5117 * @since 2.1.0
     5118 *
     5119 * @param int|WP_Post $post Optional. Attachment ID. Default 0.
     5120 * @return bool Whether the attachment is an image.
     5121 */
     5122function wp_attachment_is_image( $post = 0 ) {
     5123        return wp_attachment_is( 'image', $post );
     5124}
     5125
     5126/**
    50995127 * Retrieve the icon for a MIME type.
    51005128 *
    51015129 * @since 2.1.0