wp_handle_upload_prefilter WordPress Filter Hook

The wp_handle_upload_prefilter hook is called before a file is uploaded to WordPress. It can be used to modify the file name or type before the upload process starts.

apply_filters( 'wp_handle_upload_prefilter', array $file ) #

Filter data for the current file to upload.


Parameters

$file

(array)An array of data for a single file.


Top ↑

More Information

When you upload Media from your WordPress admin dashboard, wp_handle_upload is called once for each file the user specified. wp_handle_upload_prefilter is an admin filter that is called by the wp_handle_upload function. The single parameter, $file, represent a single element of the $_FILES array. The wp_handle_upload_prefilter provides you with an opportunity to examine or alter the filename before the file is moved to its final location.

Using this, in conjunction with the upload_dir, you can dynamically determine which directory to upload to, based on the files you upload.

add_filter('wp_handle_upload_prefilter', 'custom_upload_filter' );

function custom_upload_filter( $file ) {
    $file['name'] = 'wordpress-is-awesome-' . $file['name'];
    return $file;
}

Top ↑

Source

File: wp-admin/includes/file.php

View on Trac


Top ↑

Changelog

Changelog
VersionDescription
2.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.