• Is there a way to always reassign posts to a different ID any time wp_delete_user is called? Are there any hooks that I can use here?

    Thank you

Viewing 5 replies - 1 through 5 (of 5 total)
  • Do you mean posts that are authored by that user? Do you always want them to default back to a known ID?

    I’m looking through the wp_delete_user function right now and it has a fairly complex workflow for deciding which posts to delete and which ones should not be deleted when a user is deleted. To circumvent that, it looks like you could hook to delete_user and change the author away from the user being deleted. Does that make sense? Here’s an example: https://gist.github.com/nickohrn/9351687

    Of course, I’d be hesitant to deploy that code because it is mostly a duplication of the existing functionality inside the wp_delete_user function, but it does accomplish what you’re looking for if I’m reading your question correctly.

    Thread Starter ndh01

    (@ndh01)

    I was hoping there was another way. Like you state, there is a lot of duplicate code there. I’m using buddy press and they you can give the user a way to delete their account using members/%username%/settings/delete-account/ It eventually calls wp_delete_user, but I don’t see a way to specify an ID to transfer the posts to.

    Do you want the user who is deleting their account to be able to specify the user, or would the user be specified globally for the entire site?

    Thread Starter ndh01

    (@ndh01)

    I was thinking of setting up a user just to catch all of the posts globally for the site.

    In that case, just grab the code from the Gist that I created above and use it. It’s a lot of duplication of what is already in there, but it does what you want to do.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Automatically reassign posts to a different ID anytime wp_delete_user is called’ is closed to new replies.