[wp-trac] [WordPress Trac] #51373: Include Site ID In WP_Post

WordPress Trac noreply at wordpress.org
Tue Sep 22 09:01:28 UTC 2020


#51373: Include Site ID In WP_Post
-------------------------------+-----------------------------
 Reporter:  xedin.unknown      |      Owner:  (none)
     Type:  enhancement        |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Posts, Post Types  |    Version:
 Severity:  normal             |   Keywords:
  Focuses:                     |
-------------------------------+-----------------------------
 Right now, it is not possible to, given a WP_Post instance, determine
 which site on a multi-site network that post came from. This is extremely
 inconvenient for many cases:

 1. Serialization/deserialization. When a post is de-serialized, it cannot
 be known what site it came from. Therefore, the data in that instance is
 completely irrelevant, since a post with the same ID can exist in any
 site.
 2. Separation of Concerns. When doing something with a post, only the
 `WP_Post` instance should be required at most. All basic information, and
 even a map of custom field names to their values, can be derived from a
 `WP_Post` instance; but not its site ID.

 So, the site ID is a critical part of the post that is required for
 actually identifying the post on a network, and is an integral part of
 what a post _is_. And yet, that crucial data is missing from `WP_Post`
 instances.

 ## Solution
 Add a `site_id` property to `WP_Post` instances. Any code that is in
 charge of fetching one or multiple posts from the database can know what
 site it belongs to by checking `get_current_blog_id()`. That code can then
 assign the `site_id` property. All consumers of `WP_Post` will then be
 guaranteed to have that data available, without making WP applications
 wrap their posts into ad-hoc interfaces etc.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51373>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list