WordPress action hook · part of WordPress core

before_delete_post

A WordPress core action that 3 plugins also fire themselves, running on 43K+ sites between them.

“Fires before a post is deleted, at the start of wp_delete_post().”

How to use before_delete_post

It's an action: your callback runs at that point and receives 2 arguments. Nothing needs to be returned. Add this to your theme's functions.php or a small custom plugin:

functions.php
add_action( 'before_delete_post', function( $ID, $store_post ) {
	// Your code runs here.
}, 10, 2 );

Argument names come from WP Store Locator's source. Other plugins may pass different values: check the call in the plugin you're targeting below.

This hook is fired by WordPress core too. Official reference on developer.wordpress.org →

3 plugins that fire before_delete_post

Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.

  1. WP Store Locator icon WP Store Locator40,000+ installs do_action( 'before_delete_post', $store_post->ID, $store_post ) includes/admin/tools/class-data-management.php:286
  2. Bulk Page Generator icon Bulk Page Generator3,000+ installs do_action( 'before_delete_post', $post_id, $post ) src/service/delete/DeletePageService.php:57
  3. Post ID Optimizer icon Post ID Optimizer10+ installs do_action( 'before_delete_post', $postid ) post-poidopt.php:2814

Need a customisation built on this hook?

Tell us what you want to change and which plugin it's for. We'll write it, test it and send it back as a small plugin.