Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am looking for a way to make two separate register pages. One will automatically assign users up as a subscriber, while the other will sign them up as a contributor.

The only thing I have thought of so far is to duplicate the *register_new_user* function in the wp-login.php file and customize it a bit.

Any ideas? Thanks in advance.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Basically all you need to do is add an hidden field named role and set the value to whatever role you want on the register form.

add_action('register_form','show_role_field');
function show_role_field(){ ?>
<input id="role" type="hidden" tabindex="20" size="25" value= "<?php if (isset($_GET['role'])){echo $_GET['role'];} ?>"  name="role"/>
    <?php
}

Next thing is to register that role when the user has submitted the registration form.

add_action('user_register', 'register_role');

function register_role($user_id, $password="", $meta=array()) {

   $userdata = array();
   $userdata['ID'] = $user_id;
   $userdata['role'] = $_POST['role'];

   //only allow if user role is my_role

   if ($userdata['role'] == "my_role"){
      wp_update_user($userdata);
   }
}

Now all that is left to do is direct the user to the register url with the role that you want as a query var, for example

http://example.com/wp-login.php?action=register&role=my_role

You can read more http://www.jasarwebsolutions.com/2010/06/27/how-to-change-a-users-role-on-the-wordpress-registration-form/ And i would suggest that you check to validate the role is allowed to register before saving it so you wont get a few new admins in your site.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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