| 1 |
<?php |
| 2 |
/** |
| 3 |
* Profile modifications for BuddyPress ( inner processing routines ). |
| 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\Profiles |
| 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_profile_mods_4bp_in")) |
| 21 |
{ |
| 22 |
/** |
| 23 |
* Profile modifications for BuddyPress ( inner processing routines ). |
| 24 |
* |
| 25 |
* @package s2Member\Profiles |
| 26 |
* @since 3.5 |
| 27 |
*/ |
| 28 |
class c_ws_plugin__s2member_profile_mods_4bp_in |
| 29 |
{ |
| 30 |
/** |
| 31 |
* Handles Profile modifications for Custom Fields *( created with s2Member )*; integrated with BuddyPress. |
| 32 |
* |
| 33 |
* @package s2Member\Profiles |
| 34 |
* @since 3.5 |
| 35 |
* |
| 36 |
* @attaches-to ``add_action("init");`` |
| 37 |
* |
| 38 |
* @return null After re-configuring the ``$current_user`` object. |
| 39 |
*/ |
| 40 |
public static function handle_profile_modifications_4bp () |
| 41 |
{ |
| 42 |
global $current_user; /* We'll need to update this global object. */ |
| 43 |
/**/ |
| 44 |
$user = &$current_user; /* Shorter reference to the ``$current_user`` object. */ |
| 45 |
/**/ |
| 46 |
do_action ("ws_plugin__s2member_before_handle_profile_modifications_4bp", get_defined_vars ()); |
| 47 |
/**/ |
| 48 |
if (!empty ($_POST["ws_plugin__s2member_profile_4bp_save"]) && is_user_logged_in () && is_object ($user) && !empty ($user->ID) && ($user_id = $user->ID)) |
| 49 |
{ |
| 50 |
if (($nonce = $_POST["ws_plugin__s2member_profile_4bp_save"]) && wp_verify_nonce ($nonce, "ws-plugin--s2member-profile-4bp-save")) |
| 51 |
{ |
| 52 |
$GLOBALS["ws_plugin__s2member_profile_4bp_saved"] = true; /* Global flag as having been saved/updated successfully. */ |
| 53 |
/**/ |
| 54 |
$_p = c_ws_plugin__s2member_utils_strings::trim_deep (stripslashes_deep ($_POST)); /* Clean ``$_POST`` vars. */ |
| 55 |
/**/ |
| 56 |
if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"]) |
| 57 |
if ($fields_applicable = c_ws_plugin__s2member_custom_reg_fields::custom_fields_configured_at_level ("auto-detection", "profile")) |
| 58 |
{ |
| 59 |
$_existing_fields = get_user_option ("s2member_custom_fields", $user_id); |
| 60 |
/**/ |
| 61 |
foreach (json_decode ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field) |
| 62 |
{ |
| 63 |
$field_var = preg_replace ("/[^a-z0-9]/i", "_", strtolower ($field["id"])); |
| 64 |
$field_id_class = preg_replace ("/_/", "-", $field_var); |
| 65 |
/**/ |
| 66 |
if (!in_array ($field["id"], $fields_applicable) || strpos ($field["editable"], "no") === 0) |
| 67 |
{ |
| 68 |
if (isset ($_existing_fields[$field_var]) && ((is_array ($_existing_fields[$field_var]) && !empty ($_existing_fields[$field_var])) || (is_string ($_existing_fields[$field_var]) && strlen ($_existing_fields[$field_var])))) |
| 69 |
$fields[$field_var] = $_existing_fields[$field_var]; |
| 70 |
else /* Else ``unset()``. */ |
| 71 |
unset($fields[$field_var]); |
| 72 |
} |
| 73 |
else if ($field["required"] === "yes" && (!isset ($_p["ws_plugin__s2member_profile_4bp_" . $field_var]) || (!is_array ($_p["ws_plugin__s2member_profile_4bp_" . $field_var]) && !is_string ($_p["ws_plugin__s2member_profile_4bp_" . $field_var])) || (is_array ($_p["ws_plugin__s2member_profile_4bp_" . $field_var]) && empty ($_p["ws_plugin__s2member_profile_4bp_" . $field_var])) || (is_string ($_p["ws_plugin__s2member_profile_4bp_" . $field_var]) && !strlen ($_p["ws_plugin__s2member_profile_4bp_" . $field_var])))) |
| 74 |
{ |
| 75 |
if (isset ($_existing_fields[$field_var]) && ((is_array ($_existing_fields[$field_var]) && !empty ($_existing_fields[$field_var])) || (is_string ($_existing_fields[$field_var]) && strlen ($_existing_fields[$field_var])))) |
| 76 |
$fields[$field_var] = $_existing_fields[$field_var]; |
| 77 |
else /* Else ``unset()``. */ |
| 78 |
unset($fields[$field_var]); |
| 79 |
} |
| 80 |
else if (isset ($_p["ws_plugin__s2member_profile_4bp_" . $field_var])) |
| 81 |
{ |
| 82 |
if ((is_array ($_p["ws_plugin__s2member_profile_4bp_" . $field_var]) && !empty ($_p["ws_plugin__s2member_profile_4bp_" . $field_var])) || (is_string ($_p["ws_plugin__s2member_profile_4bp_" . $field_var]) && strlen ($_p["ws_plugin__s2member_profile_4bp_" . $field_var]))) |
| 83 |
$fields[$field_var] = $_p["ws_plugin__s2member_profile_4bp_" . $field_var]; |
| 84 |
else /* Else ``unset()``. */ |
| 85 |
unset($fields[$field_var]); |
| 86 |
} |
| 87 |
else /* Else ``unset()``. */ |
| 88 |
unset($fields[$field_var]); |
| 89 |
} |
| 90 |
/**/ |
| 91 |
if (!empty ($fields)) |
| 92 |
update_user_option ($user_id, "s2member_custom_fields", $fields); |
| 93 |
else /* Else delete their Custom Fields? */ |
| 94 |
delete_user_option ($user_id, "s2member_custom_fields"); |
| 95 |
} |
| 96 |
/**/ |
| 97 |
eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); |
| 98 |
do_action ("ws_plugin__s2member_during_handle_profile_modifications_4bp", get_defined_vars ()); |
| 99 |
unset ($__refs, $__v); /* Unset defined __refs, __v. */ |
| 100 |
/**/ |
| 101 |
$user = new WP_User ($user_id); /* Update the ``WP_User`` object for the current User/Member. */ |
| 102 |
(function_exists ("setup_userdata")) ? setup_userdata () : null; /* Update global vars. */ |
| 103 |
} |
| 104 |
} |
| 105 |
/**/ |
| 106 |
do_action ("ws_plugin__s2member_after_handle_profile_modifications_4bp", get_defined_vars ()); |
| 107 |
/**/ |
| 108 |
return; /* Return for uniformity. */ |
| 109 |
} |
| 110 |
} |
| 111 |
} |
| 112 |
?> |