Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save travislima/19eaede715b49a8fff2569f027e18000 to your computer and use it in GitHub Desktop.
Save travislima/19eaede715b49a8fff2569f027e18000 to your computer and use it in GitHub Desktop.
First Time Login Redirect For Paid Memberships Pro
<?php
/**
* Redirect a member for first time login.
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
* www.paidmembershipspro.com
*/
function first_time_login_redirect( $redirect_to, $request, $user ) {
//check level
if ( ! empty( $user ) && ! empty( $user->ID ) && function_exists( 'pmpro_getMembershipLevelForUser' ) ) {
$first_login = get_user_meta( $user->ID, 'first_login', true );
if ( $first_login == 'no' ) {
return $redirect_to;
}
$level = pmpro_getMembershipLevelForUser( $user->ID );
// Change case 'x': to level ID and $redirect_to URL to redirect the user on first login.
switch ( $level->ID ) {
case '1':
update_user_meta( $user->ID, 'first_login', 'no' );
$redirect_to = home_url();
break;
case '2':
update_user_meta( $user->ID, 'first_login', 'no' );
$redirect_to = home_url( '/page-slug-2' );
break;
case '3':
update_user_meta( $user->ID, 'first_login', 'no' );
$redirect_to = home_url( '/page-slug-3' );
break;
}
}
return $redirect_to;
}
add_filter( 'login_redirect', 'first_time_login_redirect', 15, 3 );
@ClickEli
Copy link

Hi! Can you tell me how i changed this code for login, not only first login?
Thanks!

@laurenhagan0306
Copy link

This recipe is included in the blog post on "Redirect new members to a specific page the first time they log in." at Paid Memberships Pro here: https://www.paidmembershipspro.com/redirect-new-members-to-a-specific-page-the-first-time-they-log-in/

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