just delete the user from the WordPress backend
go to users>all users then search for the user you want to delete
hover around there avatar and name and you will a bunch of links which one of them says delete
click that
then the next screen which is added from bbPress which says
[] delete all content
[] attribute all content to: {some username}
tick delete all content then confirm deletion
Hello Robkk! Thanks a lot for your detailed suggestion. I know this way to delete users from wordpress backend, but I’m looking for the function who does this in order to add a little code to my bbpress frontend 🙂
Well, what I want in wordpress is:
add_action('delete_user', 'delete_posts_and_attachments');
function delete_posts_and_attachments($user_id) {
$args = array (
'numberposts' => -1,
'post_type' => 'any',
'author' => $user_id
);
// get all posts by this user: posts, pages, attachments, etc..
$user_posts = get_posts($args);
if (empty($user_posts)) return;
// delete all the user posts
foreach ($user_posts as $user_post) {
wp_delete_post($user_post->ID, true);
}
}
But where and how can I delete posts from bbpress? any help will be appreciated :\
Sorry for the thread up, but hope there is a function by default to delete all user posts at bbpress forums. Someone know what function is?
Thanks a lot in advance.
Sorry for the thread up
nah its two weeks its okay.
as for your function , instead of doing a function because you would have to do it for every user you want to delete.
how about do this so you can bulk delete the posts by the users in the replies/topics section.
first create a new user named “deleted” or “removed” some kind of variation of that.
then whenever you want to delete a user attribute all the content to that user you just created.
then in the topics/replies section bulk delete the posts by searching the “deleted” user first. then clicking on the author link in the topics/replies section which should only show that users posts from there so you can bulk delete the posts.
and to change the number of posts shown in one page of the topics/repies section change the default number to like say 75 or so.
other than that maybe changing the post type of your function to reply or topic might make it work , also if you found the users id you want to delete and input into the id field.