Arrow

redirect based on roles | Peter's Login Redirect | Forum

Back to the login redirect plugin page

Please consider registering
guest

Log In

Lost password?
Advanced Search

— Forum Scope —

  

— Match —

   

— Forum Options —

   

Minimum search word length is 4 characters - maximum search word length is 84 characters

Topic RSS
redirect based on roles
February 2, 2012
11:58 am
creo
Guest

ok I'm ready to punch my monitor. I have been trying to tackle this all day but can't figure out what I'm doing wrong.

I have install the redirect plugin and want to redirect based on roles. I have set up two roles "employee" and "vendor" and want to redirect each to their appropriate page after logging in.

I'm using the WP-member plugin for users to register. Once registered I have assigned them a role.

When I log in as a registered user it keeps me on the login page and says I'm logged in... it doesn't redirect to the page I had specified in the setup.

If enter in a URL for the ALL USERS log out function.. that seems to work when I log out.

Any idea where I should be looking to correct the redirect based on roles?

February 2, 2012
3:36 pm
Peter
Admin
Forum Posts: 841
Offline

Sorry to hear about your troubles. I have tested this on your site by logging in through the admin panel and the redirect was performed successfully. It of course fails when logging in through the front-end. I would suggest getting support from your theme provider as it looks like they are hooking into the login redirect action and "hijacking" the behavior.

February 2, 2012
3:42 pm
Peter
Admin
Forum Posts: 841
Offline

You could also do a test by modifying this line near the bottom of my plugin and setting the second parameter to 1 instead of 10:

add_filter( 'login_redirect', 'redirect_wrapper', 10, 3 );

However, if the theme also tries to take the highest priority, it might still win out.

February 6, 2012
6:37 am
creo
Guest

Ok I contacted my theme support and they have run some tests and determined that is not the theme causing the issues,,, it is the plugin WP-Members. Below is the message I had received from them.
I'm not sure if there is a way to disable the redirect and let your Plugin handle the redirect.

____________________

In the end it wasn't our theme causing the redirect issue with the "Peters Login Redirect" plugin, but instead it was the "WP Members" plugin causing the issue.

If you open up the following file on your server wp-members/wp-members-dialogs.php and go to line # 794 you'll see the input field:

';

This input field gets outputted on the login form on your homepage.

When I viewed source on your homepage I noticed that the input field value was blank:

Now if you open up the following file on your server plugins/wp-members/wp-members-core.php and go to line # 367 - 370 you'll see the following code:

$redirect_to = $_POST['redirect_to'];
if (!$redirect_to) {
$redirect_to = $_SERVER['PHP_SELF'];
}
This code is saying if the $_POST['redirect_to'] field is empty set the $redirect_to variable to $_SERVER['PHP_SELF'] which means redirect to the page you're on.

The line of code that handles the redirect is on line # 386 in the same file:

wp_redirect($redirect_to);

This is why the "Peters Login Redirect" plugin isn't working.

February 6, 2012
7:29 am
Peter
Admin
Forum Posts: 841
Offline

As a quick fix, you can replace the lines you referenced (367 to 370) with:

$redirect_to = apply_filters('login_redirect', $redirect_to, isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '', $user);

For future maintainability, though, since they are bypassing the standard login_redirect WordPress hook, I'd suggest having them implement a similar mechanism into future releases.

February 16, 2012
10:56 am
Andrew Cartmill
Guest

I'm having the same issue with wp-members, but the prescribed solution of replacing likes 367-370 didn't work for me, and ends up breaking my redirect entirely (the page doesn't load, but it does show the correct url in the address bar)..

any idea why?

Andrew

February 16, 2012
11:02 pm
Peter
Admin
Forum Posts: 841
Offline

It's likely most efficient for the wp-members creators to use the standard login_redirect hook. Unfortunately I don't know the inner-workings of their plugin well enough to suggest a more sophisticated workaround.

March 29, 2012
12:29 pm
mortenmr
Guest

I have the same problem, but looks like the code have been rewritten since this workaround was posted. I'm not too familiar with writing code, so I very thankful if you could have a look at it;

Lines 819-847:
function wpmem_login()
{
if( isset( $_POST['redirect_to'] ) ) {
$redirect_to = $_POST['redirect_to'];
} else {
$redirect_to = $_SERVER['PHP_SELF'];
}
$redirect_to = apply_filters( 'wpmem_login_redirect', $redirect_to );
if( isset( $_POST['rememberme'] ) == 'forever' ) {
$rememberme = true;
} else {
$rememberme = false;
}
Surprised