admin管理员组文章数量:1122826
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
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'] );
}
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
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'] );
}
Share
Improve this question
edited Dec 18, 2014 at 12:19
Tom J Nowell♦
60.7k7 gold badges77 silver badges147 bronze badges
asked Nov 22, 2011 at 11:02
PhilippPhilipp
1192 silver badges12 bronze badges
3
- Could you not require administrator approval before a registration completes? Saves people passing around the registration key – Tom J Nowell ♦ Commented Nov 22, 2011 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 Commented Nov 22, 2011 at 12:11
- For everyone who is searching for something like this - I ended at the "Secure Invites" Plugin which is quite good. :) – Philipp Commented Dec 1, 2011 at 13:54
2 Answers
Reset to default 0 Want to improve this post? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. Answers without enough detail may be edited or deleted.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.
You are saying that this is for an university broadcasting station. So I would assume everyone involved has an @univeristy.edu
email address. If not, I'm still posting this (even if it's a late reply) because it can be a good alternative solution for people who are in a similar situation.
So this could be too restrictive or not for your use case, but you could only authorize people with valid email domain to register.
From this answer
add_filter( 'registration_errors', 'my_authorized_domains', 10, 3 );
function my_authorized_domains( $errors, $sanitized_user_login, $user_email ) {
if (! preg_match('/( |^)[^ ]+@university\.edu( |$)/', $user_email )) {
$errors->add( 'invalid_email', __( 'ERROR: Only valid "university" email address is allowed.' ));
$user_email = '';
}
return $errors;
}
Registration will fail if email address is not from authorized domain and removes the need for sharing an authorization key, but the caveat is that their email address should be issued from a predictable domain.
But then again, adding an extra check (or modifying to check against the shared registration key) wouldn't be too hard using the above function
本文标签: Registration key
版权声明:本文标题:Registration key 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736293324a1929123.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论