When switching site, also switch network as well#119
When switching site, also switch network as well#119spacedmonkey wants to merge 1 commit intostuttter:masterfrom spacedmonkey:switch_network
Conversation
|
I like it! |
|
|
||
| function switch_blog_and_network ( $new_blog, $prev_blog_id ){ | ||
| $site_object = get_site( $new_blog ); | ||
| if ( !($site_object instanceof WP_Site ) ){ |
There was a problem hiding this comment.
This can be simplified to just ! $site_object.
|
I'm not sure switching the network should happen automatically, as this may introduce all sorts of unexpected behavior, particularly because plugins (unfortunately) don't expect the network to be switched. To some degree I'd love for this to be the case, but due to the historic circumstances it may work better as an optional feature. Maybe we could introduce the action function, but not automatically hook it in? Then custom setups could decide on that, but it wouldn't be the default. Or there could be a |
|
Or we could have a function that toggles network-switching on/off, kind of like how caching has? |
Currently when switching blog (site), the network is not changed. This can have issues when it comes to context aware function, that need the current network id to be correct. An example might be
wp_update_network_site_counts. By switching network, it stops possible issues.Doing a get_site on switch_to_blog, will add some overhead. On sites with object caching, it may result in another query. However, most times using switch_to_blog the wp_site_query class is also used like in network admin. wp_site_query will prime the wp_site object in cache (in without object caching). But there will be places where this isn't the case.
This PR includes tests, to prove it works. There maybe more tests that can be done.
fixes: #118