[wp-trac] [WordPress Trac] #38645: Improve roles reinit when switching between sites
WordPress Trac
noreply at wordpress.org
Thu Nov 3 18:15:45 UTC 2016
#38645: Improve roles reinit when switching between sites
-------------------------------------------+------------------------------
Reporter: johnjamesjacoby | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Role/Capability | Version: trunk
Severity: normal | Resolution:
Keywords: has-patch needs-testing early | Focuses: multisite
-------------------------------------------+------------------------------
Old 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.
New 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 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.
--
Comment (by johnjamesjacoby):
(Edited typos and added a missing word.)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38645#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list