2014-03-14 106 views
1

在我的wordpress項目中,我爲用戶創建了一個前端登錄,當用戶輸入錯誤的登錄信息時,它必須將登錄失敗的附件重定向到url。下面的代碼首次執行此操作,然後在嘗試登錄時連續追加到網址。我如何限制此操作。wordpress登錄失敗的重定向url無法正常工作

add_action('wp_login_failed', 'my_front_end_login_fail'); 

    function my_front_end_login_fail($username){ 
     // Get the reffering page, where did the post submission come from? 
     $referrer = $_SERVER['HTTP_REFERER']; 

     // if there's a valid referrer, and it's not the default log-in screen 
     if(!empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin')){ 
      // let's append some information (login=failed) to the URL for the theme to use 


       wp_redirect($referrer . '&login=failed'); 

     exit; 
     } 

    } 

任何幫助,將不勝感激。

回答

1

試試這個代碼

add_action('wp_login_failed', 'my_front_end_login_fail'); 

    function my_front_end_login_fail($username){ 
     // Get the reffering page, where did the post submission come from? 
     $referrer = $_SERVER['HTTP_REFERER']; 



     // if there's a valid referrer, and it's not the default log-in screen 
     if(!empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin')){ 
      // let's append some information (login=failed) to the URL for the theme to use 

       ////already not login failed append 
       if(!strstr($referrer,'&login=failed')) 
       { 
       wp_redirect($referrer . '&login=failed'); 
       } 
       else 
       { 
       ////if alreday append go to same url 
       wp_redirect($referrer); 
       } 

     exit; 
     } 

    }