Created
May 21, 2025 10:23
-
-
Save ipokkel/b3f314e1ffb471135cf70647d666e24f to your computer and use it in GitHub Desktop.
Redirect old members to the membership account page on login.
This file contains hidden or 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 old members to the membership account page on login. | |
* | |
* 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_old_members_to_membership_account( $redirect_to, $request, $user ) { | |
// Is PMPro active? | |
if ( ! function_exists( 'pmpro_url' ) ) { | |
return $redirect_to; | |
} | |
// Redirect old members to the membership account page. | |
if ( ! pmpro_hasMembershipLevel() && ! empty( pmpro_getMembershipLevelsForUser( $user->ID, true ) ) ) { | |
$redirect_to = pmpro_url( 'account' ); | |
} | |
return $redirect_to; | |
} | |
add_filter( 'login_redirect', 'my_login_redirect_old_members_to_membership_account', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment