Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/11/2020 11:29:36 PM (6 years ago)
Author:
imath
Message:

Ensure cached data is cleared in BP_XProfile_ProfileData::delete_data_for_user().

Data was being deleted in bulk using a direct SQL query, bypassing the xprofile_data_before_delete and xprofile_data_after_delete actions, resulting in stale data persisting in the xprofile cache. This change uses xprofile_delete_field_data() to delete the user's data so that the action hooks are called.

Props dd32, r-a-y, dcavins.

See #8388 (branch 6.0).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/6.0/src/bp-xprofile/classes/class-bp-xprofile-profiledata.php

    r11866 r12785  
    682682                $bp = buddypress();
    683683
    684                 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE user_id = %d", $user_id ) );
     684                $field_ids = $wpdb->get_col( $wpdb->prepare( "SELECT field_id FROM {$bp->profile->table_name_data} WHERE user_id = %d", $user_id ) );
     685
     686                if ( ! $field_ids ) {
     687                        return false;
     688                }
     689
     690                foreach ( $field_ids as $field_id ) {
     691                        xprofile_delete_field_data( $field_id, $user_id );
     692                }
     693
     694                return count( $field_ids );
    685695        }
    686696
Note: See TracChangeset for help on using the changeset viewer.