do_action( 'before_delete_post', int $postid, WP_Post $post )

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


Description Description

See also See also


Top ↑

Parameters Parameters

$postid

(int) Post ID.

$post

(WP_Post) Post object.


Top ↑

More Information More Information

It’s important to note the hook runs only when the WordPress user empties the Trash. If you’re using this hook note that it will not fire if the user is deleting an Attachment, since attachments are force deleted, i.e., not sent to the Trash. Instead use the delete_post() hook.


Top ↑

Source Source

File: wp-includes/post.php

View on Trac



Top ↑

Changelog Changelog

Changelog
Version Description
5.5.0 Added the $post parameter.
3.2.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Collins Mbaka

    Let’s suppose you have a plugin and when a certain post_type is deleted you want to perform some action.

    <?php
    add_action( 'before_delete_post', 'wpdocs_my_func' );
    function wpdocs_my_func( $postid ) {
    
        // We check if the global post type isn't ours and just return
        global $post_type;   
    
        if ( 'wpdocs_my_custom_post_type' !== $post_type ) {
            return;
        }
    
        // My custom stuff for deleting my custom post type here
    }
    ?>
    

You must log in before being able to contribute a note or feedback.