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

WordPress Trac noreply at wordpress.org
Wed Mar 15 22:08:13 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 close                 |
-------------------------------------------------+-------------------------

Comment (by Howdy_McGee):

 > Yes, but that's not an excuse to accept inconsistent parameters in
 functions that work on images

 Developers can continue to pass an Integer $attachment_id to the
 `image_*()` functions. That has not changed. The patch allows developers
 to also pass a WP_Post object instead of a $attachment_id if they choose
 to do so. This would make the parameters consistent with the other
 attachment functions in this patch.

 Accepting a WP_Post Object or Post ID is verified in the patch tests as
 well.

 > Yes, exactly. WP_Post is cached and get_post() uses that cache.

 In 99% of cases, the WP_Post object will be cached, but that is not
 necessarily a guarantee. Should we allow developers to make that
 distinction? If they have the WP_Post object not cached and don't want to
 make additional database calls this patch handles that. If the developer
 doesn't know the difference between passing a post_id or WP_Post it
 shouldn't matter since the results are unchanged.

 Forcing developers to pass an Integer to a function that's going to call
 `get_post()` just seems like an unnecessary inconvenience when the results
 come out the same.

 That all being said there hasn't been much else activity on this ticket
 other than patch refreshes. Maybe the image/attachment tests can be
 salvaged?

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


More information about the wp-trac mailing list