[wp-trac] [WordPress Trac] #25293: Switch_to_blog not switching the siteid
WordPress Trac
noreply at wordpress.org
Tue Sep 6 18:31:18 UTC 2016
#25293: Switch_to_blog not switching the siteid
------------------------------------------------+--------------------------
Reporter: Rahe | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Future
Component: Networks and Sites | Release
Severity: minor | Version: 3.0
Keywords: has-patch dev-feedback 2nd-opinion | Resolution:
| Focuses: multisite
------------------------------------------------+--------------------------
Changes (by flixos90):
* keywords: => has-patch dev-feedback 2nd-opinion
Comment:
Based on this ticket and also #37958 (plus today's Multisite chat
discussion), I implemented a first take on a `WP_State` class in
[attachment:25293.diff]. This class manages switching between sites and
contains some enhanced functionality:
* not only `$blog_id` is switched, but also the `$current_blog` global
* if the network ID of the new site is different than the network ID of
the old site, the network (`$current_site`) is switched as well (also the
`$wpdb->siteid` property)
* it is possible to set a named breakpoint at any time
(`WP_State::set_breakpoint()`): this will store the current state and
allow to restore it later (`WP_State::restore_breakpoint()`) (see #37958
for more information)
* a lot of duplicate code from `switch_to_blog()` and
`restore_current_blog()` has been removed by outsourcing similar parts
into private methods
* the `_wp_switched_stack` global is gone - since it's marked private, I
simply removed it and now use a class property instead; if we need to keep
it for BC, that shouldn't be a problem though
The `WP_State` instance is currently stored in a global in this patch, but
obviously I don't wanna introduce one. If we get to put this idea into
Core, we should make the instance available through something like
`WP::get( 'state' )`. Also, the name `WP_State` sounds pretty "global" for
something only available on Multisite. Maybe another name would be more
suitable.
This was basically me playing around what an improved switching structure
could look like. So feel free to discuss it, take it apart, address
possible performance issues. :)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/25293#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list