Page 1 of 1

EOT Value Remains Post-Expiration?

PostPosted: June 10th, 2011, 4:45 pm
by adamarling
Hi,

I was wondering if there's any hack to trick to maintaining the EOT timestamp value associated with an s2Membership, once a Member's Membership has expired? Reason being, I have a need to run reports which pull 30-day, 60-day, etc....post expiration reports, and currently I'm having to create a decent amount of code to parse the Member Notes field in order to get the previous EOT date from the "Demoted on:..." line within a Member's Notes.

I've checked the EOT Behavior options, so maybe there is a hack?

thanks,
Adam

Also Last Payment Date affected

PostPosted: June 10th, 2011, 4:52 pm
by adamarling
Just noticed that the Last Payment Time value is also removed from the database when a Member is demoted by s2Member on their expiration date. I cannot find where this value is saved post-demotion (as opposed to being able to pull the EOT value from Member Notes mentioned above). Any ideas on how I could maintain this Last Payment Time value also?

Re: EOT Value Remains Post-Expiration?

PostPosted: June 14th, 2011, 12:56 am
by Cristián Lávaque
Hi Adam.

No, this is not logged by s2Member, but you could keep you own log using the EOT/Deletion Notification and a custom script to save the data. WP Admin -> s2Member -> API / Notifications -> EOT/Deletion Notification

I hope that helps.

Re: EOT Value Remains Post-Expiration?

PostPosted: June 16th, 2011, 1:23 pm
by adamarling
Hi Chritian,

Thanks again for your attention on this posting...

I put together an EOT script which attempts to write a Member's Last Payment Time & EOT to a new table I created, when s2members's Automatic EOT function demotes a member on their Expiration Date. However s2member's script demotes a Member (and erases the data I need) before I can pull the Last Payment Time ( s2member_last_payment_time ) variable and EOT Automatic variable ( s2member_auto_eot_time ) from the database. Note my attempted script below:

Code: Select all
<?
$wp_user_id = $_GET["wp_user_id"];
$eot_del_type = $_GET["eot_del_type"];

$user_data = get_userdata($user_id);

if (get_user_option("s2member_auto_eot_time", $user_id) == NULL) { $eot = '';}
else { $eot = date("Y-m-d", get_user_option("s2member_auto_eot_time", $user_id)); }

if (get_user_option("s2member_last_payment_time", $user_id) == NULL) { $lpd = '';}
else { $lpd = date("Y-m-d", get_user_option("s2member_last_payment_time", $user_id)); }

// insert Member's previous Last Payment Time & EOT values so I can access them post-demotion
$insertEOT = mysql_query("INSERT INTO expirations (id, wp_user_id, eot, lpd, eot_del_type) VALUES ('', $wp_user_id, '$eot', '$lpd', '$eot_del_type')") or die('Query failed: ' . mysql_error());               
       
?>


So my questions now would be:
1.) Are there any other s2member custom variable(s) which may hold these values post-demotion?
2.) Is there a way to call an EOT Automatic Notice script prior to the actual demotion? Like pre 1 day or pre 10 minutes or something?

Basically I'm trying to avoid storing Last Payment Time and EOT Automatic time in 2 separate database tables, so as to avoid confusion. It'd be awesome (for me at least) if EOT and Last Payment Time values existed forever until the same Member decided to pay for a subscription again.

I suppose I could write a script which would update a table I've created with Last Payment Date value when a Member pays (via the Notification script). And then update (in this same created table) an EOT value when the Member's term expires via the script I noted above. But just seems to me I'd be potentially storing the same data in 2 separate locations, which seems like could cause problems/confusion down the road.

Anyhow, if you have the time and see something that I'm just missing in s2Member's processing in a scenario like this, as always much appreciated.

thanks,
Adam

Re: EOT Value Remains Post-Expiration?

PostPosted: June 16th, 2011, 4:40 pm
by Cristián Lávaque
I looked at the code and found that you could keep the paid registration time using the filter ws_plugin__s2member_preserve_paid_registration_times. viewtopic.php?f=40&t=9557&src_doc_v=110605#src_doc_line_158

About the EOT, that's deleted and I didn't find a hook to prevent it, but s2Member makes a note with time of this, which you may be able to use. viewtopic.php?f=40&t=9557&src_doc_v=110605#src_doc_line_169

Code: Select all
$s2_notes = get_user_option('s2member_notes', $user_id); 


I hope that helps.

Re: EOT Value Remains Post-Expiration?

PostPosted: June 17th, 2011, 11:49 am
by adamarling
Hi Cristian,

Wow, fantastic. I've never used Hooks or Filters before in my current project. How do I apply a filter ws_plugin__s2member_preserve_paid_registration_times ?

I tried placing the following line of code in /wp-content/mu-plugins/s2-hacks.php , however Last Payment Time variable was still erased.

apply_filters ("ws_plugin__s2member_preserve_paid_registration_times", true, get_defined_vars ());

Is there additional code I will need from the link you sent above? Or is there a different directory I should be placing this filter in?

thanks again.
- Adam

Re: EOT Value Remains Post-Expiration?

PostPosted: June 17th, 2011, 5:36 pm
by Cristián Lávaque
Try this instead in the s2hacks.php file:

Code: Select all
add_filter("ws_plugin__s2member_preserve_paid_registration_times""__return_true");
  

Re: EOT Value Remains Post-Expiration?

PostPosted: June 19th, 2011, 5:14 pm
by adamarling
Hi Cristian,

Sorry, I placed that code and the Automatic EOT function still erased my Last Payment Time value. I'll play around with some variations...

- Adam

Re: EOT Value Remains Post-Expiration?

PostPosted: June 19th, 2011, 7:45 pm
by Cristián Lávaque
How about "__return_false"? I like to trial-and-error just in case lol.

Re: EOT Value Remains Post-Expiration?

PostPosted: June 20th, 2011, 11:18 am
by adamarling
Hi Cristian,

Here's an update on how all this works through a bunch of testing:

The following code in the s2-hacks.php file works:

Code: Select all
add_filter("ws_plugin__s2member_preserve_paid_registration_times", "__return_true");


It preserves the values in this associative array variable:
s2member_paid_registration_times


It does not preserve these variables:
s2member_auto_eot_time, s2member_last_payment_time
. These get erased under all situations I've tested.

So, for my particular situation (any anyone else who may have a similar need of retaining expired member's last payment dates), I'll consult this variable (s2member_paid_registration_times) when the s2member_last_payment_time variable is NULL or blank. s2member_paid_registration_times will return an array of all last payment times for each member level, so I just loop through those, find the most recent if multiple exist.

Code: Select all
<?
$prts_arr = get_user_option("s2member_paid_registration_times", $user_id);
            
while( $element = each( $prts_arr ) )
{
   echo $element[ 'key' ];
   echo ' - ';
   echo date("Y-m-d", $element[ 'value' ]);
   echo '<br />';
}
?>


To retain an expired Member's EOT variable value, my script will go in and pull the latest "Demotion Message" within the wp_s2member_notes variable.

Kind of a wraparound way of getting this info, but I think it will work.

Thanks for your help, and maybe this will help others also...

- Adam

Re: EOT Value Remains Post-Expiration?

PostPosted: June 20th, 2011, 9:54 pm
by Cristián Lávaque
Thank you Adam for sharing this.

We hope to improve this in a future release of s2Member.