Changeset 5699
- Timestamp:
- 02/11/2012 02:14:07 AM (13 years ago)
- Location:
- trunk/bp-xprofile
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-xprofile/bp-xprofile-actions.php
r5329 r5699 1 1 <?php 2 /******************************************************************************* 3 * Action functions are exactly the same as screen functions, however they do 4 * not have a template screen associated with them. Usually they will send the 5 * user back to the default screen after execution. 2 3 /** 4 * BuddyPress XProfile Actions 5 * 6 * Action functions are exactly the same as screen functions, however they do not 7 * have a template screen associated with them. Usually they will send the user 8 * back to the default screen after execution. 9 * 10 * @package BuddyPress 11 * @subpackage XProfileActions 6 12 */ 7 13 … … 16 22 * 17 23 * @package BuddyPress Xprofile 18 * @global object $bp Global BuddyPress settings object19 24 * @uses bp_core_delete_avatar() Deletes the active avatar for the logged in user. 20 25 * @uses add_action() Runs a specific function for an action when it fires. … … 22 27 */ 23 28 function xprofile_action_delete_avatar() { 24 global $bp;25 29 26 30 if ( !bp_is_user_change_avatar() || !bp_is_action_variable( 'delete-avatar', 0 ) ) -
trunk/bp-xprofile/bp-xprofile-activity.php
r5437 r5699 1 1 <?php 2 2 3 /** 3 4 * BuddyPress XProfile Activity & Notification Functions … … 7 8 * 8 9 * @package BuddyPress 9 * @subpackage XProfile 10 * @subpackage XProfileActivity 10 11 */ 11 12 … … 29 30 * it will show in the users activity stream (if installed) 30 31 * 31 * @package BuddyPress XProfile 32 * @package BuddyPress 33 * @subpackage XProfileActivity 32 34 * @param $args Array containing all variables used after extract() call 33 35 * @global $bp The global BuddyPress settings variable created in bp_core_current_times() … … 35 37 */ 36 38 function xprofile_record_activity( $args = '' ) { 37 global $bp;38 39 39 40 if ( !bp_is_active( 'activity' ) ) 40 41 return false; 42 43 global $bp; 41 44 42 45 $defaults = array ( … … 80 83 */ 81 84 function xprofile_delete_activity( $args = '' ) { 85 86 if ( ! bp_is_active( 'activity' ) ) 87 return false; 88 82 89 global $bp; 83 90 84 if ( bp_is_active( 'activity' ) ) {91 extract( $args ); 85 92 86 extract( $args ); 87 88 bp_activity_delete_by_item_id( array( 89 'item_id' => $item_id, 90 'component' => $bp->profile->id, 91 'type' => $type, 92 'user_id' => $user_id, 93 'secondary_item_id' => $secondary_item_id 94 ) ); 95 } 93 bp_activity_delete_by_item_id( array( 94 'item_id' => $item_id, 95 'component' => $bp->profile->id, 96 'type' => $type, 97 'user_id' => $user_id, 98 'secondary_item_id' => $secondary_item_id 99 ) ); 96 100 } 97 101 … … 113 117 */ 114 118 function bp_xprofile_new_avatar_activity() { 115 global $bp;116 119 117 120 if ( !bp_is_active( 'activity' ) ) … … 130 133 } 131 134 add_action( 'xprofile_avatar_uploaded', 'bp_xprofile_new_avatar_activity' ); 135 132 136 ?> -
trunk/bp-xprofile/bp-xprofile-admin.php
r5598 r5699 1 1 <?php 2 3 /** 4 * BuddyPress XProfile Admin 5 * 6 * @package BuddyPress 7 * @subpackage XProfileAdmin 8 */ 9 2 10 // Exit if accessed directly 3 11 if ( !defined( 'ABSPATH' ) ) exit; … … 8 16 * 9 17 * @package BuddyPress XProfile 10 * @global object $bp Global BuddyPress settings object11 * @global $wpdb WordPress DB access object.12 18 * @uses bp_current_user_can() returns true if the current user is a site admin, false if not 13 19 * @uses bp_xprofile_install() runs the installation of DB tables for the xprofile component … … 18 24 */ 19 25 function xprofile_add_admin_menu() { 20 global $wpdb, $bp;21 26 22 27 if ( !bp_current_user_can( 'bp_moderate' ) ) … … 34 39 */ 35 40 function xprofile_admin( $message = '', $type = 'error' ) { 36 global $bp;37 41 38 42 $type = preg_replace( '|[^a-z]|i', '', $type ); … … 40 44 $groups = BP_XProfile_Group::get( array( 41 45 'fetch_fields' => true 42 ) );46 ) ); 43 47 44 48 if ( isset( $_GET['mode'] ) && isset( $_GET['group_id'] ) && 'add_field' == $_GET['mode'] ) … … 63 67 xprofile_admin_manage_group( $_GET['group_id'] ); 64 68 65 else { 66 ?> 69 else { ?> 67 70 68 71 <div class="wrap"> … … 71 74 72 75 <h2> 73 74 76 <?php _e( 'Profile Fields', 'buddypress'); ?> 75 76 <a id="add_group" class="add-new-h2" href="admin.php?page=bp-profile-setup&mode=add_group"><?php _e( 'Add New Group', 'buddypress' ); ?></a> 77 <a id="add_group" class="add-new-h2" href="admin.php?page=bp-profile-setup&mode=add_group"><?php _e( 'Add New Field Group', 'buddypress' ); ?></a> 77 78 </h2> 78 79 79 <p><?php _e( 'Your users will distinguish themselves through their profile page. You must give them profile fields that allow them to describe themselves in a way that is relevant to the theme of your social network.', 'buddypress'); ?></p> 80 <p><?php echo sprintf( __( 'NOTE: Any fields in the "%s" group will appear on the signup page.', 'buddypress' ), esc_html( stripslashes( bp_get_option( 'bp-xprofile-base-group-name' ) ) ) ) ?></p> 80 <p><?php echo sprintf( __( 'Fields in the "%s" group will appear on the signup page.', 'buddypress' ), esc_html( stripslashes( bp_get_option( 'bp-xprofile-base-group-name' ) ) ) ) ?></p> 81 81 82 82 <form action="" id="profile-field-form" method="post"> 83 83 84 <?php wp_nonce_field( 'bp_reorder_fields', '_wpnonce_reorder_fields' ); ?> 85 86 <?php wp_nonce_field( 'bp_reorder_groups', '_wpnonce_reorder_groups', false ); 84 <?php 85 86 wp_nonce_field( 'bp_reorder_fields', '_wpnonce_reorder_fields' ); 87 wp_nonce_field( 'bp_reorder_groups', '_wpnonce_reorder_groups', false ); 87 88 88 89 if ( !empty( $message ) ) : … … 93 94 </div> 94 95 95 <?phpendif; ?>96 <?php endif; ?> 96 97 97 98 <div id="tabs"> 98 99 <ul id="field-group-tabs"> 99 <?php 100 if ( !empty( $groups ) ) : 101 foreach ( $groups as $group ) { ?> 102 103 <li id="group_<?php echo $group->id; ?>"><a href="#tabs-<?php echo $group->id; ?>" class="ui-tab"><?php echo esc_attr( $group->name ); ?><?php if ( !$group->can_delete ) : ?> <?php _e( '(Primary)', 'buddypress'); endif; ?></a></li> 104 105 <?php } 106 endif; ?> 100 101 <?php if ( !empty( $groups ) ) : foreach ( $groups as $group ) : ?> 102 103 <li id="group_<?php echo $group->id; ?>"><a href="#tabs-<?php echo $group->id; ?>" class="ui-tab"><?php echo esc_attr( $group->name ); ?><?php if ( !$group->can_delete ) : ?> <?php _e( '(Primary)', 'buddypress'); endif; ?></a></li> 104 105 <?php endforeach; endif; ?> 107 106 108 107 </ul> 109 108 110 <?php if ( !empty( $groups ) ) : 111 foreach ( $groups as $group ) { ?> 109 <?php if ( !empty( $groups ) ) : foreach ( $groups as $group ) : ?> 112 110 113 111 <noscript> … … 121 119 <a class="button edit" href="admin.php?page=bp-profile-setup&mode=edit_group&group_id=<?php echo esc_attr( $group->id ); ?>"><?php _e( 'Edit Group', 'buddypress' ); ?></a> 122 120 123 <?phpif ( $group->can_delete ) : ?>124 125 <a class="submitdelete deletion ajax-option-delete" href="admin.php?page=bp-profile-setup&mode=delete_group&group_id=<?php echo esc_attr( $group->id ); ?>"><?php _e( 'Delete Group', 'buddypress' ); ?></a>126 127 <?phpendif; ?>121 <?php if ( $group->can_delete ) : ?> 122 123 <a class="submitdelete deletion ajax-option-delete" href="admin.php?page=bp-profile-setup&mode=delete_group&group_id=<?php echo esc_attr( $group->id ); ?>"><?php _e( 'Delete Group', 'buddypress' ); ?></a> 124 125 <?php endif; ?> 128 126 129 127 </div> … … 132 130 <fieldset id="<?php echo $group->id; ?>" class="connectedSortable field-group"> 133 131 134 <?php if( $group->description ) : ?> 135 136 <legend><?php echo esc_attr( $group->description ) ?></legend> 137 138 <?php endif; 139 140 if ( !empty( $group->fields ) ) : 141 foreach ( $group->fields as $field ) { 142 143 // Load the field 144 $field = new BP_XProfile_Field( $field->id ); 145 146 $class = ''; 147 if ( !$field->can_delete ) 148 $class = ' core nodrag'; 149 150 /* This function handles the WYSIWYG profile field 151 * display for the xprofile admin setup screen 152 */ 153 xprofile_admin_field( $field, $group, $class ); 154 155 } // end for 156 157 else : // !$group->fields 158 ?> 159 160 <p class="nodrag nofields"><?php _e( 'There are no fields in this group.', 'buddypress' ); ?></p> 161 162 <?php 163 endif; // end $group->fields 164 ?> 132 <?php if ( $group->description ) : ?> 133 134 <legend><?php echo esc_attr( $group->description ) ?></legend> 135 136 <?php endif; 137 138 if ( !empty( $group->fields ) ) : 139 foreach ( $group->fields as $field ) { 140 141 // Load the field 142 $field = new BP_XProfile_Field( $field->id ); 143 144 $class = ''; 145 if ( !$field->can_delete ) 146 $class = ' core nodrag'; 147 148 /* This function handles the WYSIWYG profile field 149 * display for the xprofile admin setup screen 150 */ 151 xprofile_admin_field( $field, $group, $class ); 152 153 } // end for 154 155 else : // !$group->fields ?> 156 157 <p class="nodrag nofields"><?php _e( 'There are no fields in this group.', 'buddypress' ); ?></p> 158 159 <?php endif; // end $group->fields ?> 165 160 166 161 </fieldset> 167 162 </div> 168 163 164 <?php endforeach; else : ?> 165 166 <div id="message" class="error"><p><?php _e( 'You have no groups.', 'buddypress' ); ?></p></div> 167 <p><a href="admin.php?page=bp-profile-setup&mode=add_group"><?php _e( 'Add New Group', 'buddypress' ); ?></a></p> 168 169 <?php endif; ?> 170 171 <div id="tabs-bottom"> </div> 172 </div> 173 </form> 174 </div> 175 169 176 <?php 170 } // End For ?> 171 172 </div> 173 <?php 174 else : 175 ?> 176 177 <div id="message" class="error"><p><?php _e( 'You have no groups.', 'buddypress' ); ?></p></div> 178 <p><a href="admin.php?page=bp-profile-setup&mode=add_group"><?php _e( 'Add New Group', 'buddypress' ); ?></a></p> 179 180 <?php 181 endif; 182 ?> 183 <div id="tabs-bottom"> 184 185 </div> 186 </form> 187 </div> 188 <?php 189 } 190 } 191 192 /************************************************************************** 193 xprofile_admin_manage_group() 194 195 Handles the adding or editing of groups. 196 **************************************************************************/ 197 177 } 178 } 179 180 /** 181 * Handles the adding or editing of groups. 182 */ 198 183 function xprofile_admin_manage_group( $group_id = null ) { 199 184 global $message, $type; … … 230 215 } 231 216 232 /************************************************************************** 233 xprofile_admin_delete_group() 234 235 Handles the deletion of profile data groups. 236 **************************************************************************/ 237 217 /** 218 * Handles the deletion of profile data groups. 219 */ 238 220 function xprofile_admin_delete_group( $group_id ) { 239 221 global $message, $type; … … 255 237 } 256 238 257 258 /************************************************************************** 259 xprofile_admin_manage_field() 260 261 Handles the adding or editing of profile field data for a user. 262 **************************************************************************/ 263 239 /** 240 * Handles the adding or editing of profile field data for a user. 241 */ 264 242 function xprofile_admin_manage_field( $group_id, $field_id = null ) { 265 243 global $bp, $wpdb, $message, $groups; 266 244 267 $field = new BP_XProfile_Field( $field_id );245 $field = new BP_XProfile_Field( $field_id ); 268 246 $field->group_id = $group_id; 269 247 … … 329 307 // @todo trust this param 330 308 $field_type = ( 'field' == $field_type ) ? __( 'field', 'buddypress' ) : __( 'option', 'buddypress' ); 331 332 $field = new BP_XProfile_Field( $field_id ); 309 $field = new BP_XProfile_Field( $field_id ); 333 310 334 311 if ( !$field->delete( (bool) $delete_data ) ) { … … 346 323 } 347 324 348 /************************************************************************** 349 xprofile_ajax_reorder_fields() 350 351 Handles the ajax reordering of fields within a group 352 **************************************************************************/ 325 /** 326 * Handles the ajax reordering of fields within a group 327 */ 353 328 function xprofile_ajax_reorder_fields() { 354 global $bp;355 329 356 330 // Check the nonce … … 361 335 362 336 parse_str( $_POST['field_order'], $order ); 337 363 338 $field_group_id = $_POST['field_group_id']; 364 339 365 foreach ( (array) $order['field'] as $position => $field_id ) 340 foreach ( (array) $order['field'] as $position => $field_id ) { 366 341 xprofile_update_field_position( (int) $field_id, (int) $position, (int) $field_group_id ); 367 342 } 368 343 } 369 344 add_action( 'wp_ajax_xprofile_reorder_fields', 'xprofile_ajax_reorder_fields' ); 370 345 371 /************************************************************************** 372 xprofile_ajax_reorder_field_groups() 373 374 Handles the reordering of field groups 375 **************************************************************************/ 346 /** 347 * Handles the reordering of field groups 348 */ 376 349 function xprofile_ajax_reorder_field_groups() { 377 global $bp;378 350 379 351 // Check the nonce … … 385 357 parse_str( $_POST['group_order'], $order ); 386 358 387 foreach ( (array) $order['group'] as $position => $field_group_id ) 359 foreach ( (array) $order['group'] as $position => $field_group_id ) { 388 360 xprofile_update_field_group_position( (int) $field_group_id, (int) $position ); 389 361 } 390 362 } 391 363 add_action( 'wp_ajax_xprofile_reorder_groups', 'xprofile_ajax_reorder_field_groups' ); 392 364 393 /************************************************************************** 394 xprofile_admin_field() 395 396 Handles the WYSIWYG display of each profile field on the edit screen 397 **************************************************************************/ 398 function xprofile_admin_field( $admin_field, $admin_group, $class='' ) { 365 /** 366 * Handles the WYSIWYG display of each profile field on the edit screen 367 */ 368 function xprofile_admin_field( $admin_field, $admin_group, $class = '' ) { 399 369 global $field; 400 370 401 371 $field = $admin_field; ?> 402 <fieldset id="field_<?php echo esc_attr( $field->id ); ?>" class="sortable<?php echo ' ' . $field->type; if ( $class ) echo ' ' . $class; ?>"> 403 <legend><span><?php bp_the_profile_field_name(); ?> <?php if( !$field->can_delete ) : ?> <?php _e( '(Primary)', 'buddypress' ); endif; ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(Required)', 'buddypress' ) ?><?php endif; ?></span></legend> 404 <div class="field-wrapper"> 372 373 <fieldset id="field_<?php echo esc_attr( $field->id ); ?>" class="sortable<?php echo ' ' . $field->type; if ( !empty( $class ) ) echo ' ' . $class; ?>"> 374 <legend><span><?php bp_the_profile_field_name(); ?> <?php if( !$field->can_delete ) : ?> <?php _e( '(Primary)', 'buddypress' ); endif; ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(Required)', 'buddypress' ) ?><?php endif; ?></span></legend> 375 <div class="field-wrapper"> 376 377 <?php switch ( $field->type ) : case 'textbox' : ?> 378 379 <input type="text" name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>" value="" /> 380 381 <?php break; case 'textarea' : ?> 382 383 <textarea rows="5" cols="40" name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>"></textarea> 384 385 <?php break; case 'selectbox' : ?> 386 387 <select name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>"> 388 389 <?php bp_the_profile_field_options() ?> 390 391 </select> 392 393 <?php break; case 'multiselectbox' : ?> 394 395 <select name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>" multiple="multiple"> 396 397 <?php bp_the_profile_field_options() ?> 398 399 </select> 400 401 <?php break; case 'radio' : ?> 402 403 <?php bp_the_profile_field_options() ?> 404 405 <?php if ( !bp_get_the_profile_field_is_required() ) : ?> 406 407 <a class="clear-value" href="javascript:clear( '<?php bp_the_profile_field_input_name() ?>' );"><?php _e( 'Clear', 'buddypress' ) ?></a> 408 409 <?php endif; ?> 410 411 <?php break; case 'checkbox' : ?> 412 413 <?php bp_the_profile_field_options(); ?> 414 415 <?php break; case 'datebox' : ?> 416 417 <select name="<?php bp_the_profile_field_input_name(); ?>_day" id="<?php bp_the_profile_field_input_name(); ?>_day"> 418 419 <?php bp_the_profile_field_options( 'type=day' ); ?> 420 421 </select> 422 423 <select name="<?php bp_the_profile_field_input_name(); ?>_month" id="<?php bp_the_profile_field_input_name(); ?>_month"> 424 425 <?php bp_the_profile_field_options( 'type=month' ); ?> 426 427 </select> 428 429 <select name="<?php bp_the_profile_field_input_name(); ?>_year" id="<?php bp_the_profile_field_input_name(); ?>_year"> 430 431 <?php bp_the_profile_field_options( 'type=year' ); ?> 432 433 </select> 434 435 <?php break; default : ?> 436 437 <?php do_action( 'xprofile_admin_field', $field, 1 ); ?> 438 439 <?php endswitch; ?> 440 441 <?php if ( $field->description ) : ?> 442 443 <p class="description"><?php echo esc_attr( $field->description ); ?></p> 444 445 <?php endif; ?> 446 447 <div class="actions"> 448 <a class="button edit" href="admin.php?page=bp-profile-setup&group_id=<?php echo esc_attr( $admin_group->id ); ?>&field_id=<?php echo esc_attr( $field->id ); ?>&mode=edit_field"><?php _e( 'Edit', 'buddypress' ); ?></a> 449 450 <?php if ( $field->can_delete ) : ?> 451 452 <a class="submit-delete deletion" href="admin.php?page=bp-profile-setup&field_id=<?php echo esc_attr( $field->id ); ?>&mode=delete_field"><?php _e( 'Delete', 'buddypress' ); ?></a> 453 454 <?php endif; ?> 455 </div> 456 </div> 457 </fieldset> 405 458 406 459 <?php 407 switch ( $field->type ) { 408 case 'textbox' : ?> 409 410 <input type="text" name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>" value="" /> 411 412 <?php break; case 'textarea' : ?> 413 414 <textarea rows="5" cols="40" name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>"></textarea> 415 416 <?php break; case 'selectbox' : ?> 417 418 <select name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>"> 419 <?php bp_the_profile_field_options() ?> 420 421 </select> 422 423 <?php break; case 'multiselectbox' : ?> 424 425 <select name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>" multiple="multiple"> 426 <?php bp_the_profile_field_options() ?> 427 428 </select> 429 430 <?php break; case 'radio' : ?> 431 432 <?php bp_the_profile_field_options() ?> 433 434 <?php if ( !bp_get_the_profile_field_is_required() ) : ?> 435 436 <a class="clear-value" href="javascript:clear( '<?php bp_the_profile_field_input_name() ?>' );"><?php _e( 'Clear', 'buddypress' ) ?></a> 437 438 <?php endif; ?> 439 440 <?php break; case 'checkbox' : ?> 441 442 <?php bp_the_profile_field_options(); ?> 443 444 <?php break; case 'datebox' : ?> 445 446 <select name="<?php bp_the_profile_field_input_name(); ?>_day" id="<?php bp_the_profile_field_input_name(); ?>_day"> 447 <?php bp_the_profile_field_options( 'type=day' ); ?> 448 449 </select> 450 451 <select name="<?php bp_the_profile_field_input_name(); ?>_month" id="<?php bp_the_profile_field_input_name(); ?>_month"> 452 <?php bp_the_profile_field_options( 'type=month' ); ?> 453 454 </select> 455 456 <select name="<?php bp_the_profile_field_input_name(); ?>_year" id="<?php bp_the_profile_field_input_name(); ?>_year"> 457 <?php bp_the_profile_field_options( 'type=year' ); ?> 458 459 </select> 460 461 <?php break; default : ?> 462 463 <?php do_action( 'xprofile_admin_field', $field, 1 ); ?> 464 465 <?php } ?> 466 467 <?php if ( $field->description ) : ?> 468 469 <p class="description"><?php echo esc_attr( $field->description ); ?></p> 470 471 <?php endif; ?> 472 473 <div class="actions"> 474 <a class="button edit" href="admin.php?page=bp-profile-setup&group_id=<?php echo esc_attr( $admin_group->id ); ?>&field_id=<?php echo esc_attr( $field->id ); ?>&mode=edit_field"><?php _e( 'Edit', 'buddypress' ); ?></a> 475 476 <?php if ( $field->can_delete ) : ?> 477 478 <a class="submit-delete deletion" href="admin.php?page=bp-profile-setup&field_id=<?php echo esc_attr( $field->id ); ?>&mode=delete_field"><?php _e( 'Delete', 'buddypress' ); ?></a> 479 480 <?php endif; ?> 481 </div> 482 </div> 483 </fieldset> 484 <?php 485 } 460 } 461 462 ?> -
trunk/bp-xprofile/bp-xprofile-buddybar.php
r4827 r5699 1 1 <?php 2 2 3 // Exit if accessed directly 3 4 if ( !defined( 'ABSPATH' ) ) exit; 5 4 6 ?> -
trunk/bp-xprofile/bp-xprofile-cache.php
r5302 r5699 1 1 <?php 2 /******************************************************************************** 3 * Caching 2 3 /** 4 * BuddyPress XProfile Template Tags 4 5 * 5 6 * Caching functions handle the clearing of cached objects and pages on specific 6 7 * actions throughout BuddyPress. 8 * 9 * @package BuddyPress 10 * @subpackage XProfileTemplate 7 11 */ 8 12 … … 11 15 12 16 function xprofile_clear_profile_groups_object_cache( $group_obj ) { 13 wp_cache_delete( 'xprofile_groups_inc_empty', 'bp' );14 wp_cache_delete( 'xprofile_group_' . $group_obj->id );17 wp_cache_delete( 'xprofile_groups_inc_empty', 'bp' ); 18 wp_cache_delete( 'xprofile_group_' . $group_obj->id, 'bp' ); 15 19 } 16 20 17 21 function xprofile_clear_profile_data_object_cache( $group_id ) { 18 global $bp;19 22 wp_cache_delete( 'bp_user_fullname_' . bp_loggedin_user_id(), 'bp' ); 20 23 } -
trunk/bp-xprofile/bp-xprofile-classes.php
r5697 r5699 1 1 <?php 2 3 /** 4 * BuddyPress XProfile Classes 5 * 6 * @package BuddyPress 7 * @subpackage XProfileClasses 8 */ 9 2 10 // Exit if accessed directly 3 11 if ( !defined( 'ABSPATH' ) ) exit; … … 11 19 var $fields; 12 20 13 function bp_xprofile_group( $id = null ) {14 $this->__construct( $id );15 }16 17 21 function __construct( $id = null ) { 18 global $bp, $wpdb; 19 20 if ( $id ) 22 if ( !empty( $id ) ) 21 23 $this->populate( $id ); 22 23 24 } 24 25 … … 46 47 do_action_ref_array( 'xprofile_group_before_save', array( $this ) ); 47 48 48 if ( $this->id)49 if ( !empty( $this->id ) ) 49 50 $sql = $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET name = %s, description = %s WHERE id = %d", $this->name, $this->description, $this->id ); 50 51 else … … 56 57 do_action_ref_array( 'xprofile_group_after_save', array( $this ) ); 57 58 58 if ( $this->id)59 if ( !empty( $this->id ) ) 59 60 return $this->id; 60 61 else … … 65 66 global $wpdb, $bp; 66 67 67 if ( !$this->can_delete)68 return false; 69 70 / * Delete field group */68 if ( empty( $this->can_delete ) ) 69 return false; 70 71 // Delete field group 71 72 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_groups} WHERE id = %d", $this->id ) ) ) { 72 73 return false; 73 74 } else { 74 /* Remove the group's fields. */ 75 76 // Remove the group's fields. 75 77 if ( BP_XProfile_Field::delete_for_group( $this->id ) ) { 76 /* Remove profile data for the groups fields */ 78 79 // Remove profile data for the groups fields 77 80 for ( $i = 0, $count = count( $this->fields ); $i < $count; ++$i ) { 78 81 BP_XProfile_ProfileData::delete_for_field( $this->fields[$i]->id ); … … 84 87 } 85 88 86 /** Static Functions**/89 /** Static Methods ********************************************************/ 87 90 88 91 /** … … 126 129 $where_sql = ''; 127 130 128 if ( $profile_group_id)131 if ( !empty( $profile_group_id ) ) 129 132 $where_sql = $wpdb->prepare( 'WHERE g.id = %d', $profile_group_id ); 130 133 elseif ( $exclude_groups ) 131 134 $where_sql = $wpdb->prepare( "WHERE g.id NOT IN ({$exclude_groups})"); 132 135 133 if ( $hide_empty_groups)136 if ( !empty( $hide_empty_groups ) ) 134 137 $groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT g.* FROM {$bp->profile->table_name_groups} g INNER JOIN {$bp->profile->table_name_fields} f ON g.id = f.group_id {$where_sql} ORDER BY g.group_order ASC" ) ); 135 138 else 136 139 $groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT g.* FROM {$bp->profile->table_name_groups} g {$where_sql} ORDER BY g.group_order ASC" ) ); 137 140 138 if ( !$fetch_fields)141 if ( empty( $fetch_fields ) ) 139 142 return $groups; 140 143 … … 151 154 152 155 $exclude_fields_sql = ''; 153 if ( $exclude_fields)156 if ( !empty( $exclude_fields ) ) 154 157 $exclude_fields_sql = $wpdb->prepare( "AND id NOT IN ({$exclude_fields})" ); 155 158 … … 160 163 return $groups; 161 164 162 if ( $fetch_field_data ) { 165 if ( !empty( $fetch_field_data ) ) { 166 163 167 // Fetch the field data for the user. 164 foreach( (array) $fields as $field )168 foreach( (array) $fields as $field ) { 165 169 $field_ids[] = $field->id; 170 } 166 171 167 172 $field_ids_sql = implode( ',', (array) $field_ids ); … … 171 176 172 177 // Remove data-less fields, if necessary 173 if ( $hide_empty_fields) {178 if ( !empty( $hide_empty_fields ) ) { 174 179 175 180 // Loop through the results and find the fields that have data. 176 181 foreach( (array)$field_data as $data ) { 182 177 183 // Empty fields may contain a serialized empty array 178 184 $maybe_value = maybe_unserialize( $data->value ); … … 220 226 221 227 foreach( (array) $fields as $field ) { 222 if ( $group->id == $field->group_id ) 228 if ( $group->id == $field->group_id ) { 223 229 $groups[$index]->fields[] = $field; 230 } 224 231 } 225 232 … … 265 272 global $message; 266 273 267 if ( !$this->id) {274 if ( empty( $this->id ) ) { 268 275 $title = __( 'Add New Field Group', 'buddypress' ); 269 276 $action = "admin.php?page=bp-profile-setup&mode=add_group"; … … 273 280 $action = "admin.php?page=bp-profile-setup&mode=edit_group&group_id=" . $this->id; 274 281 $button = __( 'Save Changes', 'buddypress' ); 275 } 276 ?> 282 } ?> 283 277 284 <div class="wrap"> 278 285 … … 282 289 <p><?php _e( 'Fields marked * are required', 'buddypress' ) ?></p> 283 290 284 <?php if ( $message != '' ) : 285 $type = ( 'error' == $type ) ? 'error' : 'updated'; ?> 291 <?php if ( !empty( $message ) ) : 292 $type = ( 'error' == $type ) ? 'error' : 'updated'; ?> 293 286 294 <div id="message" class="<?php echo $type; ?> fade"> 287 295 <p><?php echo $message; ?></p> 288 296 </div> 289 <?php endif; ?> 297 298 <?php endif; ?> 299 290 300 <div id="poststuff"> 291 301 <form action="<?php echo esc_attr( $action ); ?>" method="post"> … … 297 307 </div> 298 308 299 <?php if ( '0' != $this->can_delete ) : ?> 300 <div id="titlediv"> 301 <h3><label for="description"><?php _e( "Group Description", 'buddypress' ); ?></label></h3> 302 <div id="titlewrap"> 303 <textarea name="group_description" id="group_description" rows="8" cols="60"><?php echo htmlspecialchars( $this->description ); ?></textarea> 309 <?php if ( '0' != $this->can_delete ) : ?> 310 311 <div id="titlediv"> 312 <h3><label for="description"><?php _e( "Group Description", 'buddypress' ); ?></label></h3> 313 <div id="titlewrap"> 314 <textarea name="group_description" id="group_description" rows="8" cols="60"><?php echo htmlspecialchars( $this->description ); ?></textarea> 315 </div> 304 316 </div> 305 </div> 306 <?php endif; ?>317 318 <?php endif; ?> 307 319 308 320 <p class="submit"> … … 314 326 </div> 315 327 </div> 328 316 329 <?php 317 330 } 318 331 } 319 320 332 321 333 class BP_XProfile_Field { … … 337 349 var $message_type = 'err'; 338 350 339 function bp_xprofile_field( $id = null, $user_id = null, $get_data = true ) {340 $this->__construct( $id, $user_id, $get_data );341 }342 343 351 function __construct( $id = null, $user_id = null, $get_data = true ) { 344 if ( $id)352 if ( !empty( $id ) ) 345 353 $this->populate( $id, $user_id, $get_data ); 346 354 } … … 349 357 global $wpdb, $userdata, $bp; 350 358 359 // @todo Why are we nooping the user_id ? 351 360 $user_id = 0; 352 361 if ( is_null( $user_id ) ) … … 369 378 $this->is_default_option = $field->is_default_option; 370 379 371 if ( $get_data && $user_id ) 372 $this->data = $this->get_field_data( $user_id ); 380 if ( $get_data && $user_id ) { 381 $this->data = $this->get_field_data( $user_id ); 382 } 373 383 } 374 384 } … … 380 390 // Prevent deletion by url when can_delete is false. 381 391 // Prevent deletion of option 1 since this invalidates fields with options. 382 if ( !$this->id || !$this->can_delete|| ( $this->parent_id && $this->option_order == 1 ) )392 if ( empty( $this->id ) || empty( $this->can_delete ) || ( $this->parent_id && $this->option_order == 1 ) ) 383 393 return false; 384 394 … … 396 406 global $wpdb, $bp; 397 407 398 $error = false;399 400 408 $this->group_id = apply_filters( 'xprofile_field_group_id_before_save', $this->group_id, $this->id ); 401 409 $this->parent_id = apply_filters( 'xprofile_field_parent_id_before_save', $this->parent_id, $this->id ); 402 $this->type = apply_filters( 'xprofile_field_type_before_save', $this->type, $this->id );403 $this->name = apply_filters( 'xprofile_field_name_before_save', $this->name, $this->id );410 $this->type = apply_filters( 'xprofile_field_type_before_save', $this->type, $this->id ); 411 $this->name = apply_filters( 'xprofile_field_name_before_save', $this->name, $this->id ); 404 412 $this->description = apply_filters( 'xprofile_field_description_before_save', $this->description, $this->id ); 405 413 $this->is_required = apply_filters( 'xprofile_field_is_required_before_save', $this->is_required, $this->id ); … … 409 417 do_action_ref_array( 'xprofile_field_before_save', array( $this ) ); 410 418 411 if ( $this->id != null ) 419 if ( $this->id != null ) { 412 420 $sql = $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET group_id = %d, parent_id = 0, type = %s, name = %s, description = %s, is_required = %d, order_by = %s, field_order = %d WHERE id = %d", $this->group_id, $this->type, $this->name, $this->description, $this->is_required, $this->order_by, $this->field_order, $this->id ); 413 else421 } else { 414 422 $sql = $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, order_by, field_order ) VALUES (%d, %d, %s, %s, %s, %d, %s, %d )", $this->group_id, $this->parent_id, $this->type, $this->name, $this->description, $this->is_required, $this->order_by, $this->field_order ); 415 416 /* 423 } 424 425 /** 417 426 * Check for null so field options can be changed without changing any other part of the field. 418 427 * The described situation will return 0 here. 419 428 */ 420 429 if ( $wpdb->query( $sql ) !== null ) { 421 if ( $this->id ) 430 431 if ( !empty( $this->id ) ) { 422 432 $field_id = $this->id; 423 else433 } else { 424 434 $field_id = $wpdb->insert_id; 425 426 /* Only do this if we are editing an existing field */ 435 } 436 437 // Only do this if we are editing an existing field 427 438 if ( $this->id != null ) { 428 /* 439 440 /** 429 441 * Remove any radio or dropdown options for this 430 442 * field. They will be re-added if needed. … … 435 447 } 436 448 437 /* 449 /** 438 450 * Check to see if this is a field with child options. 439 451 * We need to add the options to the db, if it is. 440 452 */ 441 453 if ( 'radio' == $this->type || 'selectbox' == $this->type || 'checkbox' == $this->type || 'multiselectbox' == $this->type ) { 442 if ( $this->id ) 454 455 if ( !empty( $this->id ) ) { 443 456 $parent_id = $this->id; 444 else457 } else { 445 458 $parent_id = $wpdb->insert_id; 459 } 446 460 447 461 if ( 'radio' == $this->type ) { … … 452 466 $defaults = apply_filters( 'xprofile_field_default_before_save', $post_default, 'radio' ); 453 467 454 } else 468 } elseif ( 'selectbox' == $this->type ) { 455 469 $post_option = !empty( $_POST['selectbox_option'] ) ? $_POST['selectbox_option'] : ''; 456 470 $post_default = !empty( $_POST['isDefault_selectbox_option'] ) ? $_POST['isDefault_selectbox_option'] : ''; … … 459 473 $defaults = apply_filters( 'xprofile_field_default_before_save', $post_default, 'selectbox' ); 460 474 461 } else 475 } elseif ( 'multiselectbox' == $this->type ) { 462 476 $post_option = !empty( $_POST['multiselectbox_option'] ) ? $_POST['multiselectbox_option'] : ''; 463 477 $post_default = !empty( $_POST['isDefault_multiselectbox_option'] ) ? $_POST['isDefault_multiselectbox_option'] : ''; … … 466 480 $defaults = apply_filters( 'xprofile_field_default_before_save', $post_default, 'multiselectbox' ); 467 481 468 } else 482 } elseif ( 'checkbox' == $this->type ) { 469 483 $post_option = !empty( $_POST['checkbox_option'] ) ? $_POST['checkbox_option'] : ''; 470 484 $post_default = !empty( $_POST['isDefault_checkbox_option'] ) ? $_POST['isDefault_checkbox_option'] : ''; … … 475 489 476 490 $counter = 1; 477 if ( $options) {491 if ( !empty( $options ) ) { 478 492 foreach ( (array)$options as $option_key => $option_value ) { 479 493 $is_default = 0; … … 488 502 489 503 if ( '' != $option_value ) { 490 if ( !$wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, option_order, is_default_option) VALUES (%d, %d, 'option', %s, '', 0, %d, %d)", $this->group_id, $parent_id, $option_value, $counter, $is_default ) ) ) 504 if ( !$wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, option_order, is_default_option) VALUES (%d, %d, 'option', %s, '', 0, %d, %d)", $this->group_id, $parent_id, $option_value, $counter, $is_default ) ) ) { 491 505 return false; 506 } 492 507 } 493 508 … … 513 528 514 529 // This is done here so we don't have problems with sql injection 515 if ( 'asc' == $this->order_by && !$for_editing )530 if ( 'asc' == $this->order_by && empty( $for_editing ) ) { 516 531 $sort_sql = 'ORDER BY name ASC'; 517 else if ( 'desc' == $this->order_by && !$for_editing )532 } elseif ( 'desc' == $this->order_by && empty( $for_editing ) ) { 518 533 $sort_sql = 'ORDER BY name DESC'; 519 else534 } else { 520 535 $sort_sql = 'ORDER BY option_order ASC'; 536 } 521 537 522 538 // This eliminates a problem with getting all fields when there is no id for the object 523 if ( !$this->id )539 if ( empty( $this->id ) ) { 524 540 $parent_id = -1; 525 else541 } else { 526 542 $parent_id = $this->id; 543 } 527 544 528 545 $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE parent_id = %d AND group_id = %d $sort_sql", $parent_id, $this->group_id ); … … 547 564 global $wpdb, $bp; 548 565 549 if ( $field_id) {566 if ( !empty( $field_id ) ) { 550 567 $sql = $wpdb->prepare( "SELECT type FROM {$bp->profile->table_name_fields} WHERE id = %d", $field_id ); 551 568 552 if ( !$field_type = $wpdb->get_var( $sql ) ) 569 if ( !$field_type = $wpdb->get_var( $sql ) ) { 553 570 return false; 571 } 554 572 555 573 return $field_type; … … 562 580 global $wpdb, $bp; 563 581 564 if ( $group_id) {582 if ( !empty( $group_id ) ) { 565 583 $sql = $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $group_id ); 566 584 567 if ( $wpdb->get_var( $sql ) === false ) 585 if ( $wpdb->get_var( $sql ) === false ) { 568 586 return false; 587 } 569 588 570 589 return true; … … 589 608 return false; 590 609 591 / * Update $field_id with new $position and $field_group_id */610 // Update $field_id with new $position and $field_group_id 592 611 if ( $parent = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET field_order = %d, group_id = %d WHERE id = %d", $position, $field_group_id, $field_id ) ) ) {; 593 /* Update any children of this $field_id */ 612 613 // Update any children of this $field_id 594 614 $children = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET group_id = %d WHERE parent_id = %d", $field_group_id, $field_id ) ); 595 615 … … 608 628 $input_types = array( 'checkbox', 'selectbox', 'multiselectbox', 'radio' ); 609 629 610 foreach ( $input_types as $type) {630 foreach ( $input_types as $type ) { 611 631 $default_name = ''; 612 632 613 if ( 'multiselectbox' == $type || 'checkbox' == $type )633 if ( ( 'multiselectbox' == $type ) || ( 'checkbox' == $type ) ) { 614 634 $default_input = 'checkbox'; 615 else635 } else { 616 636 $default_input = 'radio'; 617 ?> 618 <div id="<?php echo $type; ?>" class="options-box" style="<?php if ( $this->type != $type ) { ?>display: none;<?php } ?> margin-left: 15px;"> 637 } 638 639 if ( $this->type != $type ) { 640 $class = 'display: none;'; 641 } 642 643 ?> 644 645 <div id="<?php echo $type; ?>" class="options-box" style="<?php echo $class; ?> margin-left: 15px;"> 619 646 <h4><?php _e( 'Please enter options for this Field:', 'buddypress' ); ?></h4> 620 647 <p><label for="sort_order_<?php echo $type; ?>"><?php _e( 'Order By:', 'buddypress' ); ?></label> … … 624 651 <option value="desc" <?php if ( 'desc' == $this->order_by ) {?> selected="selected"<?php } ?>><?php _e( 'Name - Descending', 'buddypress' ); ?></option> 625 652 </select> 626 <?php 627 if ( !$options = $this->get_children( true ) ) { 653 654 <?php if ( !$options = $this->get_children( true ) ) { 655 628 656 $i = 1; 629 657 while ( isset( $_POST[$type . '_option'][$i] ) ) { 630 658 (array) $options[] = (object) array( 631 'id' => -1, 632 'name' => $_POST[$type . '_option'][$i], 633 'is_default_option' => ( 'multiselectbox' != $type && 634 'checkbox' != $type && 635 $_POST["isDefault_{$type}_option"] == $i ) ? 636 1 : 637 $_POST["isDefault_{$type}_option"][$i] 659 'id' => -1, 660 'name' => $_POST[$type . '_option'][$i], 661 'is_default_option' => ( ( 'multiselectbox' != $type ) && ( 'checkbox' != $type ) && ( $_POST["isDefault_{$type}_option"] == $i ) ) ? 1 : $_POST["isDefault_{$type}_option"][$i] 638 662 ); 639 663 … … 647 671 648 672 if ( 'multiselectbox' == $type || 'checkbox' == $type ) 649 $default_name = '[' . $j . ']'; 650 ?> 651 <p><?php _e( 'Option', 'buddypress'); ?> <?php echo $j; ?>:673 $default_name = '[' . $j . ']'; ?> 674 675 <p><?php _e( 'Option', 'buddypress' ); ?> <?php echo $j; ?>: 652 676 <input type="text" name="<?php echo $type; ?>_option[<?php echo $j; ?>]" id="<?php echo $type; ?>_option<?php echo $j; ?>" value="<?php echo stripslashes( esc_attr( $options[$i]->name ) ); ?>" /> 653 677 <input type="<?php echo $default_input; ?>" name="isDefault_<?php echo $type; ?>_option<?php echo $default_name; ?>" <?php if ( (int) $options[$i]->is_default_option ) {?> checked="checked"<?php } ?> " value="<?php echo $j; ?>" /> <?php _e( 'Default Value', 'buddypress' ); ?> 654 <?php 655 if ( $j != 1 && $options[$i]->id != -1 ) : ?> 656 <a href="admin.php?page=bp-profile-setup&mode=delete_option&option_id=<?php echo $options[$i]->id ?>" class="ajax-option-delete" id="delete-<?php echo $options[$i]->id; ?>">[x]</a> 657 <?php endif; ?> 678 679 <?php if ( $j != 1 && $options[$i]->id != -1 ) : ?> 680 681 <a href="admin.php?page=bp-profile-setup&mode=delete_option&option_id=<?php echo $options[$i]->id ?>" class="ajax-option-delete" id="delete-<?php echo $options[$i]->id; ?>">[x]</a> 682 683 <?php endif; ?> 684 658 685 </p> 659 <?php } /* end for */ ?> 686 687 <?php } /* end for */ ?> 660 688 661 689 <input type="hidden" name="<?php echo $type; ?>_option_number" id="<?php echo $type; ?>_option_number" value="<?php echo $j + 1; ?>" /> 662 <?php 663 } else { 690 691 <?php } else { 692 664 693 if ( 'multiselectbox' == $type || 'checkbox' == $type ) 665 $default_name = '[1]'; 666 ?> 694 $default_name = '[1]'; ?> 667 695 668 696 <p><?php _e( 'Option', 'buddypress' ); ?> 1: <input type="text" name="<?php echo $type; ?>_option[1]" id="<?php echo $type; ?>_option1" /> … … 670 698 <input type="hidden" name="<?php echo $type; ?>_option_number" id="<?php echo $type; ?>_option_number" value="2" /> 671 699 672 <?php} /* end if */ ?>700 <?php } /* end if */ ?> 673 701 674 702 <div id="<?php echo $type; ?>_more"></div> … … 680 708 681 709 function render_admin_form( $message = '' ) { 682 if ( !$this->id) {710 if ( empty( $this->id ) ) { 683 711 $title = __( 'Add Field', 'buddypress' ); 684 712 $action = "admin.php?page=bp-profile-setup&group_id=" . $this->group_id . "&mode=add_field#tabs-" . $this->group_id; 685 713 686 714 if ( !empty( $_POST['saveField'] ) ) { 687 $this->name = $_POST['title']; 688 $this->description = $_POST['description']; 689 $this->is_required = $_POST['required']; 690 $this->type = $_POST['fieldtype']; 691 $this->order_by = $_POST["sort_order_{$this->type}"]; 692 $this->field_order = $_POST['field_order']; 693 } 694 } else { 695 $title = __( 'Edit Field', 'buddypress' ); 696 $action = "admin.php?page=bp-profile-setup&mode=edit_field&group_id=" . $this->group_id . "&field_id=" . $this->id . "#tabs-" . $this->group_id; 697 } 698 ?> 699 <div class="wrap"> 700 <div id="icon-users" class="icon32"><br /></div> 701 <h2><?php echo $title; ?></h2> 702 <p><?php _e( 'Fields marked * are required', 'buddypress' ) ?></p> 703 704 <?php 705 if ( $message != '' ) { 706 ?> 707 <div id="message" class="error fade"> 708 <p><?php echo $message; ?></p> 709 </div> 710 <?php } ?> 711 712 <form action="<?php echo $action; ?>" method="post"> 713 <div id="poststuff"> 714 <div id="titlediv"> 715 <h3><label for="title"><?php _e( 'Field Title', 'buddypress' ); ?> *</label></h3> 716 <div id="titlewrap"> 717 <input type="text" name="title" id="title" value="<?php echo esc_attr( $this->name ); ?>" style="width:50%" /> 715 $this->name = $_POST['title']; 716 $this->description = $_POST['description']; 717 $this->is_required = $_POST['required']; 718 $this->type = $_POST['fieldtype']; 719 $this->order_by = $_POST["sort_order_{$this->type}"]; 720 $this->field_order = $_POST['field_order']; 721 } 722 } else { 723 $title = __( 'Edit Field', 'buddypress' ); 724 $action = "admin.php?page=bp-profile-setup&mode=edit_field&group_id=" . $this->group_id . "&field_id=" . $this->id . "#tabs-" . $this->group_id; 725 } ?> 726 727 <div class="wrap"> 728 <div id="icon-users" class="icon32"><br /></div> 729 <h2><?php echo $title; ?></h2> 730 <p><?php _e( 'Fields marked * are required', 'buddypress' ) ?></p> 731 732 <?php if ( !empty( $message ) ) : ?> 733 734 <div id="message" class="error fade"> 735 <p><?php echo $message; ?></p> 736 </div> 737 738 <?php endif; ?> 739 740 <form action="<?php echo $action; ?>" method="post"> 741 <div id="poststuff"> 742 <div id="titlediv"> 743 <h3><label for="title"><?php _e( 'Field Title', 'buddypress' ); ?> *</label></h3> 744 <div id="titlewrap"> 745 <input type="text" name="title" id="title" value="<?php echo esc_attr( $this->name ); ?>" style="width:50%" /> 746 </div> 718 747 </div> 748 749 <div id="titlediv"> 750 <h3><label for="description"><?php _e("Field Description", 'buddypress'); ?></label></h3> 751 <div id="titlewrap"> 752 <textarea name="description" id="description" rows="8" cols="60"><?php echo htmlspecialchars( $this->description ); ?></textarea> 753 </div> 754 </div> 755 756 <?php if ( '0' != $this->can_delete ) { ?> 757 758 <div id="titlediv"> 759 <h3><label for="required"><?php _e( "Is This Field Required?", 'buddypress' ); ?> *</label></h3> 760 <select name="required" id="required" style="width: 30%"> 761 <option value="0"<?php if ( $this->is_required == '0' ) { ?> selected="selected"<?php } ?>><?php _e( 'Not Required', 'buddypress' ); ?></option> 762 <option value="1"<?php if ( $this->is_required == '1' ) { ?> selected="selected"<?php } ?>><?php _e( 'Required', 'buddypress' ); ?></option> 763 </select> 764 </div> 765 766 <div id="titlediv"> 767 <h3><label for="fieldtype"><?php _e("Field Type", 'buddypress'); ?> *</label></h3> 768 <select name="fieldtype" id="fieldtype" onchange="show_options(this.value)" style="width: 30%"> 769 <option value="textbox"<?php if ( $this->type == 'textbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Text Box', 'buddypress' ); ?></option> 770 <option value="textarea"<?php if ( $this->type == 'textarea' ) {?> selected="selected"<?php } ?>><?php _e( 'Multi-line Text Box', 'buddypress' ); ?></option> 771 <option value="datebox"<?php if ( $this->type == 'datebox' ) {?> selected="selected"<?php } ?>><?php _e( 'Date Selector', 'buddypress' ); ?></option> 772 <option value="radio"<?php if ( $this->type == 'radio' ) {?> selected="selected"<?php } ?>><?php _e( 'Radio Buttons', 'buddypress' ); ?></option> 773 <option value="selectbox"<?php if ( $this->type == 'selectbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Drop Down Select Box', 'buddypress' ); ?></option> 774 <option value="multiselectbox"<?php if ( $this->type == 'multiselectbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Multi Select Box', 'buddypress' ); ?></option> 775 <option value="checkbox"<?php if ( $this->type == 'checkbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Checkboxes', 'buddypress' ); ?></option> 776 </select> 777 </div> 778 779 <?php do_action_ref_array( 'xprofile_field_additional_options', array( $this ) ); ?> 780 781 <?php $this->render_admin_form_children(); ?> 782 783 <?php } else { ?> 784 785 <input type="hidden" name="required" id="required" value="1" /> 786 <input type="hidden" name="fieldtype" id="fieldtype" value="textbox" /> 787 788 <?php } ?> 789 790 <p class="submit"> 791 <input type="hidden" name="field_order" id="field_order" value="<?php echo esc_attr( $this->field_order ); ?>" /> 792 <input type="submit" value="<?php _e( 'Save', 'buddypress' ); ?>" name="saveField" id="saveField" style="font-weight: bold" class="button-primary" /> 793 <?php _e( 'or', 'buddypress' ); ?> <a href="admin.php?page=bp-profile-setup" class="deletion"><?php _e( 'Cancel', 'buddypress' ); ?></a> 794 </p> 795 719 796 </div> 720 797 721 <div id="titlediv"> 722 <h3><label for="description"><?php _e("Field Description", 'buddypress'); ?></label></h3> 723 <div id="titlewrap"> 724 <textarea name="description" id="description" rows="8" cols="60"><?php echo htmlspecialchars( $this->description ); ?></textarea> 725 </div> 726 </div> 727 728 <?php 729 if ( '0' != $this->can_delete ) { 730 ?> 731 <div id="titlediv"> 732 <h3><label for="required"><?php _e( "Is This Field Required?", 'buddypress' ); ?> *</label></h3> 733 <select name="required" id="required" style="width: 30%"> 734 <option value="0"<?php if ( $this->is_required == '0' ) { ?> selected="selected"<?php } ?>><?php _e( 'Not Required', 'buddypress' ); ?></option> 735 <option value="1"<?php if ( $this->is_required == '1' ) { ?> selected="selected"<?php } ?>><?php _e( 'Required', 'buddypress' ); ?></option> 736 </select> 737 </div> 738 739 <div id="titlediv"> 740 <h3><label for="fieldtype"><?php _e("Field Type", 'buddypress'); ?> *</label></h3> 741 <select name="fieldtype" id="fieldtype" onchange="show_options(this.value)" style="width: 30%"> 742 <option value="textbox"<?php if ( $this->type == 'textbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Text Box', 'buddypress' ); ?></option> 743 <option value="textarea"<?php if ( $this->type == 'textarea' ) {?> selected="selected"<?php } ?>><?php _e( 'Multi-line Text Box', 'buddypress' ); ?></option> 744 <option value="datebox"<?php if ( $this->type == 'datebox' ) {?> selected="selected"<?php } ?>><?php _e( 'Date Selector', 'buddypress' ); ?></option> 745 <option value="radio"<?php if ( $this->type == 'radio' ) {?> selected="selected"<?php } ?>><?php _e( 'Radio Buttons', 'buddypress' ); ?></option> 746 <option value="selectbox"<?php if ( $this->type == 'selectbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Drop Down Select Box', 'buddypress' ); ?></option> 747 <option value="multiselectbox"<?php if ( $this->type == 'multiselectbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Multi Select Box', 'buddypress' ); ?></option> 748 <option value="checkbox"<?php if ( $this->type == 'checkbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Checkboxes', 'buddypress' ); ?></option> 749 </select> 750 </div> 751 752 <?php do_action_ref_array( 'xprofile_field_additional_options', array( $this ) ); ?> 753 754 <?php $this->render_admin_form_children(); ?> 755 <?php } else { ?> 756 <input type="hidden" name="required" id="required" value="1" /> 757 <input type="hidden" name="fieldtype" id="fieldtype" value="textbox" /> 758 <?php } ?> 759 <p class="submit"> 760 <input type="hidden" name="field_order" id="field_order" value="<?php echo esc_attr( $this->field_order ); ?>" /> 761 <input type="submit" value="<?php _e( 'Save', 'buddypress' ); ?>" name="saveField" id="saveField" style="font-weight: bold" class="button-primary" /> 762 <?php _e( 'or', 'buddypress' ); ?> <a href="admin.php?page=bp-profile-setup" class="deletion"><?php _e( 'Cancel', 'buddypress' ); ?></a> 763 </p> 764 765 </div> 766 767 <?php wp_nonce_field( 'xprofile_delete_option' ); ?> 768 769 </form> 770 </div> 798 <?php wp_nonce_field( 'xprofile_delete_option' ); ?> 799 800 </form> 801 </div> 771 802 772 803 <?php … … 776 807 global $message; 777 808 778 / * Validate Form */809 // Validate Form 779 810 if ( '' == $_POST['title'] || '' == $_POST['required'] || '' == $_POST['fieldtype'] ) { 780 811 $message = __( 'Please make sure you fill out all required fields.', 'buddypress' ); … … 806 837 var $last_updated; 807 838 808 function bp_xprofile_profiledata( $field_id = null, $user_id = null ) {809 $this->__construct( $field_id, $user_id );810 }811 812 839 function __construct( $field_id = null, $user_id = null ) { 813 if ( $field_id)840 if ( !empty( $field_id ) ) 814 841 $this->populate( $field_id, $user_id ); 815 842 } … … 923 950 $profile_data = array(); 924 951 925 if ( $results) {952 if ( !empty( $results ) ) { 926 953 $profile_data['user_login'] = $results[0]->user_login; 927 954 $profile_data['user_nicename'] = $results[0]->user_nicename; … … 945 972 global $wpdb, $bp; 946 973 947 if ( !$user_ids)974 if ( empty( $user_ids ) ) 948 975 $user_ids = bp_displayed_user_id(); 949 976 … … 961 988 global $bp, $wpdb; 962 989 963 if ( !$fields)964 return false; 965 966 if ( !$user_id)990 if ( empty( $fields ) ) 991 return false; 992 993 if ( empty( $user_id ) ) 967 994 $user_id = bp_displayed_user_id(); 968 995 … … 1006 1033 1007 1034 function delete_for_field( $field_id ) { 1008 global $wpdb, $ userdata, $bp;1035 global $wpdb, $bp; 1009 1036 1010 1037 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE field_id = %d", $field_id ) ) ) … … 1031 1058 global $wpdb, $bp; 1032 1059 1033 if ( $exclude_fullname)1060 if ( !empty( $exclude_fullname ) ) 1034 1061 $exclude_sql = $wpdb->prepare( " AND pf.id != 1" ); 1035 1062 … … 1038 1065 1039 1066 function get_fullname( $user_id = 0 ) { 1040 global $bp; 1041 1042 if ( !$user_id ) 1067 1068 if ( empty( $user_id ) ) 1043 1069 $user_id = bp_displayed_user_id(); 1044 1070 -
trunk/bp-xprofile/bp-xprofile-cssjs.php
r5599 r5699 1 1 <?php 2 3 /** 4 * BuddyPress XProfile CSS and JS 5 * 6 * @package BuddyPress 7 * @subpackage XProfileScripts 8 */ 2 9 3 10 // Exit if accessed directly -
trunk/bp-xprofile/bp-xprofile-filters.php
r5131 r5699 1 1 <?php 2 3 /** 4 * BuddyPress XProfile Filters 5 * 6 * Apply WordPress defined filters 7 * 8 * @package BuddyPress 9 * @subpackage XProfileFilters 10 */ 11 2 12 // Exit if accessed directly 3 13 if ( !defined( 'ABSPATH' ) ) exit; 4 14 5 /* Apply WordPress defined filters */ 6 7 add_filter( 'bp_get_the_profile_group_name', 'wp_filter_kses', 1 ); 8 add_filter( 'bp_get_the_profile_group_description', 'wp_filter_kses', 1 ); 9 add_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_kses', 1 ); 10 add_filter( 'bp_get_the_profile_field_name', 'wp_filter_kses', 1 ); 11 add_filter( 'bp_get_the_profile_field_edit_value', 'wp_filter_kses', 1 ); 12 add_filter( 'bp_get_the_profile_field_description', 'wp_filter_kses', 1 ); 13 14 add_filter( 'bp_get_the_profile_field_value', 'wptexturize' ); 15 add_filter( 'bp_get_the_profile_field_value', 'convert_smilies', 2 ); 16 add_filter( 'bp_get_the_profile_field_value', 'convert_chars' ); 17 add_filter( 'bp_get_the_profile_field_value', 'wpautop' ); 18 add_filter( 'bp_get_the_profile_field_value', 'make_clickable', 8 ); 19 add_filter( 'bp_get_the_profile_field_value', 'force_balance_tags' ); 20 21 add_filter( 'bp_get_the_profile_field_edit_value', 'force_balance_tags' ); 22 add_filter( 'bp_get_the_profile_field_edit_value', 'esc_html' ); 23 24 add_filter( 'bp_get_the_profile_group_name', 'stripslashes' ); 25 add_filter( 'bp_get_the_profile_group_description', 'stripslashes' ); 26 add_filter( 'bp_get_the_profile_field_value', 'stripslashes' ); 27 add_filter( 'bp_get_the_profile_field_edit_value', 'stripslashes' ); 28 add_filter( 'bp_get_the_profile_field_name', 'stripslashes' ); 29 add_filter( 'bp_get_the_profile_field_description', 'stripslashes' ); 30 31 add_filter( 'xprofile_get_field_data', 'wp_filter_kses', 1 ); 32 add_filter( 'xprofile_field_name_before_save', 'wp_filter_kses', 1 ); 33 add_filter( 'xprofile_field_description_before_save', 'wp_filter_kses', 1 ); 34 35 add_filter( 'xprofile_get_field_data', 'force_balance_tags' ); 36 add_filter( 'xprofile_field_name_before_save', 'force_balance_tags' ); 37 add_filter( 'xprofile_field_description_before_save', 'force_balance_tags' ); 38 39 add_filter( 'xprofile_get_field_data', 'stripslashes' ); 40 41 /* Custom BuddyPress filters */ 42 43 add_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_format_field_value', 1, 2 ); 44 add_filter( 'bp_get_the_site_member_profile_data', 'xprofile_filter_format_field_value', 1, 2 ); 45 add_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 ); 46 47 add_filter( 'xprofile_data_value_before_save', 'xprofile_sanitize_data_value_before_save', 1, 2 ); 15 add_filter( 'bp_get_the_profile_group_name', 'wp_filter_kses', 1 ); 16 add_filter( 'bp_get_the_profile_group_description', 'wp_filter_kses', 1 ); 17 add_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_kses', 1 ); 18 add_filter( 'bp_get_the_profile_field_name', 'wp_filter_kses', 1 ); 19 add_filter( 'bp_get_the_profile_field_edit_value', 'wp_filter_kses', 1 ); 20 add_filter( 'bp_get_the_profile_field_description', 'wp_filter_kses', 1 ); 21 22 add_filter( 'bp_get_the_profile_field_value', 'wptexturize' ); 23 add_filter( 'bp_get_the_profile_field_value', 'convert_smilies', 2 ); 24 add_filter( 'bp_get_the_profile_field_value', 'convert_chars' ); 25 add_filter( 'bp_get_the_profile_field_value', 'wpautop' ); 26 add_filter( 'bp_get_the_profile_field_value', 'make_clickable', 8 ); 27 add_filter( 'bp_get_the_profile_field_value', 'force_balance_tags' ); 28 29 add_filter( 'bp_get_the_profile_field_edit_value', 'force_balance_tags' ); 30 add_filter( 'bp_get_the_profile_field_edit_value', 'esc_html' ); 31 32 add_filter( 'bp_get_the_profile_group_name', 'stripslashes' ); 33 add_filter( 'bp_get_the_profile_group_description', 'stripslashes' ); 34 add_filter( 'bp_get_the_profile_field_value', 'stripslashes' ); 35 add_filter( 'bp_get_the_profile_field_edit_value', 'stripslashes' ); 36 add_filter( 'bp_get_the_profile_field_name', 'stripslashes' ); 37 add_filter( 'bp_get_the_profile_field_description', 'stripslashes' ); 38 39 add_filter( 'xprofile_get_field_data', 'wp_filter_kses', 1 ); 40 add_filter( 'xprofile_field_name_before_save', 'wp_filter_kses', 1 ); 41 add_filter( 'xprofile_field_description_before_save', 'wp_filter_kses', 1 ); 42 43 add_filter( 'xprofile_get_field_data', 'force_balance_tags' ); 44 add_filter( 'xprofile_field_name_before_save', 'force_balance_tags' ); 45 add_filter( 'xprofile_field_description_before_save', 'force_balance_tags' ); 46 47 add_filter( 'xprofile_get_field_data', 'stripslashes' ); 48 49 add_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_format_field_value', 1, 2 ); 50 add_filter( 'bp_get_the_site_member_profile_data', 'xprofile_filter_format_field_value', 1, 2 ); 51 add_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 ); 52 53 add_filter( 'xprofile_data_value_before_save', 'xprofile_sanitize_data_value_before_save', 1, 2 ); 48 54 add_filter( 'xprofile_filtered_data_value_before_save', 'trim', 2 ); 49 55 … … 101 107 } 102 108 103 if ( $reserialize)109 if ( !empty( $reserialize ) ) 104 110 $filtered_field_value = serialize( $filtered_values ); 105 111 else … … 132 138 133 139 // If Unix timestamp 134 if ( is_numeric( $field_value ) ) 140 if ( is_numeric( $field_value ) ) { 135 141 $field_value = bp_format_time( $field_value, true, false ); 136 142 137 143 // If MySQL timestamp 138 else144 } else { 139 145 $field_value = bp_format_time( strtotime( $field_value ), true, false ); 146 } 140 147 141 148 } else { … … 155 162 $values = explode( ',', $field_value ); 156 163 157 if ( $values) {164 if ( !empty( $values ) ) { 158 165 foreach ( (array)$values as $value ) { 159 166 $value = trim( $value ); -
trunk/bp-xprofile/bp-xprofile-functions.php
r5329 r5699 1 1 <?php 2 /******************************************************************************** 3 * Business Functions 2 3 /** 4 * BuddyPress XProfile Filters 4 5 * 5 6 * Business functions are where all the magic happens in BuddyPress. They will … … 7 8 * hand off to a database class for data access, then return 8 9 * true or false on success or failure. 10 * 11 * @package BuddyPress 12 * @subpackage XProfileFilters 9 13 */ 10 14 … … 25 29 extract( $r, EXTR_SKIP ); 26 30 27 if ( !$name)31 if ( empty( $name ) ) 28 32 return false; 29 33 … … 79 83 80 84 // Check we have the minimum details 81 if ( !$field_group_id)85 if ( empty( $field_group_id ) ) 82 86 return false; 83 87 … … 87 91 88 92 // Instantiate a new field object 89 if ( $field_id)93 if ( !empty( $field_id ) ) 90 94 $field = new BP_XProfile_Field( $field_id ); 91 95 else … … 148 152 * @param mixed $field The ID of the field, or the $name of the field. 149 153 * @param int $user_id The ID of the user 150 * @global object $bp Global BuddyPress settings object151 154 * @uses BP_XProfile_ProfileData::get_value_byid() Fetches the value based on the params passed. 152 155 * @return mixed The profile field data. 153 156 */ 154 157 function xprofile_get_field_data( $field, $user_id = 0 ) { 155 global $bp;156 158 157 159 if ( empty( $user_id ) ) … … 216 218 } 217 219 220 $possible_values = array(); 221 218 222 // Check the value is an acceptable value 219 223 if ( 'checkbox' == $field->type || 'radio' == $field->type || 'selectbox' == $field->type || 'multiselectbox' == $field->type ) { … … 225 229 if ( is_array( $value ) ) { 226 230 foreach( $value as $i => $single ) { 227 if ( !in_array( $single, (array)$possible_values ) ) {231 if ( !in_array( $single, $possible_values ) ) { 228 232 unset( $value[$i] ); 229 233 } … … 233 237 $value = array_merge( array(), $value ); 234 238 } else { 235 if ( !in_array( $value, (array)$possible_values ) ) {239 if ( !in_array( $value, $possible_values ) ) { 236 240 return false; 237 241 } … … 301 305 */ 302 306 function xprofile_get_random_profile_data( $user_id, $exclude_fullname = true ) { 303 $field_data 304 305 if ( !$field_data)307 $field_data = BP_XProfile_ProfileData::get_random( $user_id, $exclude_fullname ); 308 309 if ( empty( $field_data ) ) 306 310 return false; 307 311 308 312 $field_data[0]->value = xprofile_format_profile_field( $field_data[0]->type, $field_data[0]->value ); 309 313 310 if ( !$field_data[0]->value ||empty( $field_data[0]->value ) )314 if ( empty( $field_data[0]->value ) ) 311 315 return false; 312 316 … … 352 356 */ 353 357 function xprofile_avatar_upload_dir( $directory = false, $user_id = 0 ) { 354 global $bp;355 358 356 359 if ( empty( $user_id ) ) -
trunk/bp-xprofile/bp-xprofile-loader.php
r5504 r5699 1 1 <?php 2 2 3 /** 3 4 * BuddyPress XProfile Loader … … 7 8 * 8 9 * @package BuddyPress 9 * @subpackage XProfile Core10 * @subpackage XProfileLoader 10 11 */ 11 12 … … 109 110 global $bp; 110 111 112 $sub_nav = array(); 113 111 114 // Add 'Profile' to the main navigation 112 115 $main_nav = array( -
trunk/bp-xprofile/bp-xprofile-screens.php
r5418 r5699 1 1 <?php 2 /******************************************************************************* 2 3 /** 4 * BuddyPress XProfile Screens 5 * 3 6 * Screen functions are the controllers of BuddyPress. They will execute when 4 7 * their specific URL is caught. They will first save or manipulate data using 5 8 * business functions, then pass on the user to a template file. 9 * 10 * @package BuddyPress 11 * @subpackage XProfileScreens 6 12 */ 7 13 … … 46 52 } 47 53 54 // No errors 55 $errors = false; 56 48 57 // Check to see if any new information has been submitted 49 58 if ( isset( $_POST['field_ids'] ) ) { … … 77 86 78 87 $is_required[$field_id] = xprofile_check_is_required_field( $field_id ); 79 if ( $is_required[$field_id] && empty( $_POST['field_' . $field_id] ) ) 88 if ( $is_required[$field_id] && empty( $_POST['field_' . $field_id] ) ) { 80 89 $errors = true; 90 } 81 91 } 82 92 … … 87 97 // No errors 88 98 } else { 99 89 100 // Reset the errors var 90 101 $errors = false; … … 108 119 109 120 // Set the feedback messages 110 if ( $errors)121 if ( !empty( $errors ) ) 111 122 bp_core_add_message( __( 'There was a problem updating some of your profile information, please try again.', 'buddypress' ), 'error' ); 112 123 else -
trunk/bp-xprofile/bp-xprofile-template.php
r5697 r5699 1 1 <?php 2 /*************************************************************************** 3 * XProfile Data Display Template Tags 4 **/ 2 3 /** 4 * BuddyPress XProfile Template Tags 5 * 6 * @package BuddyPress 7 * @subpackage XProfileTemplate 8 */ 5 9 6 10 // Exit if accessed directly … … 20 24 var $in_the_loop; 21 25 var $user_id; 22 23 function bp_xprofile_data_template( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false, $hide_empty_fields = false ) {24 $this->__construct( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields, $hide_empty_fields );25 }26 26 27 27 function __construct( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false, $hide_empty_fields = false ) { … … 152 152 153 153 function bp_has_profile( $args = '' ) { 154 global $ bp, $profile_template;154 global $profile_template; 155 155 156 156 // Only show empty fields if we're on the Dashboard, or we're on a user's profile edit page, … … 411 411 global $field; 412 412 413 // Generally a required dropdown field will not get a blank value at 414 // the top. Set 'null_on_required' to true if you want this blank value 415 // even on required fields. 413 416 $defaults = array( 414 'type' => false, 415 'null_on_required' => false // Generally, a required dropdown field will not 416 // get a blank value at the top. Set to true if 417 // you want this blank value even on 418 // required fields 417 'type' => false, 418 'null_on_required' => false 419 419 ); 420 420 … … 433 433 switch ( $field->type ) { 434 434 case 'selectbox': 435 if ( !$field->is_required || $null_on_required ) 435 436 if ( !$field->is_required || $null_on_required ) { 436 437 $html .= '<option value="">' . /* translators: no option picked in select box */ __( '----', 'buddypress' ) . '</option>'; 438 } 437 439 438 440 $original_option_values = ''; 439 441 $original_option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field->id ) ); 440 442 441 if ( empty( $original_option_values ) && !empty( $_POST['field_' . $field->id] ) ) 443 if ( empty( $original_option_values ) && !empty( $_POST['field_' . $field->id] ) ) { 442 444 $original_option_values = $_POST['field_' . $field->id]; 445 } 443 446 444 447 $option_values = (array) $original_option_values; 445 448 446 449 for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) { 450 447 451 // Check for updated posted values, but errors preventing them from being saved first time 448 452 foreach( $option_values as $i => $option_value ) { 449 453 if ( isset( $_POST['field_' . $field->id] ) && $_POST['field_' . $field->id] != $option_value ) { 450 if ( !empty( $_POST['field_' . $field->id] ) ) 454 if ( !empty( $_POST['field_' . $field->id] ) ) { 451 455 $option_values[$i] = $_POST['field_' . $field->id]; 456 } 452 457 } 453 458 } 459 454 460 $selected = ''; 455 461 … … 458 464 459 465 // First, check to see whether the user-entered value matches 460 if ( in_array( $allowed_options, (array) $option_values ) ) 466 if ( in_array( $allowed_options, (array) $option_values ) ) { 461 467 $selected = ' selected="selected"'; 468 } 462 469 463 470 // Then, if the user has not provided a value, check for defaults 464 if ( !is_array( $original_option_values ) && empty( $option_values ) && $options[$k]->is_default_option ) 471 if ( !is_array( $original_option_values ) && empty( $option_values ) && $options[$k]->is_default_option ) { 465 472 $selected = ' selected="selected"'; 473 } 466 474 467 475 $html .= apply_filters( 'bp_get_the_profile_field_options_select', '<option' . $selected . ' value="' . esc_attr( stripslashes( $options[$k]->name ) ) . '">' . esc_attr( stripslashes( $options[$k]->name ) ) . '</option>', $options[$k], $field->id, $selected, $k ); … … 473 481 $original_option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field->id ) ); 474 482 475 if ( empty( $original_option_values ) && !empty( $_POST['field_' . $field->id] ) ) 483 if ( empty( $original_option_values ) && !empty( $_POST['field_' . $field->id] ) ) { 476 484 $original_option_values = $_POST['field_' . $field->id]; 485 } 477 486 478 487 $option_values = (array) $original_option_values; 479 488 480 489 for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) { 490 481 491 // Check for updated posted values, but errors preventing them from being saved first time 482 492 foreach( $option_values as $i => $option_value ) { 483 493 if ( isset( $_POST['field_' . $field->id] ) && $_POST['field_' . $field->id][$i] != $option_value ) { 484 if ( !empty( $_POST['field_' . $field->id][$i] ) ) 494 if ( !empty( $_POST['field_' . $field->id][$i] ) ) { 485 495 $option_values[] = $_POST['field_' . $field->id][$i]; 496 } 486 497 } 487 498 } … … 492 503 493 504 // First, check to see whether the user-entered value matches 494 if ( in_array( $allowed_options, (array) $option_values ) ) 505 if ( in_array( $allowed_options, (array) $option_values ) ) { 495 506 $selected = ' selected="selected"'; 507 } 496 508 497 509 // Then, if the user has not provided a value, check for defaults 498 if ( !is_array( $original_option_values ) && empty( $option_values ) && $options[$k]->is_default_option )510 if ( !is_array( $original_option_values ) && empty( $option_values ) && !empty( $options[$k]->is_default_option ) ) { 499 511 $selected = ' selected="selected"'; 512 } 500 513 501 514 $html .= apply_filters( 'bp_get_the_profile_field_options_multiselect', '<option' . $selected . ' value="' . esc_attr( stripslashes( $options[$k]->name ) ) . '">' . esc_attr( stripslashes( $options[$k]->name ) ) . '</option>', $options[$k], $field->id, $selected, $k ); … … 508 521 509 522 for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) { 523 510 524 // Check for updated posted values, but errors preventing them from being saved first time 511 525 if ( isset( $_POST['field_' . $field->id] ) && $option_value != $_POST['field_' . $field->id] ) { 512 if ( !empty( $_POST['field_' . $field->id] ) ) 526 if ( !empty( $_POST['field_' . $field->id] ) ) { 513 527 $option_value = $_POST['field_' . $field->id]; 528 } 514 529 } 515 530 … … 517 532 // filter, so we'll be sure to get a match 518 533 $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false ); 519 520 $selected = ''; 521 if ( $option_value == $allowed_options || !empty( $value ) && $value == $allowed_options || ( empty( $option_value ) && $options[$k]->is_default_option ) ) 534 $selected = ''; 535 536 // @todo $value is never created 537 if ( $option_value == $allowed_options || !empty( $value ) && $value == $allowed_options || ( empty( $option_value ) && !empty( $options[$k]->is_default_option ) ) ) 522 538 $selected = ' checked="checked"'; 523 539 … … 549 565 $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false ); 550 566 567 // @todo $value is never created 551 568 if ( $option_values[$j] == $allowed_options || @in_array( $allowed_options, $value ) ) { 552 569 $selected = ' checked="checked"'; … … 557 574 // If the user has not yet supplied a value for this field, 558 575 // check to see whether there is a default value available 559 if ( !is_array( $option_values ) && empty( $option_values ) && !$selected && $options[$k]->is_default_option) {576 if ( !is_array( $option_values ) && empty( $option_values ) && empty( $selected ) && !empty( $options[$k]->is_default_option ) ) { 560 577 $selected = ' checked="checked"'; 561 578 } … … 574 591 575 592 if ( !empty( $date ) ) { 593 576 594 // If Unix timestamp 577 595 if ( is_numeric( $date ) ) { … … 588 606 } 589 607 590 // Check for updated posted values, but errors preventing them from being saved first time 608 // Check for updated posted values, and errors preventing 609 // them from being saved first time. 591 610 if ( !empty( $_POST['field_' . $field->id . '_day'] ) ) { 592 if ( $day != $_POST['field_' . $field->id . '_day'] ) 611 if ( $day != $_POST['field_' . $field->id . '_day'] ) { 593 612 $day = $_POST['field_' . $field->id . '_day']; 613 } 594 614 } 595 615 596 616 if ( !empty( $_POST['field_' . $field->id . '_month'] ) ) { 597 if ( $month != $_POST['field_' . $field->id . '_month'] ) 617 if ( $month != $_POST['field_' . $field->id . '_month'] ) { 598 618 $month = $_POST['field_' . $field->id . '_month']; 619 } 599 620 } 600 621 601 622 if ( !empty( $_POST['field_' . $field->id . '_year'] ) ) { 602 if ( $year != date( "j", $_POST['field_' . $field->id . '_year'] ) ) 623 if ( $year != date( "j", $_POST['field_' . $field->id . '_year'] ) ) { 603 624 $year = $_POST['field_' . $field->id . '_year']; 604 } 605 625 } 626 } 627 628 // $type will be passed by calling function when needed 606 629 switch ( $type ) { 607 630 case 'day': … … 689 712 } 690 713 function bp_get_profile_field_data( $args = '' ) { 691 global $bp;692 714 693 715 $defaults = array( … … 765 787 766 788 function bp_profile_last_updated() { 767 global $bp;768 789 769 790 $last_updated = bp_get_profile_last_updated(); … … 776 797 } 777 798 function bp_get_profile_last_updated() { 778 global $bp;779 799 780 800 $last_updated = bp_get_user_meta( bp_displayed_user_id(), 'profile_last_updated', true ); … … 806 826 807 827 function bp_get_user_has_avatar() { 808 global $bp;809 828 810 829 if ( !bp_core_fetch_avatar( array( 'item_id' => bp_displayed_user_id(), 'no_grav' => true ) ) ) … … 828 847 ) ); 829 848 } 849 830 850 ?>
Note: See TracChangeset
for help on using the changeset viewer.