latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Temporary One Time Use Customer Login

Home Forums Community Forum Temporary One Time Use Customer Login

This topic contains 4 replies, has 2 voices. Last updated by  Mike (Volunteer Moderator) 3 years, 5 months ago.

Topic Author Topic
Posted: Tuesday Jul 30th, 2013 at 10:30 pm #54434
leroy james
Username: leroy

List Of Topic Replies

Viewing 4 replies - 1 through 4 (of 4 total)
Author Replies
Author Replies
Posted: Wednesday Jul 31st, 2013 at 3:47 pm #54533
leroy james
Username: leroy

Since it seems like this might be a feature not many has asked for, is it possible to set up a login/password that one person can only use for 24 hours?

Posted: Thursday Aug 1st, 2013 at 1:43 pm #54622
Moderator

This would require some custom code.

Here’s an idea that perhaps you can build from; or get someone to help you with.

Please create this directory and file:
/wp-content/mu-plugins/s2-hacks.php
(NOTE: these are MUST USE plugins, see: http://codex.wordpress.org/Must_Use_Plugins)
(See also: http://www.s2member.com/kb/hacking-s2member/)

<?php
add_filter('wp_authenticate_user', 'check_login_status');
function check_login_status($user)
	{
		$identifying_prefix = 'lt_'; // Username prefix indicates it's for a limited time.
		
		if($user instanceof WP_User && stripos($user->user_login, $identifying_prefix) === 0)
			{
				$last_login_time = (integer)get_user_option('s2member_last_login_time', $user->ID);
				$total_previous_logins = (integer)get_user_option('s2member_login_counter', $user->ID);
				
				if($last_login_time || $total_previous_logins)
					return new WP_Error('expired', 'Sorry, your Username has expired.');
			}
		return $user; // Default passthrough.
	}

Another way (perhaps more secure); would be a CRON job that sets a flag against certain accounts after they have logged in for the first time. With that in place, you might have something like this variation of the above routine.

<?php
add_filter('wp_authenticate_user', 'check_login_status');
function check_login_status($user)
	{
		if($user instanceof WP_User && get_user_option('login_expiration_flag', $user->ID))
			return new WP_Error('expired', 'Sorry, your Username has expired.');

		return $user; // Default passthrough.
	}

Combine one of these techniques with a real-time check on every page as well; like this.

<?php
add_filter('init', 'check_login_status_while_on_site');
function check_login_status_while_on_site()
	{
		if(($user = wp_get_current_user()) && get_user_option('login_expiration_flag', $user->ID))
			wp_redirect(wp_login_url()).exit();
	}
Posted: Thursday Aug 1st, 2013 at 11:30 pm #54722
leroy james
Username: leroy

That’s pretty brilliant. I’ll do it and report back my results.

Posted: Sunday Aug 4th, 2013 at 6:40 pm #55136
Moderator

That’s pretty brilliant. I’ll do it and report back my results.

Thank you. I’ll appreciate any feedback :-)

Viewing 4 replies - 1 through 4 (of 4 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.