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