WordPress filter hook · part of WordPress core
wp_delete_file
A WordPress core filter that 14 plugins also fire themselves, running on 136K+ sites between them.
“This filter is documented in wp-includes/functions.php”
How to use wp_delete_file
It's a filter: your callback receives the value, and must return the (changed) value.
Add this to your theme's functions.php or a small custom plugin:
add_filter( 'wp_delete_file', function( $file ) {
// Change $file here.
return $file;
}, 10, 1 );Argument names come from Secure Custom Fields's source. Other plugins may pass different values: check the call in the plugin you're targeting below.
This hook is fired by WordPress core too. Official reference on developer.wordpress.org →
14 plugins that fire wp_delete_file
Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.
-
Secure Custom Fields100,000+ installs
apply_filters( 'wp_delete_file', $file )includes/local-json.php:338 -
Media Library Organizer20,000+ installs
apply_filters( 'wp_delete_file', $original_file )includes/global/class-media-library-organizer-replace.php:110 -
Replace Image8,000+ installs
apply_filters( 'wp_delete_file', $thumbfile )hm-replace-image.php:124 -
RSFirewall!4,000+ installs
apply_filters( 'wp_delete_file', $file )models/configuration.php:152 -
OPML Importer3,000+ installs
do_action( 'wp_delete_file', $opml_url )opml-importer.php:182 -
Avatar Privacy1,000+ installs
apply_filters( 'wp_delete_file', $file )includes/avatar-privacy/tools/functions.php:45 -
PicDefense.io100+ installs
apply_filters( 'wp_delete_file', $thumbfile )picdefense.php:174 -
FastMigrate80+ installs
apply_filters( 'wp_delete_file', $file )fast-migrate-server-to-server.php:164 -
Private Media40+ installs
apply_filters( 'wp_delete_file', $thumbfile )inc/class-private-media-attachment-manager.php:236 -
Rotating Header10+ installs
apply_filters( 'wp_delete_file', $medium )rotating_header.php:496 -
Profile CCT10+ installs
apply_filters( 'wp_delete_file', $medium )views/fields/picture.php:566 -
Admin User Search10+ installs
apply_filters( 'wp_delete_file', $exist_cache_location )admin/class-admin-user-search-admin.php:234 -
WG Responsive SliderFewer than 10 installs
apply_filters( 'wp_delete_file', $file )class.wgrs.slider.php:369 -
AsciifyFewer than 10 installs
apply_filters( 'wp_delete_file', $filename )asciify.php:212 -
PageFerryFewer than 10 installs
apply_filters( 'wp_delete_file', $path )includes/class-pageferry-filesystem.php:152
Need a customisation built on this hook?
Tell us what you want to change and which plugin it's for. We'll write it, test it and send it back as a small plugin.