首先,我会advise against editing the core files 因为下次更新WordPress时它将被覆盖。
此外,您应该更新WordPress,因为它通常包含安全更新。(最近been reported 对使用过时WordPress版本的网站进行了大量攻击)
为了实现您真正想要做的事情,我建议您使用hooks 作为编辑WordPress的最佳方式。
因此,要在登录页面上创建额外字段,可以使用login_form
行动挂钩:
add_action(\'login_form\',\'my_added_login_field\');
function my_added_login_field(){
//Output your HTML
?>
<p>
<label for="my_extra_field">My extra field<br>
<input type="text" tabindex="20" size="20" value="" class="input" id="my_extra_field" name="my_extra_field_name"></label>
</p>
<?php
}
接下来,我们需要验证他们在字段中输入的内容是否与您存储的内容相匹配。在下面的代码中,我假设您已将标识码存储为带有元键的用户元值
my_ident_code
.
You should do this rather than create your own column!. 有关详细信息,请参阅Codex页面
add_user_meta
功能update_user_meta
功能get_user_meta
功能验证用户可以使用authenticate
滤器这将传递输入的用户名和密码。如果识别码正确,返回null
允许WordPress验证密码和用户名。如果不正确,请删除WordPress的身份验证并返回错误。这将强制用户返回到登录页面,在那里他们将看到显示的错误。add_filter( \'authenticate\', \'my_custom_authenticate\', 10, 3 );
function my_custom_authenticate( $user, $username, $password ){
//Get POSTED value
$my_value = $_POST[\'my_extra_field_name\'];
//Get user object
$user = get_user_by(\'login\', $username );
//Get stored value
$stored_value = get_user_meta($user->ID, \'my_ident_code\', true);
if(!$user || empty($my_value) || $my_value !=$stored_value){
//User note found, or no value entered or doesn\'t match stored value - don\'t proceed.
remove_action(\'authenticate\', \'wp_authenticate_username_password\', 20);
remove_action(\'authenticate\', \'wp_authenticate_email_password\', 20);
//Create an error to return to user
return new WP_Error( \'denied\', __("<strong>ERROR</strong>: You\'re unique identifier was invalid.") );
}
//Make sure you return null
return null;
}