Skip to:
Content

BuddyPress.org

Ticket #7049: admin-xprofile_updated_profile.diff

File admin-xprofile_updated_profile.diff, 3.2 KB (added by nickmomrik, 8 years ago)
  • bp-xprofile/classes/class-bp-xprofile-user-admin.php

     
    250250                        $errors = false;
    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
    255256                                // Certain types of fields (checkboxes, multiselects) may come
     
    257258                                // get overwritten by the default on the next edit.
    258259                                $value = isset( $_POST['field_' . $field_id] ) ? $_POST['field_' . $field_id] : '';
    259260
    260                                 if ( ! xprofile_set_field_data( $field_id, $user_id, $value, $is_required[ $field_id ] ) ) {
     261                                // Save the old and new values. They will be
     262                                // passed to the filter and used to determine
     263                                // whether an activity item should be posted.
     264                                $old_values[ $field_id ] = array(
     265                                        'value'      => xprofile_get_field_data( $field_id, $user_id ),
     266                                        'visibility' => xprofile_get_field_visibility_level( $field_id, $user_id ),
     267                                );
     268
     269                                // Update the field data and visibility level.
     270                                $visibility_level = ! empty( $_POST['field_' . $field_id . '_visibility'] ) ? $_POST['field_' . $field_id . '_visibility'] : 'public';
     271                                xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level );
     272                                $field_updated = xprofile_set_field_data( $field_id, $user_id, $value, $is_required[ $field_id ] );
     273                                $value         = xprofile_get_field_data( $field_id, $user_id );
     274
     275                                $new_values[ $field_id ] = array(
     276                                        'value'      => $value,
     277                                        'visibility' => xprofile_get_field_visibility_level( $field_id, $user_id ),
     278                                );
     279
     280                                if ( ! $field_updated ) {
    261281                                        $errors = true;
    262282                                } else {
    263283
     
    271291                                         */
    272292                                        do_action( 'xprofile_profile_field_data_updated', $field_id, $value );
    273293                                }
    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 );
    278294                        }
    279295
    280296                        /**
    281                          * Fires after all of the profile fields have been saved.
     297                         * Fires after all XProfile fields have been saved for the current profile.
    282298                         *
    283299                         * @since 1.0.0
    284300                         *
    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.
     301                         * @param int   $value            Displayed user ID.
     302                         * @param array $posted_field_ids Array of field IDs that were edited.
     303                         * @param bool  $errors           Whether or not any errors occurred.
     304                         * @param array $old_values       Array of original values before updated.
     305                         * @param array $new_values       Array of newly saved values after update.
    288306                         */
    289                         do_action( 'xprofile_updated_profile', $user_id, $posted_field_ids, $errors );
     307                        do_action( 'xprofile_updated_profile', $user_id, $posted_field_ids, $errors, $old_values, $new_values );
    290308
    291309                        // Set the feedback messages.
    292310                        if ( ! empty( $errors ) ) {