Source Code Documentation


s2member\includes\classes\custom-reg-fields.inc.php


  1. <?php
  2. /**
  3. * Custom Registration/Profile Fields for s2Member.
  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\Custom_Reg_Fields
  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_custom_reg_fields"))
  21. {
  22. /**
  23. * Custom Registration/Profile Fields for s2Member.
  24. *
  25. * @package s2Member\Custom_Reg_Fields
  26. * @since 3.5
  27. */
  28. class c_ws_plugin__s2member_custom_reg_fields
  29. {
  30. /**
  31. * Generates all Custom Fields.
  32. *
  33. * @package s2Member\Custom_Reg_Fields
  34. * @since 3.5
  35. *
  36. * @param str $_function Function calling upon this routine.
  37. * @param array $_field The Field array of configuration options.
  38. * @param str $_name_prefix The `name=""` attribute prefix.
  39. * @param str $_id_prefix The `id=""` attribute prefix.
  40. * @param str $_classes Optional. String of space separated classes that will go inside the Field's `class=""` attribute.
  41. * @param str $_styles Optional. String of CSS styles that will go inside the Field's `style=""` attribute.
  42. * @param str|int $_tabindex. Optional numeric tabindex for the `tabindex=""` attribute.
  43. * @param str $_attrs Optional. Some additional Field attributes and values.
  44. * @param array $_submission Optional. But should be passed in with any submission data related to this Field. For instance, you might pass in ``$_POST``.
  45. * @param str|array $_value Optional. The value of this Field, either by default, or from the ``$_submission`` array.
  46. * @param str $_editable_context Optional. One of `profile|profile-view|registration`.
  47. * @return str The resulting Custom Field, in HTML format.
  48. */
  49. public static function custom_field_gen($_function = FALSE, $_field = FALSE, $_name_prefix = FALSE, $_id_prefix = FALSE, $_classes = FALSE, $_styles = FALSE, $_tabindex = FALSE, $_attrs = FALSE, $_submission = FALSE, $_value = FALSE, $_editable_context = FALSE)
  50. {
  51. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  52. do_action("ws_plugin__s2member_before_custom_field_gen", get_defined_vars());
  53. unset /* Unset defined __refs, __v. */($__refs, $__v);
  54.  
  55. if(!($gen = "") && $_function && is_array($field = $_field) && !empty($field["type"]) && !empty($field["id"]) && $_name_prefix && $_id_prefix)
  56. {
  57. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  58. do_action("ws_plugin__s2member_during_custom_field_gen_before", get_defined_vars());
  59. unset /* Unset defined __refs, __v. */($__refs, $__v);
  60.  
  61. $field_var = preg_replace("/[^a-z0-9]/i", "_", strtolower($field["id"]));
  62. $field_id_class = preg_replace("/_/", "-", $field_var);
  63.  
  64. $name_suffix = (preg_match("/\[$/", $_name_prefix)) ? ']' : '';
  65. $field_name = trim($_name_prefix.$field_var.$name_suffix);
  66.  
  67. $common = /* Common attributes. */ '';
  68. $common .= ' name="'.esc_attr($field_name).'"';
  69. $common .= ' id="'.esc_attr($_id_prefix.$field_id_class).'"';
  70. $common .= ((!empty($field["required"]) && $field["required"] === "yes") ? ' aria-required="true"' : '');
  71. $common .= ((strlen($_tabindex)) ? ' tabindex="'.esc_attr($_tabindex).'"' : /* No tabindex if empty. */ '');
  72. $common .= (( /* Certain data expected? */!empty($field["expected"])) ? ' data-expected="'.esc_attr($field["expected"]).'"' : '');
  73. $common .= (($_editable_context === "profile-view" || ($_editable_context === "profile" && !empty($field["editable"]) && strpos($field["editable"], "no") === 0)) ? ' disabled="disabled"' : '');
  74. $common .= (($_classes || !empty($field["classes"])) ? ' class="'.esc_attr(trim($_classes.((!empty($field["classes"])) ? ' '.$field["classes"] : ''))).'"' : '');
  75. $common .= (($_styles || !empty($field["styles"])) ? ' style="'.esc_attr(trim($_styles.((!empty($field["styles"])) ? ' '.$field["styles"] : ''))).'"' : '');
  76. $common .= (($_attrs || !empty($field["attrs"])) ? ' '.trim($_attrs.((!empty($field["attrs"])) ? ' '.$field["attrs"] : '')) : '');
  77.  
  78. if($field["type"] === "text")
  79. {
  80. if($_editable_context === "profile-view")
  81. $gen = esc_html((string)$_value);
  82.  
  83. else // Else handle normally.
  84. {
  85. $gen = '<input type="text" maxlength="100" autocomplete="off"';
  86. $gen .= ' value="'.format_to_edit((!$_submission && isset($field["deflt"]) && strlen((string)$field["deflt"])) ? (string)$field["deflt"] : (string)$_value).'"';
  87. $gen .= $common.' />';
  88. }
  89. }
  90. else if($field["type"] === "textarea")
  91. {
  92. if($_editable_context === "profile-view")
  93. $gen = nl2br(esc_html((string)$_value));
  94.  
  95. else // Else handle normally.
  96. {
  97. $gen = '<textarea rows="3"'.$common.'>';
  98. $gen .= format_to_edit((!$_submission && isset($field["deflt"]) && strlen((string)$field["deflt"])) ? (string)$field["deflt"] : (string)$_value);
  99. $gen .= '</textarea>';
  100. }
  101. }
  102. else if($field["type"] === "select" && !empty($field["options"]))
  103. {
  104. if($_editable_context === "profile-view")
  105. {
  106. foreach(preg_split("/[\r\n\t]+/", $field["options"]) as $option_line)
  107. {
  108. list($option_value, $option_label, $option_default) = c_ws_plugin__s2member_utils_strings::trim_deep(preg_split("/\|/", trim($option_line)));
  109. if($option_value === (string)$_value)
  110. {
  111. $gen = $option_label;
  112. break;
  113. }
  114. }
  115. }
  116. else // Else handle normally.
  117. {
  118. $gen = '<select'.$common.'>';
  119. $selected_default_option = false;
  120. foreach(preg_split("/[\r\n\t]+/", $field["options"]) as $option_line)
  121. {
  122. list($option_value, $option_label, $option_default) = c_ws_plugin__s2member_utils_strings::trim_deep(preg_split("/\|/", trim($option_line)));
  123. $gen .= '<option value="'.esc_attr($option_value).'"'.(((($option_default && !$_submission) || ($option_value === (string)$_value && !$selected_default_option)) && ($selected_default_option = true)) ? ' selected="selected"' : '').'>'.$option_label.'</option>';
  124. }
  125. $gen .= '</select>';
  126. }
  127. }
  128. else if($field["type"] === "selects" && !empty($field["options"]))
  129. {
  130. if($_editable_context === "profile-view")
  131. {
  132. foreach(preg_split("/[\r\n\t]+/", $field["options"]) as $option_line)
  133. {
  134. list($option_value, $option_label, $option_default) = c_ws_plugin__s2member_utils_strings::trim_deep(preg_split("/\|/", trim($option_line)));
  135. if(in_array($option_value, (array)$_value))
  136. $gen .= $option_label.", ";
  137. }
  138. $gen = c_ws_plugin__s2member_utils_strings::trim($gen, 0, ",");
  139. }
  140. else // Else handle normally.
  141. {
  142. $common = preg_replace('/ name\="(.+?)"/', ' name="$1[]"', $common);
  143. $common = preg_replace('/ style\="(.+?)"/', ' style="height:auto; $1"', $common);
  144.  
  145. $gen = '<select multiple="multiple" size="3"'.$common.'>';
  146. foreach(preg_split("/[\r\n\t]+/", $field["options"]) as $option_line)
  147. {
  148. list($option_value, $option_label, $option_default) = c_ws_plugin__s2member_utils_strings::trim_deep(preg_split("/\|/", trim($option_line)));
  149. $gen .= '<option value="'.esc_attr($option_value).'"'.((($option_default && !$_submission) || in_array($option_value, (array)$_value)) ? ' selected="selected"' : '').'>'.$option_label.'</option>';
  150. }
  151. $gen .= '</select>';
  152. }
  153. }
  154. else if($field["type"] === "checkbox" && !empty($field["label"]))
  155. {
  156. if($_editable_context === "profile-view")
  157. $gen = ((string)$_value) ? "yes" : "no";
  158.  
  159. else // Else handle normally.
  160. {
  161. $gen = '<input type="checkbox" value="1"';
  162. $gen .= (((string)$_value) ? ' checked="checked"' : '');
  163. $gen .= $common.' /><label for="'.esc_attr($_id_prefix.$field_id_class).'" style="display:inline !important; margin:0 !important;">'.$field["label"].'</label>';
  164. }
  165. }
  166. else if($field["type"] === "pre_checkbox" && !empty($field["label"]))
  167. {
  168. if($_editable_context === "profile-view")
  169. $gen = ((string)$_value) ? "yes" : "no";
  170.  
  171. else // Else handle normally.
  172. {
  173. $gen = '<input type="checkbox" value="1"';
  174. $gen .= ((!$_submission || (string)$_value) ? ' checked="checked"' : '');
  175. $gen .= $common.' /><label for="'.esc_attr($_id_prefix.$field_id_class).'" style="display:inline !important; margin:0 !important;">'.$field["label"].'</label>';
  176. }
  177. }
  178. else if($field["type"] === "checkboxes" && !empty($field["options"]))
  179. {
  180. if($_editable_context === "profile-view")
  181. {
  182. foreach(preg_split("/[\r\n\t]+/", $field["options"]) as $i => $option_line)
  183. {
  184. list($option_value, $option_label, $option_default) = c_ws_plugin__s2member_utils_strings::trim_deep(preg_split("/\|/", trim($option_line)));
  185. if(in_array($option_value, (array)$_value))
  186. $gen .= $option_label.", ";
  187. }
  188. $gen = c_ws_plugin__s2member_utils_strings::trim($gen, 0, ",");
  189. }
  190. else // Else handle normally.
  191. {
  192. $common = preg_replace('/ name\="(.+?)"/', ' name="$1[]"', $common);
  193.  
  194. $sep = apply_filters("ws_plugin__s2member_custom_field_gen_checkboxes_sep", "&nbsp;&nbsp;", get_defined_vars());
  195. $opl = apply_filters("ws_plugin__s2member_custom_field_gen_checkboxes_opl", "ws-plugin--s2member-custom-reg-field-op-l", get_defined_vars());
  196.  
  197. foreach(preg_split("/[\r\n\t]+/", $field["options"]) as $i => $option_line)
  198. {
  199. $common_i = preg_replace('/ id\="(.+?)"/', ' id="$1---'.($i).'"', $common);
  200.  
  201. list($option_value, $option_label, $option_default) = c_ws_plugin__s2member_utils_strings::trim_deep(preg_split("/\|/", trim($option_line)));
  202.  
  203. $gen .= ($i > 0) ? $sep : ''; // Separators can be filtered above.
  204. $gen .= '<input type="checkbox" value="'.esc_attr($option_value).'"';
  205. $gen .= ((($option_default && !$_submission) || in_array($option_value, (array)$_value)) ? ' checked="checked"' : '');
  206. $gen .= $common_i.' /><label for="'.esc_attr($_id_prefix.$field_id_class."-".$i).'" class="'.esc_attr($opl).'" style="display:inline !important; margin:0 !important;">'.$option_label.'</label>';
  207. }
  208. }
  209. }
  210. else if($field["type"] === "radios" && !empty($field["options"]))
  211. {
  212. if($_editable_context === "profile-view")
  213. {
  214. foreach(preg_split("/[\r\n\t]+/", $field["options"]) as $i => $option_line)
  215. {
  216. list($option_value, $option_label, $option_default) = c_ws_plugin__s2member_utils_strings::trim_deep(preg_split("/\|/", trim($option_line)));
  217. if($option_value === (string)$_value)
  218. {
  219. $gen = $option_label;
  220. break;
  221. }
  222. }
  223. }
  224. else // Else handle normally.
  225. {
  226. $sep = apply_filters("ws_plugin__s2member_custom_field_gen_radios_sep", "&nbsp;&nbsp;", get_defined_vars());
  227. $opl = apply_filters("ws_plugin__s2member_custom_field_gen_radios_opl", "ws-plugin--s2member-custom-reg-field-op-l", get_defined_vars());
  228.  
  229. foreach(preg_split("/[\r\n\t]+/", $field["options"]) as $i => $option_line)
  230. {
  231. $common_i = preg_replace('/ id\="(.+?)"/', ' id="$1---'.($i).'"', $common);
  232.  
  233. list($option_value, $option_label, $option_default) = c_ws_plugin__s2member_utils_strings::trim_deep(preg_split("/\|/", trim($option_line)));
  234.  
  235. $gen .= ($i > 0) ? $sep : ''; // Separators can be filtered above.
  236. $gen .= '<input type="radio" value="'.esc_attr($option_value).'"';
  237. $gen .= ((($option_default && !$_submission) || $option_value === (string)$_value) ? ' checked="checked"' : '');
  238. $gen .= $common_i.' /><label for="'.esc_attr($_id_prefix.$field_id_class."-".$i).'" class="'.esc_attr($opl).'" style="display:inline !important; margin:0 !important;">'.$option_label.'</label>';
  239. }
  240. }
  241. }
  242. else // Default to a text field input type when nothing matches.
  243. {
  244. if($_editable_context === "profile-view")
  245. $gen = esc_html((string)$_value);
  246.  
  247. else // Else handle normally.
  248. {
  249. $gen = '<input type="text" maxlength="100" autocomplete="off"';
  250. $gen .= ' value="'.format_to_edit((!$_submission && isset($field["deflt"]) && strlen((string)$field["deflt"])) ? (string)$field["deflt"] : (string)$_value).'"';
  251. $gen .= $common.' />';
  252. }
  253. }
  254. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  255. do_action("ws_plugin__s2member_during_custom_field_gen_after", get_defined_vars());
  256. unset /* Unset defined __refs, __v. */($__refs, $__v);
  257. }
  258. return apply_filters("ws_plugin__s2member_custom_field_gen", $gen, get_defined_vars());
  259. }
  260. /**
  261. * Determines which Custom Fields apply to a specific Level.
  262. *
  263. * @package s2Member\Custom_Reg_Fields
  264. * @since 3.5
  265. *
  266. * @param str|int $_level Optional. Defaults to the current User's Access Level number.
  267. * You can either pass in a numeric Level number, or the string `auto-detection`.
  268. * @param str $_editable_context Optional. One of `profile|profile-view|registration`.
  269. * @return array Array of Custom Field IDs applicable.
  270. */
  271. public static function custom_fields_configured_at_level($_level = "auto-detection", $_editable_context = FALSE)
  272. {
  273. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  274. do_action("ws_plugin__s2member_before_custom_fields_configured_at_level", get_defined_vars());
  275. unset /* Unset defined __refs, __v. */($__refs, $__v);
  276.  
  277. $level = ($_level === "auto-detection") ? c_ws_plugin__s2member_user_access::user_access_level() : $_level;
  278. if($_level === "auto-detection" && $level < 0 && ($reg_cookies = c_ws_plugin__s2member_register_access::reg_cookies_ok()) && extract($reg_cookies) && preg_match($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["membership_item_number_w_level_regex"], $item_number, $m) && !empty($m[1]) && is_numeric($m[1]))
  279. $level = /* A numeric Membership Level # . */ $m[1];
  280.  
  281. $level = ($level !== "any" && (!is_numeric($level) || $level < 0)) ? 0 : /* Default. */ $level;
  282.  
  283. if(($level === "any" || (is_numeric($level) && $level >= 0)) && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"])
  284. {
  285. foreach(json_decode($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field)
  286. if($level === "any" || $field["levels"] === "all" || in_array($level, preg_split("/[;,]+/", preg_replace("/[^0-9;,]/", "", $field["levels"]))))
  287. if(empty($_editable_context) || $_editable_context === "administrative" || ($_editable_context === "registration" && $field["editable"] !== "no-always-invisible" && $field["editable"] !== "yes-invisible") || (($_editable_context === "profile" || $_editable_context === "profile-view") && $field["editable"] !== "no-invisible" && $field["editable"] !== "no-always-invisible"))
  288. $configured[] = /* Add this to the array. */ $field["id"];
  289. }
  290. return apply_filters("ws_plugin__s2member_custom_fields_configured_at_level", ((!empty($configured)) ? $configured : array()), get_defined_vars());
  291. }
  292. /**
  293. * Adds Custom Fields to: `/wp-signup.php`.
  294. *
  295. * For Multisite Blog Farms.
  296. *
  297. * @package s2Member\Custom_Reg_Fields
  298. * @since 3.5
  299. *
  300. * @attaches-to ``add_action("signup_extra_fields");``
  301. *
  302. * @return null
  303. *
  304. * @todo Optimize with ``empty()``.
  305. */
  306. public static function ms_custom_registration_fields()
  307. {
  308. do_action("ws_plugin__s2member_before_ms_custom_registration_fields", get_defined_vars());
  309.  
  310. if /* Must be Main Site of a Network. */(is_multisite() && is_main_site())
  311. {
  312. $_p = (!empty($_POST)) ? c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_POST)) : array();
  313.  
  314. echo '<input type="hidden" name="ws_plugin__s2member_registration" value="'.esc_attr(wp_create_nonce("ws-plugin--s2member-registration")).'" />'."\n";
  315.  
  316. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  317. do_action("ws_plugin__s2member_during_ms_custom_registration_fields_before", get_defined_vars());
  318. unset /* Unset defined __refs, __v. */($__refs, $__v);
  319.  
  320. if($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_names"])
  321. {
  322. echo '<div class="ws-plugin--s2member-custom-reg-field-divider-section"></div>'."\n";
  323.  
  324. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  325. do_action("ws_plugin__s2member_during_ms_custom_registration_fields_before_first_name", get_defined_vars());
  326. unset /* Unset defined __refs, __v. */($__refs, $__v);
  327.  
  328. echo '<label for="ws-plugin--s2member-custom-reg-field-first-name">'._x("First Name", "s2member-front", "s2member").' *</label>'."\n";
  329. echo '<input type="text" aria-required="true" maxlength="100" autocomplete="off" name="ws_plugin__s2member_custom_reg_field_first_name" id="ws-plugin--s2member-custom-reg-field-first-name" class="ws-plugin--s2member-custom-reg-field" value="'.esc_attr($_p["ws_plugin__s2member_custom_reg_field_first_name"]).'" />'."\n";
  330. echo '<br />'."\n";
  331.  
  332. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  333. do_action("ws_plugin__s2member_during_ms_custom_registration_fields_after_first_name", get_defined_vars());
  334. unset /* Unset defined __refs, __v. */($__refs, $__v);
  335.  
  336. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  337. do_action("ws_plugin__s2member_during_ms_custom_registration_fields_before_last_name", get_defined_vars());
  338. unset /* Unset defined __refs, __v. */($__refs, $__v);
  339.  
  340. echo '<label for="ws-plugin--s2member-custom-reg-field-last-name">'._x("Last Name", "s2member-front", "s2member").' *</label>'."\n";
  341. echo '<input type="text" aria-required="true" maxlength="100" autocomplete="off" name="ws_plugin__s2member_custom_reg_field_last_name" id="ws-plugin--s2member-custom-reg-field-last-name" class="ws-plugin--s2member-custom-reg-field" value="'.esc_attr($_p["ws_plugin__s2member_custom_reg_field_last_name"]).'" />'."\n";
  342. echo '<br />'."\n";
  343.  
  344. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  345. do_action("ws_plugin__s2member_during_ms_custom_registration_fields_after_last_name", get_defined_vars());
  346. unset /* Unset defined __refs, __v. */($__refs, $__v);
  347. }
  348. if($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"])
  349. if($fields_applicable = c_ws_plugin__s2member_custom_reg_fields::custom_fields_configured_at_level("auto-detection", "registration"))
  350. foreach(json_decode($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field)
  351. {
  352. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  353. do_action("ws_plugin__s2member_during_ms_custom_registration_fields_before_custom_fields", get_defined_vars());
  354. unset /* Unset defined __refs, __v. */($__refs, $__v);
  355.  
  356. if /* Field applicable? */(in_array($field["id"], $fields_applicable))
  357. {
  358. $field_var = preg_replace("/[^a-z0-9]/i", "_", strtolower($field["id"]));
  359. $field_id_class = preg_replace("/_/", "-", $field_var);
  360.  
  361. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  362. if(apply_filters("ws_plugin__s2member_during_ms_custom_registration_fields_during_custom_fields_display", true, get_defined_vars()))
  363. {
  364. if /* Starts a new section? */(!empty($field["section"]) && $field["section"] === "yes")
  365. echo '<div class="ws-plugin--s2member-custom-reg-field-divider-section'.((!empty($field["sectitle"])) ? '-title' : '').'">'.((!empty($field["sectitle"])) ? $field["sectitle"] : '').'</div>';
  366.  
  367. echo '<label for="ws-plugin--s2member-custom-reg-field-'.esc_attr($field_id_class).'"'.((preg_match("/^(checkbox|pre_checkbox)$/", $field["type"])) ? ' style="display:none;"' : '').'>'.$field["label"].(($field["required"] === "yes") ? ' *' : '').'</label>'.((preg_match("/^(checkbox|pre_checkbox)$/", $field["type"])) ? '<br />' : '')."\n";
  368. echo c_ws_plugin__s2member_custom_reg_fields::custom_field_gen(__FUNCTION__, $field, "ws_plugin__s2member_custom_reg_field_", "ws-plugin--s2member-custom-reg-field-", "ws-plugin--s2member-custom-reg-field", "", "", "", $_p, $_p["ws_plugin__s2member_custom_reg_field_".$field_var], "registration");
  369. echo '<br />'."\n";
  370. }
  371. unset /* Unset defined __refs, __v. */($__refs, $__v);
  372. }
  373. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  374. do_action("ws_plugin__s2member_during_ms_custom_registration_fields_after_custom_fields", get_defined_vars());
  375. unset /* Unset defined __refs, __v. */($__refs, $__v);
  376. }
  377. if($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_opt_in"] && c_ws_plugin__s2member_list_servers::list_servers_integrated())
  378. {
  379. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  380. do_action("ws_plugin__s2member_during_ms_custom_registration_fields_before_opt_in", get_defined_vars());
  381. unset /* Unset defined __refs, __v. */($__refs, $__v);
  382.  
  383. echo '<label for="ws-plugin--s2member-custom-reg-field-opt-in">'."\n";
  384. echo '<input type="checkbox" name="ws_plugin__s2member_custom_reg_field_opt_in" id="ws-plugin--s2member-custom-reg-field-opt-in" class="ws-plugin--s2member-custom-reg-field" value="1"'.(((empty($_p) && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_opt_in"] == 1) || $_p["ws_plugin__s2member_custom_reg_field_opt_in"]) ? ' checked="checked"' : '').' />'."\n";
  385. echo $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_opt_in_label"]."\n";
  386. echo '</label>'."\n";
  387. echo '<br />'."\n";
  388.  
  389. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  390. do_action("ws_plugin__s2member_during_ms_custom_registration_fields_after_opt_in", get_defined_vars());
  391. unset /* Unset defined __refs, __v. */($__refs, $__v);
  392. }
  393. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  394. do_action("ws_plugin__s2member_during_ms_custom_registration_fields_after", get_defined_vars());
  395. unset /* Unset defined __refs, __v. */($__refs, $__v);
  396. }
  397. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  398. do_action("ws_plugin__s2member_after_ms_custom_registration_fields", get_defined_vars());
  399. unset /* Unset defined __refs, __v. */($__refs, $__v);
  400.  
  401. return /* Return for uniformity. */;
  402. }
  403. /**
  404. * Adds Custom Fields to: `/wp-login.php?action=register`.
  405. *
  406. * @package s2Member\Custom_Reg_Fields
  407. * @since 3.5
  408. *
  409. * @attaches-to ``add_action("register_form");``
  410. *
  411. * @return null
  412. *
  413. * @todo Optimize with ``empty()``.
  414. */
  415. public static function custom_registration_fields()
  416. {
  417. do_action("ws_plugin__s2member_before_custom_registration_fields", get_defined_vars());
  418.  
  419. $_p = (!empty($_POST)) ? c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_POST)) : array();
  420.  
  421. echo '<input type="hidden" name="ws_plugin__s2member_registration" value="'.esc_attr(wp_create_nonce("ws-plugin--s2member-registration")).'" />'."\n";
  422.  
  423. $tabindex = /* Incremented tabindex starting with 20. */ 20;
  424.  
  425. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  426. do_action("ws_plugin__s2member_during_custom_registration_fields_before", get_defined_vars());
  427. unset /* Unset defined __refs, __v. */($__refs, $__v);
  428.  
  429. if($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_password"])
  430. {
  431. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  432. do_action("ws_plugin__s2member_during_custom_registration_fields_before_user_pass", get_defined_vars());
  433. unset /* Unset defined __refs, __v. */($__refs, $__v);
  434.  
  435. echo '<p>'."\n";
  436.  
  437. echo '<label for="ws-plugin--s2member-custom-reg-field-user-pass1" title="'.esc_attr(_x("Please type your Password twice to confirm.", "s2member-front", "s2member")).'">'."\n";
  438. echo '<span>'._x("Password (please type it twice)", "s2member-front", "s2member").' *</span><br />'."\n";
  439. echo '<input type="password" aria-required="true" maxlength="100" autocomplete="off" name="ws_plugin__s2member_custom_reg_field_user_pass1" id="ws-plugin--s2member-custom-reg-field-user-pass1" class="ws-plugin--s2member-custom-reg-field" value="'.format_to_edit($_p["ws_plugin__s2member_custom_reg_field_user_pass1"]).'" tabindex="'.esc_attr(($tabindex = $tabindex + 10)).'" />'."\n";
  440. echo '</label>'."\n";
  441.  
  442. echo '<label for="ws-plugin--s2member-custom-reg-field-user-pass2" title="'.esc_attr(_x("Please type your Password twice to confirm.", "s2member-front", "s2member")).'">'."\n";
  443. echo '<input type="password" maxlength="100" autocomplete="off" name="ws_plugin__s2member_custom_reg_field_user_pass2" id="ws-plugin--s2member-custom-reg-field-user-pass2" class="ws-plugin--s2member-custom-reg-field" value="'.format_to_edit($_p["ws_plugin__s2member_custom_reg_field_user_pass2"]).'" tabindex="'.esc_attr(($tabindex = $tabindex + 10)).'" />'."\n";
  444. echo '</label>'."\n";
  445.  
  446. echo '<div id="ws-plugin--s2member-custom-reg-field-user-pass-strength" class="ws-plugin--s2member-password-strength"><em>'._x("password strength indicator", "s2member-front", "s2member").'</em></div>'."\n";
  447.  
  448. echo '</p>'."\n";
  449.  
  450. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  451. do_action("ws_plugin__s2member_during_custom_registration_fields_after_user_pass", get_defined_vars());
  452. unset /* Unset defined __refs, __v. */($__refs, $__v);
  453. }
  454. if($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_names"])
  455. {
  456. echo '<div class="ws-plugin--s2member-custom-reg-field-divider-section"></div>'."\n";
  457.  
  458. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  459. do_action("ws_plugin__s2member_during_custom_registration_fields_before_first_name", get_defined_vars());
  460. unset /* Unset defined __refs, __v. */($__refs, $__v);
  461.  
  462. echo '<p>'."\n";
  463. echo '<label for="ws-plugin--s2member-custom-reg-field-first-name">'."\n";
  464. echo '<span>'._x("First Name", "s2member-front", "s2member").' *</span><br />'."\n";
  465. echo '<input type="text" aria-required="true" maxlength="100" autocomplete="off" name="ws_plugin__s2member_custom_reg_field_first_name" id="ws-plugin--s2member-custom-reg-field-first-name" class="ws-plugin--s2member-custom-reg-field" value="'.esc_attr($_p["ws_plugin__s2member_custom_reg_field_first_name"]).'" tabindex="'.esc_attr(($tabindex = $tabindex + 10)).'" />'."\n";
  466. echo '</label>'."\n";
  467. echo '</p>'."\n";
  468.  
  469. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  470. do_action("ws_plugin__s2member_during_custom_registration_fields_after_first_name", get_defined_vars());
  471. unset /* Unset defined __refs, __v. */($__refs, $__v);
  472.  
  473. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  474. do_action("ws_plugin__s2member_during_custom_registration_fields_before_last_name", get_defined_vars());
  475. unset /* Unset defined __refs, __v. */($__refs, $__v);
  476.  
  477. echo '<p>'."\n";
  478. echo '<label for="ws-plugin--s2member-custom-reg-field-last-name">'."\n";
  479. echo '<span>'._x("Last Name", "s2member-front", "s2member").' *</span><br />'."\n";
  480. echo '<input type="text" aria-required="true" maxlength="100" autocomplete="off" name="ws_plugin__s2member_custom_reg_field_last_name" id="ws-plugin--s2member-custom-reg-field-last-name" class="ws-plugin--s2member-custom-reg-field" value="'.esc_attr($_p["ws_plugin__s2member_custom_reg_field_last_name"]).'" tabindex="'.esc_attr(($tabindex = $tabindex + 10)).'" />'."\n";
  481. echo '</label>'."\n";
  482. echo '</p>'."\n";
  483.  
  484. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  485. do_action("ws_plugin__s2member_during_custom_registration_fields_after_last_name", get_defined_vars());
  486. unset /* Unset defined __refs, __v. */($__refs, $__v);
  487. }
  488. if($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"])
  489. if($fields_applicable = c_ws_plugin__s2member_custom_reg_fields::custom_fields_configured_at_level("auto-detection", "registration"))
  490. {
  491. $tabindex = /* Start tabindex at +9 ( +1 below ). */ $tabindex + 9;
  492.  
  493. foreach(json_decode($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field)
  494. {
  495. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  496. do_action("ws_plugin__s2member_during_custom_registration_fields_before_custom_fields", get_defined_vars());
  497. unset /* Unset defined __refs, __v. */($__refs, $__v);
  498.  
  499. if /* Field applicable? */(in_array($field["id"], $fields_applicable))
  500. {
  501. $field_var = preg_replace("/[^a-z0-9]/i", "_", strtolower($field["id"]));
  502. $field_id_class = preg_replace("/_/", "-", $field_var);
  503.  
  504. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  505. if(apply_filters("ws_plugin__s2member_during_custom_registration_fields_during_custom_fields_display", true, get_defined_vars()))
  506. {
  507. if /* Starts a new section? */(!empty($field["section"]) && $field["section"] === "yes")
  508. echo '<div class="ws-plugin--s2member-custom-reg-field-divider-section'.((!empty($field["sectitle"])) ? '-title' : '').'">'.((!empty($field["sectitle"])) ? $field["sectitle"] : '').'</div>';
  509.  
  510. echo '<p>'."\n";
  511. echo '<label for="ws-plugin--s2member-custom-reg-field-'.esc_attr($field_id_class).'">'."\n";
  512. echo '<span'.((preg_match("/^(checkbox|pre_checkbox)$/", $field["type"])) ? ' style="display:none;"' : '').'>'.$field["label"].(($field["required"] === "yes") ? ' *' : '').'</span></label>'.((preg_match("/^(checkbox|pre_checkbox)$/", $field["type"])) ? '' : '<br />')."\n";
  513. echo c_ws_plugin__s2member_custom_reg_fields::custom_field_gen(__FUNCTION__, $field, "ws_plugin__s2member_custom_reg_field_", "ws-plugin--s2member-custom-reg-field-", "ws-plugin--s2member-custom-reg-field", "", ($tabindex = $tabindex + 1), "", $_p, $_p["ws_plugin__s2member_custom_reg_field_".$field_var], "registration");
  514. echo '</p>'."\n";
  515. }
  516. unset /* Unset defined __refs, __v. */($__refs, $__v);
  517. }
  518. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  519. do_action("ws_plugin__s2member_during_custom_registration_fields_after_custom_fields", get_defined_vars());
  520. unset /* Unset defined __refs, __v. */($__refs, $__v);
  521. }
  522. }
  523. if($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_opt_in"] && c_ws_plugin__s2member_list_servers::list_servers_integrated())
  524. {
  525. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  526. do_action("ws_plugin__s2member_during_custom_registration_fields_before_opt_in", get_defined_vars());
  527. unset /* Unset defined __refs, __v. */($__refs, $__v);
  528.  
  529. echo '<p>'."\n";
  530. echo '<label for="ws-plugin--s2member-custom-reg-field-opt-in">'."\n";
  531. echo '<input type="checkbox" name="ws_plugin__s2member_custom_reg_field_opt_in" id="ws-plugin--s2member-custom-reg-field-opt-in" class="ws-plugin--s2member-custom-reg-field" value="1"'.(((empty($_p) && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_opt_in"] == 1) || $_p["ws_plugin__s2member_custom_reg_field_opt_in"]) ? ' checked="checked"' : '').' tabindex="'.esc_attr(($tabindex = $tabindex + 10)).'" />'."\n";
  532. echo $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_opt_in_label"]."\n";
  533. echo '</label>'."\n";
  534. echo '</p>'."\n";
  535.  
  536. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  537. do_action("ws_plugin__s2member_during_custom_registration_fields_after_opt_in", get_defined_vars());
  538. unset /* Unset defined __refs, __v. */($__refs, $__v);
  539. }
  540. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  541. do_action("ws_plugin__s2member_during_custom_registration_fields_after", get_defined_vars());
  542. unset /* Unset defined __refs, __v. */($__refs, $__v);
  543.  
  544. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  545. do_action("ws_plugin__s2member_after_custom_registration_fields", get_defined_vars());
  546. unset /* Unset defined __refs, __v. */($__refs, $__v);
  547.  
  548. return /* Return for uniformity. */;
  549. }
  550. }
  551. }
  552. ?>

s2member\includes\classes\custom-reg-fields.inc.php

Source Code Documentation