BP_Bbp_Gdpr_Topics::topics_eraser( $email_address, int $page = 1 )

Delete forum topics created by member.

Description

Parameters

$email_address

(Required)

$page

(Optional)

Default value: 1

Return

(array)

Source

File: bp-core/gdpr/class-bp-bbp-gdpr-topics.php

195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
function topics_eraser( $email_address, $page = 1 ) {
    $per_page = 500; // Limit us to avoid timing out
    $page     = (int) $page;
 
    $user = get_user_by( 'email', $email_address );
    if ( false === $user ) {
        return array(
            'items_removed'  => false,
            'items_retained' => false,
            'messages'       => array(),
            'done'           => true,
        );
    }
 
    $items_removed  = false;
    $items_retained = false;
    $messages       = array();
 
    $items = $this->get_topics( $user, 1, $per_page );
 
    if ( ! $items ) {
        return array(
            'items_removed'  => false,
            'items_retained' => false,
            'messages'       => array(),
            'done'           => true,
        );
    }
 
    $total  = isset( $items['total'] ) ? $items['total'] : 0;
    $topics = ! empty( $items['topics'] ) ? $items['topics'] : array();
 
    if ( $total ) {
        foreach ( (array) $topics as $topic ) {
            $attachments = get_posts( array(
                'post_type'      => 'attachment',
                'posts_per_page' => - 1,
                'post_parent'    => $topic->ID,
            ) );
 
            if ( $attachments ) {
                foreach ( $attachments as $attachment ) {
                    wp_delete_post( $attachment->ID, true );
                }
            }
            wp_delete_post( $topic->ID, true );
            $items_removed = true;
        }
    }
 
    $offset = ( $page - 1 ) * $per_page;
 
    // Tell core if we have more comments to work on still
    $done = $total < $offset;
 
    return array(
        'items_removed'  => $items_removed,
        'items_retained' => $items_retained,
        'messages'       => $messages,
        'done'           => $done,
    );
}

Changelog

Changelog
Version Description
BuddyBoss 1.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.