BP_Bbp_Gdpr_Forums::forums_eraser( $email_address, int $page = 1 )

Delete all forums created by member.

Description

Parameters

$email_address

(Required)

$page

(Optional)

Default value: 1

Return

(array)

Source

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

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
257
258
259
function forums_eraser( $email_address, $page = 1 ) {
    $per_page = 500; // Limit to avoid timeout
    $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_forums( $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;
    $forums = ! empty( $items['forums'] ) ? $items['forums'] : array();
 
    if ( $total ) {
        foreach ( (array) $forums as $forum ) {
            $attachments = get_posts( array(
                'post_type'      => 'attachment',
                'posts_per_page' => - 1,
                'post_parent'    => $forum->ID,
            ) );
 
            if ( $attachments ) {
                foreach ( $attachments as $attachment ) {
                    wp_delete_post( $attachment->ID, true );
                }
            }
            wp_delete_post( $forum->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.