Source Code Documentation


s2member-pro\includes\classes\remote-ops-in.inc.php


  1. <?php
  2. /**
  3. * s2Member Pro Remote Operations API ( inner processing routines ).
  4. *
  5. * Copyright: © 2009-2011
  6. * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
  7. * ( coded in the USA )
  8. *
  9. * This WordPress® plugin ( s2Member Pro ) is comprised of two parts:
  10. *
  11. * o (1) Its PHP code is licensed under the GPL license, as is WordPress®.
  12. * You should have received a copy of the GNU General Public License,
  13. * along with this software. In the main directory, see: /licensing/
  14. * If not, see: {@link http://www.gnu.org/licenses/}.
  15. *
  16. * o (2) All other parts of ( s2Member Pro ); including, but not limited to:
  17. * the CSS code, some JavaScript code, images, and design;
  18. * are licensed according to the license purchased.
  19. * See: {@link http://www.s2member.com/prices/}
  20. *
  21. * Unless you have our prior written consent, you must NOT directly or indirectly license,
  22. * sub-license, sell, resell, or provide for free; part (2) of the s2Member Pro Module;
  23. * or make an offer to do any of these things. All of these things are strictly
  24. * prohibited with part (2) of the s2Member Pro Module.
  25. *
  26. * Your purchase of s2Member Pro includes free lifetime upgrades via s2Member.com
  27. * ( i.e. new features, bug fixes, updates, improvements ); along with full access
  28. * to our video tutorial library: {@link http://www.s2member.com/videos/}
  29. *
  30. * @package s2Member\API_Remote_Ops
  31. * @since 110713
  32. */
  33. if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
  34. exit("Do not access this file directly.");
  35. /**/
  36. if (!class_exists ("c_ws_plugin__s2member_pro_remote_ops_in"))
  37. {
  38. /**
  39. * s2Member Pro Remote Operations API ( inner processing routines ).
  40. *
  41. * @package s2Member\API_Remote_Ops
  42. * @since 110713
  43. */
  44. class c_ws_plugin__s2member_pro_remote_ops_in
  45. {
  46. /**
  47. * Creates a new User.
  48. *
  49. * @package s2Member\API_Remote_Ops
  50. * @since 110713
  51. *
  52. * @param array An input array of Remote Operation parameters.
  53. * @return str Returns a serialized array with an `ID` element object on success,
  54. * else returns a string beginning with `Error:` on failure; which will include details regarding the error.
  55. */
  56. public static function create_user ($op = FALSE)
  57. {
  58. if (!empty ($op["op"]) && $op["op"] === "create_user" && !empty ($op["data"]) && is_array ($op["data"]))
  59. {
  60. $GLOBALS["ws_plugin__s2member_registration_vars"] = /* Array. */ array ();
  61. $v = /* Shorter reference. */ &$GLOBALS["ws_plugin__s2member_registration_vars"];
  62. /**/
  63. $v["ws_plugin__s2member_custom_reg_field_user_login"] = (string)@$op["data"]["user_login"];
  64. $v["ws_plugin__s2member_custom_reg_field_user_email"] = (string)@$op["data"]["user_email"];
  65. /**/
  66. if (empty ($op["data"]["user_pass"]) || !is_string ($op["data"]["user_pass"]))
  67. $op["data"]["user_pass"] = /* Auto-generate. */ wp_generate_password ();
  68. $GLOBALS["ws_plugin__s2member_generate_password_return"] = $op["data"]["user_pass"];
  69. /**/
  70. $v["ws_plugin__s2member_custom_reg_field_first_name"] = (string)@$op["data"]["first_name"];
  71. $v["ws_plugin__s2member_custom_reg_field_last_name"] = (string)@$op["data"]["last_name"];
  72. /**/
  73. $v["ws_plugin__s2member_custom_reg_field_s2member_level"] = (string)@$op["data"]["s2member_level"];
  74. $v["ws_plugin__s2member_custom_reg_field_s2member_ccaps"] = (string)@$op["data"]["s2member_ccaps"];
  75. /**/
  76. $v["ws_plugin__s2member_custom_reg_field_s2member_registration_ip"] = (string)@$op["data"]["s2member_registration_ip"];
  77. /**/
  78. $v["ws_plugin__s2member_custom_reg_field_s2member_subscr_gateway"] = (string)@$op["data"]["s2member_subscr_gateway"];
  79. $v["ws_plugin__s2member_custom_reg_field_s2member_subscr_id"] = (string)@$op["data"]["s2member_subscr_id"];
  80. $v["ws_plugin__s2member_custom_reg_field_s2member_custom"] = (string)@$op["data"]["s2member_custom"];
  81. /**/
  82. $v["ws_plugin__s2member_custom_reg_field_s2member_auto_eot_time"] = (string)@$op["data"]["s2member_auto_eot_time"];
  83. /**/
  84. $v["ws_plugin__s2member_custom_reg_field_s2member_notes"] = (string)@$op["data"]["s2member_notes"];
  85. /**/
  86. $v["ws_plugin__s2member_custom_reg_field_opt_in"] = (string)@$op["data"]["opt_in"];
  87. /**/
  88. if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"])
  89. foreach (json_decode ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field)
  90. {
  91. $field_var = preg_replace ("/[^a-z0-9]/i", "_", strtolower ($field["id"]));
  92. $field_id_class = preg_replace ("/_/", "-", $field_var);
  93. /**/
  94. if (isset /* Has this Registration/Profile Field been set? */ ($op["data"]["custom_fields"][$field_var]))
  95. $v["ws_plugin__s2member_custom_reg_field_" . $field_var] = $op["data"]["custom_fields"][$field_var];
  96. }
  97. /**/
  98. $create = array ("user_login" => (string)@$op["data"]["user_login"], "user_pass" => (string)@$op["data"]["user_pass"], "user_email" => (string)@$op["data"]["user_email"]);
  99. /**/
  100. if (((is_multisite () && ($new = $user_id = c_ws_plugin__s2member_registrations::ms_create_existing_user ($create["user_login"], $create["user_email"], $create["user_pass"]))) || ($new = $user_id = wp_create_user ($create["user_login"], $create["user_pass"], $create["user_email"]))) && !is_wp_error ($new))
  101. {
  102. if (is_object ($user = new WP_User ($user_id)) && !empty ($user->ID) && ($user_id = $user->ID))
  103. {
  104. if ( /* Send New User Notification? */!empty ($op["data"]["notification"]))
  105. wp_new_user_notification ($user_id, $op["data"]["user_pass"]);
  106. /**/
  107. return serialize /* Serialized array. */ (array ("ID" => $user_id));
  108. }
  109. else /* Else the creation of the User account may have failed. */
  110. return "Error: Creation may have failed. Unable to obtain WP_User ID.";
  111. }
  112. else if (is_wp_error ($new) && $new->get_error_code ()) /* Error message? */
  113. return "Error: " . $new->get_error_message (); /* Return message. */
  114. /**/
  115. else /* Else we really don't know why creation failed. Return generic error. */
  116. return "Error: User creation failed for an unknown reason. Please try again.";
  117. }
  118. else /* Empty request, or calling upon wrong Remote Op. */
  119. return "Error: Empty or invalid request ( `create_user` ). Please try again.";
  120. }
  121. /**
  122. * Modifies an existing User.
  123. *
  124. * @package s2Member\API_Remote_Ops
  125. * @since 110713
  126. *
  127. * @param array An input array of Remote Operation parameters.
  128. * @return str Returns a serialized array with an `ID` element object on success,
  129. * else returns a string beginning with `Error:` on failure; which will include details regarding the error.
  130. */
  131. public static function modify_user ($op = FALSE)
  132. {
  133. if (!empty ($op["op"]) && $op["op"] === "modify_user" && !empty ($op["data"]) && is_array ($op["data"]))
  134. {
  135. return "Error: Empty or invalid request ( `modify_user` ). Please try again.";
  136. }
  137. else /* Empty request, or calling upon wrong Remote Op. */
  138. return "Error: Empty or invalid request ( `modify_user` ). Please try again.";
  139. }
  140. /**
  141. * Deletes an existing User.
  142. *
  143. * @package s2Member\API_Remote_Ops
  144. * @since 110713
  145. *
  146. * @param array An input array of Remote Operation parameters.
  147. * @return str Returns a serialized array with an `ID` element object on success,
  148. * else returns a string beginning with `Error:` on failure; which will include details regarding the error.
  149. */
  150. public static function delete_user ($op = FALSE)
  151. {
  152. if (!empty ($op["op"]) && $op["op"] === "delete_user" && !empty ($op["data"]) && is_array ($op["data"]))
  153. {
  154. return "Error: Empty or invalid request ( `delete_user` ). Please try again.";
  155. }
  156. else /* Empty request, or calling upon wrong Remote Op. */
  157. return "Error: Empty or invalid request ( `delete_user` ). Please try again.";
  158. }
  159. }
  160. }
  161. ?>

s2member-pro\includes\classes\remote-ops-in.inc.php

Source Code Documentation