Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Description:

I'm using a WordPress plugin that applies specific redirects after logging in based on users and roles.

The problem:

  • I'm using a sidebar widget to allow users to log in on blog and forum (bbPress) pages.
  • This widget doesn't have a perceptible redirect (stays on the same page).
  • The plugin applies a redirect to this widget. I don't want it to.

Information:

This is the documentation on how to extend the plugin: http://wordpress.org/extend/plugins/peters-login-redirect/other_notes/

It uses the following filters:

rul_before_user
rul_before_role
rul_before_capability
rul_before_fallback

...and the following variable for each:

$empty
$redirect_to
$requested_redirect_to
$user

I'm using bbPress 2.0 as a plugin for WordPress. The log-in widget comes with this.

An example:

This code shows how to write custom redirect logic for the plugin I'm using:

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 );

I'm not sure how to manipulate this condition for it to read:

if (user has logged in using sidebar widget){
Keep on same page;
}
else{
Redirect the user as usual;
}

My question(s):

  • How do I set my log-in widget to ignore the redirect being applied by the plugin?
  • Should I try to achieve this by tackling bbPress or the plugin?
  • Any ideas on how to edit the above example?
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Answer:

I've figured this out myself.

Add the following code to your theme's functions.php file:

// 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 );

This will effectively disable the plugin's redirect settings anytime a user logs in from a forum or blog page. The standard wp-login.php page will inherit the plugin's redirect settings.

You can find a detailed explanation of the code at my blog:

http://www.dominornovus.com/2011/11/14/restrict-peters-login-redirect-to-same-page-redirection/

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.