2017-07-07 77 views

回答

3

YES,就可以實現這一點。

規則1: WordPress需要用戶名。我們必須提供一個用戶名。

規則2:不要編輯WordPress核心代碼。

我們可以通過隱藏用戶名字段,獲取電子郵件並將其存儲爲用戶名來實現此目的。

步驟-1:刪除用戶名文本框

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 
}); 

步驟2:刪除用戶名錯誤

//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); 

步驟3:操縱背景註冊功能。

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的文件把上面的代碼。