Change user role on registration
Author | Posts |
---|---|
August 24, 2013 at 12:57 am 7395 | |
nonameolsson | Hello! I've been reading the documentation, and it really a good one! But I can't get this to work, and I have read the explanation in another thread: http://wedevs.com/support/topic/choose-user-type-on-registration/#post-2403 I have four user roles: Administrator(WP admin), Administration, Full time and Part time. On registration the choice is between: Administrator, Full time and Part time. I'm using the code example but can't get it to work. This is my code in my functions.php: [php] function wpufe_my_switch_reg( $args ) { if ( $_POST['membertype'] == 'Deltid' ) { $args['role'] = 'parttime'; } elseif ( $_POST['membertype'] == 'Heltid' ){ $args['role'] = 'fulltime'; } elseif ( $_POST['membertype'] == 'Administration' ){ $args['role'] = 'administration'; } return $args; } add_filter( 'wpuf_register_user_args', 'wpufe_my_switch_reg' ); [/php] In the form I use a drop down with the meta key: membertype. The preset values are: Heltid, Deltid and Administration. What am I doing wrong? I tried adding, after the elseif-arguments, add an else. I noticed that it always enters the last else statement. So I think that I'm doing something wrong, since it never enters some of the first statements. I appreciate all help available! |
August 24, 2013 at 1:34 am 7396 | |
Tareq Hasan | The code seems fine, possibly the problem is with the user role names. Please check if you are giving the correct role names. In default WordPress, the role names are all small caps: |
August 24, 2013 at 2:03 am 7400 | |
nonameolsson | Thanks for a quick reply! |
August 25, 2013 at 2:00 am 7462 | |
Tareq Hasan | The names looks okay. Check another thing, goto add new user page in admin and see the select dropdown of user role. The option values should be correct. |
August 25, 2013 at 2:38 am 7465 | |
nonameolsson | I did that. The drop down options have the same value as in the function. I tried with a new WordPress installation also, with the out-of-the-box user roles. But it doesn’t work either. Here are screenshots of my current new WordPress installation. I can’t understand what I’m doing wrong here. I’ve been trying this for hours now! I appreciate all the help! Thanks for great support! |
August 25, 2013 at 3:00 am 7466 | |
Tareq Hasan | The problem is, the [php] if ( !isset( $_POST[‘user_role’] ) ) { // get the first element of the array switch ( $user_role ) { case ‘Subscriber’: case ‘Shop Worker’: case ‘Shop Manager’: return $args; |
August 26, 2013 at 6:17 pm 7493 | |
nonameolsson | Thank you very much! Now it works as it should! |