Absolutely YES, 你可以做到这一点。
Rule 1: WordPress需要用户名。我们必须提供用户名。
Rule 2: 不要编辑WordPress核心代码。
我们可以通过隐藏用户名字段、获取电子邮件并将其存储为用户名来实现这一点。
Step-1: Remove Username textfield
add_action(\'login_head\', function(){
?>
<style>
#registerform > p:first-child{
display:none;
}
</style>
<script type="text/javascript" src="<?php echo site_url(\'/wp-includes/js/jquery/jquery.js\'); ?>"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
$(\'#registerform > p:first-child\').css(\'display\', \'none\');
});
</script>
<?php
});
Step-2: Remove Username error
//Remove error for username, only show error for email only.
add_filter(\'registration_errors\', function($wp_error, $sanitized_user_login, $user_email){
if(isset($wp_error->errors[\'empty_username\'])){
unset($wp_error->errors[\'empty_username\']);
}
if(isset($wp_error->errors[\'username_exists\'])){
unset($wp_error->errors[\'username_exists\']);
}
return $wp_error;
}, 10, 3);
Step-3: Manipulate Background Registration Functionality.
add_action(\'login_form_register\', function(){
if(isset($_POST[\'user_login\']) && isset($_POST[\'user_email\']) && !empty($_POST[\'user_email\'])){
$_POST[\'user_login\'] = $_POST[\'user_email\'];
}
});
将以上代码放入主题中
functions.php 文件
You can also download a complete plugin to achieve this.
插件:
https://wordpress.org/plugins/smart-wp-login/