Filter hook 'pre_delete_attachment'

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

View Source

pre_delete_attachment

Filter Hook
Description
Filters whether an attachment deletion should take place.

Hook Information

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

Hook Parameters

Type Name Description
WP_Post|false|null $delete Whether to go forward with deletion.
WP_Post $post Post object.
bool $force_delete Whether to bypass the Trash.

Usage Examples

Basic Usage
<?php
// Hook into pre_delete_attachment
add_filter('pre_delete_attachment', 'my_custom_filter', 10, 3);

function my_custom_filter($delete, $post, $force_delete) {
    // Your custom filtering logic here
    return $delete;
}

Source Code Context

wp-includes/post.php:6630 - How this hook is used in WordPress core
<?php
6625  	 *
6626  	 * @param WP_Post|false|null $delete       Whether to go forward with deletion.
6627  	 * @param WP_Post            $post         Post object.
6628  	 * @param bool               $force_delete Whether to bypass the Trash.
6629  	 */
6630  	$check = apply_filters( 'pre_delete_attachment', null, $post, $force_delete );
6631  	if ( null !== $check ) {
6632  		return $check;
6633  	}
6634  
6635  	delete_post_meta( $post_id, '_wp_trash_meta_status' );

PHP Documentation

<?php
/**
	 * Filters whether an attachment deletion should take place.
	 *
	 * @since 5.5.0
	 *
	 * @param WP_Post|false|null $delete       Whether to go forward with deletion.
	 * @param WP_Post            $post         Post object.
	 * @param bool               $force_delete Whether to bypass the Trash.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 3
  • File: wp-includes/post.php
Related Hooks

Related hooks will be displayed here in future updates.