Opened 3 years ago
Closed 7 months ago
#14190 closed defect (bug) (wontfix)
switch_to_blog() should affect $current_blog global
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Multisite | Version: | 3.0 |
| Severity: | normal | Keywords: | has-patch |
| Cc: | scribu@… |
Description
Currently, switch_to_blog() does not change the $current_blog global set of variables. So functions such as is_main_site() will continue to use the previous set blog id.
So for example if you switch to another blog while acting as a site admin to flush rewrite rules on a non-main blog, the non-main blog gets the main-blog-specific rewrite rules.
My general suggestion is that we move $current_blog into a function like get_current_blog and not count on the global to be populated correctly, then replace $current_blog global variable references with calls to get_current_blog, which will handle the current blog situation correctly.
Attachments (1)
Change History (6)
wonderboymusic — 8 months ago
comment:2
wonderboymusic — 8 months ago
- Keywords has-patch added; needs-patch removed
- Milestone changed from Future Release to 3.5
#22090 pretty much deprecates $current_blog. Perhaps we should leave it as the current blog at init rather than switching it.
Seeing that it is now only used in sunrise/ms-settings, and that $current_site is the same thing and also not switched, that makes sense. I actually think the case could be made to not switch them, back compat concerns aside. But , the possible side effects of switching $current_blog aren't pretty either, and we've already done a lot of changes to switching this release.
We should probably look to phase out $current_site with a push for multi-network support in a future version.

get_blog_details is cached, it seems natural that $current_blog would be updated, but it's not. Hooking into 'switch_blog' to set it is a hack. I do so on eMusic and have had zero problems. Feel like this should be the default way it works.