Login Redirect Users Registered Before X Date | Peter's Login Redirect | Forum
Back to the login redirect plugin page
8:45 am
I have an event website that uses a Gravity Forms registration form to gather information, collect a registration fee, and create a username and password for my site. Once the form is submitted, they become a logged in site user. This works great for new users but I was having a problem with users who joined last year's event because they were able to bypass the registration form by logging in using their existing login info from last year and they weren't being sent to the registration form.
I've created a registration renewal form, that doesn't register them as a site user, and I'd like to redirect existing users to that form when they press "submit" from the login screen. I don't want new users to be redirected there when they login. I read your post: http://www.theblog.ca/wordpres.....irst-login and I'm wondering how I can accomplish the opposite of what you wrote here:
use a date-based check so that all registered users before a certain date are ignored
I'm trying to ignore all registered users after a certain date and only focus on those that were registered last year.
Hope that wasn't confusing.
Thanks!
12:11 pm
Wow! Thanks Peter, that was fast! I'm obviously making a stupid mistake because I'm getting the following error :-/
Fatal error: Cannot redeclare redirectOnFirstLogin() (previously declared in /home/content/58/8803458/html/wp-content/plugins/peters_redirect_first_login_meta/peters_redirect_first_login_meta.php:11) in /home/content/58/8803458/html/wp-content/themes/JeremysJump/functions.php on line 112
Here's my code:
function redirectOnFirstLogin( $redirect_to, $requested_redirect_to, $user )
{
// URL to redirect to
$redirect_url = 'http://myrealurlhere.com/renew-registration';
// How many times to redirect the user
$num_redirects = 1;
// If they're on the login page, don't do anything
// if( !isset( $user->user_login ) )
// {
// return $redirect_to;
// }
$key_name = 'redirect_on_first_login';
// Third parameter ensures that the result is a string
$current_redirect_value = get_user_meta( $user->ID, $key_name, true );
if( strtotime( $user->user_registered ) < ( mktime( 0, 0, 0, 1, 1, 2014 ) )
&& ( '' == $current_redirect_value || intval( $current_redirect_value ) < $num_redirects )
)
{
if( '' != $current_redirect_value )
{
$num_redirects = intval( $current_redirect_value ) + 1;
}
update_user_meta( $user->ID, $key_name, $num_redirects );
return $redirect_url;
}
else
{
return $redirect_to;
}
}
add_filter( 'login_redirect', 'redirectOnFirstLogin', 10, 3 );