Forked from andrewlimaza/first-time-login-redirect.php
Created
April 10, 2018 03:14
-
-
Save travislima/19eaede715b49a8fff2569f027e18000 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 ); |
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
Hi! Can you tell me how i changed this code for login, not only first login?
Thanks!