Make WordPress Core

Opened 9 years ago

Last modified 5 years ago

#32796 new enhancement

User deletion API is inconsistent between MS and non-MS

Reported by: boonebgorges's profile boonebgorges Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Users Keywords: needs-unit-tests has-patch
Focuses: multisite Cc:

Description

On non-multisite, wp_delete_user( $u ) does what you'd expect: it deletes user $u from the database. On multisite, the same function basically wraps remove_user_from_blog(); if you want to delete a user from the database altogether, you've got to use wpmu_delete_user().

I understand the historical reasons behind the divergence, but it's pretty lame from a developer's point of view to have to check is_multisite() before removing a user from the database.

There's a note in the docblock for wpmu_delete_user() that says * @todo Merge with wp_delete_user() ?. Maybe we could actually make this happen?

Attachments (1)

32796.diff (8.6 KB) - added by jeremyfelt 9 years ago.

Download all attachments as: .zip

Change History (3)

#1 @boonebgorges
9 years ago

In 32953:

Introduce WP_UnitTestCase::delete_user().

This static method provides a multisite-agnostic way to delete users during
automated testing.

See #32796.

@jeremyfelt
9 years ago

#2 @jeremyfelt
9 years ago

  • Keywords has-patch added; needs-patch removed

32796.diff is a first attempt at a merge of wpmu_delete_user() into wp_delete_user().

It's not as bad as I thought it would be so far, though a full suite of tests to go along with this will be nice. I have not done any extensive testing, but it passes our current (limited) tests and I'm able to do basic things as expected.

Notes:

  • I've added a $context parameter to wp_delete_user() so that we can determine if a user is being deleted from a network or from an individual site on the network. Single site should always be in the site context.
  • It's worth looking at #12720 as part of this ticket. @danielbachhuber's comment about explicit core APIs makes sense. There could be room for something like wp_reassign_user_content() and wp_delete_user_content() here.
Note: See TracTickets for help on using tickets.