Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimcoleman/67e7f97021d6d61f1b29bc572a63c2aa to your computer and use it in GitHub Desktop.
Save kimcoleman/67e7f97021d6d61f1b29bc572a63c2aa to your computer and use it in GitHub Desktop.
Redirect members on login to a specific page based on their level.
<?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 );
@laurenhagan0306
Copy link

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment