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
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
| 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.