how do i delete all topics and replies for a user
-
When the delete_user action is called I want to delete all the bbPress forum topics and replies for a specified user.
I think the problem is the posts are having their user id set to 1 as part of the deletion process and by the time the delete_user action is called, it is too late.
The code I have so far is given below. I’m not quite sure what the current state of this code is, but I think it deletes topics but not replies.
// Get remaining replies by user (not already removed with topics)
$replies = get_posts(array(
‘author’ => $user_id,
‘post_type’ => bbp_get_reply_post_type(),
‘post_status’ => array(‘publish’, ‘closed’, ‘spam’, ‘pending’, ‘trash’, ‘inherit’),
‘numberposts’ => -1,
‘fields’ => ‘ids’));// Delete replies
if (!empty($replies))
{
foreach($replies as $reply_id)
{
bbp_delete_reply($reply_id, true);
}
}// Get all topics by user
$topics = get_posts(array(
‘author’ => $user_id,
‘post_type’ => bbp_get_topic_post_type(),
‘post_status’ => ‘any’,
‘numberposts’ => -1,
‘fields’ => ‘ids’));// Delete topics (this also deletes their replies)
if (!empty($topics))
{
foreach ($topics as $topic_id)
{
bbp_delete_topic($topic_id, true); // true = force delete
}
}
- You must be logged in to reply to this topic.