Skip to content

Commit

Permalink
Delete user WP media uploads when account is deleted.
Browse files Browse the repository at this point in the history
See #3399.
  • Loading branch information
boonebgorges committed Jul 29, 2024
1 parent 89d230c commit e680215
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions wp-content/plugins/wds-citytech/wds-citytech.php
Original file line number Diff line number Diff line change
Expand Up @@ -3830,5 +3830,26 @@ function openlab_delete_user_files_on_account_deletion( $user_id ) {
$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->group_documents->table_name} WHERE id = %d", $user_file_id ) );
}
}

// Site media.
$user_blogs = get_blogs_of_user( $user_id );
foreach ( $user_blogs as $user_blog ) {
switch_to_blog( $user_blog->userblog_id );

$media_query = new WP_Query(
[
'post_type' => 'attachment',
'posts_per_page' => -1,
'author' => $user_id,
'post_status' => 'any',
]
);

foreach ( $media_query->posts as $media_post ) {
wp_delete_attachment( $media_post->ID, true );
}

restore_current_blog();
}
}
add_action( 'bp_core_pre_delete_account', 'openlab_delete_user_files_on_account_deletion' );

0 comments on commit e680215

Please sign in to comment.