This is a follow up of this pre-sale topic:
http://www.s2member.com/forums/topic/yearly-renewal-of-free-membership/#post-11364
Scope:
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 (http://www.s2member.com/forums/users/cristian/) 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: http://twoway.se
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: http://twoway.se
*/
// 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());
$user->set_role("s2member_level1");
} // 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")) {
wp_redirect(site_url('/fornya-medlemsskap'));
}
}
//add_action('ws_plugin__s2member_during_login_redirect','my_login_function');
add_action('wp_header','my_login_function');
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());
$user->set_role("s2member_level1");
// 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
Result:
– 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
Problem:
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.