[英]registration_redirect Not working in plugin file
我想在注册后将用户重定向到OTP验证页面。 我在主题的functions.php中使用了以下代码来实现此功能,但效果很好,但是当我在自定义插件文件中使用此代码时,则无法正常工作。
add_filter( 'registration_redirect', 'wpesov_registration_redirect' );
function wpesov_registration_redirect() {
return home_url( '/otp-verification');
}
我需要在插件中更改什么,或者我缺少什么?
TIA
我认为您的问题是在wordpress可以使用其内容之前加载了插件文件。
如果您在这样的主插件文件中使用class:
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' ) );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.