2017-02-21 36 views
0

我想將用戶重定向到OTP驗證 n註冊後的頁面。我在我的主題的functions.php中使用了以下代碼,但它在我的自定義插件文件中使用此代碼時無法正常工作。registration_redirect在插件文件中不工作

add_filter('registration_redirect', 'wpesov_registration_redirect'); 

function wpesov_registration_redirect() { 

     return home_url('/otp-verification'); 

    } 

我應該在我的插件中更改哪些內容或者我缺少什麼?

TIA

回答

0

我覺得你的問題是之前的WordPress可以用它的工作內容加載的插件文件。

如果使用類的主要插件文件是這樣的:

class my_plugin 
{ 

    public static function init() { 
     $class = __CLASS__; 
     new $class; 
    } 

    function __construct() { 
     add_filter('registration_redirect', array($this, 'wpesov_registration_redirect')); 
    } 

    public function wpesov_registration_redirect() { 
     return home_url('/otp-verification'); 
    } 
} 

add_action('plugins_loaded', array('my_plugin', 'init')); 

並正確加載,那麼你應該添加的功能插件類的方法,並在構造函數中註冊過濾器。有不同的方法可以初始化你的插件,因爲我不知道你正在使用哪一個,所以我無法進一步提供幫助。嘗試實現上面的代碼,或者如果它不起作用或你的init不同,可以在這裏發佈你的主要插件文件結構。

編輯:或添加靜態方法到您的插件類,外註冊過濾器:

class my_plugin 
{ 

    public static function init() { 
     $class = __CLASS__; 
     new $class; 
    } 

    public static function wpesov_registration_redirect() { 
     return home_url('/otp-verification'); 
    } 
} 
// init plugin 
add_action('plugins_loaded', array('my_plugin', 'init')); 

// init registration_redirect hook 
add_filter('registration_redirect', array('my_plugin', 'wpesov_registration_redirect')); 
+0

嘗試過,但直到沒有奏效。會有什麼問題? –

+0

正如我質疑 - 你確定該文件已加載並正在執行代碼?例如。如果你把回聲「嗨」;它會打印在網站頁面上? – keyBeatz

+0

如果可以的話,您可以在註冊表單中添加'',這應該始終有效。 – keyBeatz