WordPress filter hook · part of WordPress core

wp_handle_upload

A WordPress core filter that 42 plugins also fire themselves, running on 2.2M+ sites between them.

“Filter the data array for the uploaded file.”

How to use wp_handle_upload

It's a filter: your callback receives the value and 1 more argument, and must return the (changed) value. Add this to your theme's functions.php or a small custom plugin:

functions.php
add_filter( 'wp_handle_upload', function( $value, $arg2 ) {
	// Change $value here.
	return $value;
}, 10, 2 );

Argument names come from Seraphinite Accelerator'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 →

42 plugins that fire wp_handle_upload

Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.

  1. WPvivid icon WPvivid900,000+ installs apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $wp_filetype['type'], 'error' => false, ), 'sideload' ) includes/class-wpvivid-importer.php:1733
  2. Enable Media Replace icon Enable Media Replace600,000+ installs apply_filters( 'wp_handle_upload', array( 'file' => $this->targetFile->getFullPath(), 'url' => $this->getTargetURL(), 'type' => $this->targetFile->getMime(), ), 'sideload' ) classes/Controller/ReplaceController.php:159
  3. Page Builder: Pagelayer icon Page Builder: Pagelayer400,000+ installs apply_filters( 'wp_handle_upload', array( 'file' => $targetFile, 'url' => $target_url, 'type' => $fileMime, ), 'sideload' ) main/replace-media.php:184
  4. Modula Image Gallery icon Modula Image Gallery100,000+ installs apply_filters( 'wp_handle_upload', array( 'file' => $destination_file_path, 'url' => $destination_url, 'type' => $type, ) ) includes/features/migrate/class-modula-ajax-migrator.php:173
  5. Add From Server icon Add From Server50,000+ installs apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ) ) class.add-from-server.php:224
  6. Seraphinite Accelerator icon Seraphinite Accelerator50,000+ installs apply_filters( 'wp_handle_upload', array( 'file' => $file[ 'name' ], 'url' => $post_img_dir . '/' . $file[ 'name' ], 'type' => $file[ 'type' ] ), 'upload' ) Cmn/Gen.php:6135
  7. Backup and Staging by WP Time Capsule icon Backup and Staging by WP Time Capsule10,000+ installs apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type, ), 'wp_handle_sideload' === $action ? 'sideload' : 'upload' ) wp-tcapsule-bridge/wp-files/file.php:405
  8. FV Flowplayer Video Player icon FV Flowplayer Video Player10,000+ installs apply_filters( 'wp_handle_upload', array( 'file' => $upload['file'], 'url' => $upload['url'], 'type' => $wp_filetype['type'] ), 'sideload' ) controller/editor.php:410
  9. User Submitted Posts icon User Submitted Posts10,000+ installs apply_filters( 'wp_handle_upload', array('file' => $file, 'url' => $guid, 'type' => $file_type) ) user-submitted-posts.php:1243
  10. BlockSpare icon BlockSpare10,000+ installs apply_filters( 'wp_handle_upload', array('file' => $file_path, 'url' => $file_url, 'type' => $file_type), 'upload' ) inc/layout/class-image-importer.php:116
  11. Microthemer icon Microthemer10,000+ installs apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ) ) src/PackTrait.php:1024
  12. HTML Import 2 icon HTML Import 25,000+ installs apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => wp_check_filetype( $file, null ) ) ) html-importer.php:742
  13. Avatar Manager icon Avatar Manager5,000+ installs apply_filters( 'wp_handle_upload', $struct, 'upload' ) avatar-manager.php:1488
  14. Add From Server Lite icon Add From Server Lite4,000+ installs apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type, ), 'sideload' ) class.add-from-server.php:1473
  15. teachPress icon teachPress2,000+ installs apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'path' => "/teachpress$extra_directory_part/$filename", 'type' => $type, 'size' => $file['size'], 'filename' => $filename ), 'upload' ) core/admin.php:791
  16. Microsoft Azure Storage for WordPress icon Microsoft Azure Storage for WordPress2,000+ installs apply_filters( 'wp_handle_upload', $struct, 'upload' ) windows-azure-storage.php:394
  17. Video Thumbnails Reloaded icon Video Thumbnails Reloaded2,000+ installs apply_filters( 'wp_handle_upload', array( 'file' => $upload['file'], 'url' => $upload['url'], 'type' => $wp_filetype['type'] ), 'sideload' ) video-thumbnails.php:428
  18. FV Player 8 icon FV Player 81,000+ installs apply_filters( 'wp_handle_upload', array( 'file' => $upload['file'], 'url' => $upload['url'], 'type' => $wp_filetype['type'] ), 'sideload' ) controller/editor.php:440
  19. Seraphinite Post .DOCX Source icon Seraphinite Post .DOCX Source800+ installs apply_filters( 'wp_handle_upload', array( 'file' => $file[ 'name' ], 'url' => $post_img_dir . '/' . $file[ 'name' ], 'type' => $file[ 'type' ] ), 'upload' ) Cmn/Gen.php:5955
  20. Skyword Publishing API icon Skyword Publishing API500+ installs apply_filters( 'wp_handle_upload', array( 'file' => $fields['fileName']['value'], 'url' => $upload['url'], ), 'upload' ) php/routes/class-skyword-authors.php:210
  21. WP Easy Uploader icon WP Easy Uploader500+ installs apply_filters( 'wp_handle_upload', array( 'file' => $uploads['path'] . '/' . $filename, 'url' => $url, 'message' => $message, 'error' => false ) ) wp-easy-uploader.php:781
  22. MediaBlaster icon MediaBlaster200+ installs apply_filters( 'wp_handle_upload', array( 'file' => $upload['file'], 'url' => $upload['url'], 'type' => $wp_filetype['type'], ), 'sideload' ) includes/controls/class-wp-smart-tv-import-ajax.php:313
  23. WooTumblog icon WooTumblog80+ installs apply_filters( 'wp_handle_upload', array( 'file' => $name, 'url' => $upload[ 'url' ], 'type' => $type , 'id' => $id ) ) functions/wootumblog_express_app_functions_deprecated.php:255
  24. Posterous Importer icon Posterous Importer80+ installs apply_filters( 'wp_handle_upload', $upload ) posterous.php:544
  25. XML-RPC Modernization icon XML-RPC Modernization80+ installs apply_filters( 'wp_handle_upload', $struct, 'upload' ) class-wp-xmlrpc-server-ext.php:2278
  26. Skyword XMLRPC publishing icon Skyword XMLRPC publishing40+ installs apply_filters( 'wp_handle_upload', array( 'file' => $name, 'url' => $upload['url'], 'type' => $type ), 'upload' ) php/class-skyword-publish.php:600
  27. ExXmlRpc for WordPressPost icon ExXmlRpc for WordPressPost30+ installs apply_filters( 'wp_handle_upload', array( 'file' => $name, 'url' => $upload[ 'url' ], 'type' => $type, 'id' => $id ), 'upload' ) exXmlRpc.php:297
  28. photostream-sync icon photostream-sync30+ installs apply_filters( 'wp_handle_upload', $struct, 'upload' ) photostream-sync.php:1535
  29. WP Developer Assistant icon WP Developer Assistant30+ installs apply_filters( 'wp_handle_upload', array( 'file' => $uploads['path'] . '/' . $filename, 'url' => $url, 'message' => $message, 'error' => false ) ) wp-developer-assistant.php:1719
  30. Seraphinite Bulk Discounts for WooCommerce icon Seraphinite Bulk Discounts for WooCommerce20+ installs apply_filters( 'wp_handle_upload', array( 'file' => $file[ 'name' ], 'url' => $post_img_dir . '/' . $file[ 'name' ], 'type' => $file[ 'type' ] ), 'upload' ) Cmn/Gen.php:5351
  31. Blue Storage icon Blue Storage10+ installs apply_filters( 'wp_handle_upload', $struct, 'upload' ) blue-storage.php:320
  32. Seraphinite Downloads Statistics icon Seraphinite Downloads Statistics10+ installs apply_filters( 'wp_handle_upload', array( 'file' => $file[ 'name' ], 'url' => $post_img_dir . '/' . $file[ 'name' ], 'type' => $file[ 'type' ] ), 'upload' ) Cmn/Gen.php:5790
  33. Seraphinite Alternative Slugs Manager icon Seraphinite Alternative Slugs Manager10+ installs apply_filters( 'wp_handle_upload', array( 'file' => $file[ 'name' ], 'url' => $post_img_dir . '/' . $file[ 'name' ], 'type' => $file[ 'type' ] ), 'upload' ) Cmn/Gen.php:5043
  34. Crypto Coin Market Prices icon Crypto Coin Market Prices10+ installs apply_filters( 'wp_handle_upload', array( 'file' => $file[ 'name' ], 'url' => $post_img_dir . '/' . $file[ 'name' ], 'type' => $file[ 'type' ] ), 'upload' ) Cmn/Gen.php:1627
  35. bbPress Post via Mail icon bbPress Post via Mail10+ installs apply_filters( 'wp_handle_upload', array('file' => $new_file, 'url' => $url,'type' => $attachment->ContentType) ) library/pvm/Reply.php:167
  36. PressRoom by Newswire icon PressRoom by Newswire10+ installs apply_filters( 'wp_handle_upload', array('file' => $new_file, 'url' => $url, 'type' => $type) ) includes/activate.php:214
  37. YouTube Post Type icon YouTube Post Type10+ installs apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ) ) youtube_post_type.php:164
  38. Webangon Image Optimizer icon Webangon Image OptimizerFewer than 10 installs apply_filters( 'wp_handle_upload', array( 'file' => $target_path, 'url' => $this->path_to_url( $target_path ), 'type' => $upload['type'], ), 'sideload' ) includes/class-webangon-media-replace.php:492
  39. Testimonials WP icon Testimonials WPFewer than 10 installs apply_filters( 'wp_handle_upload', array('file' => $file_path, 'url' => $file_url, 'type' => $file_type), 'upload' ) php_libraries/twp_image_class.php:42
  40. Share Cluster icon Share ClusterFewer than 10 installs apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ), 'upload' ) cluster-includes/functions.php:1297
  41. LoveIt.com Importer icon LoveIt.com ImporterFewer than 10 installs apply_filters( 'wp_handle_upload', $upload ) loveit-importer-class.php:931
  42. Exhibit to WP Gallery icon Exhibit to WP GalleryFewer than 10 installs apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ) ) exhibit-to-wp-gallery.php:336

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.