Forked from pbrocks/customize-pmpro-login-redirect-url.php
Created
July 1, 2018 00:03
-
-
Save itsjusteileen/6b421bc3784cdf05b1778eba950e92d1 to your computer and use it in GitHub Desktop.
Redirect your members based on their PMPro subscription level. If any users aren't members, the site's home url is returned.
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 | |
/** | |
* customize_pmpro_login_redirect_url Creates conditions for each level to have its own confirmation URL | |
* | |
* @param [type] $return_url Different URL for each level | |
* @param [type] $request URL the user is coming from, ie login url. | |
* @param [type] $user user data | |
* @return [type] The URL of the level for user logging in | |
*/ | |
function customize_pmpro_login_redirect_url( $return_url, $request, $user ) { | |
// is there a user to check? If user exists, we can check levels | |
if ( ! empty( $user->ID ) ) { | |
if ( pmpro_hasMembershipLevel( 1, $user->ID ) ) { | |
$return_url = home_url( 'level-one' ); | |
} elseif ( pmpro_hasMembershipLevel( 2, $user->ID ) ) { | |
$return_url = home_url( 'level-two' ); | |
} elseif ( pmpro_hasMembershipLevel( 3, $user->ID ) ) { | |
$return_url = home_url( 'level-three' ); | |
} | |
return $return_url; | |
} | |
return home_url(); | |
} | |
add_filter( 'login_redirect', 'customize_pmpro_login_redirect_url', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment