[wp-hackers] action on change of role only
Andrew Gray
andrew at graymerica.com
Wed Jul 14 04:34:06 UTC 2010
Sergey,
thank you for the code,
>
> function change_role_notify($meta_id, $object_id, $meta_key, $_meta_value) {
> $user = new WP_User($object_id);
> if ( $meta_key == $user->cap_key ) {
> $previous_user_role = array_shift( $user->roles );
> $current_user_role = array_shift( array_keys($_meta_value) );
> ...
> }
> }
> add_action('update_user_meta', 'change_role_notify', 10, 4);
>
However, I can not get this action to fire on the update, when I used the multiple user role change function from the user list
Here is what I did (which is pretty hackish, but worked)
I added another action, that stores the previous role in the bottom of the user info edit screen form in a hidden field
add_action('edit_user_profile' , 'store_previous_role') ;
function store_previous_role() {
$user_info = get_userdata($_REQUEST['user_id']);
$previousRoles = implode("," , array_keys($user_info->wp_capabilities)) ;
echo "<input type='hidden' name='previousRole' value='$previousRoles'>" ;
}
In my change_role_notify function, I now look to see if the function is being called from the multiple user select list or a single menu form and react correctly,
function change_role_notify($id, $role) {
if (isset($_REQUEST['changeit']) and $_REQUEST['changeit'] != 'Change') { return ; } // from the multi select list
if (isset($_REQUEST['previousRole']) and $_REQUEST['previousRole'] != 'Pending') { return ; } // from my action above
...
//The rest of the notify function
}
Hope this helps someone else in the future. I think I am going to make a real plugin out of this to provide this functionality with an admin for the message.
Andrew, I like both your ideas, and I will work on a patch to solve this in a better method
thanks,
>
>
More information about the wp-hackers
mailing list