[wp-trac] [WordPress Trac] #37255: Update attachment functions to accept a post object in addition to ID
WordPress Trac
noreply at wordpress.org
Wed Apr 26 21:37:21 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 azaozz):
Replying to [comment:53 Howdy_McGee]:
> In 99% of cases, the WP_Post object will be cached, but that is not
necessarily a guarantee.
Not sure if that's true. If you can access the `WP_Post` object for a
specific post, that means the post was retrieved from the database with
`WP_Post::get_instance()` and is already cached, see
https://developer.wordpress.org/reference/classes/wp_post/get_instance/.
> Forcing developers to pass an Integer to a function that's going to call
`get_post()` just seems like an unnecessary inconvenience
Perhaps some developers see it that way, however the inconvenience of
having to use `$post->ID` instead of `$post` is super trivial imho, just 4
more characters to type. On the other hand the inconsistency of some image
functions accepting `WP_Post` objects but others only accepting
`$attachment_id` seems quite annoying and perhaps "wrong" from software
architecture point of view.
> Maybe the image/attachment tests can be salvaged?
Yep, seems some of the tests can be used but lets move them to a new
ticket. Would be a lot clearer that way.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/37255#comment:55>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list