[wp-trac] [WordPress Trac] #60592: Redefining roles

WordPress Trac noreply at wordpress.org
Wed Feb 21 18:24:10 UTC 2024


#60592: Redefining roles
--------------------------+-------------------------
 Reporter:  n1ck500       |       Owner:  (none)
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:
Component:  Users         |     Version:
 Severity:  normal        |  Resolution:  worksforme
 Keywords:                |     Focuses:
--------------------------+-------------------------
Changes (by swissspidy):

 * status:  new => closed
 * resolution:   => worksforme
 * component:  Plugins => Users
 * severity:  critical => normal
 * milestone:  Awaiting Review =>


Comment:

 Hi there and welcome to WordPress Trac!

 Yes. This is expected behavior in PHP and WordPress.
 `wp_get_current_user()` returns the global `$current_user` object, which
 is always the same `WP_User` instance. So with your code you are modifying
 the `roles` property on this object.

 You should make a copy of `wp_get_current_user()->roles` before making any
 modifications.

 So this is not a bug but working as intended.

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


More information about the wp-trac mailing list