[wp-trac] [WordPress Trac] #46641: Add blog_id to post object

WordPress Trac noreply at wordpress.org
Thu May 26 18:36:21 UTC 2022


#46641: Add blog_id to post object
--------------------------------+------------------------------
 Reporter:  Spidlace            |       Owner:  (none)
     Type:  enhancement         |      Status:  new
 Priority:  normal              |   Milestone:  Awaiting Review
Component:  Networks and Sites  |     Version:  5.1
 Severity:  normal              |  Resolution:
 Keywords:                      |     Focuses:  multisite
--------------------------------+------------------------------

Comment (by giuseppe.mazzapica):

 3 years now, let's try to put back some interest in this.

 To me it look pretty straightforward:

 - Add a new site_id property to WP_Post
 - In the class constructor, set the property to `get_current_blog_id()`

 With the property being there, `__get()` would not be called, so no risk
 it would look into metadata, and there's no need to involve DB at all.
 There's the precedent of `$filter` property being in WP_Post but not in
 the DB, and that had never been a problem.

 Doing that in "userland" is not possible, because the WP_Post constructor
 does not trigger any filter (nor does `get_post`), but for core is
 literally a 100% backward compatible 2 lines change.

 The best way would be a private prop with a getter method, but even a
 public property (for consistence with the other class properties) would be
 already better than nothing.

 Maybe, just maybe, it could be nice to have a pre-save check to not store
 the post in DB if the current site ID is different than what stored in the
 post object. If you think that can never happen, you have never worked
 with sites that make heavy use of switch_to_blog.

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


More information about the wp-trac mailing list