[wp-trac] [WordPress Trac] #37255: Update attachment functions to accept a post object in addition to ID

WordPress Trac noreply at wordpress.org
Mon Mar 6 01:28:46 UTC 2023


#37255: Update attachment functions to accept a post object in addition to ID
-------------------------------------------------+-------------------------
 Reporter:  wido                                 |       Owner:
                                                 |  johnbillion
     Type:  enhancement                          |      Status:  accepted
 Priority:  normal                               |   Milestone:  Future
                                                 |  Release
Component:  Media                                |     Version:  4.6
 Severity:  normal                               |  Resolution:
 Keywords:  needs-testing needs-dev-note needs-  |     Focuses:
  testing-info 2nd-opinion                       |
-------------------------------------------------+-------------------------

Comment (by Howdy_McGee):

 Both `image_downsize()` and `image_get_intermediate_size` eventually call
 the `get_post()` function.

 {{{
 image_downsize -> wp_attachment_is_image -> wp_attachment_is -> get_post()

 image_get_intermediate_size -> wp_get_attachment_url -> get_post()
 }}}

 If passed an object instead of an ID we can skip `WP_Post::get_instsance(
 $post_id )` which checks the cache, and makes a possible database call to
 grab the object. Instead, we can populate the object directly.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/37255#comment:48>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list