描述:
我正在使用WordPress插件,该插件在登录后根据用户和角色应用特定重定向。
它使用以下过滤器:
rul_before_user
rul_before_role
rul_before_capability
rul_before_fallback
。。。以及每个变量的以下变量:
$empty
$redirect_to
$requested_redirect_to
$user
我正在使用bbPress 2.0作为WordPress的插件。登录小部件附带此功能。
例如:
这段代码显示了如何为我使用的插件编写自定义重定向逻辑:
function redirectByIP( $empty, $redirect_to, $requested_redirect_to, $user )
{
$ip_check = \'192.168.0\';
if( 0 === strpos( $_SERVER[\'REMOTE_ADDR\'], $ip_check ) )
{
return \'/secret_area\';
}
else
{
return false;
}
}
add_filter( \'rul_before_user\', \'redirectByIP\', 10, 4 );
我不确定如何操纵此条件以使其读取:
if (user has logged in using sidebar widget){
Keep on same page;
}
else{
Redirect the user as usual;
}
我的问题:如何设置登录小部件以忽略插件应用的重定向我应该通过解决bbPress或插件来实现这一点吗关于如何编辑上述示例,您有什么想法吗
最合适的回答,由SO网友:Dominor Novus 整理而成
回答:
我自己就知道了。
将以下代码添加到主题的函数中。php文件:
// Plugin by http://wordpress.org/extend/plugins/peters-login-redirect/
// Solution by http://www.dominornovus.com
function login_widget_redirect( $empty, $redirect_to, $requested_redirect_to, $user )
{
// If the referring page contains "/forums/"...
if (stripos($_SERVER[\'HTTP_REFERER\'],\'/forums/\') !== false)
{
$referringpage = $_SERVER[HTTP_REFERER];
return $referringpage;
}
//Otherwise, check the referring page contains "/blog/"...
else if (stripos($_SERVER[\'HTTP_REFERER\'],\'/blog/\') !== false)
{
$referringpage = $_SERVER[HTTP_REFERER];
return $referringpage;
}
// Otherwise, default to the plugin\'s redirect settings...
else
{
return false;
}
}
add_filter( \'rul_before_user\', \'login_widget_redirect\', 10, 4 );
这将在用户从论坛或博客页面登录时有效禁用插件的重定向设置。标准wp登录。php页面将继承插件的重定向设置。
您可以在我的博客上找到代码的详细解释:
http://www.dominornovus.com/2011/11/14/restrict-peters-login-redirect-to-same-page-redirection/