Skip to:
Content
Pages
Categories
Search
Top
Bottom

how do i delete all topics and replies for a user

  • @marisa2023

    Participant

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

Viewing 1 replies (of 1 total)
  • @robin-w

    Moderator

    Presuming that you want to delete the user and any comments made in wordpress as well, then

    dashboard>users>select the user and press delete

    You will then be given the option to delete all content and the user.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar