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