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