Select User Role on Registration

This topic contains 6 replies, has 3 voices, and was last updated by  Paolo 7 years, 10 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #346005

    boyntonjamie
    Expired Member
    Post count: 25

    Hello

    I’ve been searching for this and saw that GeoDir uses WordPress registration/users etc.

    This is fine – however when I try to modify the WordPress form using plugins (to allow a user to select role on registration) it doesn’t change the registration form. I’ve tried a few plugins to no avail.

    Is there a separate GeoDir login form that I need to manually edit? How can I allow role selection in the form? I will want to allow 2 of 4 user roles to be selected.

    #346019

    Guust
    Moderator
    Post count: 29970

    What plugins are you trying?
    I don’t think there are any plugins that allow a user to decide for themselves what role they will have.
    You can achieve something like that by running the registration process through another plugin than GD, like a membership plugin.

    #346644

    boyntonjamie
    Expired Member
    Post count: 25

    I tried WP Roles at Registration (out of date but tried anyway), ProfilePress (tested and working on my version of WorPress) and one more I can’t recall (also out of date but tried anyway).

    I understand GeoDir can work with BuddyPress and think BuddyPress has this function? However I don’t want all the social side of BuddyPress on my site. Is it possible to just change the registration form but leave the rest of the site untouched?

    Assuming GD just pulls out the WordPress registration and puts it onto a different page, I should in theory be able to just use a registration form-modifying plugin, and the changes that make will appear in the form that GD displays, right?

    As the plugins (one confirmed working on my version of WP) didn’t work, I wondered if maybe the GD registration wasn’t just the standard WP registration form.

    #346674

    Guust
    Moderator
    Post count: 29970

    Those extend the profile fields, nothing to do with user roles. User roles are like admin/author/editor etc.

    Buddypress allows you to create extra profile fields, yes.
    You can use as little or as much of Buddypress as you like.
    You can use BP just as an extended profile plugin and turn off all the rest.

    All plugins use WP registration, it is just that they modify it differently.

    I suggest you use Buddypress with the GD Buddypress integration; that should do exactly what you want.

    #348263

    boyntonjamie
    Expired Member
    Post count: 25

    All three plugins I used claim to put user role selection on the signup page, that is what I want. I can’t find the feature in BuddyPress, I can find the option to add additional fields but not the option to make one of those fields user role selection.

    Searching online I’ve found this code:

    
    
    <?php
    //1. Add a new form element...
    add_action( 'register_form', 'myplugin_register_form' );
    function myplugin_register_form() {
    
        global $wp_roles;
    
        echo '<select name="role" class="input">';
        foreach ( $wp_roles->roles as $key=>$value ):
           echo '<option value="'.$key.'">'.$value['name'].'</option>';
        endforeach;
        echo '</select>';
    }
    
    //2. Add validation.
    add_filter( 'registration_errors', 'myplugin_registration_errors', 10, 3 );
    function myplugin_registration_errors( $errors, $sanitized_user_login, $user_email ) {
    
        if ( empty( $_POST['role'] ) || ! empty( $_POST['role'] ) && trim( $_POST['role'] ) == '' ) {
             $errors->add( 'role_error', __( '<strong>ERROR</strong>: You must include a role.', 'mydomain' ) );
        }
    
        return $errors;
    }
    
    //3. Finally, save our extra registration user meta.
    add_action( 'user_register', 'myplugin_user_register' );
    function myplugin_user_register( $user_id ) {
    
       $user_id = wp_update_user( array( 'ID' => $user_id, 'role' => $_POST['role'] ) );
    } ?>

    But placing it in functions.php didn’t do anything and I’m not sure where else to put it.

    #348266

    boyntonjamie
    Expired Member
    Post count: 25

    Okay so after checking further I can see that one of the plugins and the code I posted above work, but only on the wp-signup.php page, so it doesn’t fit the rest of the site with the theme/layout from GD and my theme.

    How can I make these changes happen on the GD signup form?

    #348696

    Paolo
    Site Admin
    Post count: 31206
Viewing 7 posts - 1 through 7 (of 7 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount