Add a field on your registration form
<label for="secret_reg_code">Secret Code: </label>
<input type="text" name="secret_reg_code" id="secret_reg_code" value="" />
then in your plugin file or in function.php add
define('MY_SECRET_REG_CODE', 'fdsfgadsfgdf');
function check_for_reg_secret_code($errors, $sanitized_user_login, $user_email) {
if (
defined('MY_SECRET_REG_CODE') &&
trim($_POST['secret_reg_code']) != MY_SECRET_REG_CODE
) {
$errors->add(
'secret_code_error',
__('<strong>ERROR</strong>: Enter a valid code postal code.', 'your_text_domain')
);
}
return $errors;
}
add_filter('registration_errors', 'check_for_reg_secret_code', 10, 3);
A more ‘flexible’ way is use WP Settings Api to create an option ‘secret_reg_code’ where to store the secret code and then the function became:
function check_for_reg_secret_code($errors, $sanitized_user_login, $user_email) {
$code = get_option('secret_reg_code');
if ( $code && trim($_POST['secret_reg_code']) != $code) {
...
In this way is easy change code periodically.
For more details see Codex for registration_errors
filter hook
Edit
To add the field on the standard registration form is possible to use the register_form
hook:
function add_secret_code_registration_field() {
?>
<p>
<label for="secret_reg_code">Secret Code<br />
<input type="text" name="secret_reg_code" id="secret_reg_code" class="input" value="" size="25" /></label>
</p>
<?php
}
add_action('register_form','add_secret_code_registration_field');