Created
March 19, 2018 08:55
-
-
Save andrewlimaza/2321f87a321aa064fb1583c74a5b0dc3 to your computer and use it in GitHub Desktop.
First Time Login Redirect For Paid Memberships Pro
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 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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment