﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	severity	resolution	keywords	cc	focuses
38645	Improve roles reinit when switching between sites	johnjamesjacoby	flixos90	"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 switched 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 be a reason or time where that control is welcome, and marrying them together now makes divorcing them later difficult.

Patch imminent."	defect (bug)	closed	normal	4.9	Role/Capability	4.7	normal	fixed	has-patch, has-unit-tests		multisite
