redirect based on roles | Peter's Login Redirect | Forum
Back to the login redirect plugin page
11:58 am
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?
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.
6:37 am
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.
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.
12:29 pm
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;
}