| 1 |
<?php |
| 2 |
// @codingStandardsIgnoreFile |
| 3 |
/** |
| 4 |
* Profile modifications for BuddyPress (inner processing routines). |
| 5 |
* |
| 6 |
* Copyright: © 2009-2011 |
| 7 |
* {@link http://websharks-inc.com/ WebSharks, Inc.} |
| 8 |
* (coded in the USA) |
| 9 |
* |
| 10 |
* Released under the terms of the GNU General Public License. |
| 11 |
* You should have received a copy of the GNU General Public License, |
| 12 |
* along with this software. In the main directory, see: /licensing/ |
| 13 |
* If not, see: {@link http://www.gnu.org/licenses/}. |
| 14 |
* |
| 15 |
* @package s2Member\Profiles |
| 16 |
* @since 3.5 |
| 17 |
*/ |
| 18 |
if(!defined('WPINC')) // MUST have WordPress. |
| 19 |
exit('Do not access this file directly.'); |
| 20 |
|
| 21 |
if(!class_exists('c_ws_plugin__s2member_profile_mods_4bp_in')) |
| 22 |
{ |
| 23 |
/** |
| 24 |
* Profile modifications for BuddyPress (inner processing routines). |
| 25 |
* |
| 26 |
* @package s2Member\Profiles |
| 27 |
* @since 3.5 |
| 28 |
*/ |
| 29 |
class c_ws_plugin__s2member_profile_mods_4bp_in |
| 30 |
{ |
| 31 |
/** |
| 32 |
* Handles Profile modifications for Custom Fields *(created with s2Member)*; integrated with BuddyPress. |
| 33 |
* |
| 34 |
* @package s2Member\Profiles |
| 35 |
* @since 3.5 |
| 36 |
* |
| 37 |
* @attaches-to ``add_action('xprofile_updated_profile');`` |
| 38 |
*/ |
| 39 |
public static function handle_profile_modifications_4bp() |
| 40 |
{ |
| 41 |
global $current_user; // We'll need to update this global object. |
| 42 |
|
| 43 |
$user = & $current_user; // Shorter reference to the ``$current_user`` object. |
| 44 |
|
| 45 |
do_action('ws_plugin__s2member_before_handle_profile_modifications_4bp', get_defined_vars()); |
| 46 |
|
| 47 |
if(!empty($_POST['ws_plugin__s2member_profile_4bp_save']) && is_user_logged_in() && is_object($user) && !empty($user->ID) && ($user_id = $user->ID)) |
| 48 |
{ |
| 49 |
if(($nonce = $_POST['ws_plugin__s2member_profile_4bp_save']) && wp_verify_nonce($nonce, 'ws-plugin--s2member-profile-4bp-save')) |
| 50 |
{ |
| 51 |
$GLOBALS['ws_plugin__s2member_profile_4bp_saved'] = TRUE; // Global flag as having been saved/updated successfully. |
| 52 |
|
| 53 |
$_p = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_POST)); // Clean ``$_POST`` vars. |
| 54 |
|
| 55 |
if($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields']) |
| 56 |
if($fields_applicable = c_ws_plugin__s2member_custom_reg_fields::custom_fields_configured_at_level('auto-detection', 'profile')) |
| 57 |
{ |
| 58 |
$fields = array(); // Initialize the array of fields. |
| 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 unset($fields[$field_var]); |
| 71 |
} |
| 72 |
else if( // If the field is required but missing; or it was provided but invalid... |
| 73 |
($field['required'] === 'yes' && (!isset ($_p['ws_plugin__s2member_profile_4bp_'.$field_var]) |
| 74 |
|| (!is_array($_p['ws_plugin__s2member_profile_4bp_'.$field_var]) && !is_string($_p['ws_plugin__s2member_profile_4bp_'.$field_var])) |
| 75 |
|| (is_array($_p['ws_plugin__s2member_profile_4bp_'.$field_var]) && empty($_p['ws_plugin__s2member_profile_4bp_'.$field_var])) |
| 76 |
|| (is_string($_p['ws_plugin__s2member_profile_4bp_'.$field_var]) && !strlen($_p['ws_plugin__s2member_profile_4bp_'.$field_var])))) |
| 77 |
|| (isset ($_p['ws_plugin__s2member_profile_4bp_'.$field_var]) && c_ws_plugin__s2member_custom_reg_fields::validation_errors(array($field_var => $_p['ws_plugin__s2member_profile_4bp_'.$field_var]), array($field))) |
| 78 |
) |
| 79 |
{ |
| 80 |
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])))) |
| 81 |
$fields[$field_var] = $_existing_fields[$field_var]; |
| 82 |
else unset($fields[$field_var]); |
| 83 |
} |
| 84 |
else if(isset ($_p['ws_plugin__s2member_profile_4bp_'.$field_var])) |
| 85 |
{ |
| 86 |
if(((is_array($_p['ws_plugin__s2member_profile_4bp_'.$field_var]) && !empty($_p['ws_plugin__s2member_profile_4bp_'.$field_var])) |
| 87 |
|| (is_string($_p['ws_plugin__s2member_profile_4bp_'.$field_var]) && strlen($_p['ws_plugin__s2member_profile_4bp_'.$field_var]))) |
| 88 |
&& !c_ws_plugin__s2member_custom_reg_fields::validation_errors(array($field_var => $_p['ws_plugin__s2member_profile_4bp_'.$field_var]), array($field)) |
| 89 |
) |
| 90 |
$fields[$field_var] = $_p['ws_plugin__s2member_profile_4bp_'.$field_var]; |
| 91 |
else unset($fields[$field_var]); |
| 92 |
} |
| 93 |
else unset($fields[$field_var]); |
| 94 |
} |
| 95 |
if(!empty($fields)) |
| 96 |
update_user_option($user_id, 's2member_custom_fields', $fields); |
| 97 |
else // Else delete their Custom Fields? |
| 98 |
delete_user_option($user_id, 's2member_custom_fields'); |
| 99 |
} |
| 100 |
foreach(array_keys(get_defined_vars()) as $__v) $__refs[$__v] =& $$__v; |
| 101 |
do_action('ws_plugin__s2member_during_handle_profile_modifications_4bp', get_defined_vars()); |
| 102 |
unset($__refs, $__v); |
| 103 |
|
| 104 |
clean_user_cache($user_id); |
| 105 |
wp_cache_delete($user_id, 'user_meta'); |
| 106 |
$user = new WP_User($user_id); // Fresh object. |
| 107 |
if(function_exists('setup_userdata')) setup_userdata(); |
| 108 |
|
| 109 |
//260829.0040 Keep BuddyPress profile integrations aligned with the standard post-save user-refresh lifecycle hook. |
| 110 |
foreach(array_keys(get_defined_vars()) as $__v) $__refs[$__v] =& $$__v; |
| 111 |
do_action('ws_plugin__s2member_during_handle_profile_modifications_4bp_after_user_refresh', get_defined_vars()); |
| 112 |
unset($__refs, $__v); |
| 113 |
|
| 114 |
$role = c_ws_plugin__s2member_user_access::user_access_role($user); |
| 115 |
$level = c_ws_plugin__s2member_user_access::user_access_role_to_level($role); |
| 116 |
|
| 117 |
if(!empty($_p['ws_plugin__s2member_profile_4bp_opt_in']) && $role && $level >= 0) |
| 118 |
{ |
| 119 |
c_ws_plugin__s2member_list_servers::process_list_servers($role, $level, $user->user_login, '', $user->user_email, $user->first_name, $user->last_name, c_ws_plugin__s2member_utils_ip::current(), TRUE, TRUE, $user_id); |
| 120 |
} |
| 121 |
else if($role && $level >= 0 && $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_opt_in']) |
| 122 |
{ |
| 123 |
c_ws_plugin__s2member_list_servers::process_list_server_removals($role, $level, $user->user_login, '', $user->user_email, $user->first_name, $user->last_name, c_ws_plugin__s2member_utils_ip::current(), TRUE, $user_id); |
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
do_action('ws_plugin__s2member_after_handle_profile_modifications_4bp', get_defined_vars()); |
| 128 |
} |
| 129 |
} |
| 130 |
} |
| 131 |
|