Action hook 'delete_post'

in WP Core File wp-includes/post.php at line 6678

View Source

delete_post

Action Hook
Description
Fires before an attachment is deleted, at the start of wp_delete_attachment().

Hook Information

File Location wp-includes/post.php View on GitHub
Hook Type Action
Line Number 6678

Hook Parameters

Type Name Description
int $post_id Attachment ID.
WP_Post $post Post object.

Usage Examples

Basic Usage
<?php
// Hook into delete_post
add_action('delete_post', 'my_custom_function', 10, 2);

function my_custom_function($post_id, $post) {
    // Your custom code here
}

Source Code Context

wp-includes/post.php:6678 - How this hook is used in WordPress core
<?php
6673  	foreach ( $post_meta_ids as $mid ) {
6674  		delete_metadata_by_mid( 'post', $mid );
6675  	}
6676  
6677  	/** This action is documented in wp-includes/post.php */
6678  	do_action( 'delete_post', $post_id, $post );
6679  	$result = $wpdb->delete( $wpdb->posts, array( 'ID' => $post_id ) );
6680  	if ( ! $result ) {
6681  		return false;
6682  	}
6683  	/** This action is documented in wp-includes/post.php */

PHP Documentation

<?php
/**
	 * Fires before an attachment is deleted, at the start of wp_delete_attachment().
	 *
	 * @since 2.0.0
	 * @since 5.5.0 Added the `$post` parameter.
	 *
	 * @param int     $post_id Attachment ID.
	 * @param WP_Post $post    Post object.
	 */
Quick Info
  • Hook Type: Action
  • Parameters: 2
  • File: wp-includes/post.php
Related Hooks

Related hooks will be displayed here in future updates.