Opened 3 years ago
Last modified 3 years ago
#58304 new defect (bug)
wp_update_image_sizes
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | blocker | Version: | 6.2 |
| Component: | Media | Keywords: | has-patch |
| Focuses: | Cc: |
Description
This blocker issue is actually introduced with WP 5.3 and still remains unsolved up to 6.2
Introduction:
Function wp_update_image_sizes calls function _wp_make_subsizes() in two ways/paths, either via function wp_create_image_subsizes() or directly.
Issue:
When function wp_update_image_sizes calls _wp_make_subsizes() via wp_create_image_subsizes(), filter intermediate_image_sizes_advanced', is invoked before calling _wp_make_subsizes().
When wp_update_image_sizes calls _wp_make_subsizes() directly, filter intermediate_image_sizes_advanced' is not available at all.
Problem:
When filter 'intermediate_image_sizes_advanced' is not available, there is no way to filter $new_sizes argument before _wp_make_subsizes() for the purpose described in function _wp_make_subsizes(), (see below):
/* * Only checks "size name" so we don't override existing images even if the dimensions * don't match the currently defined size with the same name. * To change the behavior, unset changed/mismatched sizes in the `sizes` array in image meta. */
Proposed solution:
1) Modify filter 'intermediate_image_sizes_advanced' by adding new argument $context argument in same way like filter 'wp_generate_attachment_metadata' added $context argument since WP 5.3.
2) In function wp_update_image_subsizes, before calling function _wp_make_subsizes(), add apply_filters 'intermediate_image_sizes_advanced' with additional argument $context and value 'update'.
3) In function wp_create_image_subsizes, in $new_sizes = apply_filters( 'intermediate_image_sizes_advanced', $new_sizes, $image_meta, $attachment_id ) add new $context argument value 'create'.
OR in function wp_update_image_subsizes before calling function _wp_make_subsizes() just add apply_filters 'intermediate_image_sizes_advanced'
OR just make some filter that available in both cases. Maybe inside function _wp_make_subsizes() at the beginning ??
Thanks
Change History (1)
This ticket was mentioned in PR #4758 on WordPress/wordpress-develop by nirav7707.
3 years ago
#1
- Keywords has-patch added; needs-patch removed
Ticket - https://core.trac.wordpress.org/ticket/58304
A pull request (PR) use to relocate the
intermediate_image_sizes_advancedfilter from thewp_create_image_subsizesfunction to the_wp_make_subsizesfunction. This change was made because thewp_update_image_subsizesfunction directly and indirectly invokes the_wp_make_subsizesfunction. When_wp_make_subsizesis called indirectly throughwp_create_image_subsizes, the filter is available. However, when_wp_make_subsizesis directly called, the filter is not available. By moving the filter to_wp_make_subsizes, it ensures consistent availability of the filter regardless of how_wp_make_subsizesis invoked.