[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 21:18:43 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 azaozz):

 Actually thinking more about it, perhaps it is not a good idea to promote
 use of the global `$post` as it might be polluted by third-party functions
 (think that was a pretty bad problem some years ago). Using `get_post()`
 is the preferred method as it retrieves the WP_Post object from cache or
 fetches it from the DB if needed. Hence it always works and is
 "guaranteed".

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


More information about the wp-trac mailing list