[wp-trac] [WordPress Trac] #58304: wp_update_image_sizes

WordPress Trac noreply at wordpress.org
Sat May 13 14:20:43 UTC 2023


#58304: wp_update_image_sizes
--------------------------+-----------------------------
 Reporter:  logotronic    |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Media         |    Version:  6.2
 Severity:  blocker       |   Keywords:  needs-patch
  Focuses:                |
--------------------------+-----------------------------
 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

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58304>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list