Arrow

Login Redirect Users Registered Before X Date | Peter's Login Redirect | Forum

Back to the login redirect plugin page

Please consider registering
guest

Log In

Lost password?
Advanced Search

— Forum Scope —

  

— Match —

   

— Forum Options —

   

Minimum search word length is 4 characters - maximum search word length is 84 characters

Topic RSS
Login Redirect Users Registered Before X Date
August 12, 2014
8:45 am
fcvolunteer
Member
Forum Posts: 4
Offline

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!

August 12, 2014
9:38 pm
Peter
Admin
Forum Posts: 841
Offline

Hi, I think this should be possible by simply switching the comparison in the code examples in that post.

If you use the $user->user_registered timestamp, then you can make a comparison so that is less than a specific timestamp instead of greater than a specific timestamp.

August 15, 2014
11:37 am
fcvolunteer
Member
Forum Posts: 4
Offline

Hi Peter,

Thanks for the reply. Pardon my ignorance, I'm still a little confused about how to tweak the code. How do I get the message period to be a date instead of seconds? I need to make sure that it only redirects to my new registration form if the user has registered before 1/1/14?

Thanks!

August 15, 2014
11:44 am
Peter
Admin
Forum Posts: 841
Offline

Hi, you can build a date using PHP's mktime function.

Thus, your check can be something like this:

if( strtotime( $user->user_registered ) < mktime( 0, 0, 0, 1, 1, 2014 ) )

August 15, 2014
12:11 pm
fcvolunteer
Member
Forum Posts: 4
Offline

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:

// Send new users to a special page
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 );

August 15, 2014
12:34 pm
fcvolunteer
Member
Forum Posts: 4
Offline

I figured it out :-) I had installed the plugin as well so once I deleted it everything seems to work.

Thanks so much for the plugin and the code help!