Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment