Source Code Documentation


s2member\includes\classes\registration-times.inc.php


  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. 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 /* Unset defined __refs, __v. */ ($__refs, $__v);
  47.  
  48. 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)
  49. {
  50. $pr_times = get_user_option ("s2member_paid_registration_times", $user_id);
  51. $pr_times["level"] = (empty ($pr_times["level"])) ? time () : $pr_times["level"];
  52. $pr_times["level" . $level] = (empty ($pr_times["level" . $level])) ? time () : $pr_times["level" . $level];
  53. update_user_option ($user_id, "s2member_paid_registration_times", $pr_times); // Update now.
  54. }
  55.  
  56. return /* Return for uniformity. */;
  57. }
  58. /**
  59. * Retrieves a Registration Time.
  60. *
  61. * @package s2Member\Registrations
  62. * @since 3.5
  63. *
  64. * @param int|str $user_id Optional. A numeric WordPress® User ID. Defaults to the current User, if logged-in.
  65. * @return int A Unix timestamp, indicating Registration Time, else `0` on failure.
  66. */
  67. public static function registration_time ($user_id = FALSE)
  68. {
  69. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  70. do_action ("ws_plugin__s2member_before_registration_time", get_defined_vars ());
  71. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  72.  
  73. $user = ($user_id) ? new WP_User ($user_id) : ((is_user_logged_in ()) ? wp_get_current_user () : false);
  74.  
  75. if (is_object ($user) && !empty ($user->ID) && ($user_id = $user->ID) && $user->user_registered)
  76. {
  77. return apply_filters ("ws_plugin__s2member_registration_time", strtotime ($user->user_registered), get_defined_vars ());
  78. }
  79. else // Else we return a default value of 0, because there is insufficient data.
  80. return apply_filters ("ws_plugin__s2member_registration_time", 0, get_defined_vars ());
  81. }
  82. /**
  83. * Retrieves a Paid Registration Time.
  84. *
  85. * @package s2Member\Registrations
  86. * @since 3.5
  87. *
  88. * @param int|str $level Optional. Defaults to the first/initial Paid Registration Time, regardless of Level#.
  89. * @param int|str $user_id Optional. A numeric WordPress® User ID. Defaults to the current User, if logged-in.
  90. * @return int A Unix timestamp, indicating Paid Registration Time, else `0` on failure.
  91. */
  92. public static function paid_registration_time ($level = FALSE, $user_id = FALSE)
  93. {
  94. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  95. do_action ("ws_plugin__s2member_before_paid_registration_time", get_defined_vars ());
  96. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  97.  
  98. $level = (!is_numeric ($level)) ? "level" : "level" . preg_replace ("/[^0-9]/", "", (string)$level);
  99. $user = ($user_id) ? new WP_User ($user_id) : ((is_user_logged_in ()) ? wp_get_current_user () : false);
  100.  
  101. 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)))
  102. {
  103. return apply_filters ("ws_plugin__s2member_paid_registration_time", ((isset ($pr_times[$level])) ? (int)$pr_times[$level] : 0), get_defined_vars ());
  104. }
  105. else // Else we return a default value of `0`, because there is insufficient data.
  106. return apply_filters ("ws_plugin__s2member_paid_registration_time", 0, get_defined_vars ());
  107. }
  108. }
  109. }
  110. ?>

s2member\includes\classes\registration-times.inc.php

Source Code Documentation