在注册表上添加字段
<label for="secret_reg_code">Secret Code: </label>
<input type="text" name="secret_reg_code" id="secret_reg_code" value="" />
然后在插件文件或函数中。php添加
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);
更“灵活”的方法是使用
WP Settings Api 要创建一个选项“secret\\u reg\\u code”,用于存储密码,然后函数变为:
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) {
...
这样就很容易定期更改代码。
有关更多详细信息,请参阅Codex for registration_errors
filter hook
编辑以在标准注册表上添加字段,可以使用register_form
钩子:
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\');