[wp-trac] [WordPress Trac] #23016: Allow plugins to manipulate WP_Roles ($wp_roles global) on construct

WordPress Trac noreply at wordpress.org
Thu Nov 3 02:58:53 UTC 2016


#23016: Allow plugins to manipulate WP_Roles ($wp_roles global) on construct
-------------------------------------------------+-------------------------
 Reporter:  johnjamesjacoby                      |       Owner:  pento
     Type:  defect (bug)                         |      Status:  closed
 Priority:  normal                               |   Milestone:  4.7
Component:  Role/Capability                      |     Version:  3.5
 Severity:  normal                               |  Resolution:  fixed
 Keywords:  has-patch has-unit-tests commit      |     Focuses:
  needs-dev-note                                 |
-------------------------------------------------+-------------------------

Comment (by johnjamesjacoby):

 Thanks @charliespider for chiming in, and @mnelson4 for the patch &
 examples.

 I think I missed the point because the behavior of `$wp_roles->reinit()`
 (and/or `_init()`) itself hasn't changed. Sorry for the confirmation bias,
 there.

 I fully understand what the issue is now. Did either of you run into
 problems in the wild with this? bbPress didn't break, and it pushes the
 envelope pretty far with roles, but it also wasn't working as reliably as
 it should have (and will now thanks to the `wp_roles_init` action.)

 If it is a problem, we need to un-deprecate `reinit()` & revert back to
 calling it, but the way I've patched it in 23016.03.patch instead.
 `$wp_roles = new WP_Roles()` will always result in a new hash ID, and the
 `reinit()` method can prevent that if that's what we want/need.

 ----

 Originally I had thought to approach this by adding a `for_blog()` method
 to `WP_Roles` like `WP_User` has, and hooking it to `switch_blog`, but
 remembered that's what both `reinit()` and `_init()` already mostly did,
 so went the route of removing duplication instead of adding to it. I have
 a hunch my original hunch is a more complete & appropriate fix, though...
 it's likely more invasive than anyone is comfortable with during beta, and
 those boundaries are in place for good reason.

 I started working on a patch tonight, but am running out of steam and can
 have it ready tomorrow for scrutiny.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/23016#comment:32>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list