WordPress.org

Make WordPress Core

Opened 7 years ago

Last modified 2 years ago

#12720 new defect (bug)

Delete user and hook confusion when deleting users in Multisite

Reported by: andreasnrb Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 3.0
Component: Users Keywords: needs-patch
Focuses: multisite Cc:

Description

Currently:
The hook wpmu_delete_user fires when deleting user in Super Admin->Users.
The hook remove_user_from_blog when deleting user under site Users->Authors & Users.
In standard WP:
The hook delete_user is called when deleting users it should be the same in MultiSite when deleting from Super Admin->Users.
Or add new hooks and deprecate previous.
delete_user_from_network for when deleting a user totally.
delete_user_from_site for when deleting a user from a specific site. This is hook also then fires in non-MultiSite mode since that then corresponds to one site.

Change History (7)

#1 @nacin
7 years ago

  • Milestone changed from Unassigned to Future Release

#2 @nacin
7 years ago

  • Keywords multisite needs-patch added; hooks delete user removed

#3 @jeremyfelt
3 years ago

Hey @andreasnrb, sorry about the wait!

  • delete_user fires before anything happens in wp_delete_user()
  • wpmu_delete_user fires before anything happens in wpmu_delete_user(), which has a todo note wondering if we can merge with wpmu_delete_user()
  • remove_user_from_blog fires before a user is removed from a site, which doesn't necessarily mean they are deleted.

I think delete_user is enough here. We could probably think about moving it alongside wpmu_delete_user in wpmu_delete_user() or figure out if a merge of the two functions is possible.

#4 @jeremyfelt
3 years ago

Interesting note - wp_delete_user() only removes the user from the current site if used in multisite. The user does not actually get deleted from the database. As it is, the hook delete_user is somewhat misleading in its documentation.

There may be a way for us to clean this up before introducing new hooks or hook changes. We could move the multisite check up to the top and just bounce over to remove_user_from_blog(). Or we could merge wp_delete_user() and wpmu_delete_user(). It'd be nice to think some of that out first before adding a hook in somewhere.

#5 follow-up: @danielbachhuber
3 years ago

wp_delete_user() only removes the user from the current site if used in multisite. The user does not actually get deleted from the database.

WP-CLI just ran into this. I'd be a huge fan of explicit core APIs for each behavior — wp_delete_user() seems to do too much right now.

#6 in reply to: ↑ 5 @DrewAPicture
3 years ago

Replying to danielbachhuber:

wp_delete_user() only removes the user from the current site if used in multisite. The user does not actually get deleted from the database.

WP-CLI just ran into this. I'd be a huge fan of explicit core APIs for each behavior — wp_delete_user() seems to do too much right now.

Seems like there might be a case for wp_remove_user() here, especially if the user isn't actually getting deleted. No time like the present to draw a distinct line between the concepts of removal vs deletion.

Note: See TracTickets for help on using tickets.