Skip to content

Instantly share code, notes, and snippets.

@pbrocks
Created June 28, 2018 16:36
Show Gist options
  • Save pbrocks/b8a1a9122de3234dc7190eb3f5c15c8e to your computer and use it in GitHub Desktop.
Save pbrocks/b8a1a9122de3234dc7190eb3f5c15c8e 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.
<?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