| 1 |
<?php |
| 2 |
/** |
| 3 |
* s2Member Profile modifications ( 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_in")) |
| 21 |
{ |
| 22 |
/** |
| 23 |
* s2Member Profile modifications ( inner processing routines ). |
| 24 |
* |
| 25 |
* @package s2Member\Profiles |
| 26 |
* @since 3.5 |
| 27 |
*/ |
| 28 |
class c_ws_plugin__s2member_profile_mods_in |
| 29 |
{ |
| 30 |
/** |
| 31 |
* Handles Profile modifications. |
| 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 |
* May also exit script execution when handling the Stand-Alone Profile Modification Form. |
| 40 |
*/ |
| 41 |
public static function handle_profile_modifications () |
| 42 |
{ |
| 43 |
global $current_user; /* We'll need to update this global object. */ |
| 44 |
/**/ |
| 45 |
$user = &$current_user; /* Shorter reference to the $current_user object. */ |
| 46 |
/**/ |
| 47 |
do_action ("ws_plugin__s2member_before_handle_profile_modifications", get_defined_vars ()); |
| 48 |
/**/ |
| 49 |
if (!empty ($_POST["ws_plugin__s2member_profile_save"]) && is_user_logged_in () && is_object ($user) && !empty ($user->ID) && ($user_id = $user->ID)) |
| 50 |
{ |
| 51 |
if (($nonce = $_POST["ws_plugin__s2member_profile_save"]) && wp_verify_nonce ($nonce, "ws-plugin--s2member-profile-save")) |
| 52 |
{ |
| 53 |
$GLOBALS["ws_plugin__s2member_profile_saved"] = true; /* Global flag as having been saved/updated successfully. */ |
| 54 |
/**/ |
| 55 |
$_p = c_ws_plugin__s2member_utils_strings::trim_deep (stripslashes_deep ($_POST)); /* Clean ``$_POST`` vars. */ |
| 56 |
/**/ |
| 57 |
$userdata["ID"] = $user_id; /* Needed for database update. */ |
| 58 |
/**/ |
| 59 |
if (!empty ($_p["ws_plugin__s2member_profile_email"])) |
| 60 |
if (is_email ($_p["ws_plugin__s2member_profile_email"])) |
| 61 |
if (!email_exists ($_p["ws_plugin__s2member_profile_email"])) |
| 62 |
$userdata["user_email"] = $_p["ws_plugin__s2member_profile_email"]; |
| 63 |
/**/ |
| 64 |
if (!empty ($_p["ws_plugin__s2member_profile_password1"])) |
| 65 |
if ($user->user_login !== "demo") /* No pass change on demo! */ |
| 66 |
$userdata["user_pass"] = $_p["ws_plugin__s2member_profile_password1"]; |
| 67 |
/**/ |
| 68 |
if (!empty ($_p["ws_plugin__s2member_profile_first_name"])) |
| 69 |
$userdata["first_name"] = $_p["ws_plugin__s2member_profile_first_name"]; |
| 70 |
/**/ |
| 71 |
if (!empty ($_p["ws_plugin__s2member_profile_display_name"])) |
| 72 |
$userdata["display_name"] = $_p["ws_plugin__s2member_profile_display_name"]; |
| 73 |
/**/ |
| 74 |
if (!empty ($_p["ws_plugin__s2member_profile_last_name"])) |
| 75 |
$userdata["last_name"] = $_p["ws_plugin__s2member_profile_last_name"]; |
| 76 |
/**/ |
| 77 |
wp_update_user($userdata); /* OK. Now send this array for an update. */ |
| 78 |
/**/ |
| 79 |
if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"]) |
| 80 |
if ($fields_applicable = c_ws_plugin__s2member_custom_reg_fields::custom_fields_configured_at_level ("auto-detection", "profile")) |
| 81 |
{ |
| 82 |
$_existing_fields = get_user_option ("s2member_custom_fields", $user_id); |
| 83 |
/**/ |
| 84 |
foreach (json_decode ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field) |
| 85 |
{ |
| 86 |
$field_var = preg_replace ("/[^a-z0-9]/i", "_", strtolower ($field["id"])); |
| 87 |
$field_id_class = preg_replace ("/_/", "-", $field_var); |
| 88 |
/**/ |
| 89 |
if (!in_array ($field["id"], $fields_applicable) || strpos ($field["editable"], "no") === 0) |
| 90 |
{ |
| 91 |
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])))) |
| 92 |
$fields[$field_var] = $_existing_fields[$field_var]; |
| 93 |
else /* Else ``unset()``. */ |
| 94 |
unset($fields[$field_var]); |
| 95 |
} |
| 96 |
else if ($field["required"] === "yes" && (!isset ($_p["ws_plugin__s2member_profile_" . $field_var]) || (!is_array ($_p["ws_plugin__s2member_profile_" . $field_var]) && !is_string ($_p["ws_plugin__s2member_profile_" . $field_var])) || (is_array ($_p["ws_plugin__s2member_profile_" . $field_var]) && empty ($_p["ws_plugin__s2member_profile_" . $field_var])) || (is_string ($_p["ws_plugin__s2member_profile_" . $field_var]) && !strlen ($_p["ws_plugin__s2member_profile_" . $field_var])))) |
| 97 |
{ |
| 98 |
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])))) |
| 99 |
$fields[$field_var] = $_existing_fields[$field_var]; |
| 100 |
else /* Else ``unset()``. */ |
| 101 |
unset($fields[$field_var]); |
| 102 |
} |
| 103 |
else if (isset ($_p["ws_plugin__s2member_profile_" . $field_var])) |
| 104 |
{ |
| 105 |
if ((is_array ($_p["ws_plugin__s2member_profile_" . $field_var]) && !empty ($_p["ws_plugin__s2member_profile_" . $field_var])) || (is_string ($_p["ws_plugin__s2member_profile_" . $field_var]) && strlen ($_p["ws_plugin__s2member_profile_" . $field_var]))) |
| 106 |
$fields[$field_var] = $_p["ws_plugin__s2member_profile_" . $field_var]; |
| 107 |
else /* Else ``unset()``. */ |
| 108 |
unset($fields[$field_var]); |
| 109 |
} |
| 110 |
else /* Else ``unset()``. */ |
| 111 |
unset($fields[$field_var]); |
| 112 |
} |
| 113 |
/**/ |
| 114 |
if (!empty ($fields)) |
| 115 |
update_user_option ($user_id, "s2member_custom_fields", $fields); |
| 116 |
else /* Else delete their Custom Fields? */ |
| 117 |
delete_user_option ($user_id, "s2member_custom_fields"); |
| 118 |
} |
| 119 |
/**/ |
| 120 |
eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); |
| 121 |
do_action ("ws_plugin__s2member_during_handle_profile_modifications", get_defined_vars ()); |
| 122 |
unset ($__refs, $__v); /* Unset defined __refs, __v. */ |
| 123 |
/**/ |
| 124 |
$user = new WP_User ($user_id); /* Update the ``WP_User`` object for the current User/Member. */ |
| 125 |
(function_exists ("setup_userdata")) ? setup_userdata () : null; /* Update global vars. */ |
| 126 |
/**/ |
| 127 |
$lwp = c_ws_plugin__s2member_login_redirects::login_redirection_url ($user); |
| 128 |
$lwp = (!$lwp) ? get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_welcome_page"]) : $lwp; |
| 129 |
/**/ |
| 130 |
if (empty ($_p["ws_plugin__s2member_sc_profile_save"])) |
| 131 |
{ |
| 132 |
echo '<script type="text/javascript">' . "\n"; |
| 133 |
echo "if(window.parent && window.parent != window) { window.parent.alert('" . c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Profile updated successfully.", "s2member-front", "s2member")) . "'); window.parent.location = '" . c_ws_plugin__s2member_utils_strings::esc_js_sq ($lwp) . "'; }"; |
| 134 |
echo "else if(window.opener) { window.alert('" . c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Profile updated successfully.", "s2member-front", "s2member")) . "'); window.opener.location = '" . c_ws_plugin__s2member_utils_strings::esc_js_sq ($lwp) . "'; window.close(); }"; |
| 135 |
echo "else { alert('" . c_ws_plugin__s2member_utils_strings::esc_js_sq (_x ("Profile updated successfully.", "s2member-front", "s2member")) . "'); window.location = '" . c_ws_plugin__s2member_utils_strings::esc_js_sq ($lwp) . "'; }"; |
| 136 |
echo '</script>' . "\n"; |
| 137 |
/**/ |
| 138 |
exit (); /* Clean exit. */ |
| 139 |
} |
| 140 |
} |
| 141 |
} |
| 142 |
/**/ |
| 143 |
do_action ("ws_plugin__s2member_after_handle_profile_modifications", get_defined_vars ()); |
| 144 |
/**/ |
| 145 |
return; /* Return for uniformity. */ |
| 146 |
} |
| 147 |
} |
| 148 |
} |
| 149 |
?> |