Created
May 17, 2020 13:53
-
-
Save kimcoleman/67e7f97021d6d61f1b29bc572a63c2aa to your computer and use it in GitHub Desktop.
Redirect members on login to a specific page based on their level.
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 members on login to a specific page based on their level. | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
* | |
*/ | |
function my_login_redirect_per_membership_level( $redirect_to, $request, $user ) { | |
//is there a user to check? | |
if ( ! empty( $user->ID ) ) { | |
//check level | |
if ( pmpro_hasMembershipLevel( 1, $user->ID ) ) { | |
return home_url( '/level-one/'); | |
} elseif ( pmpro_hasMembershipLevel( 2, $user->ID ) ) { | |
return home_url( '/level-two/' ); | |
} elseif ( pmpro_hasMembershipLevel( 3, $user->ID ) ) { | |
return home_url( '/level-three/' ); | |
} else { | |
return home_url(); | |
} | |
} | |
} | |
add_filter( 'login_redirect', 'my_login_redirect_per_membership_level', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This recipe is included in the blog post on "Redirect Members to Pages Based on Their Level" at Paid Memberships Pro here: https://www.paidmembershipspro.com/redirect-members-to-pages-based-on-their-level/