PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 110913
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v110913
260917 260913 260909 260829 260814 260805 110710 110731 110812 110815 110912 110913 110915 110926 110927 111002 111003 111011 111017 111029 111105 111206 111216 111220 120213 All 189 releases
s2member / includes / classes / registration-times.inc.php

registration-times.inc.php in s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions 110913, at includes/classes/registration-times.inc.php

111 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Registration Times.
4 *
5 * Copyright: © 2009-2011
6 * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
7 * ( coded in the USA )
8 *
9 * Released under the terms of the GNU General Public License.
10 * You should have received a copy of the GNU General Public License,
11 * along with this software. In the main directory, see: /licensing/
12 * If not, see: {@link http://www.gnu.org/licenses/}.
13 *
14 * @package s2Member\Registrations
15 * @since 3.5
16 */
17 if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
18 exit ("Do not access this file directly.");
19 /**/
20 if (!class_exists ("c_ws_plugin__s2member_registration_times"))
21 {
22 /**
23 * Registration Times.
24 *
25 * @package s2Member\Registrations
26 * @since 3.5
27 */
28 class c_ws_plugin__s2member_registration_times
29 {
30 /**
31 * Synchronizes Paid Registration Times with Role assignments.
32 *
33 * @package s2Member\Registrations
34 * @since 3.5
35 *
36 * @attaches-to: ``add_action("set_user_role");``
37 *
38 * @param int|str $user_id A numeric WordPress® User ID should be passed in by the Action Hook.
39 * @param str $role A WordPress® Role ID/Name should be passed in by the Action Hook.
40 * @return null
41 */
42 public static function synchronize_paid_reg_times ($user_id = FALSE, $role = FALSE)
43 {
44 eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
45 do_action ("ws_plugin__s2member_before_synchronize_paid_reg_times", get_defined_vars ());
46 unset ($__refs, $__v); /* Unset defined __refs, __v. */
47 /**/
48 if ($user_id && is_object ($user = new WP_User ($user_id)) && $user->ID)
49 if (($level = c_ws_plugin__s2member_user_access::user_access_level ($user)) > 0)
50 {
51 $pr_times = get_user_option ("s2member_paid_registration_times", $user_id);
52 $pr_times["level"] = (!$pr_times["level"]) ? time () : $pr_times["level"]; /* Preserve. */
53 $pr_times["level" . $level] = (!$pr_times["level" . $level]) ? time () : $pr_times["level" . $level];
54 update_user_option ($user_id, "s2member_paid_registration_times", $pr_times); /* Update now. */
55 }
56 /**/
57 return; /* Return for uniformity. */
58 }
59 /**
60 * Retrieves a Registration Time.
61 *
62 * @package s2Member\Registrations
63 * @since 3.5
64 *
65 * @param int|str $user_id Optional. A numeric WordPress® User ID. Defaults to the current User, if logged-in.
66 * @return int A Unix timestamp, indicating Registration Time, else `0` on failure.
67 */
68 public static function registration_time ($user_id = FALSE)
69 {
70 eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
71 do_action ("ws_plugin__s2member_before_registration_time", get_defined_vars ());
72 unset ($__refs, $__v); /* Unset defined __refs, __v. */
73 /**/
74 $user = ($user_id) ? new WP_User ($user_id) : ((is_user_logged_in ()) ? wp_get_current_user () : false);
75 /**/
76 if (is_object ($user) && ($user_id = $user->ID) && $user->user_registered)
77 {
78 return apply_filters ("ws_plugin__s2member_registration_time", strtotime ($user->user_registered), get_defined_vars ());
79 }
80 else /* Else we return a default value of 0, because there is insufficient data. */
81 return apply_filters ("ws_plugin__s2member_registration_time", 0, get_defined_vars ());
82 }
83 /**
84 * Retrieves a Paid Registration Time.
85 *
86 * @package s2Member\Registrations
87 * @since 3.5
88 *
89 * @param int|str $level Optional. Defaults to the first/initial Paid Registration Time, regardless of Level#.
90 * @param int|str $user_id Optional. A numeric WordPress® User ID. Defaults to the current User, if logged-in.
91 * @return int A Unix timestamp, indicating Paid Registration Time, else `0` on failure.
92 */
93 public static function paid_registration_time ($level = FALSE, $user_id = FALSE)
94 {
95 eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
96 do_action ("ws_plugin__s2member_before_paid_registration_time", get_defined_vars ());
97 unset ($__refs, $__v); /* Unset defined __refs, __v. */
98 /**/
99 $level = (!strlen ($level)) ? "level" : "level" . preg_replace ("/[^0-9]/", "", $level);
100 $user = ($user_id) ? new WP_User ($user_id) : ((is_user_logged_in ()) ? wp_get_current_user () : false);
101 /**/
102 if ($level && is_object ($user) && ($user_id = $user->ID) && is_array ($pr_times = get_user_option ("s2member_paid_registration_times", $user_id)))
103 {
104 return apply_filters ("ws_plugin__s2member_paid_registration_time", (int)$pr_times[$level], get_defined_vars ());
105 }
106 else /* Else we return a default value of 0, because there is insufficient data. */
107 return apply_filters ("ws_plugin__s2member_paid_registration_time", 0, get_defined_vars ());
108 }
109 }
110 }
111 ?>