WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


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.


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:


...and the following variable for each:


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';
        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;
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
up vote 0 down vote accepted


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...
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:


share|improve this answer

Your Answer


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.