I’m using the User-registration form and when I use the “update” form with my admin account, when I click on submit, my account is turned into a user based role…
How to protect the admin users from the update user form ?
Hi Sebatien. If you are logged in as administrator and submit a form with an Update User feed, your user is the one that will be updated. If you want to change the user that is updated when submitting and Update User form, you can override the user ID with the gform_user_registration_update_user_id filter.
You can create a custom user meta merge tag and then you can hide the submit button using the merge tag.
If you prefer a snippet, Gravity Wiz created one.
You can add the snippet below to your functions.php file then use user_role in any fields you want to hide when an admin is viewing the form. Just check the enable field to be populated dynamically option.
/**
* Dynamically Populating User Role
* http://gravitywiz.com/2012/04/30/dynamically-populating-user-role/
*/
add_filter('gform_field_value_user_role', 'gform_populate_user_role');
function gform_populate_user_role($value){
$user = wp_get_current_user();
$role = $user->roles;
return reset($role);
}
Unfortunately, the PHP code provided broke the website… Also, I can’t add the dynamic change for user role, maybe because it’s managed by the user registration it self…
It must be possible to keep the role of the user when he try to edit he’s account…