我使用此基本方法来启用电子邮件登录,类似于另一个答案,但我认为首先测试更干净:
add_filter( \'authenticate\', \'custom_allow_email_login\', 20, 3);
function custom_allow_email_login( $user, $username, $password )
{
if ( is_email($username) )
{
$user = get_user_by_email( $username );
if ( $user ) $username = $user->user_login;
}
return wp_authenticate_username_password( null, $username, $password );
}
不幸的是,如果您想更改表单上的标签,您必须使用Javascript或使用自己的可自定义表单创建自己的登录页面。
使用Javascript:
add_action( \'login_enqueue_scripts\', \'custom_login_enqueue_scripts\' );
function custom_login_enqueue_scripts()
{
wp_enqueue_script(\'jquery\');
}
add_action( \'login_form\', \'custom_change_username\' );
function custom_change_username()
{
echo "\\n" . \'
<script type="text/javascript">
jQuery(document).ready(function($) {
$("label").html(function(index,html){
return html.replace("Username", "Username or Email");
});
});
</script>\' . "\\n";
}
您可以使用
wp_login_form 在您自己的页面上包含登录表单。