Ticket #48472: 48472.diff
File 48472.diff, 3.1 KB (added by , 4 years ago) |
---|
-
src/wp-admin/includes/image.php
142 142 // Previously failed upload? 143 143 // If there is an uploaded file, make all sub-sizes and generate all of the attachment meta. 144 144 if ( ! empty( $image_file ) ) { 145 returnwp_create_image_subsizes( $image_file, $attachment_id );145 $image_meta = wp_create_image_subsizes( $image_file, $attachment_id ); 146 146 } else { 147 147 return new WP_Error( 'invalid_attachment', __( 'The attached file cannot be found.' ) ); 148 148 } 149 } 149 } else { 150 $missing_sizes = wp_get_missing_image_subsizes( $attachment_id ); 150 151 151 $missing_sizes = wp_get_missing_image_subsizes( $attachment_id ); 152 if ( empty( $missing_sizes ) ) { 153 return $image_meta; 154 } 152 155 153 if ( empty( $missing_sizes ) ) {154 return $image_meta;156 // This also updates the image meta. 157 $image_meta = _wp_make_subsizes( $missing_sizes, $image_file, $image_meta, $attachment_id ); 155 158 } 156 159 157 // This also updates the image meta. 158 return _wp_make_subsizes( $missing_sizes, $image_file, $image_meta, $attachment_id ); 160 /** This filter is documented in wp-admin/includes/image.php */ 161 $image_meta = apply_filters( 'wp_generate_attachment_metadata', $image_meta, $attachment_id, 'update' ); 162 163 // Save the updated metadata. 164 wp_update_attachment_metadata( $attachment_id, $image_meta ); 165 166 return $image_meta; 159 167 } 160 168 161 169 /** … … 275 283 $image_meta['image_meta']['orientation'] = 1; 276 284 } 277 285 286 // Initial save of the new metadata when the original image was scaled. 287 // At this point the file was uploaded and moved to the uploads directory 288 // but the image sub-sizes haven't been created yet and the `sizes` array is empty. 278 289 wp_update_attachment_metadata( $attachment_id, $image_meta ); 279 290 } else { 280 291 // TODO: log errors. … … 307 318 $image_meta['image_meta']['orientation'] = 1; 308 319 } 309 320 321 // Initial save of the new metadata when the original image was rotated. 310 322 wp_update_attachment_metadata( $attachment_id, $image_meta ); 311 323 } else { 312 324 // TODO: log errors. 313 325 } 314 326 } 327 } else { 328 // Initial save of the new metadata when the image was not scaled or rotated. 329 wp_update_attachment_metadata( $attachment_id, $image_meta ); 315 330 } 316 331 317 332 $new_sizes = wp_get_registered_image_subsizes(); … … 578 593 * 579 594 * @since 2.1.0 580 595 * 581 * @param array $metadata An array of attachment meta data. 582 * @param int $attachment_id Current attachment ID. 596 * @param array $metadata An array of attachment meta data. 597 * @param int $attachment_id Current attachment ID. 598 * @param string $context Additional context. Can be 'create' when metadata was initially created for new attachment 599 * or 'update' when the metadata was updated. 583 600 */ 584 return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id );601 return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id, 'create' ); 585 602 } 586 603 587 604 /**