Skip to:
Content

BuddyPress.org

Changeset 10822


Ignore:
Timestamp:
05/29/2016 12:34:05 PM (3 years ago)
Author:
dcavins
Message:

Harmonize parameters sent with xprofile_updated_profile action.

Update the action xprofile_updated_profile
in BP_XProfile_User_Admin::user_admin_load()
so that the same parameters are passed as
when the when the same action occurs in
xprofile_screen_edit_profile().

Fixes #7049.

Props nickmomrik.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-user-admin.php

    r10740 r10822  
    251251
    252252            // Now we've checked for required fields, let's save the values.
     253            $old_values = $new_values = array();
    253254            foreach ( (array) $posted_field_ids as $field_id ) {
    254255
    255                 // Certain types of fields (checkboxes, multiselects) may come
    256                 // through empty. Save them as an empty array so that they don't
    257                 // get overwritten by the default on the next edit.
     256                /*
     257                 * Certain types of fields (checkboxes, multiselects) may come
     258                 * through empty. Save them as an empty array so that they don't
     259                 * get overwritten by the default on the next edit.
     260                 */
    258261                $value = isset( $_POST['field_' . $field_id] ) ? $_POST['field_' . $field_id] : '';
    259262
    260                 if ( ! xprofile_set_field_data( $field_id, $user_id, $value, $is_required[ $field_id ] ) ) {
     263                $visibility_level = ! empty( $_POST['field_' . $field_id . '_visibility'] ) ? $_POST['field_' . $field_id . '_visibility'] : 'public';
     264                /*
     265                 * Save the old and new values. They will be
     266                 * passed to the filter and used to determine
     267                 * whether an activity item should be posted.
     268                 */
     269                $old_values[ $field_id ] = array(
     270                    'value'      => xprofile_get_field_data( $field_id, $user_id ),
     271                    'visibility' => xprofile_get_field_visibility_level( $field_id, $user_id ),
     272                );
     273
     274                // Update the field data and visibility level.
     275                xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level );
     276                $field_updated = xprofile_set_field_data( $field_id, $user_id, $value, $is_required[ $field_id ] );
     277                $value         = xprofile_get_field_data( $field_id, $user_id );
     278
     279                $new_values[ $field_id ] = array(
     280                    'value'      => $value,
     281                    'visibility' => xprofile_get_field_visibility_level( $field_id, $user_id ),
     282                );
     283
     284                if ( ! $field_updated ) {
    261285                    $errors = true;
    262286                } else {
     
    272296                    do_action( 'xprofile_profile_field_data_updated', $field_id, $value );
    273297                }
    274 
    275                 // Save the visibility level.
    276                 $visibility_level = ! empty( $_POST['field_' . $field_id . '_visibility'] ) ? $_POST['field_' . $field_id . '_visibility'] : 'public';
    277                 xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level );
    278298            }
    279299
    280300            /**
    281              * Fires after all of the profile fields have been saved.
     301             * Fires after all XProfile fields have been saved for the current profile.
    282302             *
    283303             * @since 1.0.0
     304             * @since 2.6.0 Added $old_values and $new_values parameters.
    284305             *
    285              * @param int   $user_id          ID of the user whose data is being saved.
    286              * @param array $posted_field_ids IDs of the fields that were submitted.
    287              * @param bool  $errors           Whether or not errors occurred during saving.
     306             * @param int   $user_id          ID for the user whose profile is being saved.
     307             * @param array $posted_field_ids Array of field IDs that were edited.
     308             * @param bool  $errors           Whether or not any errors occurred.
     309             * @param array $old_values       Array of original values before update.
     310             * @param array $new_values       Array of newly saved values after update.
    288311             */
    289             do_action( 'xprofile_updated_profile', $user_id, $posted_field_ids, $errors );
     312            do_action( 'xprofile_updated_profile', $user_id, $posted_field_ids, $errors, $old_values, $new_values );
    290313
    291314            // Set the feedback messages.
Note: See TracChangeset for help on using the changeset viewer.