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.

Issues with s2member_paid_registration_time()

Home Forums Community Forum Issues with s2member_paid_registration_time()

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

Topic Author Topic
Posted: Thursday Aug 22nd, 2013 at 10:23 pm #56492
Don Pezet
Username: dpezet

I have been working on some payment/cancelation notification hooks and I have noticed some odd behavior with the s2member_paid_registration_time() function. In short, it doesn’t seem to work. For example, I have a test user. Here is their information straight from the MySQL database:

user_id=17
wp_4_s2member_subscr_id=18060320
wp_4_s2member_paid_registration_times=a:2:{s:5:”level”;i:1377223363;s:6:”level3″;i:1377223363;}

But, no matter how I call it, s2member_paid_registration_time() always seems to return 0. To test it, I whipped up this PHP file:

<?php
include "../wp-load.php";
$user_id = '17';
$subscr_id = '18060320';
$user = new WP_User($user_id);
echo &#039;User ID : &#039; . $user_id . &#039;<br>';
echo 'Subscription ID : ' . $subscr_id . '<br>';
echo 'Registration Time: ' . s2member_registration_time($user_id) . '<br>';
echo 'First Paid Registration Time (No user_id specified): ' . s2member_paid_registration_time() . '<br>';
echo 'First Paid Registration Time: ' . s2member_paid_registration_time('level',$user_id) . '<br>';
echo 'Level 1 Paid Registration Time: ' . s2member_paid_registration_time('level1',$user_id) . '<br>';
echo 'Level 2 Paid Registration Time: ' . s2member_paid_registration_time('level2',$user_id) . '<br>';
echo 'Level 3 Paid Registration Time: ' . s2member_paid_registration_time('level3',$user_id) . '<br>';
echo 'Level 4 Paid Registration Time: ' . s2member_paid_registration_time('level4',$user_id) . '<br>';
?&gt;

When executed, that returns the following:

User ID : 17
Subscription ID : 18060320
Registration Time: 1377223363
First Paid Registration Time (No user_id specified): 0
First Paid Registration Time: 0
Level 1 Paid Registration Time: 0
Level 2 Paid Registration Time: 0
Level 3 Paid Registration Time: 0
Level 4 Paid Registration Time: 0

Do you guys have any idea why that function is not returning the values that I know are there?

Thanks,

Don

List Of Topic Replies

Viewing 7 replies - 1 through 7 (of 7 total)
Author Replies
Author Replies
Posted: Wednesday Aug 28th, 2013 at 2:00 pm #58813
Don Pezet
Username: dpezet

Is there any chance I could get some help with this? It appears to be a bug in s2member_paid_registration_time() as the function is not behaving as described in the s2Member Codex.

Posted: Wednesday Aug 28th, 2013 at 2:38 pm #58815
Don Pezet
Username: dpezet

It occurred to me that the function may not be mutlisite aware. I am running WordPress 3.6 Multisite. My root site does not allow user registration. So, the user in my example is a paid member of one of my subsites. Their paid registration time is stored in “wp_4_s2member_paid_registration_times” in MySQL as that particular subsite is site #4. I would bet that the s2member_paid_registration_time() is querying “wp_s2member_paid_registration_times” instead which is not going to return anything, thus the zeros. Is there a way to tell s2Member which site number it should be working with? The codex doesn’t seem to show anything.

Thanks,

Don

Posted: Thursday Aug 29th, 2013 at 8:09 am #58843

Thanks for the update, Don.

I don’t know, but I’ll ask Jason about the multisite thing and get back to you as soon as I hear back from him. :)

Posted: Thursday Aug 29th, 2013 at 8:16 am #58844

By the way, have you tried this?

[hilite pre_code]
$user_id = 17;
$s2member_paid_registration_times = get_user_option('s2member_paid_registration_times', $user_id);
print_r($s2member_paid_registration_times);
[/hilite]

Does it work?

Posted: Thursday Aug 29th, 2013 at 8:28 am #58846

Here’s what Jason said:

If you are calling this function from that particular Child Blog (that would be better); then s2Member will pull the data for that particular Child Blog automatically (e.g. the current Child Blog is always assumed).

Otherwise, if you are calling this function from a different Child Blog, where you want to know about information from another Child Blog, you simply call this function before you call the API Function provided by s2Member. See: http://codex.wordpress.org/Function_Reference/switch_to_blog

In short, s2Member IS multisite-aware; but calls like this from one Child Blog to another must be done properly using the WordPress core function I referenced above.

See also: http://codex.wordpress.org/Function_Reference/restore_current_blog

Posted: Thursday Aug 29th, 2013 at 9:29 am #58852
Don Pezet
Username: dpezet

OK, we are definitely getting closer. Using the switch_to_blog() function was definitely a missing piece in my solution, and I am now able to get values. However, s2member_paid_registration_time() is still not behaving as explained in the API. Here is my current example:

I have a PHP page coded as follows:

<html>
<body>
<?php
include "../wp-load.php";
switch_to_blog(4);
$user_id = (integer)$_GET['user_id'];
$blog_id = (integer)$_GET['blog_id'];
$user = new WP_User($user_id);
echo '$user_id : ' . $user_id . '<br>';
echo 's2member_registration_time($user_id): ' . s2member_registration_time($user_id) . '<br>';
echo 'Paid Registration Times from MySQL: ';
$s2member_paid_registration_times = get_user_option('s2member_paid_registration_times', $user_id);
print_r($s2member_paid_registration_times);
echo '<br>';
echo 's2member_paid_registration_time(): ' . s2member_paid_registration_time() . '<br>';
echo 's2member_paid_registration_time(\'level\',$user_id): ' . s2member_paid_registration_time('level',$user_id) . '<br>';
echo 's2member_paid_registration_time(\'level1\',$user_id): ' . s2member_paid_registration_time('level1',$user_id) . '<br>';
echo 's2member_paid_registration_time(\'level2\',$user_id): ' . s2member_paid_registration_time('level2',$user_id) . '<br>';
echo 's2member_paid_registration_time(\'level3\',$user_id): ' . s2member_paid_registration_time('level3',$user_id) . '<br>';
echo 's2member_paid_registration_time(\'level4\',$user_id): ' . s2member_paid_registration_time('level4',$user_id) . '<br>';
?>
</body>
</html>

I call it from a web browser via the following URL:

http://edutainmentlive.com/dpcustom/cancelation.php?user_id=18&subscr_id=18103761&blog_id=4

The page returns the folllowing:

$user_id : 18
s2member_registration_time($user_id): 1377574405
Paid Registration Times from MySQL: Array ( [level] => 1377574406 [level2] => 1377574406 ) 
s2member_paid_registration_time(): 0
s2member_paid_registration_time('level',$user_id): 1377574406
s2member_paid_registration_time('level1',$user_id): 1377574406
s2member_paid_registration_time('level2',$user_id): 1377574406
s2member_paid_registration_time('level3',$user_id): 1377574406
s2member_paid_registration_time('level4',$user_id): 1377574406

This user has only purchased one membership in their lifetime and it was a level 2 membership. The array reflects that as expected. However, the output from s2member_paid_registration_time() reflects something different. It shows that level 1, 3 and 4 memberships were also purchased. It also shows a 0 value when querying for the “first” paid membership (which is the value I want to use in the hook I am writing). The API documentation says that it should behave as follows:

<?php
$time = s2member_registration_time (); # first registration time (free or otherwise).
$time = s2member_paid_registration_time (); # first "paid" registration and/or upgrade time.
$time = s2member_paid_registration_time ("level1"); # first "paid" registration or upgrade time at Level#1.
$time = s2member_paid_registration_time ("level2"); # first "paid" registration or upgrade time at Level#2.
$time = s2member_paid_registration_time ("level3"); # first "paid" registration or upgrade time at Level#3.
$time = s2member_paid_registration_time ("level4"); # first "paid" registration or upgrade time at Level#4.
?>

So if I am reading that correctly, instead of what I got above, my page should be returning this:

$user_id : 18
s2member_registration_time($user_id): 1377574405
Paid Registration Times from MySQL: Array ( [level] => 1377574406 [level2] => 1377574406 ) 
s2member_paid_registration_time(): 1377574406
s2member_paid_registration_time('level',$user_id): 1377574406
s2member_paid_registration_time('level1',$user_id): 0
s2member_paid_registration_time('level2',$user_id): 1377574406
s2member_paid_registration_time('level3',$user_id): 0
s2member_paid_registration_time('level4',$user_id): 0

Do you or Jason have any ideas as to why I am getting the errant results? I’m not too concerned about the individual levels, but my primary goal is that I need a way to query how long it has been since a user paid for their first subscription, regardless of what level it was. Calling s2member_paid_registration_time() without any arguments is supposed to return that, but I am getting 0. Calling s2member_paid_registration_time(‘level’,$user_id) seems to return the value I want, but it is undocumented in the API and I want to make sure I am writing code that will survive future updates.

Thanks again,

Don

Posted: Thursday Aug 29th, 2013 at 11:05 pm #58869

I see. It’s strange.

Do you have the same problem if you try the function from a WP page in the child blog the user registered from? I’m wondering if the odd behavior happens only when loading WP from a custom script as you’re doing or not.

I see in your test that the [hilite mono]get_user_option[/hilite] approach worked, though, so I’d probably try going with that… If you need the oldest time out of all, then it could be something like:

[hilite pre_code]
foreach (get_user_option('s2member_paid_registration_times', $user_id) as $level => $time) {
if ($time > 0 && $time < $first_level_time) $first_level_time = $time; } [/hilite]
Viewing 7 replies - 1 through 7 (of 7 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.