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.

Yearly renewal of free membership? (continued

Home Forums Community Forum Yearly renewal of free membership? (continued

This topic contains 5 replies, has 2 voices. Last updated by  Cristián Lávaque 4 years, 8 months ago.

Topic Author Topic
Posted: Monday Apr 23rd, 2012 at 5:03 pm #11637

This is a follow up of this pre-sale topic:

Know i know a bit more about S2 Member Pro options, the current installation, and the functions i want to have.

The current installation have +1000 registered users all with BuddyPress Extended Profile Fields. The goal is to keep access to these fields and implement S2 Membership handling.
When Cristián ( answered my pre-sale question he was not informed about BuddyPress so the solution with Pay Pal Pro Forms would have worked out. But if i want to keep BuddyPress normal registration and the existing Extended Profile Fields i cant get the pro-forms to work out for me. (i cant have the BuddyPress extended profile fields and S2 Member extra profile fields at the same time)
Is this correct?

Installation environment is:
– WP 3.3.2
– BuddyPress 1.5.5
– bbPress 2.0.2 for sitewide forum functionality

This is what i would like to solve:
1. When a new user registers for free (using BuddyPress normal registration) EOT date i set to last day of current year and the role ‘s2member_level1’ is set.
2. When the user logs in during the ‘s2member_level1’ period the user is redirected to the site home page (not the login welcome page).
3. On EOT the user is demoted to level 0 ‘Subscriber’ and on the first login after EOT the user is redirected to a page with a link that says ‘Give me free membership for one more year’. If that link is clicked a page is loaded and a script is run that sets a new EOT date and sets the role back to ‘s2member_level1’.

So… I read many topics in these forums and wached the videos. This is what i came up with.
– Changed the role ‘subscriber’ so posting in forums is not allowed.
– Created a plugin (will move to s2hacks.php in mu-plugins directory later). The plugin code contains this code (warning for cowboy coding):

/*    Plugin Name: S2 Member Update Member Addon
Plugin URI:
Description: Plugin for setting a role and EOT to a new registered user and redirect to renewpage when EOT occurs.
Author: Torbjörn Sjögren
Version: 1.0
Author URI:

// Sets role and EOT on first login
function set_role_and_eot_first_login () {
 if ( (S2MEMBER_CURRENT_USER_LOGIN_COUNTER == 1) && (current_user_can("subscriber")) ) {
// Set EOT
 //update_user_option(get_current_user_id(), 's2member_auto_eot_time', strtotime('+2 minutes')); // Short time to test demotion
 update_user_option(get_current_user_id(), 's2member_auto_eot_time', strtotime(date('Y') .      '-12-31')); //Set EOT to last day of current year

 //Set role
 $user = new WP_User(get_current_user_id());
 } // end if
} // End function

add_action( 'wp_footer', 'set_role_and_eot_first_login' );

// If user is demoted or role 'subscriber' redirect to renew membership page.

function my_login_function(){
 if (current_user_can("subscriber")) {

Then i created two pages to handle the member upgrade:
Page one: ‘Renew membership’. A page where the user i redirected to. On that page a link that says ‘Renew my membership one more year’ that link loads page two
Page two: ‘Membership renewed’. This page holds the code below (php execution plugin activated) that upgrades the user from ‘subscriber’ to ‘s2member_level1’ and sets EOT time to last day of current year.

// Renew membership for current user

// If user is subscriber set user to s2member_level1

if (current_user_can("subscriber")) {

//Set role

$user = new WP_User(get_current_user_id());


// Set the membership time. When the time expires the member gets role 'subscriber'

update_user_option(get_current_user_id(), 's2member_auto_eot_time', strtotime(date('Y') . '-12-31'));// Last day of current year

// Shorter time for testing

//update_user_option(get_current_user_id(), 's2member_auto_eot_time', strtotime('+2 minutes')); // Test two minutes

// Message on success

echo 'Your membership is now renewed';

}// end if

– The set new role and EOT on first login works great = Check
– The redirect after demotion dosen´t work = Fail
– The renewal of membership (when page ‘Membership Renewed’ loads) works great = Check

When a user logs in, the login welcome page is not loaded. Instead the home page is loaded. This is OK for me but i wonder why this is?
The code that redirects the demoted user don’t work (the user is not redirected). Instead the home page loads. Please provide code to solve this.

Alternative solution?:
Maybe there is a much more simpe solution to this situation. If so please advice and provide instructions.

List Of Topic Replies

Viewing 5 replies - 1 through 5 (of 5 total)
Author Replies
Author Replies
Posted: Tuesday Apr 24th, 2012 at 5:33 am #11667

Try current_user_can(‘subscriber’) or current_user_is(‘subscriber’). That may be the problem with your redirection.

This video may help with the Login Welcome page problem: Video » s2Member (Login Welcome Page Conflicts?)

Posted: Tuesday Apr 24th, 2012 at 10:37 am #11694

Tried varius tricks and its not working out for me (regarding) redirection. Please advice. I can send links and login if needed.

Posted: Tuesday Apr 24th, 2012 at 2:20 pm #11721

OK, try “s2member_level0” instead of “subscriber” for the role.

Posted: Tuesday Apr 24th, 2012 at 5:10 pm #11758

Its not working.

Please confirm this code that i try to use. The code is moved to mu-plugins s2-hacks.php and the same code is in the inactive plugin.

In login welcome page setting i have the site hompage selected in Special Redirection URL field.

function my_login_function(){
	//if (current_user_can("subscriber")) {
	if (current_user_can("s2member_level0"))
Posted: Tuesday Apr 24th, 2012 at 8:56 pm #11788

Hmm… OK, I’m not sure what the problem is, but next thing I’d try is having the conditional in the Login Welcome page itself, with a JavaScript redirection. Something like:

[hilite pre_code]
[[s2If current_user_is(s2member_level0)]

* I haven’t tested it, it’s an idea for you to explore. If it doesn’t work with the shortcodes, do it with a PHP conditional.

I hope it helps. :)

Viewing 5 replies - 1 through 5 (of 5 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.