WordPress.org

Make WordPress Core

Ticket #48451: 48451.diff

File 48451.diff, 3.1 KB (added by azaozz, 3 weeks ago)
  • src/wp-admin/includes/image.php

     
    282282                                if ( true === $rotated && ! empty( $image_meta['image_meta']['orientation'] ) ) {
    283283                                        $image_meta['image_meta']['orientation'] = 1;
    284284                                }
    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.
    289                                 wp_update_attachment_metadata( $attachment_id, $image_meta );
    290285                        } else {
    291286                                // TODO: log errors.
    292287                        }
     
    317312                                if ( ! empty( $image_meta['image_meta']['orientation'] ) ) {
    318313                                        $image_meta['image_meta']['orientation'] = 1;
    319314                                }
    320 
    321                                 // Initial save of the new metadata when the original image was rotated.
    322                                 wp_update_attachment_metadata( $attachment_id, $image_meta );
    323315                        } else {
    324316                                // TODO: log errors.
    325317                        }
    326318                }
    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 );
    330319        }
    331320
     321        /**
     322         * Runs at interim updates to the attachment metadata.
     323         *
     324         * May run several times while the metadata is being created and updated. For example when creating image sub-sizes
     325         * after upload, or when creating additional image sub-sizes for an existing image.
     326         *
     327         * @since 5.3.0
     328         *
     329         * @param array $image_meta    The attachment metadata.
     330         * @param int   $attachment_id Attachment post ID.
     331         */
     332        $image_meta = apply_filters( 'wp_interim_update_attachment_metadata', $image_meta, $attachment_id );
     333
     334        // Initial save of the new metadata.
     335        // At this point the file was uploaded and moved to the uploads directory
     336        // but the image sub-sizes haven't been created yet and the `sizes` array is empty.
     337        update_post_meta( $attachment_id, '_wp_attachment_metadata', $image_meta );
     338
    332339        $new_sizes = wp_get_registered_image_subsizes();
    333340
    334341        /**
     
    424431                        } else {
    425432                                // Save the size meta value.
    426433                                $image_meta['sizes'][ $new_size_name ] = $new_size_meta;
    427                                 wp_update_attachment_metadata( $attachment_id, $image_meta );
     434
     435                                /** This filter is documented in wp-admin/includes/image.php */
     436                                $image_meta = apply_filters( 'wp_interim_update_attachment_metadata', $image_meta, $attachment_id );
     437
     438                                // Save the updated metadata.
     439                                // At this point some or all of the image sub-sizes have been created.
     440                                update_post_meta( $attachment_id, '_wp_attachment_metadata', $image_meta );
    428441                        }
    429442                }
    430443        } else {
     
    433446
    434447                if ( ! empty( $created_sizes ) ) {
    435448                        $image_meta['sizes'] = array_merge( $image_meta['sizes'], $created_sizes );
    436                         wp_update_attachment_metadata( $attachment_id, $image_meta );
     449
     450                        /** This filter is documented in wp-admin/includes/image.php */
     451                        $image_meta = apply_filters( 'wp_interim_update_attachment_metadata', $image_meta, $attachment_id );
     452
     453                        // Save the updated metadata.
     454                        update_post_meta( $attachment_id, '_wp_attachment_metadata', $image_meta );
    437455                }
    438456        }
    439457