2015-11-25 53 views
1

我有一個自定義WP註冊腳本,很好地工作,雖然我不能讓它自動登錄用戶。我可以確認它會創建用戶配置文件。我也嘗試過觸發wp_signon()而沒有運氣。有什麼建議麼?自定義註冊後WordPress自動登錄

<?php 
function complete_registration() { 
    global $reg_errors, $username, $password, $email; 
    if (1 > count($reg_errors->get_error_messages())) { 
     $data = array(
      'user_login' => $username, 
      'user_email' => $email, 
      'user_pass'  => $password 
     ); 
     $user = wp_insert_user($data); 

     if(!is_wp_error($user)) 
      wp_set_current_user($user); 
      wp_set_auth_cookie($user); 
    } 
} 
?> 
+0

這你有什麼功能,你用什麼動作連接到它? – Ohgodwhy

+0

它是一些功能的一部分,但最終它被稱爲短代碼: add_shortcode('user_registration','user_registration_function'); function user_registration_function(){ ob_start(); custom_registration_function(); return ob_get_clean(); } –

+0

對不起,在custom_registration_function()中,它會清理表單信息並將其傳遞給complete_registration()函數。 –

回答

1

函數在執行鏈中觸發得太晚。

0

有自定義登記表同樣的功能從this tutorial並希望使用相同的選項自動登錄其不也是工作,因爲頁面頭部已經發送..所以只需添加此代碼,它會運行

add_action('init', 'custom_registration_shortcode');