Changeset 46621 for trunk/src/wp-admin/includes/image.php
- Timestamp:
- 10/30/2019 09:08:32 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/image.php
r46565 r46621 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 } 150 151 $missing_sizes = wp_get_missing_image_subsizes( $attachment_id ); 152 153 if ( empty( $missing_sizes ) ) { 154 return $image_meta; 155 } 156 157 // This also updates the image meta. 158 return _wp_make_subsizes( $missing_sizes, $image_file, $image_meta, $attachment_id ); 149 } else { 150 $missing_sizes = wp_get_missing_image_subsizes( $attachment_id ); 151 152 if ( empty( $missing_sizes ) ) { 153 return $image_meta; 154 } 155 156 // This also updates the image meta. 157 $image_meta = _wp_make_subsizes( $missing_sizes, $image_file, $image_meta, $attachment_id ); 158 } 159 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 … … 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 { … … 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 { … … 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 … … 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
Note: See TracChangeset
for help on using the changeset viewer.