I am trying to save secondary role field in user-edit.php which is independent of WP's main roles. I had no problem with saving other custom fields that are unique but for roles (wp_capabilities), it looks like it first saves my roles (I set sleep(10) to check in database in the process) and at the end of request, WP saves main role field which overwrites my previously saved role.
Is there any way to order events somehow so my function executes at the very end of request?
Here's what I've got so far:
Hooks:
<?php
add_action( 'edit_user_profile', array( $this, 'test_profile_form'));
add_action( 'edit_user_profile_update', array( $this, 'test_save_profile_form' ));
Callbacks:
function hook_save_profile_form($user_id) {
if(!current_user_can("edit_user",$user_id)) {
return false;
}
$user = new WP_User($user_id);
$user->add_role($_POST['secondary-role']);
//debug
sleep(10);
}
a:2:{s:13:"administrator";b:1;s:13:"bbp_keymaster";b:1;}