Home › Forums › Plugin Support › Assign role in registration process
Tagged: role hook
- This topic has 15 replies, 9 voices, and was last updated 11 years, 10 months ago by Support.
-
AuthorPosts
-
March 8, 2012 at 4:10 pm #858March 9, 2012 at 12:39 am #861KhaledMember
For now, you can add role as hidden field(there may be some security issue),
we will give a way to assign role to form in next version.Thanks.
June 25, 2012 at 8:04 pm #1644raoniMemberHi,
When This feature will be avaliable!?
Thanks!
September 3, 2012 at 3:13 pm #1973lemondesignMemberalso curious when this will be implemented. At least, is there any workaround to this?
September 14, 2012 at 3:27 am #2083toddz70MemberHi.
On March 9, 2012, khaledsaikat said we can use a Hidden field on a Registration form to set the Role for the user being registered. How would this actually work? What should we enter for the meta-key to connect this Hidden field to the wp-Role? Will this override the WP setting for the default Role?Is there a way to use the actual WordPress Role field instead? I tried that, but
– it does not seem to override the default Role specified in wp settings.
– it’s not very secure since the user can change the selection, even if the dropdown/select is disabled, he can re-enable it in firebug or something, change his selection, and submit the form.Is there any hook we can use to perform our own custom validation in php, to make it more secure? Can you suggest some simple code for that?
Thanks. –Todd
September 14, 2012 at 5:48 am #2084toddz70MemberI was able to accomplish this using a Filter hook. Here’s what i did, if it helps anyone.
My Scenario — I have two different Registration forms, one for Students, and another for Schools. The Students reg form has a field with “my-school” as the meta-key. My function checks for the existence of that field in the submitted data from the form, and if found, we know the submission is from the Student form; otherwise it’s from the School form. So in my functions.php :
add_filter('user_meta_pre_user_register', 'tz_registration_role');
function tz_registration_role($userData){
if( isset($userData['my-school'])){
// registration for Student
$userData['role'] = 'student';
} else {
// registration for School
$userData['role'] = 'school';
}
return $userData;
}This lets me assign the Role dynamically, based on which Registration form was used.
- This reply was modified 12 years, 3 months ago by toddz70. Reason: cleaned up the code
October 10, 2012 at 7:50 pm #2228maxwinMemberi tried to use the script which was posted by you on my site but after registration, the new role is not assigned to the meta key field of my form. Note i have two forms which is demo and active. the new role created by my user role plugin is subscriber(default wordpress role) and demo. A quick solution to this will be appreciated
October 16, 2012 at 4:20 pm #2322maxwinMemberThanks… User role assignment works fine now
October 31, 2012 at 9:58 pm #2401mcaMemberle 31 october 2012
thank you toddz70
your hook is very helpfull !
mcaNovember 7, 2012 at 8:58 pm #2429mcaMemberi use your hook on my two forms and it’s great!
But now i have one question : if the user want to upgrade his role (form school to student) he use the second form with the hidden field but your hook doesn’t achieve to upgrade his new role why ?
best regard,
mcaNovember 7, 2012 at 9:18 pm #2430toddz70Member@mca – The form i’m using is a REGISTRATION form, which creates a new User in wordpress. It sounds to me like a form that allows an existing user to change his role would need to be a totally different form – a Profile Edit form, not a Registration form, since that’s what you’re really trying to do – edit his role.
November 7, 2012 at 9:39 pm #2431mcaMemberYes it’s what i’m trying to do : a form that allows an existing user to change his role. i need some advice to do that 🙂
November 7, 2012 at 9:45 pm #2432toddz70Member@mca – That’s a totally different topic that this thread, i think you should ask it in a different post in this forum, with a more accurate title. You’ll be more likely to get the help you need.
November 7, 2012 at 9:51 pm #2433mcaMemberok you ‘re right.
February 2, 2013 at 9:30 am #2975earthrootMemberIn the Pro version how do we set the user role when they fill out a registration form? I’ve figured out pretty much everything but that.
I need one form to create an Author, and another to create a Contributor.
Any help is appreciated.
-
AuthorPosts
- You must be logged in to reply to this topic.