Changeset 23766 for trunk/wp-admin/includes/image.php
- Timestamp:
- 03/21/2013 04:55:42 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/image.php
r23632 r23766 74 74 75 75 $metadata = array(); 76 $support = false; 76 77 if ( preg_match('!^image/!', get_post_mime_type( $attachment )) && file_is_displayable_image($file) ) { 77 78 $imagesize = getimagesize( $file ); … … 118 119 $metadata['image_meta'] = $image_meta; 119 120 120 } 121 } elseif ( preg_match( '#^video/#', get_post_mime_type( $attachment ) ) ) { 122 $metadata = wp_read_video_metadata( $file ); 123 $support = current_theme_supports( 'post-thumbnails', 'attachment:video' ) && post_type_supports( 'attachment:video', 'thumbnail' ); 124 } elseif ( preg_match( '#^audio/#', get_post_mime_type( $attachment ) ) ) { 125 $metadata = wp_read_audio_metadata( $file ); 126 $support = current_theme_supports( 'post-thumbnails', 'attachment:audio' ) && post_type_supports( 'attachment:audio', 'thumbnail' ); 127 } 128 129 if ( $support && ! empty( $metadata['image']['data'] ) ) { 130 $ext = '.jpg'; 131 switch ( $metadata['image']['mime'] ) { 132 case 'image/gif': 133 $ext = '.gif'; 134 break; 135 case 'image/png': 136 $ext = '.png'; 137 break; 138 } 139 $basename = str_replace( '.', '-', basename( $file ) ) . '-image' . $ext; 140 $uploaded = wp_upload_bits( $basename, '', $metadata['image']['data'] ); 141 if ( false === $uploaded['error'] ) { 142 $attachment = array( 143 'post_mime_type' => $metadata['image']['mime'], 144 'post_type' => 'attachment', 145 'post_content' => '', 146 ); 147 $sub_attachment_id = wp_insert_attachment( $attachment, $uploaded['file'] ); 148 $attach_data = wp_generate_attachment_metadata( $sub_attachment_id, $uploaded['file'] ); 149 wp_update_attachment_metadata( $sub_attachment_id, $attach_data ); 150 update_post_meta( $attachment_id, '_thumbnail_id', $sub_attachment_id ); 151 } 152 } 153 // remove the blob of binary data from the array 154 unset( $metadata['image']['data'] ); 121 155 122 156 return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id );
Note: See TracChangeset
for help on using the changeset viewer.