Created
June 13, 2018 23:55
-
-
Save pbrocks/860f308f53fed5f3d8bdbc920289d12c to your computer and use it in GitHub Desktop.
Replacement redirect for logins after TML update. This recipe will redirect PMPro admins to dashboard reports, single out subscribers to go to the Account page and everyone else to the Invoice page.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Redirect user based on user role after successful login. | |
* | |
* $pmpro_pages returns an array: | |
* * $pmpro_pages['account'] | |
* * $pmpro_pages['billing'] | |
* * $pmpro_pages['cancel'] | |
* * $pmpro_pages['checkout'] | |
* * $pmpro_pages['confirmation'] | |
* * $pmpro_pages['invoice'] | |
* * $pmpro_pages['levels'] | |
* | |
* @param string $redirect_to URL to redirect to. | |
* @param string $request URL the user is coming from. | |
* @param object $user Logged user's data. | |
* @return string | |
*/ | |
function replacement_login_redirect( $redirect_to, $request, $user ) { | |
global $pmpro_pages; | |
// is there a user to check? | |
if ( isset( $user->roles ) && is_array( $user->roles ) ) { | |
if ( in_array( 'administrator', $user->roles ) ) { | |
// redirect them to dashboard reports page | |
$redirect_to = admin_url( 'admin.php?page=pmpro-reports' ); | |
} | |
// check for subscribers | |
elseif ( in_array( 'subscriber', $user->roles ) ) { | |
// redirect them to account page | |
$redirect_to = get_permalink( $pmpro_pages['account'] ); | |
} else { | |
// redirect them to account page | |
$redirect_to = get_permalink( $pmpro_pages['invoice'] ); | |
} | |
} | |
return $redirect_to; | |
} | |
add_filter( 'login_redirect', 'replacement_login_redirect', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment