WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to make my single wordpress installation a closed community. Only people who know the registration key should be able to sign up. I already added some more fields to the registration form but I can't fin a simple solution for the registration form to check if the code is correct!?

Looking forward for some ideas! Thank you!

Here's what I do have until now:

// This function shows the form fiend on registration page

// This is a check to see if you want to make a field required

// This inserts the data
add_action('user_register', 'register_extra_fields');

// This is the forms The Two forms that will be added to the wp register page
function show_first_name_field(){

<label>Vorname<br />
<input id="user_email" class="input" type="text" tabindex="20" size="25" value="<?php echo $_POST['first']; ?>" name="first"/>

<label>Nachname<br />
<input id="user_email" class="input" type="text" tabindex="20" size="25" value="<?php echo $_POST['last']; ?>" name="last"/>

<label>Hochschule<br />
<select name="hochschule" id="hochschule" class="input">
<option value="Uni Augsburg" <?php selected( 'Uni Augsburg', get_the_author_meta( 'hochschule', $user->ID ) ); ?>>Uni Augsburg</option>
<option value="Hochschule Augsburg" <?php selected( 'Hochschule Augsburg', get_the_author_meta( 'hochschule', $user->ID ) ); ?>>Hochschule Augsburg</option>

<label>Studiengang<br />
<input type="text" class="input" name="studiengang" id="studiengang" value="<?php echo esc_attr( get_the_author_meta( 'studiengang', $user->ID ) ); ?>" class="regular-text" />

<label>Geschlecht<br />
<select name="geschlecht" id="geschlecht" class="input">
<option value="männlich" <?php selected( 'männlich', get_the_author_meta( 'geschlecht', $user->ID ) ); ?>>männlich</option>
<option value="weiblich" <?php selected( 'weiblich', get_the_author_meta( 'geschlecht', $user->ID ) ); ?>>weiblich</option>


// This function checks to see if they didn't enter them
// If no first name or last name display Error
function check_fields($login, $email, $errors) {
    global $firstname, $lastname;
    if ($_POST['first'] == '') {
        $errors->add('empty_realname', "<strong>Fehler</strong>: Bitte gib deinen Vornamen ein.");
    } else {
        $firstname = $_POST['first'];
    if ($_POST['last'] == '') {
        $errors->add('empty_realname', "<strong>Fehler</strong>: Bitte gib deinen Nachnamen ein.");
    } else {
        $firstname = $_POST['last'];
        global $hochschule;
    if ( $_POST['hochschule'] == '' ) {
        $errors->add( 'empty_realname', "<strong>Fehler</strong>: Bitte gib deine Hochschule an." );
    } else  {
        $hochschule = $_POST['hochschule'];
        global $studiengang;
    if ( $_POST['studiengang'] == '' ) {
        $errors->add( 'empty_realname', "<strong>Fehler</strong>: Bitte gib deinen Studiengang ein." );
    } else  {
        $studiengang = $_POST['studiengang'];
        global $geschlecht;
    if ( $_POST['geschlecht'] == '' ) {
        $errors->add( 'empty_realname', "<strong>Fehler</strong>: Bitte gib dein Geschlecht an." );
    } else  {
        $geschlecht = $_POST['geschlecht'];


// This is where the magiv happens
function register_extra_fields($user_id, $password="", $meta=array())  {

// Gotta put all the info into an array
$userdata = array();
$userdata['ID'] = $user_id;

// First name
$userdata['first_name'] = $_POST['first'];

// Last Name
$userdata['last_name'] = $_POST['last'];

// Enters into DB
update_usermeta( $user_id, ‘geschlecht’, $_POST['geschlecht'] );
update_usermeta( $user_id, ‘hochschule’, $_POST['hochschule'] );
update_usermeta( $user_id, ‘studiengang’, $_POST['studiengang'] );

share|improve this question
Could you not require administrator approval before a registration completes? Saves people passing around the registration key – Tom J Nowell Nov 22 '11 at 11:05
Hi! I think the best way would be to have a registration key. Because the website is for a broadcasting station at university and everyone who is involved should be able to register. So e.g. just to have one word "Password" and everyone who knows it is able to register... ;) Best! – Philipp Nov 22 '11 at 12:11
For everyone who is searching for something like this - I ended at the "Secure Invites" Plugin which is quite good. :) – Philipp Dec 1 '11 at 13:54

You could use plugin Pie Register for the invitation codes or have look at this snippet ( Creating a Closed Wordpress Community Using Referral Codes ). This forum post could be useful too.

share|improve this answer

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

Thank you for the answer. But "Pie Register" and other Plugins as "Register Plus Redux" do have problems with the latest Wordpress release (3.2.1). That's why I want to add it to the function.php. I already saw this snippet (gist.github.com/1181933) but doesn't help me, because I do have to less knowledge about PHP. Maybe another idea?! :) Thanks! – Philipp Nov 22 '11 at 11:55
Answers should be more than plain links. They should actually be an answer instead of a route where someone will maybe find an answer. Please help preventing link rot, edit your answer and provide the needed information that helps the OP as well as later visitors to solve their problem. – kaiser Nov 22 '14 at 8:53

Your Answer


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.