Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/22/2021 07:45:24 PM (6 months ago)
Author:
imath
Message:

Prepare the xProfile component to handle the WordPress field types

  • Add a cache group to cache usermeta IDs by user IDs to avoid requesting information more than necessary when it hasn't been updated.
  • Edit the Profile field sanitization filter bp_xprofile_escape_field_data so that WordPress fields are escaped the way WordPress does.
  • Add the two new Field types wp-biography & wp-textbox to the available ones. See bp_xprofile_get_field_types().
  • Introduce the bp_xprofile_get_field_type() function to get the fied type of a field thanks to its ID.
  • Introduce a new filter bp_xprofile_set_field_data_pre_save. This filter returns false by default. You can use it to avoid using the Profile data DB table to save a field value by returning a WP_Error object or true. This filter is used by the WordPress field types to avoid duplicating the corresponding usermeta values into the Profile data DB table.
  • Introduce the bp_xprofile_get_wp_user_keys() function to inform about the supported WordPress fields (first_name, last_name, user_url, description and potential WP contact methods).
  • Edit the BP_XProfile_ProfileData methods to fetch field data so that they now try to fetch data within the usermeta table if the xProfile field has a WordPress field type.
  • Deprecate the BP_XProfile_ProfileData::get_value_byfieldname() as it's no more used into BP Core code.
  • Edit the function used to output the fields into the WP Admin/Extended profile screen so that WordPress fields are ignored as they can be updated from the WP Admin regular profile.

Props DJPaul, Offereins, needle, netweb, vapvarun

See #7162

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/screens/edit.php

    r11928 r12869  
    5050        $posted_field_ids = wp_parse_id_list( $_POST['field_ids'] );
    5151        $is_required      = array();
     52
     53        $bp_displayed_user = bp_get_displayed_user();
     54        $bp_displayed_user->updated_keys = array();
    5255
    5356        // Loop through the posted fields formatting any datebox values then validate the field.
     
    127130            do_action( 'xprofile_updated_profile', bp_displayed_user_id(), $posted_field_ids, $errors, $old_values, $new_values );
    128131
     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
    129150            // Set the feedback messages.
    130151            if ( !empty( $errors ) ) {
Note: See TracChangeset for help on using the changeset viewer.