delete_attachment
Action HookDescription
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 | 6655 |
Hook Parameters
Type | Name | Description |
---|---|---|
int
|
$post_id
|
Attachment ID. |
WP_Post
|
$post
|
Post object. |
Usage Examples
Basic Usage
<?php
// Hook into delete_attachment
add_action('delete_attachment', 'my_custom_function', 10, 2);
function my_custom_function($post_id, $post) {
// Your custom code here
}
Source Code Context
wp-includes/post.php:6655
- How this hook is used in WordPress core
<?php
6650 * @since 5.5.0 Added the `$post` parameter.
6651 *
6652 * @param int $post_id Attachment ID.
6653 * @param WP_Post $post Post object.
6654 */
6655 do_action( 'delete_attachment', $post_id, $post );
6656
6657 wp_delete_object_term_relationships( $post_id, array( 'category', 'post_tag' ) );
6658 wp_delete_object_term_relationships( $post_id, get_object_taxonomies( $post->post_type ) );
6659
6660 // Delete all for any posts.
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.