Make WordPress Core

Opened 15 years ago

Closed 15 years ago

#10716 closed enhancement (fixed)

New hook for user role change

Reported by: usermrpapa's profile usermrpapa Owned by:
Milestone: 2.9 Priority: normal
Severity: normal Version: 2.8.4
Component: Role/Capability Keywords: has-patch
Focuses: Cc:

Description

It would be nice to have an action to hook into for user role changes. We have a plugin that cares about role changes as a way of controlling features/access in a plugin.

I can grab role changes just fine if they are made on the users profile page (user-edit.php) via one of the profile hooks, but if the changes are made to roles via the user bulk changes editor (users.php), there isn't a way (unless I have just missed it) to know that any user roles were changed.

I have opened this ticket for 2.8.5, but not sure how its potentially affected by the upcoming roles/capabilities changes slated for 2.9.

Attachments (2)

roleaction.patch (1005 bytes) - added by usermrpapa 15 years ago.
10716.diff (418 bytes) - added by jamescollins 15 years ago.
Patch against trunk r11902

Download all attachments as: .zip

Change History (14)

#1 @dd32
15 years ago

  • Keywords needs-patch added
  • Milestone changed from 2.8.5 to Future Release

It shouldn't be affected by the capabilities changes in 2.9, infact, it'll probably be easier (As it'll be a role transition, rather than a roll add/roll removal which is currently possible).

How are you planning on using the hook? To change cached permission values?

Milestone: Future release pending patch for enhancements, Current-trunk upon patch being added for consideration, point release back-porting at commiters discretion. (Generic reply for when I change the milestone)

#2 @usermrpapa
15 years ago

When the hook was fired, we would execute some additional code in our plugin to take action based on the role change for that user.

Personally, I wouldnt want to affect the role change itself or any cached permissions values.

#3 @usermrpapa
15 years ago

Probably should know how to create a patch, but I dont. I think its pretty much as easy as adding a

do_action('user_role_update', $user_id);

or some other more appropriate name in

wp-admin/includes/user.php (around line 80 in wp 2.8.4)

and

wp-admin/users.php (around line 67 in wp 2.8.4)

my wp 2.9 test site is a bit out of date (getting ready to release new version of our plugin), but guess I should bring it up to date.

#4 @usermrpapa
15 years ago

figures... its just $id in the second location...

#5 @usermrpapa
15 years ago

  • Cc usermrpapa added

#6 @usermrpapa
15 years ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Future Release to 2.9

okay, lets try adding a patch for this (be gentile) ;)

this is against trunk, rev [11898]

would be nice if applied to the 2.8 line too...

@jamescollins
15 years ago

Patch against trunk r11902

#7 @jamescollins
15 years ago

I have attached an patch that is an alternative to roleaction.patch.

My patch runs the action as part of the WP_User::set_role() function, which I think is a better place.

The action also passes the user ID and new role name as part of the action.

#8 @usermrpapa
15 years ago

even better!

#9 @jamescollins
15 years ago

Is there any chance in getting this one line patch committed in time for WordPress 2.9?

Thanks very much.

#10 @usermrpapa
15 years ago

please, pretty please - or tell us how to improve...

#11 @usermrpapa
15 years ago

with 2.9 sort of dated now (based on wp dev chat today) and feature freeze occurring and beta by month end, sure would be nice to get this bad boy included. ;)

#12 @markjaquith
15 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [12028]) Add set_user_role action hook. props jamescollins, usermrpapa. fixes #10716

Note: See TracTickets for help on using tickets.