Changeset 12869
- Timestamp:
- 03/22/2021 07:45:24 PM (3 years ago)
- Location:
- trunk/src/bp-xprofile
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-xprofile/bp-xprofile-cache.php
r12529 r12869 303 303 // List actions to clear super cached pages on, if super cache is installed. 304 304 add_action( 'xprofile_updated_profile', 'bp_core_clear_cache' ); 305 306 /** 307 * Resets the User Metadata ids cache. 308 * 309 * @since 8.0.0 310 * 311 * @param integer $user_id The user ID. 312 */ 313 function bp_xprofile_reset_user_mid_cache( $user_id ) { 314 wp_cache_delete( $user_id, 'bp_user_mid' ); 315 } 316 add_action( 'profile_update', 'bp_xprofile_reset_user_mid_cache', 10, 1 ); -
trunk/src/bp-xprofile/bp-xprofile-filters.php
r12806 r12869 353 353 */ 354 354 function bp_xprofile_escape_field_data( $value, $field_type, $field_id ) { 355 // Sanitization for these types is directly done into their `display_filter()` method. 356 if ( 'wp-biography' === $field_type || 'wp-textbox' === $field_type ) { 357 return $value; 358 } 359 355 360 if ( bp_xprofile_is_richtext_enabled_for_field( $field_id ) ) { 356 361 // The xprofile_filter_kses() expects a BP_XProfile_ProfileData object. -
trunk/src/bp-xprofile/bp-xprofile-functions.php
r12768 r12869 160 160 'textbox' => 'BP_XProfile_Field_Type_Textbox', 161 161 'telephone' => 'BP_XProfile_Field_Type_Telephone', 162 'wp-biography' => 'BP_XProfile_Field_Type_WordPress_Biography', 163 'wp-textbox' => 'BP_XProfile_Field_Type_WordPress_Textbox', 162 164 ); 163 165 … … 312 314 313 315 /** 316 * Get a profile Field Type object. 317 * 318 * @since 8.0.0 319 * 320 * @param int $field_id ID of the field. 321 * @return BP_XProfile_Field_Type|null Field Type object if found, otherwise null. 322 */ 323 function bp_xprofile_get_field_type( $field_id ) { 324 $field_type = null; 325 $field = xprofile_get_field( $field_id, null, false ); 326 327 if ( $field instanceof BP_XProfile_Field ) { 328 $field_type = $field->type_obj; 329 } 330 331 return $field_type; 332 } 333 334 /** 314 335 * Delete a profile field object. 315 336 * … … 463 484 } 464 485 465 $field = new BP_XProfile_ProfileData(); 466 $field->field_id = $field_id; 467 $field->user_id = $user_id; 468 469 // Gets un/reserialized via xprofile_sanitize_data_value_before_save(). 470 $field->value = maybe_serialize( $value ); 471 472 return $field->save(); 486 $field_args = compact( 'field_type_obj', 'field', 'user_id', 'value', 'is_required' ); 487 488 /** 489 * Return a WP_Error object or true to use your custom way of saving field values. 490 * 491 * @since 8.0.0 492 * 493 * @param boolean Whether to shortcircuit the $bp->profile->table_name_data table. 494 * @param array $field_args { 495 * An array of arguments. 496 * 497 * @type object $field_type_obj Field type object. 498 * @type BP_XProfile_Field $field Field object. 499 * @type integer $user_id The user ID. 500 * @type mixed $value Value passed to xprofile_set_field_data(). 501 * @type boolean $is_required Whether or not the field is required. 502 * } 503 */ 504 $retval = apply_filters( 'bp_xprofile_set_field_data_pre_save', false, $field_args ); 505 506 if ( is_wp_error( $retval ) ) { 507 return false; 508 } 509 510 if ( false === $retval ) { 511 $field = new BP_XProfile_ProfileData(); 512 $field->field_id = $field_id; 513 $field->user_id = $user_id; 514 515 // Gets un/reserialized via xprofile_sanitize_data_value_before_save(). 516 $field->value = maybe_serialize( $value ); 517 518 $retval = $field->save(); 519 } 520 521 return $retval; 473 522 } 474 523 … … 1358 1407 ); 1359 1408 } 1409 1410 /** 1411 * Returns the list of supporterd WordPress field meta keys. 1412 * 1413 * @since 8.0.0 1414 * 1415 * @return string[] List of supported WordPress user keys. 1416 */ 1417 function bp_xprofile_get_wp_user_keys() { 1418 return array_merge( 1419 array( 'first_name', 'last_name', 'user_url', 'description' ), 1420 array_keys( wp_get_user_contact_methods() ) 1421 ); 1422 } -
trunk/src/bp-xprofile/classes/class-bp-xprofile-component.php
r12694 r12869 411 411 'bp_xprofile_fields', 412 412 'bp_xprofile_groups', 413 'xprofile_meta' 413 'xprofile_meta', 414 'bp_user_mid', 414 415 ) ); 415 416 -
trunk/src/bp-xprofile/classes/class-bp-xprofile-profiledata.php
r12781 r12869 317 317 * 318 318 * @since 2.0.0 319 * 320 * @param int $user_id ID of user whose data is being queried. 321 * @param array $field_ids Array of field IDs to query for. 319 * @since 8.0.0 Checks if a null field data is an xProfile WP Field. 320 * Adds a new parameter `$field_type_objects` to pass the list of field type objects. 321 * 322 * @param int $user_id ID of user whose data is being queried. 323 * @param array $field_ids Array of field IDs to query for. 324 * @param array $field_type_objects Array of field type objects keyed by the queried filed IDs. 322 325 * @return array 323 326 */ 324 public static function get_data_for_user( $user_id, $field_ids ) {327 public static function get_data_for_user( $user_id, $field_ids, $field_type_objects = array() ) { 325 328 global $wpdb; 326 329 … … 340 343 $d = new stdClass; 341 344 $d->id = $ud->id; 345 $d->table_name = $bp->profile->table_name_data; 342 346 $d->user_id = $ud->user_id; 343 347 $d->field_id = $ud->field_id; … … 360 364 // to avoid future cache misses. 361 365 } else { 362 $d = new stdClass; 363 $d->id = ''; 366 $d = new stdClass; 367 368 // Check WordPress if it's a WordPress field. 369 if ( isset( $field_type_objects[ $field_id ]->wp_user_key ) ) { 370 $meta = $field_type_objects[ $field_id ]->get_field_value( $user_id, $field_id ); 371 $d->id = $meta['id']; 372 $d->value = $meta['value']; 373 $d->table_name = $meta['table_name']; 374 375 } else { 376 $d->id = ''; 377 $d->value = ''; 378 } 379 380 $d->table_name = ''; 364 381 $d->user_id = $user_id; 365 382 $d->field_id = $field_id; 366 $d->value = '';367 383 $d->last_updated = ''; 368 384 … … 397 413 * 398 414 * @since 1.2.0 415 * @since 8.0.0 Checks if a null field data is an xProfile WP Field. 399 416 * 400 417 * @param int $user_id ID of the user. … … 431 448 'field_id' => $field->id, 432 449 'field_type' => $field->type, 433 'field_data' => $field->data->value,434 450 ); 451 452 if ( is_null( $field->data ) ) { 453 if ( 1 === $field->id ) { 454 $profile_data[ $field->name ]['field_data'] = $user->display_name; 455 } elseif ( isset( $field->type_obj ) && $field->type_obj instanceof BP_XProfile_Field_Type && isset( $field->type_obj->wp_user_key ) ) { 456 $meta = $field->type_obj->get_field_value( $user->ID, $field->id ); 457 458 if ( isset( $meta['value'] ) ) { 459 $profile_data[ $field->name ]['field_data'] = $meta['value']; 460 } 461 } else { 462 $profile_data[ $field->name ]['field_data'] = false; 463 } 464 } else { 465 $profile_data[ $field->name ]['field_data'] = $field->data->value; 466 } 435 467 } 436 468 } … … 476 508 * 477 509 * @since 1.0.0 510 * @since 8.0.0 Checks if a null field data is an xProfile WP Field. 478 511 * 479 512 * @param int $field_id ID of the field. … … 525 558 // avoid cache misses and PHP notices. 526 559 } else { 527 $d = new stdClass; 528 $d->id = ''; 560 $d = new stdClass; 561 $field_type = bp_xprofile_get_field_type( $field_id ); 562 563 // Check WordPress if it's a WordPress field. 564 if ( isset( $field_type->wp_user_key ) ) { 565 $meta = $field_type->get_field_value( $user_id, $field_id ); 566 $d->id = $meta['id']; 567 $d->value = $meta['value']; 568 $d->table_name = $meta['table_name']; 569 570 } else { 571 $d->id = ''; 572 $d->value = ''; 573 } 574 575 $d->table_name = ''; 529 576 $d->user_id = $id; 530 577 $d->field_id = $field_id; 531 $d->value = '';532 578 $d->last_updated = ''; 533 579 } … … 571 617 * 572 618 * @since 1.0.0 619 * @deprecated 8.0.0 This function is not used anymore. 573 620 * 574 621 * @param array|string $fields Field(s) to get. … … 577 624 */ 578 625 public static function get_value_byfieldname( $fields, $user_id = null ) { 626 _deprecated_function( __FUNCTION__, '8.0.0' ); 579 627 global $wpdb; 580 628 -
trunk/src/bp-xprofile/classes/class-bp-xprofile-user-admin.php
r12554 r12869 273 273 $r = bp_parse_args( $args['args'], array( 274 274 'profile_group_id' => 0, 275 'user_id' => $user->ID 275 'user_id' => $user->ID, 276 'hide_field_types' => array( 'wp-textbox', 'wp-biography' ), 276 277 ), 'bp_xprofile_user_admin_profile_loop_args' ); 277 278 -
trunk/src/bp-xprofile/screens/edit.php
r11928 r12869 50 50 $posted_field_ids = wp_parse_id_list( $_POST['field_ids'] ); 51 51 $is_required = array(); 52 53 $bp_displayed_user = bp_get_displayed_user(); 54 $bp_displayed_user->updated_keys = array(); 52 55 53 56 // Loop through the posted fields formatting any datebox values then validate the field. … … 127 130 do_action( 'xprofile_updated_profile', bp_displayed_user_id(), $posted_field_ids, $errors, $old_values, $new_values ); 128 131 132 // Some WP User keys have been updated: let's update the WP fiels all together. 133 if ( $bp_displayed_user->updated_keys ) { 134 $user_id = wp_update_user( 135 array_merge( 136 array( 137 'ID' => bp_displayed_user_id(), 138 ), 139 $bp_displayed_user->updated_keys 140 ) 141 ); 142 143 $bp_displayed_user->updated_keys = array(); 144 145 if ( is_wp_error( $user_id ) ) { 146 $errors = true; 147 } 148 } 149 129 150 // Set the feedback messages. 130 151 if ( !empty( $errors ) ) {
Note: See TracChangeset
for help on using the changeset viewer.