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

WordPress Trac noreply at wordpress.org
Thu Oct 15 05:21:31 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             |  Resolution:
 Keywords:  2nd-opinion        |     Focuses:  multisite
-------------------------------+------------------------------

Comment (by manfcarlo):

 I am developing [https://wordpress.org/plugins/wp-super-network/ a plugin]
 that handles post objects from foreign sites within a network and I can
 see this being helpful, but I also think it would be somewhat impotent
 given the bigger problem that is the widespread use of post ID alone to
 identify posts.

 As an example,
 [https://developer.wordpress.org/reference/functions/get_permalink/
 get_permalink] can take either an ID or a post object.

 Currently, if a foreign post object is provided, `get_permalink` returns
 an incorrect and broken permalink that mixes the foreign post properties
 with the local permalink structure and homeurl.

 If the site ID were included as a property on the `WP_Post` class, it
 would make it possible for `get_permalink` to return the correct permalink
 for a foreign post.

 What it won't solve is when `get_permalink` and similar functions are
 called up with only a post ID. Core and plugins do this pervasively, even
 in cases where they have direct access to the full post object and are
 literally extracting the ID from it using `$post->ID`.

 What I encounter a lot with my plugin is to fetch foreign posts from the
 database using `switch_to_blog`, only to have core and other plugins
 discard all of their data other than the post ID.

 Example: [https://woocommerce.github.io/code-reference/classes/WC-Product-
 Data-Store-CPT.html#method_get_product_type this method] calls up
 [https://developer.wordpress.org/reference/functions/get_post_type/
 get_post_type] using the ID only. Even if the original post object was a
 product from a foreign site, `get_post_type` ends up checking the current
 site and finding the ID is most likely not associated with a product. The
 post object, however, was withheld by [https://woocommerce.github.io/code-
 reference/classes/WC-Product-Factory.html#method_get_product an earlier
 method], so a site ID property would not be of much help to correct the
 subsequent output of `get_post_type`.

 Including the site ID on `WP_Post` is only half of the solution. The
 second half is ensuring the site ID is routinely able to flow through to
 widely used functions such as `get_permalink`, `get_post_type` and
 similar.

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


More information about the wp-trac mailing list