Action hook 'deleted_post'

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

View Source

deleted_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 6684

Hook Parameters

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

Usage Examples

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

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

Source Code Context

wp-includes/post.php:6684 - How this hook is used in WordPress core
<?php
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 */
6684  	do_action( 'deleted_post', $post_id, $post );
6685  
6686  	wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file );
6687  
6688  	clean_post_cache( $post );
6689  

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.