Home › Forums › Plugin Support › Field visibility based on role
Tagged: role field visibile
- This topic has 5 replies, 3 voices, and was last updated 10 years, 10 months ago by crs-group.
-
AuthorPosts
-
February 16, 2014 at 6:36 pm #4844February 17, 2014 at 7:55 pm #4849KhaledMember
Hello,
add_action( 'user_meta_after_form', 'toggleRoleBasedFields' ); function toggleRoleBasedFields( $formName ) { //if ( 'Your_Form_Name' != $formName ) return; echo " <script> jQuery(document).ready(function() { jQuery(\"input[name=role]\").change(function(){ roleName = jQuery(\"input[name=role]:checked\").val(); if(roleName=='tourist'){ jQuery(\".class_to_hide\").hide(); jQuery(\".class_to_show\").show(); } }); }); </script> "; }
Those code may be helpful for you. class_to_hide and class_to_show are name of classes that you want to hide or show, you can assign custom class name to any field via User Meta >> Fields Editor.
Thanks.
February 17, 2014 at 8:45 pm #4850soulsacrifireMemberHi Khaled,
thanks a lot for your suggestion.
I’ve changed idea and I’ve created a first login redirection after the login phase.
Based on the role value I’m able to show/hide fields but not the field label!add_filter( 'user_meta_field_display', 'user_meta_field_display_function', 10, 3 ); function user_meta_field_display_function($html, $fieldID, $formName){ global $userMeta, $user_ID; $role = $userMeta->getUserRole( $user_ID ); if( in_array( $role, array( 'other' ) ) && ( $fieldID == '5' || $fieldID == '18' || $fieldID == '7' || $fieldID == '22' || $fieldID == '6' || $fieldID == '9' || $fieldID == '10' || $fieldID == '11' || $fieldID == '19' )) return null; return $html; }
February 17, 2014 at 10:33 pm #4851soulsacrifireMemberHi Khaled,
this is my redirect code. I’m not able to have the right redirectionadd_filter( 'user_meta_filter_list', 'enableLoginRedirect' ); function enableLoginRedirect( $list ){ $list['login_redirect'] = true; return $list; } add_filter( 'login_redirect', 'redirectToProfile', 10, 3 ); function redirectToProfile( $redirect_to, $redirect, $user ){ global $userMeta, $user_ID; $role = $userMeta->getUserRole( $user_ID ); if( ( in_array( $role, array( 'other' ) ) )) { $redirect_to = 'http://www.google.com'; } elseif( ( in_array( $role, array( 'touristguide', 'touroperator', 'hotel' ) ) )) { $redirect_to = 'http://www.bing.com'; } update_user_meta( $user->ID, 'first_login_detected', '1' ); return $redirect_to; }
February 19, 2014 at 10:26 pm #4865soulsacrifireMemberHello Khaled,
I use your code.
It works!
Thanks a lot very much!February 25, 2014 at 1:50 pm #4908crs-groupMemberHey guys!
Thank you so far for these informations.
I’ve got the same problem: I’d like to set a radio button in the registration-form.
I.e.:
Do you have some pets?
o Yes o NoIf “Yes” is checked, a Textfield should appear. (i.e. “name of the pet”)
Sorry but I’m a very newbie at action-hooks and how they work.
Would you please give me a hint how I can make it work?
Which fields I have to align in the code from Khaled and where I have to insert the code in my theme? functions.php, custom_functions.php?This would make my registration-form perfect! Thank you so far!
Best regards
-
AuthorPosts
- You must be logged in to reply to this topic.