Ticket #25275: 25275.2.diff
File 25275.2.diff, 8.1 KB (added by , 10 years ago) |
---|
-
src/wp-admin/edit-form-advanced.php
52 52 53 53 $thumbnail_support = current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' ); 54 54 if ( ! $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 ) ) { 56 56 $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 ) ) { 58 58 $thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:video' ); 59 59 } 60 60 } … … 178 178 add_meta_box( 'submitdiv', __('Save'), 'attachment_submit_meta_box', null, 'side', 'core' ); 179 179 add_action( 'edit_form_after_title', 'edit_form_image_editor' ); 180 180 181 if ( 0 === strpos( $post->post_mime_type, 'audio/') ) {181 if ( wp_attachment_is( 'audio', $post ) ) { 182 182 add_meta_box( 'attachment-id3', __( 'Metadata' ), 'attachment_id3_data_meta_box', null, 'normal', 'core' ); 183 183 } 184 184 } else { -
src/wp-admin/includes/ajax-actions.php
2290 2290 } 2291 2291 } 2292 2292 2293 if ( 0 === strpos( $post['post_mime_type'], 'audio/') ) {2293 if ( wp_attachment_is( 'audio', $post['ID'] ) ) { 2294 2294 $changed = false; 2295 2295 $id3data = wp_get_attachment_metadata( $post['ID'] ); 2296 2296 if ( ! is_array( $id3data ) ) { … … 2448 2448 $caption = isset( $attachment['post_excerpt'] ) ? $attachment['post_excerpt'] : ''; 2449 2449 $title = ''; // We no longer insert title tags into <img> tags, as they are redundant. 2450 2450 $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 ) ) { 2452 2452 $html = stripslashes_deep( $_POST['html'] ); 2453 2453 } 2454 2454 -
src/wp-admin/includes/image.php
127 127 if ( $image_meta ) 128 128 $metadata['image_meta'] = $image_meta; 129 129 130 } elseif ( preg_match( '#^video/#', get_post_mime_type( $attachment )) ) {130 } elseif ( wp_attachment_is( 'video', $attachment ) ) { 131 131 $metadata = wp_read_video_metadata( $file ); 132 132 $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 ) ) { 134 134 $metadata = wp_read_audio_metadata( $file ); 135 135 $support = current_theme_supports( 'post-thumbnails', 'attachment:audio' ) || post_type_supports( 'attachment:audio', 'thumbnail' ); 136 136 } -
src/wp-admin/includes/media.php
2653 2653 <?php if ( $open ) wp_image_editor( $attachment_id ); ?> 2654 2654 </div> 2655 2655 <?php 2656 elseif ( $attachment_id && 0 === strpos( $post->post_mime_type, 'audio/') ):2656 elseif ( $attachment_id && wp_attachment_is( 'audio', $post ) ): 2657 2657 2658 2658 wp_maybe_generate_attachment_metadata( $post ); 2659 2659 2660 2660 echo wp_audio_shortcode( array( 'src' => $att_url ) ); 2661 2661 2662 elseif ( $attachment_id && 0 === strpos( $post->post_mime_type, 'video/') ):2662 elseif ( $attachment_id && wp_attachment_is( 'video', $post ) ): 2663 2663 2664 2664 wp_maybe_generate_attachment_metadata( $post ); 2665 2665 -
src/wp-includes/media.php
2976 2976 2977 2977 $thumbnail_support = current_theme_supports( 'post-thumbnails', $post->post_type ) && post_type_supports( $post->post_type, 'thumbnail' ); 2978 2978 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 ) ) { 2980 2980 $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 ) ) { 2982 2982 $thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:video' ); 2983 2983 } 2984 2984 } -
src/wp-includes/post-template.php
1550 1550 if ( empty($post->post_type) || $post->post_type != 'attachment' ) 1551 1551 return $content; 1552 1552 1553 if ( 0 === strpos( $post->post_mime_type, 'video') ) {1553 if ( wp_attachment_is( 'video', $post ) ) { 1554 1554 $meta = wp_get_attachment_metadata( get_the_ID() ); 1555 1555 $atts = array( 'src' => wp_get_attachment_url() ); 1556 1556 if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) { … … 1561 1561 $atts['poster'] = wp_get_attachment_url( get_post_thumbnail_id() ); 1562 1562 } 1563 1563 $p = wp_video_shortcode( $atts ); 1564 } elseif ( 0 === strpos( $post->post_mime_type, 'audio') ) {1564 } elseif ( wp_attachment_is( 'audio', $post ) ) { 1565 1565 $p = wp_audio_shortcode( array( 'src' => wp_get_attachment_url() ) ); 1566 1566 } else { 1567 1567 $p = '<p class="attachment">'; -
src/wp-includes/post.php
5071 5071 } 5072 5072 5073 5073 /** 5074 * Check if the attachment is an image.5074 * Verfify the attachment as being of a specific type 5075 5075 * 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 5080 5079 */ 5081 function wp_attachment_is_image( $post_id = 0 ) { 5082 $post_id = (int) $post_id; 5083 if ( !$post = get_post( $post_id ) ) 5080 function wp_attachment_is( $type, $post_id = 0 ) { 5081 if ( ! $post = get_post( $post_id ) ) { 5084 5082 return false; 5083 } 5085 5084 5086 if ( ! $file = get_attached_file( $post->ID ) )5085 if ( ! $file = get_attached_file( $post->ID ) ) { 5087 5086 return false; 5087 } 5088 5088 5089 $ext = preg_match('/\.([^.]+)$/', $file, $matches) ? strtolower($matches[1]) : false; 5089 if ( 0 === strpos( $post->post_mime_type, $type . '/' ) ) { 5090 return true; 5091 } 5090 5092 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']; 5092 5098 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 5095 5111 return false; 5096 5112 } 5097 5113 5098 5114 /** 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 */ 5122 function wp_attachment_is_image( $post = 0 ) { 5123 return wp_attachment_is( 'image', $post ); 5124 } 5125 5126 /** 5099 5127 * Retrieve the icon for a MIME type. 5100 5128 * 5101 5129 * @since 2.1.0