I want to get my single wordpress installation a closed community. Just 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
add_action('register_form','show_first_name_field');
// This is a check to see if you want to make a field required
add_action('register_post','check_fields',10,3);
// 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(){
?>
<p>
<label>Vorname<br />
<input id="user_email" class="input" type="text" tabindex="20" size="25" value="<?php echo $_POST['first']; ?>" name="first"/>
</label>
</p>
<p>
<label>Nachname<br />
<input id="user_email" class="input" type="text" tabindex="20" size="25" value="<?php echo $_POST['last']; ?>" name="last"/>
</label>
</p>
<p>
<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>
</select>
</label>
</p>
<p>
<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>
</p>
<p>
<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>
</label>
</p>
<?php
}
// 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
wp_update_user($userdata);
update_usermeta( $user_id, ‘geschlecht’, $_POST['geschlecht'] );
update_usermeta( $user_id, ‘hochschule’, $_POST['hochschule'] );
update_usermeta( $user_id, ‘studiengang’, $_POST['studiengang'] );
}