I have a classipress site and want to have the user choose upon registering with the site if they are a teacher, or student. These will be different roles. I have been trying to get roles at registration plugin to work because it is basically what I need, but since classipress has a custom reg page it does not seem to work. Any ideas?

  • 1
    are you working in a child theme? probably the best will be to modify the registration template...
    – brasofilo
    Mar 27, 2012 at 0:17
  • hi can you post your register form and register process function that classipress uses by delfault
    – fritids
    May 5, 2012 at 22:25

1 Answer 1


In your functions.php file do this:

add_action('user_register', 'register_role_fieldforuser');    
// This will register new field in registration form
function register_role_field(){ ?>
    <label>Choose your role:<br/>
    <!--- Let's check if there role already set. If $_GET['role'] = 0 -then this is teacher if 1 = student ---> 
    <?php if ( isset( $_GET['role'] ) ) { ?>
        <select id="role" class="checkboxas" name="role">
        <option value="0" <?php if( $_GET['role'] == '0' ) echo 'selected="selected"';?>>Teacher</option>
        <option value="1" <?php if( $_GET['role'] == '1' ) echo 'selected="selected"';?>>Student</option>
  <?php } else { ?>
        <!--- Incase we don't get role ---->
        <select id="role" class="checkboxas" name="role">
        <option value="0">Teacher</option>
        <option value="1" selected="selected">Student</option>

   <?php } ?>

<?php }

// Here we will check fields in this case only one
function check_fields( $login, $email, $errors ) {
    if( !is_numeric( $_POST['role'] ) )  
       $errors->add( 'bad_role', "ERROR: You have to select role" );

 function register_role_fieldforuser( $user_id, $password="", $meta=array() )  {
    if( is_numeric( $_POST['role'] ) ) {
        $userdata = array();  
        $userdata['ID'] = $user_id;
        $userdata['first_name'] = $_POST['first'];
        $userdata['last_name'] = $_POST['last'];
        if( $_POST['role'] == 0 ) 
            $userdata['role'] = 'teacher';
       else $userdata['role'] = 'student'; 

You can make 2 links in your website: 1 for teachers: http://yourwebsite.com/wp-login.php?action=register&role=0 and another for students http://yourwebsite.com/wp-login.php?action=register&role=1

So registration form automaticaly will select user role based on role set in uer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.