PageRenderTime 26ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/s2member/src/includes/classes/registration-times.inc.php

https://gitlab.com/pankajmohale/chef2go
PHP | 113 lines | 49 code | 8 blank | 56 comment | 17 complexity | 5a432edf0d764dea7bfacb226db7398f MD5 | raw file
  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. 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 integer|string $user_id A numeric WordPress User ID should be passed in by the Action Hook.
  39. * @param string $role A WordPress Role ID/Name should be passed in by the Action Hook.
  40. *
  41. * @return null
  42. */
  43. public static function synchronize_paid_reg_times($user_id = FALSE, $role = FALSE)
  44. {
  45. foreach(array_keys(get_defined_vars()) as $__v) $__refs[$__v] =& $$__v;
  46. do_action("ws_plugin__s2member_before_synchronize_paid_reg_times", get_defined_vars());
  47. unset($__refs, $__v);
  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. /**
  57. * Retrieves a Registration Time.
  58. *
  59. * @package s2Member\Registrations
  60. * @since 3.5
  61. *
  62. * @param integer|string $user_id Optional. A numeric WordPress User ID. Defaults to the current User, if logged-in.
  63. *
  64. * @return int A Unix timestamp, indicating Registration Time, else `0` on failure.
  65. */
  66. public static function registration_time($user_id = 0)
  67. {
  68. foreach(array_keys(get_defined_vars()) as $__v) $__refs[$__v] =& $$__v;
  69. do_action("ws_plugin__s2member_before_registration_time", get_defined_vars());
  70. unset($__refs, $__v);
  71. $user = ($user_id) ? new WP_User ($user_id) : ((is_user_logged_in()) ? wp_get_current_user() : FALSE);
  72. if(is_object($user) && !empty($user->ID) && ($user_id = $user->ID) && $user->user_registered)
  73. {
  74. return apply_filters("ws_plugin__s2member_registration_time", strtotime($user->user_registered), get_defined_vars());
  75. }
  76. else // Else we return a default value of 0, because there is insufficient data.
  77. return apply_filters("ws_plugin__s2member_registration_time", 0, get_defined_vars());
  78. }
  79. /**
  80. * Retrieves a Paid Registration Time.
  81. *
  82. * @package s2Member\Registrations
  83. * @since 3.5
  84. *
  85. * @param int|string $level Optional. Defaults to the first/initial Paid Registration Time, regardless of Level#.
  86. * @param int|string $user_id Optional. A numeric WordPress User ID. Defaults to the current User, if logged-in.
  87. *
  88. * @return int A Unix timestamp, indicating Paid Registration Time, else `0` on failure.
  89. */
  90. public static function paid_registration_time($level = FALSE, $user_id = FALSE)
  91. {
  92. foreach(array_keys(get_defined_vars()) as $__v) $__refs[$__v] =& $$__v;
  93. do_action("ws_plugin__s2member_before_paid_registration_time", get_defined_vars());
  94. unset($__refs, $__v);
  95. $level = (!is_numeric($level)) ? "level" : "level".preg_replace("/[^0-9]/", "", (string)$level);
  96. $user = ($user_id) ? new WP_User ($user_id) : ((is_user_logged_in()) ? wp_get_current_user() : FALSE);
  97. 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)))
  98. {
  99. return apply_filters("ws_plugin__s2member_paid_registration_time", ((isset ($pr_times[$level])) ? (int)$pr_times[$level] : 0), get_defined_vars());
  100. }
  101. else // Else we return a default value of `0`, because there is insufficient data.
  102. return apply_filters("ws_plugin__s2member_paid_registration_time", 0, get_defined_vars());
  103. }
  104. }
  105. }