PageRenderTime 37ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/s2member/includes/classes/custom-reg-fields-4bp.inc.php

https://gitlab.com/Gashler/dp
PHP | 286 lines | 195 code | 38 blank | 53 comment | 63 complexity | dab8a6872666cd8373b608b8480cea23 MD5 | raw file
  1. <?php
  2. /**
  3. * Custom Registration/Profile Fields for BuddyPress integration.
  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. if (!class_exists ("c_ws_plugin__s2member_custom_reg_fields_4bp"))
  20. {
  21. /**
  22. * Custom Registration/Profile Fields for BuddyPress integration.
  23. *
  24. * @package s2Member\Custom_Reg_Fields
  25. * @since 3.5
  26. */
  27. class c_ws_plugin__s2member_custom_reg_fields_4bp
  28. {
  29. /**
  30. * Adds Custom Fields to BuddyPress Registration Form.
  31. *
  32. * @package s2Member\Custom_Reg_Fields
  33. * @since 110524RC
  34. *
  35. * @attaches-to ``add_action("bp_after_signup_profile_fields");``
  36. *
  37. * @return null
  38. *
  39. * @todo Optimize with ``empty()``.
  40. */
  41. public static function custom_registration_fields_4bp ()
  42. {
  43. static $processed = /* Process this routine only one time. */ false;
  44. do_action ("ws_plugin__s2member_before_custom_registration_fields_4bp", get_defined_vars ());
  45. if (!$processed && in_array ("registration", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields_4bp"]))
  46. if (apply_filters ("ws_plugin__s2member_custom_registration_fields_4bp_display", true, get_defined_vars ()))
  47. if (bp_is_register_page () && ($processed = true))
  48. {
  49. $_p = (!empty ($_POST)) ? c_ws_plugin__s2member_utils_strings::trim_deep (stripslashes_deep ($_POST)) : array ();
  50. if (($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"] && ($fields_applicable = c_ws_plugin__s2member_custom_reg_fields::custom_fields_configured_at_level ("auto-detection", "registration"))) || ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_opt_in"] && c_ws_plugin__s2member_list_servers::list_servers_integrated ()))
  51. if (($close_section_container = true))
  52. {
  53. echo '<div id="ws-plugin--s2member-custom-reg-fields-4bp-section" class="ws-plugin--s2member-custom-reg-fields-4bp-section register-section">' . "\n";
  54. echo '<div id="ws-plugin--s2member-custom-reg-fields-4bp-container" class="ws-plugin--s2member-custom-reg-fields-4bp-container">' . "\n";
  55. echo '<input type="hidden" name="ws_plugin__s2member_registration" value="' . esc_attr (wp_create_nonce ("ws-plugin--s2member-registration")) . '" />' . "\n";
  56. }
  57. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  58. do_action ("ws_plugin__s2member_during_custom_registration_fields_4bp_before", get_defined_vars ());
  59. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  60. if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"])
  61. if ($fields_applicable = c_ws_plugin__s2member_custom_reg_fields::custom_fields_configured_at_level ("auto-detection", "registration"))
  62. {
  63. foreach (json_decode ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field)
  64. {
  65. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  66. do_action ("ws_plugin__s2member_during_custom_registration_fields_4bp_before_custom_fields", get_defined_vars ());
  67. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  68. if /* Field applicable? */ (in_array ($field["id"], $fields_applicable))
  69. {
  70. $field_var = preg_replace ("/[^a-z0-9]/i", "_", strtolower ($field["id"]));
  71. $field_id_class = preg_replace ("/_/", "-", $field_var);
  72. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  73. if (apply_filters ("ws_plugin__s2member_during_custom_registration_fields_4bp_during_custom_fields_display", true, get_defined_vars ()))
  74. {
  75. if /* Starts a new section? */ (!empty ($field["section"]) && $field["section"] === "yes")
  76. echo '<div class="ws-plugin--s2member-custom-reg-field-4bp-divider-section' . ((!empty ($field["sectitle"])) ? '-title' : '') . '">' . ((!empty ($field["sectitle"])) ? $field["sectitle"] : '') . '</div>';
  77. echo '<div class="ws-plugin--s2member-custom-reg-field-4bp ws-plugin--s2member-custom-reg-field-4bp-' . esc_attr ($field_id_class) . ' field_' . esc_attr ($field_var) . ' editfield">' . "\n";
  78. echo '<label for="ws-plugin--s2member-custom-reg-field-4bp-' . esc_attr ($field_id_class) . '">' . "\n";
  79. echo '<span' . ((preg_match ("/^(checkbox|pre_checkbox)$/", $field["type"])) ? ' style="display:none;"' : '') . '>' . $field["label"] . (($field["required"] === "yes") ? ' *' : '') . '</span></label>' . "\n";
  80. 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-4bp-", "ws-plugin--s2member-custom-reg-field-4bp", "", "", "", $_p, $_p["ws_plugin__s2member_custom_reg_field_" . $field_var], "registration");
  81. echo '</div>' . "\n";
  82. }
  83. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  84. }
  85. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  86. do_action ("ws_plugin__s2member_during_custom_registration_fields_4bp_after_custom_fields", get_defined_vars ());
  87. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  88. }
  89. }
  90. if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_opt_in"] && c_ws_plugin__s2member_list_servers::list_servers_integrated ())
  91. {
  92. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  93. do_action ("ws_plugin__s2member_during_custom_registration_fields_4bp_before_opt_in", get_defined_vars ());
  94. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  95. echo '<div class="ws-plugin--s2member-custom-reg-field-4bp field_opt_in editfield">' . "\n";
  96. echo '<label for="ws-plugin--s2member-custom-reg-field-4bp-opt-in">' . "\n";
  97. echo '<input type="checkbox" name="ws_plugin__s2member_custom_reg_field_opt_in" id="ws-plugin--s2member-custom-reg-field-4bp-opt-in" class="ws-plugin--s2member-custom-reg-field-4bp" 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";
  98. echo $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_opt_in_label"] . "\n";
  99. echo '</label>' . "\n";
  100. echo '</div>' . "\n";
  101. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  102. do_action ("ws_plugin__s2member_during_custom_registration_fields_4bp_after_opt_in", get_defined_vars ());
  103. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  104. }
  105. if (isset ($close_section_container) && $close_section_container)
  106. echo '</div>' . "\n" . '</div>' . "\n";
  107. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  108. do_action ("ws_plugin__s2member_during_custom_registration_fields_4bp_after", get_defined_vars ());
  109. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  110. }
  111. do_action ("ws_plugin__s2member_after_custom_registration_fields_4bp", get_defined_vars ());
  112. return /* Return for uniformity. */;
  113. }
  114. /**
  115. * Adds Custom Fields to BuddyPress Profiles.
  116. *
  117. * @package s2Member\Custom_Reg_Fields
  118. * @since 110524RC
  119. *
  120. * @attaches-to ``add_action("bp_after_profile_field_content");``
  121. *
  122. * @return null
  123. */
  124. public static function custom_profile_fields_4bp ()
  125. {
  126. global /* Global BuddyPress object reference. */ $bp;
  127. static $processed = /* Process this routine only one time. */ false;
  128. do_action ("ws_plugin__s2member_before_custom_profile_fields_4bp", get_defined_vars ());
  129. if (!$processed && in_array ("profile", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields_4bp"]))
  130. if (apply_filters ("ws_plugin__s2member_custom_profile_fields_4bp_display", true, get_defined_vars ()))
  131. if (bp_is_user_profile () && (( /* BuddyPress v1.5. */function_exists ("bp_is_user_profile_edit") && bp_is_user_profile_edit ())
  132. || ( /* for BuddyPress < v1.5. */function_exists ("bp_is_profile_edit") && bp_is_profile_edit ())) && (int)bp_get_the_profile_group_id () === 1)
  133. if (isset ($bp->displayed_user->id) && ($user_id = $bp->displayed_user->id))
  134. if (($processed = true) /* Mark as having been processed now. */)
  135. {
  136. echo '<input type="hidden" name="ws_plugin__s2member_profile_4bp_save" id="ws-plugin--s2member-profile-4bp-save" value="' . esc_attr (wp_create_nonce ("ws-plugin--s2member-profile-4bp-save")) . '" />' . "\n";
  137. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  138. do_action ("ws_plugin__s2member_during_custom_profile_fields_4bp_before", get_defined_vars ());
  139. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  140. if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"])
  141. if (($level = c_ws_plugin__s2member_user_access::user_access_level (new WP_User ($user_id))) >= 0)
  142. if ($fields_applicable = c_ws_plugin__s2member_custom_reg_fields::custom_fields_configured_at_level ($level, "profile"))
  143. {
  144. $fields = /* Existing Custom Fields. */get_user_option ("s2member_custom_fields", $user_id);
  145. foreach (json_decode ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field)
  146. {
  147. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  148. do_action ("ws_plugin__s2member_during_custom_profile_fields_4bp_before_custom_fields", get_defined_vars ());
  149. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  150. if /* Field applicable? */ (in_array ($field["id"], $fields_applicable))
  151. {
  152. $field_var = preg_replace ("/[^a-z0-9]/i", "_", strtolower ($field["id"]));
  153. $field_id_class = preg_replace ("/_/", "-", $field_var);
  154. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  155. if (apply_filters ("ws_plugin__s2member_during_custom_profile_fields_4bp_during_custom_fields_display", true, get_defined_vars ()))
  156. {
  157. if /* Starts a new section? */ (!empty ($field["section"]) && $field["section"] === "yes")
  158. echo '<div class="ws-plugin--s2member-profile-field-4bp-divider-section' . ((!empty ($field["sectitle"])) ? '-title' : '') . '">' . ((!empty ($field["sectitle"])) ? $field["sectitle"] : '') . '</div>';
  159. echo '<div class="ws-plugin--s2member-profile-field-4bp ws-plugin--s2member-profile-4bp-' . esc_attr ($field_id_class) . ' field_' . esc_attr ($field_var) . ' editfield">' . "\n";
  160. echo '<label for="ws-plugin--s2member-profile-4bp-' . esc_attr ($field_id_class) . '">' . "\n";
  161. echo '<span' . ((preg_match ("/^(checkbox|pre_checkbox)$/", $field["type"])) ? ' style="display:none;"' : '') . '>' . $field["label"] . (($field["required"] === "yes") ? ' *' : '') . '</span></label>' . "\n";
  162. echo c_ws_plugin__s2member_custom_reg_fields::custom_field_gen (__FUNCTION__, $field, "ws_plugin__s2member_profile_4bp_", "ws-plugin--s2member-profile-4bp-", "ws-plugin--s2member-profile-field-4bp", "", "", "", $fields, $fields[$field_var], "profile");
  163. echo '</div>' . "\n";
  164. }
  165. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  166. }
  167. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  168. do_action ("ws_plugin__s2member_during_custom_profile_fields_4bp_after_custom_fields", get_defined_vars ());
  169. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  170. }
  171. }
  172. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  173. do_action ("ws_plugin__s2member_during_custom_profile_fields_4bp_after", get_defined_vars ());
  174. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  175. }
  176. do_action ("ws_plugin__s2member_after_custom_profile_fields_4bp", get_defined_vars ());
  177. return /* Return for uniformity. */;
  178. }
  179. /**
  180. * Adds Custom Fields to BuddyPress Profiles in public view.
  181. *
  182. * @package s2Member\Custom_Reg_Fields
  183. * @since 110524RC
  184. *
  185. * @attaches-to ``add_action("bp_profile_field_item");``
  186. *
  187. * @return null
  188. */
  189. public static function custom_profile_field_items_4bp ()
  190. {
  191. global /* Global BuddyPress object reference. */ $bp;
  192. static $processed = /* Process this routine only one time. */ false;
  193. do_action ("ws_plugin__s2member_before_custom_profile_field_items_4bp", get_defined_vars ());
  194. if (!$processed && in_array ("profile-view", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields_4bp"]))
  195. if (apply_filters ("ws_plugin__s2member_custom_profile_field_items_4bp_display", true, get_defined_vars ()))
  196. if (bp_is_user_profile () && (( /* BuddyPress v1.5. */function_exists ("bp_is_user_profile_edit") && !bp_is_user_profile_edit ())
  197. || ( /* for BuddyPress < v1.5. */function_exists ("bp_is_profile_edit") && !bp_is_profile_edit ())) && (int)bp_get_the_profile_group_id () === 1)
  198. if (isset ($bp->displayed_user->id) && ($user_id = $bp->displayed_user->id))
  199. if /* Mark as having been processed now. */ (($processed = true))
  200. {
  201. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  202. do_action ("ws_plugin__s2member_during_custom_profile_field_items_4bp_before", get_defined_vars ());
  203. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  204. if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"])
  205. if (($level = c_ws_plugin__s2member_user_access::user_access_level (new WP_User ($user_id))) >= 0)
  206. if ($fields_applicable = c_ws_plugin__s2member_custom_reg_fields::custom_fields_configured_at_level ($level, "profile-view"))
  207. {
  208. $fields = /* Existing Custom Fields. */ get_user_option ("s2member_custom_fields", $user_id);
  209. foreach (json_decode ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field)
  210. {
  211. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  212. do_action ("ws_plugin__s2member_during_custom_profile_field_items_4bp_before_custom_fields", get_defined_vars ());
  213. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  214. if /* Field applicable? */ (in_array ($field["id"], $fields_applicable))
  215. {
  216. $field_var = preg_replace ("/[^a-z0-9]/i", "_", strtolower ($field["id"]));
  217. $field_id_class = preg_replace ("/_/", "-", $field_var);
  218. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  219. if (apply_filters ("ws_plugin__s2member_during_custom_profile_field_items_4bp_during_custom_fields_display", true, get_defined_vars ()))
  220. {
  221. if /* New section? */ (!empty ($field["section"]) && $field["section"] === "yes")
  222. {
  223. echo '<tr class="ws-plugin--s2member-profile-field-4bp-divider-section">' . "\n";
  224. echo '<td colspan="2"><div class="ws-plugin--s2member-profile-field-4bp-divider-section' . ((!empty ($field["sectitle"])) ? '-title' : '') . '">' . ((!empty ($field["sectitle"])) ? $field["sectitle"] : '') . '</div></td>' . "\n";
  225. echo '</tr>' . "\n";
  226. }
  227. echo '<tr class="ws-plugin--s2member-profile-field-4bp ws-plugin--s2member-profile-4bp-' . esc_attr ($field_id_class) . ' field_' . esc_attr ($field_var) . '">' . "\n";
  228. echo '<td class="ws-plugin--s2member-profile-field-4bp ws-plugin--s2member-profile-4bp-' . esc_attr ($field_id_class) . ' field_' . esc_attr ($field_var) . ' label"><span>' . $field["label"] . '</span></td>' . "\n";
  229. echo '<td class="ws-plugin--s2member-profile-field-4bp ws-plugin--s2member-profile-4bp-' . esc_attr ($field_id_class) . ' field_' . esc_attr ($field_var) . ' data">' . c_ws_plugin__s2member_custom_reg_fields::custom_field_gen (__FUNCTION__, $field, "ws_plugin__s2member_profile_4bp_", "ws-plugin--s2member-profile-4bp-", "ws-plugin--s2member-profile-field-4bp", "", "", "", $fields, $fields[$field_var], "profile-view") . '</td>' . "\n";
  230. echo '</tr>' . "\n";
  231. }
  232. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  233. }
  234. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  235. do_action ("ws_plugin__s2member_during_custom_profile_field_items_4bp_after_custom_fields", get_defined_vars ());
  236. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  237. }
  238. }
  239. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  240. do_action ("ws_plugin__s2member_during_custom_profile_field_items_4bp_after", get_defined_vars ());
  241. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  242. }
  243. do_action ("ws_plugin__s2member_after_custom_profile_field_items_4bp", get_defined_vars ());
  244. return /* Return for uniformity. */;
  245. }
  246. }
  247. }
  248. ?>