WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 2 years ago

#38645 closed defect (bug)

Improve roles reinit when switching between sites — at Initial Version

Reported by: johnjamesjacoby Owned by:
Milestone: 4.9 Priority: normal
Severity: normal Version: 4.7
Component: Role/Capability Keywords: has-patch, has-unit-tests
Focuses: multisite Cc:
PR Number:

Description

When switching between sites (since r39083) the $wp_roles global is being recreated instead of adjusting the values of the existing global.

The current regression means if a plugin was keeping its own copy of the $wp_roles global around (maybe as a property in a class, or for some other convenience sake) then then newly created $wp_roles global no longer points to that same copy. (See #23016 for more details & examples.)

History lesson: previous to that changeset, the reinit() method was used to update the roles for the witched site. That method was largely a copy of the _init() method, and was purpose built for blog switching.


Anecdotally, it's unlikely this will cause very many problems, but it is still a regression from previous behavior, and I believe the fix is fairly straightforward.

We can take inspiration from the WP_User::for_blog() method, and introduce a for_blog() method to the WP_Roles class to basically do the exact same thing in the exact same way. We can make alterations to the blog switching functions to update the $wp_roles and $current_user->roles values in unison.

Architecturally, I think it makes sense to call these methods together, but not have one call the other all the time, because there may a reason or time where that control is welcome, and marrying them together now makes divorcing them later difficult.

Patch imminent.

Change History (1)

Note: See TracTickets for help on using tickets.