Make WordPress Core

Opened 14 years ago

Closed 11 years ago

#14190 closed defect (bug) (wontfix)

switch_to_blog() should affect $current_blog global

Reported by: filosofo's profile filosofo Owned by: filosofo's profile filosofo
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Multisite Keywords: has-patch
Focuses: Cc:

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)

current-blog-update-on-switch.diff (491 bytes) - added by wonderboymusic 12 years ago.

Download all attachments as: .zip

Change History (6)

#1 @scribu
14 years ago

  • Cc scribu@… added

#2 @wonderboymusic
12 years ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Future Release to 3.5

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.

#3 @ryan
11 years ago

#22090 pretty much deprecates $current_blog. Perhaps we should leave it as the current blog at init rather than switching it.

#4 @nacin
11 years ago

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.

#5 @ryan
11 years ago

  • Milestone 3.5 deleted
  • Resolution set to wontfix
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.