2012-09-10 306 views
-2

我已經按照下面描述的方式使用了這個掛鉤,可能會出現什麼問題?Login_redirect掛鉤不能正常工作

class my_plugin { 

    function __construct() 
    { 
     parent::__construct(); 

     var_dump(__LINE__); // run 
     add_filter('login_redirect', array($this, 'login_redirect')); 
    } 

    function login_redirect() 
    { 
     var_dump(__LINE__); // not run 
    } 

} 

EDIT 1

hook此運行後成功登錄過程。正如我所說我已經在另一個插件中使用了這個鉤子。問題是什麼可能導致這種故障?

+0

必須看到更多代碼我在想。 – Jeremy1026

回答

1

好吧,明白了。

爲了記錄在案:

可以肯定的是能幫助別人。事實上,我前段時間遭受同樣的原因引發了一個問題:is_admin()不正確使用:

簡化版代碼:

if (is_admin()) 
{ 
    // block 1 
    // 
    // run admin classes 
    // including my_plugin class 
    // that includes login_redirect hook // WRONG! 
} 
else 
{ 
    // block 2 
    // 
    // run frontend classes 
} 

login_redirect鉤不管理頁面(is_admin()條件)

內運行解決方案:將login_redirect掛鉤移動到前端塊

+1

那麼你會看看,這個問題在你最初提供的代碼之外撒謊。很高興你能弄明白。 – Jeremy1026

+0

@ jeremy1026男人放輕鬆。我想你會說!大聲笑我不能把所有的WP代碼放在這裏,對吧?這就是爲什麼我告訴你,當你知道我在說什麼時(你的個人資料中有0個WP標籤),請求更多的代碼。 –

+0

@ jeremy1026請撤銷downvote,好嗎?沒有理由。這個問題對其他WP編碼器非常有用。我對此非常肯定。和平... –