Make WordPress Core

Opened 4 months ago

Last modified 4 months ago

#61448 new enhancement

Add a 'pre_delete_user' filter to allows some checks to potentially prevent user deletion

Reported by: axi35's profile axi35 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Users Keywords:
Focuses: Cc:

Description

Context:
I'm developping a complex website based on woocommerce + wc booking, where the owner of products are not the admin but some users (hosts). There's some moment where a user (host, clien) MUST not be deleted, for example if a booking is planned & paid but not done yet.
I need to prevent user from being delete by themselves (unsubscribe action, easy to act on) but also if an admin try to in wp-admin (no nice & easy way to do it).

Currently, I use the 'delete_user' action and throw a wp_die() when my checks says the deletion is not allowed but it's not ideal.

Proposition:
Adding a a new 'pre_delete_user' filter would allow to act more nicely on this low-level action.
There's already some 'pre_delete_X' hooks existing, like 'pre_delete_post', 'pre_delete_attachment' and woocommerce use it for all its types 'woocommerce_pre_delete_OBJECT_TYPE' so it looks like a good way to handle those checks.

Change History (1)

#1 @ramon fincken
4 months ago

I like your explanation about other hooks :)

As a sidenote: you _can_ filter the capabilities of someone during runtime, so you can revoke "delete_user" capabilities on a single PHP call.

Note: See TracTickets for help on using tickets.