wp_handle_upload_prefilter filter-hookWP 2.9.0

Filters the data for a file before it is uploaded to WordPress.

This is one of the variants of the dynamic hook (action)_prefilter

Usage

add_filter( 'wp_handle_upload_prefilter', 'wp_kama_handle_upload_prefilter' );

/**
 * Function for `wp_handle_upload_prefilter` filter-hook.
 * 
 * @param array $file Reference to a single element from `$_FILES`.
 *
 * @return array
 */
function wp_kama_handle_upload_prefilter( $file ){

	// filter...
	return $file;
}
$file(array)

Reference to a single element from $_FILES.

  • name(string)
    The original name of the file on the client machine.

  • type(string)
    The mime type of the file, if the browser provided this information.

  • tmp_name(string)
    The temporary filename of the file in which the uploaded file was stored on the server.

  • size(int)
    The size, in bytes, of the uploaded file.

  • error(int)
    The error code associated with this file upload.

Changelog

Since 2.9.0 Introduced.
Since 2.9.0 as wp_handle_upload_prefilter.
Since 4.0.0 Converted to a dynamic hook with $action.

Where the hook is called

_wp_handle_upload()
wp_handle_upload_prefilter
wp-admin/includes/file.php 833
$file = apply_filters( "{$action}_prefilter", $file );

Where the hook is used in WordPress

wp-admin/includes/ms-admin-filters.php 11
add_filter( 'wp_handle_upload_prefilter', 'check_upload_size' );