Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#10810 closed enhancement (wontfix)

Addition of: can_delete_(post|user|...) filters

Reported by: 5ubliminal Owned by: westi
Milestone: Priority: high
Severity: normal Version: 2.8.4
Component: Plugins Keywords:
Focuses: Cc:


Any delete_* action should be preceded by a can_delete_* filter to allow plugins to prevent deletion of ... stuff. And: if(apply_filters('can_delete_user', true, $user_ID) == false) return false;

E.g.: I have a plugin that deletes users who have no logged in for 3 months. But when I issue wp_delete_user I want to allow other plugins to prevent deletion. Let's say that user has bought something from my blog. I want to keep it even if administrator tries to delete it.

This way ... if I choose 50 users to delete I could just internally skip those un-deletable. I know I can wp_die when I don't want to delete a user [on delete_user] but I'd rather protect the user silently than having to delete again after de-selecting that user from the selection.

E.g.: Inside wp_delete_user ... instead of:

do_action('delete_user', $id);


if(!apply_filters('can_delete_user', true, $id)) return false;
do_action('delete_user', $id);

PS: Hope I make any sense.

Attachments (1)

wpd.candeletes.php (3.6 KB) - added by 5ubliminal 9 years ago.
This is my fix but I'd rather you include these filters in the core.

Download all attachments as: .zip

Change History (6)

9 years ago

This is my fix but I'd rather you include these filters in the core.

#1 @scribu
9 years ago

  • Milestone changed from 2.8.5 to 2.9

Enhancements go to major milestones.

#2 @scribu
9 years ago

  • Severity changed from blocker to normal

#3 @scribu
9 years ago

Perhaps you should add the filters to that plugin instead.

#4 @5ubliminal
9 years ago

Filters should be in the core. The attached plugin parses all .php files in WP and adds the can_delete_* wherever it finds delete_*. I attached it just as a demo of what you should do ... the best way to explain is by example.

#5 @westi
9 years ago

  • Milestone 2.9 deleted
  • Resolution set to wontfix
  • Status changed from new to closed

I am not convinced this is necessary at all.

The plugin usecase here should be handled by the plugin firing it's own filter/action before it calls wp_delete_user IMHO.

Closing as WONTFIX.

Note: See TracTickets for help on using tickets.