before_delete_post WordPress Action Hook

The before_delete_post hook is called before a post is deleted from the database. It is passed the ID of the post to be deleted.

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

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


Description

Top ↑

See also


Top ↑

Parameters

$postid

(int)Post ID.

$post

(WP_Post)Post object.


Top ↑

More Information

This hook runs:

  • Just before other data associated with the post is deleted – like meta data. After the other data is deleted, the delete_post action executes, the primary post is removed, and then the deleted_post action is executed.
  • When items marked for trash are going through final (forced) deletion (e.g. the trash is disabled and an item is deleted).

This hook does not run:

  • For posts that are being marked as trash (unforced). The wp_trash_post hook is the functional equivalent, executed just before items are marked as trash.
  • For attachments. The delete_attachment hook is the functional equivalent, executed just before posts of type attachment are processed. With attachments, exactly as with other post types, meta data is removed, the delete_post action is run, then the attachment is removed from the database, and finally, the deleted_post action is run.

Top ↑

Source

File: wp-includes/post.php

View on Trac



Top ↑

Changelog

Changelog
VersionDescription
5.5.0Added the $post parameter.
3.2.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More