Ticket #5220: 5220.04b.patch
File 5220.04b.patch, 5.2 KB (added by , 11 years ago) |
---|
-
bp-xprofile/bp-xprofile-classes.php
1094 1094 do_action_ref_array( 'xprofile_data_before_save', array( $this ) ); 1095 1095 1096 1096 if ( $this->is_valid_field() ) { 1097 if ( $this->exists() && !empty( $this->value ) &&strlen( trim( $this->value ) ) ) {1097 if ( $this->exists() && strlen( trim( $this->value ) ) ) { 1098 1098 $result = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_data} SET value = %s, last_updated = %s WHERE user_id = %d AND field_id = %d", $this->value, $this->last_updated, $this->user_id, $this->field_id ) ); 1099 1099 1100 1100 } else if ( $this->exists() && empty( $this->value ) ) { … … 2431 2431 $this->category = _x( 'Single Fields', 'xprofile field type category', 'buddypress' ); 2432 2432 $this->name = _x( 'Number', 'xprofile field type', 'buddypress' ); 2433 2433 2434 $this->accepts_null_value = true; 2435 2434 2436 $this->set_format( '/^\d+$/', 'replace' ); 2435 2437 do_action( 'bp_xprofile_field_type_number', $this ); 2436 2438 } … … 2453 2455 $html = $this->get_edit_field_html_elements( array_merge( 2454 2456 array( 2455 2457 'type' => 'number', 2456 'value' => bp_get_the_profile_field_edit_value(),2458 'value' => (int) bp_get_the_profile_field_edit_value(), 2457 2459 ), 2458 2460 $raw_properties 2459 2461 ) ); -
bp-xprofile/bp-xprofile-filters.php
85 85 function xprofile_sanitize_data_value_before_save ( $field_value, $field_id, $reserialize = true ) { 86 86 87 87 // Return if empty 88 if ( empty( $field_value ) ) 89 return; 88 if ( empty( $field_value ) ) { 89 return $field_value; 90 } 90 91 91 92 // Value might be serialized 92 93 $field_value = maybe_unserialize( $field_value ); 93 94 94 95 // Filter single value 95 if ( ! is_array( $field_value ) ) {96 if ( ! is_array( $field_value ) ) { 96 97 $kses_field_value = xprofile_filter_kses( $field_value ); 97 98 $filtered_field_value = wp_rel_nofollow( force_balance_tags( $kses_field_value ) ); 98 99 $filtered_field_value = apply_filters( 'xprofile_filtered_data_value_before_save', $filtered_field_value, $field_value ); -
bp-xprofile/bp-xprofile-functions.php
256 256 if ( empty( $field_id ) ) 257 257 return false; 258 258 259 if ( $is_required && ( empty( $value ) || !is_array( $value ) && !strlen( trim( $value ) ) ) ) 259 if ( $is_required && ( empty( $value ) || !is_array( $value ) && !strlen( trim( $value ) ) ) ) { 260 260 return false; 261 } 261 262 262 263 $field = new BP_XProfile_Field( $field_id ); 263 $field_type_obj = bp_xprofile_create_field_type( BP_XProfile_Field::get_type( $field_id ) ); 264 $field_type = BP_XProfile_Field::get_type( $field_id ); 265 $field_type_obj = bp_xprofile_create_field_type( $field_type ); 266 267 // Certain types of fields (checkboxes, multiselects) may come through empty. 268 // Save as empty array so this isn't overwritten by the default on next edit. 269 if ( empty( $value ) && in_array( $field_type, array( 'multiselectbox', 'checkbox' ) ) ) { 270 $value = array(); 271 } 264 272 265 // If the value is empty, then delete any field data that exists, unless the field is of a type where null values are semantically meaningful 273 // If the value is empty, then delete any field data that exists, unless the 274 // field is of a type where null values are semantically meaningful 266 275 if ( empty( $value ) && ! $field_type_obj->accepts_null_value ) { 267 276 xprofile_delete_field_data( $field_id, $user_id ); 268 277 return true; -
bp-xprofile/bp-xprofile-screens.php
105 105 $old_values = $new_values = array(); 106 106 foreach ( (array) $posted_field_ids as $field_id ) { 107 107 108 // Certain types of fields (checkboxes, multiselects) may come through empty. Save them as an empty array so that they don't get overwritten by the default on the next edit. 109 if ( empty( $_POST['field_' . $field_id] ) ) { 110 $value = array(); 111 } else { 112 $value = $_POST['field_' . $field_id]; 113 } 108 $value = isset( $_POST['field_' . $field_id] ) ? $_POST['field_' . $field_id] : ''; 114 109 115 110 if ( !xprofile_set_field_data( $field_id, bp_displayed_user_id(), $value, $is_required[$field_id] ) ) { 116 111 $errors = true; -
tests/testcases/xprofile/functions.php
542 542 543 543 $this->assertSame( 'foo', $found ); 544 544 } 545 546 /** 547 * @group xprofile_set_field_data 548 */ 549 public function test_get_field_data_integer_zero() { 550 $u = $this->create_user(); 551 $g = $this->factory->xprofile_group->create(); 552 $f = $this->factory->xprofile_field->create( array( 553 'field_group_id' => $g, 554 'type' => 'number', 555 'name' => 'Pens', 556 ) ); 557 xprofile_set_field_data( $f, $u, 0 ); 558 559 $this->assertEquals( 0, xprofile_get_field_data( 'Pens', $u ) ); 560 } 545 561 }