_wp_handle_upload( array $file, array|false $overrides, string $time, string $action ): array
- Since
- 4.0.0
- Source
wp-admin/includes/file.php:802
Description
Sanitizes file names, checks extensions for mime type, and moves the file to the appropriate directory within the uploads directory.
Compatibility
- WordPress
- since 4.0.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$filearray- Reference to a single element from
$_FILES. Call the function once for each uploaded file.$namestringThe original name of the file on the client machine.$typestringThe mime type of the file, if the browser provided this information.$tmp_namestringThe temporary filename of the file in which the uploaded file was stored on the server.$sizeintThe size, in bytes, of the uploaded file.$errorintThe error code associated with this file upload.
$overridesarray|false- An array of override parameters for this file, or boolean false if none are provided.
$upload_error_handlercallableFunction to call when there is an error during the upload process. See wp_handle_upload_error().$unique_filename_callbackcallableFunction to call when determining a unique file name for the file. See wp_unique_filename().$upload_error_stringsstring[]The strings that describe the error indicated in$_FILES[{form field}]['error'].$test_formboolWhether to test that the$_POST['action']parameter is as expected.$test_sizeboolWhether to test that the file size is greater than zero bytes.$test_typeboolWhether to test that the mime type of the file is as expected.$mimesstring[]Array of allowed mime types keyed by their file extension regex.
$timestring- Time formatted in 'yyyy/mm'.
$actionstring- Expected value for
$_POST['action'].
Return value
array- On success, returns an associative array of file attributes. On failure, returns
$overrides['upload_error_handler']( &$file, $message )orarray( 'error' => $message ).$filestringFilename of the newly-uploaded file.$urlstringURL of the newly-uploaded file.$typestringMime type of the newly-uploaded file.
Performance profile
How much work a call to _wp_handle_upload() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Constant
- Instructions
- 121–228
- Plugin surface
- 4 hooks
- Called by
- 2
Reads or writes the filesystem via filesize().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 386.
Third-party callbacks on '{$action}_prefilter', '{$action}_overrides', 'pre_move_uploaded_file' run inside this call, and their cost is not bounded by anything here.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - filesystemfilesystem access
filesize()called directly - transienttransient
get_transient()one call below _wp_handle_upload()
Further down the call graph this can also reach option, cache, query and serialize. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 70 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost _wp_handle_upload() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
function_exists() && !isset($overrides) && !isset($file) | 121–124 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_upload_dir() |
function_exists() && !isset($overrides) && !isset($file) && $action !== "wp_handle_upload" | 123–128 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_upload_dir() |
function_exists() && !isset($overrides) && !isset($file) && $action !== "wp_handle_upload" && $test_file_size && is_multisite() | 125 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), is_multisite(), __() |
function_exists() && !isset($overrides) && !isset($file) && $action !== "wp_handle_upload" && $test_file_size && !is_multisite() | 130 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), is_multisite(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && !empty($wp_filetype) && !current_user_can() | 145–148 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_check_filetype_and_ext(), current_user_can(), __() |
function_exists() && !isset($overrides) && !isset($file) && !empty($wp_filetype) | 146–155 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_check_filetype_and_ext(), wp_upload_dir() |
function_exists() && !isset($overrides) && !isset($file) && $action !== "wp_handle_upload" && !current_user_can() | 147–155 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_check_filetype_and_ext(), current_user_can(), __() |
function_exists() && !isset($overrides) && !isset($file) && $action !== "wp_handle_upload" | 148–161 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_check_filetype_and_ext(), wp_upload_dir() |
function_exists() && !isset($overrides) && !isset($file) && !empty($wp_filetype) && current_user_can() | 149–158 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_check_filetype_and_ext(), current_user_can(), wp_upload_dir() |
function_exists() && !isset($overrides) && !isset($file) && $action !== "wp_handle_upload" && current_user_can() | 151–165 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_check_filetype_and_ext(), current_user_can(), wp_upload_dir() |
function_exists() && !isset($overrides) && !isset($file) && $move_new_file !== null && !is_multisite() | 168–169 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_upload_dir(), wp_unique_filename(), apply_filters(), stat(), chmod(), is_multisite(), file() |
function_exists() && !isset($overrides) && !isset($file) && $action !== "wp_handle_upload" && $move_new_file !== null && !is_multisite() | 170–173 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_upload_dir(), wp_unique_filename(), apply_filters(), stat(), chmod(), is_multisite(), file() |
58 further outcomes, up to 228 instructions
function_exists() && !isset($overrides) && !isset($file) && $move_new_file !== null && is_multisite() | 171–172 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_upload_dir(), wp_unique_filename(), apply_filters(), stat(), chmod(), is_multisite(), clean_dirsize_cache(), file() |
function_exists() && !isset($overrides) && !isset($file) && $move_new_file === null && $move_new_file === false | 173 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_upload_dir(), wp_unique_filename(), apply_filters(), move_uploaded_file(), basename(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && $action !== "wp_handle_upload" && $move_new_file !== null && is_multisite() | 173–176 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_upload_dir(), wp_unique_filename(), apply_filters(), stat(), chmod(), is_multisite(), clean_dirsize_cache(), file() |
function_exists() && !isset($overrides) && !isset($file) && $move_new_file === null && $move_new_file === false | 174 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_upload_dir(), wp_unique_filename(), apply_filters(), move_uploaded_file(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && $move_new_file === null && $move_new_file === false | 175–177 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_upload_dir(), wp_unique_filename(), apply_filters(), move_uploaded_file(), basename(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && $move_new_file === null && $move_new_file === false | 176–178 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_upload_dir(), wp_unique_filename(), apply_filters(), move_uploaded_file(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && $move_new_file === null && $move_new_file === false | 176 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_upload_dir(), wp_unique_filename(), apply_filters(), copy(), unlink(), basename(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && $move_new_file === null && $move_new_file === false | 177 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_upload_dir(), wp_unique_filename(), apply_filters(), copy(), unlink(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && $action !== "wp_handle_upload" && $move_new_file === null && $move_new_file === false | 178–180 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_upload_dir(), wp_unique_filename(), apply_filters(), copy(), unlink(), basename(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && $action !== "wp_handle_upload" && $move_new_file === null && $move_new_file === false | 179–181 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_upload_dir(), wp_unique_filename(), apply_filters(), copy(), unlink(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && $move_new_file === null && $move_new_file !== false && !is_multisite() | 180–181 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_upload_dir(), wp_unique_filename(), apply_filters(), move_uploaded_file(), stat(), chmod(), is_multisite(), file() |
function_exists() && !isset($overrides) && !isset($file) && $move_new_file === null && $move_new_file !== false && !is_multisite() | 182–185 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_upload_dir(), wp_unique_filename(), apply_filters(), move_uploaded_file(), stat(), chmod(), is_multisite(), file() |
function_exists() && !isset($overrides) && !isset($file) && $move_new_file === null && $move_new_file !== false && !is_multisite() | 183–184 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_upload_dir(), wp_unique_filename(), apply_filters(), copy(), unlink(), stat(), chmod(), is_multisite(), file() |
function_exists() && !isset($overrides) && !isset($file) && $move_new_file === null && $move_new_file !== false && is_multisite() | 183–184 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_upload_dir(), wp_unique_filename(), apply_filters(), move_uploaded_file(), stat(), chmod(), is_multisite(), clean_dirsize_cache(), file() |
function_exists() && !isset($overrides) && !isset($file) && $action !== "wp_handle_upload" && $move_new_file === null && $move_new_file !== false && !is_multisite() | 185–188 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_upload_dir(), wp_unique_filename(), apply_filters(), copy(), unlink(), stat(), chmod(), is_multisite(), file() |
function_exists() && !isset($overrides) && !isset($file) && $move_new_file === null && $move_new_file !== false && is_multisite() | 185–188 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_upload_dir(), wp_unique_filename(), apply_filters(), move_uploaded_file(), stat(), chmod(), is_multisite(), clean_dirsize_cache(), file() |
function_exists() && !isset($overrides) && !isset($file) && $move_new_file === null && $move_new_file !== false && is_multisite() | 186–187 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_upload_dir(), wp_unique_filename(), apply_filters(), copy(), unlink(), stat(), chmod(), is_multisite(), clean_dirsize_cache(), file() |
function_exists() && !isset($overrides) && !isset($file) && $action !== "wp_handle_upload" && $move_new_file === null && $move_new_file !== false && is_multisite() | 188–191 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_upload_dir(), wp_unique_filename(), apply_filters(), copy(), unlink(), stat(), chmod(), is_multisite(), clean_dirsize_cache(), file() |
function_exists() && !isset($overrides) && !isset($file) && !empty($wp_filetype) && $move_new_file !== null && !is_multisite() | 193–200 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_check_filetype_and_ext(), wp_upload_dir(), wp_unique_filename(), apply_filters(), stat(), chmod(), is_multisite(), file() |
function_exists() && !isset($overrides) && !isset($file) && $action !== "wp_handle_upload" && $move_new_file !== null && !is_multisite() | 195–206 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_check_filetype_and_ext(), wp_upload_dir(), wp_unique_filename(), apply_filters(), stat(), chmod(), is_multisite(), file() |
function_exists() && !isset($overrides) && !isset($file) && !empty($wp_filetype) && current_user_can() && $move_new_file !== null && !is_multisite() | 196–204 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_check_filetype_and_ext(), current_user_can(), wp_upload_dir(), wp_unique_filename(), apply_filters(), stat(), chmod(), is_multisite(), file() |
function_exists() && !isset($overrides) && !isset($file) && !empty($wp_filetype) && $move_new_file !== null && is_multisite() | 196–203 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_check_filetype_and_ext(), wp_upload_dir(), wp_unique_filename(), apply_filters(), stat(), chmod(), is_multisite(), clean_dirsize_cache(), file() |
function_exists() && !isset($overrides) && !isset($file) && !empty($wp_filetype) && $move_new_file === null && $move_new_file === false | 198–204 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_check_filetype_and_ext(), wp_upload_dir(), wp_unique_filename(), apply_filters(), move_uploaded_file(), basename(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && $action !== "wp_handle_upload" && current_user_can() && $move_new_file !== null && !is_multisite() | 198–210 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_check_filetype_and_ext(), current_user_can(), wp_upload_dir(), wp_unique_filename(), apply_filters(), stat(), chmod(), is_multisite(), file() |
function_exists() && !isset($overrides) && !isset($file) && $action !== "wp_handle_upload" && $move_new_file !== null && is_multisite() | 198–209 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_check_filetype_and_ext(), wp_upload_dir(), wp_unique_filename(), apply_filters(), stat(), chmod(), is_multisite(), clean_dirsize_cache(), file() |
function_exists() && !isset($overrides) && !isset($file) && !empty($wp_filetype) && $move_new_file === null && $move_new_file === false | 199–205 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_check_filetype_and_ext(), wp_upload_dir(), wp_unique_filename(), apply_filters(), move_uploaded_file(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && !empty($wp_filetype) && current_user_can() && $move_new_file !== null && is_multisite() | 199–206 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_check_filetype_and_ext(), current_user_can(), wp_upload_dir(), wp_unique_filename(), apply_filters(), stat(), chmod(), is_multisite(), clean_dirsize_cache(), file() |
function_exists() && !isset($overrides) && !isset($file) && $move_new_file === null && $move_new_file === false | 200–210 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_check_filetype_and_ext(), wp_upload_dir(), wp_unique_filename(), apply_filters(), move_uploaded_file(), basename(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && $move_new_file === null && $move_new_file === false | 201–211 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_check_filetype_and_ext(), wp_upload_dir(), wp_unique_filename(), apply_filters(), move_uploaded_file(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && !empty($wp_filetype) && current_user_can() && $move_new_file === null && $move_new_file === false | 201–207 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_check_filetype_and_ext(), current_user_can(), wp_upload_dir(), wp_unique_filename(), apply_filters(), move_uploaded_file(), basename(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && !empty($wp_filetype) && $move_new_file === null && $move_new_file === false | 201–207 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_check_filetype_and_ext(), wp_upload_dir(), wp_unique_filename(), apply_filters(), copy(), unlink(), basename(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && $action !== "wp_handle_upload" && current_user_can() && $move_new_file !== null && is_multisite() | 201–213 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_check_filetype_and_ext(), current_user_can(), wp_upload_dir(), wp_unique_filename(), apply_filters(), stat(), chmod(), is_multisite(), clean_dirsize_cache(), file() |
function_exists() && !isset($overrides) && !isset($file) && !empty($wp_filetype) && current_user_can() && $move_new_file === null && $move_new_file === false | 202–208 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_check_filetype_and_ext(), current_user_can(), wp_upload_dir(), wp_unique_filename(), apply_filters(), move_uploaded_file(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && !empty($wp_filetype) && $move_new_file === null && $move_new_file === false | 202–208 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_check_filetype_and_ext(), wp_upload_dir(), wp_unique_filename(), apply_filters(), copy(), unlink(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && current_user_can() && $move_new_file === null && $move_new_file === false | 203–214 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_check_filetype_and_ext(), current_user_can(), wp_upload_dir(), wp_unique_filename(), apply_filters(), move_uploaded_file(), basename(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && $action !== "wp_handle_upload" && $move_new_file === null && $move_new_file === false | 203–213 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_check_filetype_and_ext(), wp_upload_dir(), wp_unique_filename(), apply_filters(), copy(), unlink(), basename(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && current_user_can() && $move_new_file === null && $move_new_file === false | 204–215 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_check_filetype_and_ext(), current_user_can(), wp_upload_dir(), wp_unique_filename(), apply_filters(), move_uploaded_file(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && $action !== "wp_handle_upload" && $move_new_file === null && $move_new_file === false | 204–214 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_check_filetype_and_ext(), wp_upload_dir(), wp_unique_filename(), apply_filters(), copy(), unlink(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && !empty($wp_filetype) && current_user_can() && $move_new_file === null && $move_new_file === false | 204–210 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_check_filetype_and_ext(), current_user_can(), wp_upload_dir(), wp_unique_filename(), apply_filters(), copy(), unlink(), basename(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && !empty($wp_filetype) && current_user_can() && $move_new_file === null && $move_new_file === false | 205–211 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_check_filetype_and_ext(), current_user_can(), wp_upload_dir(), wp_unique_filename(), apply_filters(), copy(), unlink(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && !empty($wp_filetype) && $move_new_file === null && $move_new_file !== false && !is_multisite() | 205–212 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_check_filetype_and_ext(), wp_upload_dir(), wp_unique_filename(), apply_filters(), move_uploaded_file(), stat(), chmod(), is_multisite(), file() |
function_exists() && !isset($overrides) && !isset($file) && $action !== "wp_handle_upload" && current_user_can() && $move_new_file === null && $move_new_file === false | 206–217 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_check_filetype_and_ext(), current_user_can(), wp_upload_dir(), wp_unique_filename(), apply_filters(), copy(), unlink(), basename(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && $action !== "wp_handle_upload" && current_user_can() && $move_new_file === null && $move_new_file === false | 207–218 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_check_filetype_and_ext(), current_user_can(), wp_upload_dir(), wp_unique_filename(), apply_filters(), copy(), unlink(), __(), sprintf() |
function_exists() && !isset($overrides) && !isset($file) && $move_new_file === null && $move_new_file !== false && !is_multisite() | 207–218 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_check_filetype_and_ext(), wp_upload_dir(), wp_unique_filename(), apply_filters(), move_uploaded_file(), stat(), chmod(), is_multisite(), file() |
function_exists() && !isset($overrides) && !isset($file) && !empty($wp_filetype) && current_user_can() && $move_new_file === null && $move_new_file !== false && !is_multisite() | 208–215 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_check_filetype_and_ext(), current_user_can(), wp_upload_dir(), wp_unique_filename(), apply_filters(), move_uploaded_file(), stat(), chmod(), is_multisite(), file() |
function_exists() && !isset($overrides) && !isset($file) && !empty($wp_filetype) && $move_new_file === null && $move_new_file !== false && !is_multisite() | 208–215 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_check_filetype_and_ext(), wp_upload_dir(), wp_unique_filename(), apply_filters(), copy(), unlink(), stat(), chmod(), is_multisite(), file() |
function_exists() && !isset($overrides) && !isset($file) && !empty($wp_filetype) && $move_new_file === null && $move_new_file !== false && is_multisite() | 208–215 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_check_filetype_and_ext(), wp_upload_dir(), wp_unique_filename(), apply_filters(), move_uploaded_file(), stat(), chmod(), is_multisite(), clean_dirsize_cache(), file() |
function_exists() && !isset($overrides) && !isset($file) && current_user_can() && $move_new_file === null && $move_new_file !== false && !is_multisite() | 210–222 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_check_filetype_and_ext(), current_user_can(), wp_upload_dir(), wp_unique_filename(), apply_filters(), move_uploaded_file(), stat(), chmod(), is_multisite(), file() |
function_exists() && !isset($overrides) && !isset($file) && $action !== "wp_handle_upload" && $move_new_file === null && $move_new_file !== false && !is_multisite() | 210–221 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_check_filetype_and_ext(), wp_upload_dir(), wp_unique_filename(), apply_filters(), copy(), unlink(), stat(), chmod(), is_multisite(), file() |
function_exists() && !isset($overrides) && !isset($file) && $move_new_file === null && $move_new_file !== false && is_multisite() | 210–221 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_check_filetype_and_ext(), wp_upload_dir(), wp_unique_filename(), apply_filters(), move_uploaded_file(), stat(), chmod(), is_multisite(), clean_dirsize_cache(), file() |
function_exists() && !isset($overrides) && !isset($file) && !empty($wp_filetype) && current_user_can() && $move_new_file === null && $move_new_file !== false && !is_multisite() | 211–218 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_check_filetype_and_ext(), current_user_can(), wp_upload_dir(), wp_unique_filename(), apply_filters(), copy(), unlink(), stat(), chmod(), is_multisite(), file() |
function_exists() && !isset($overrides) && !isset($file) && !empty($wp_filetype) && current_user_can() && $move_new_file === null && $move_new_file !== false && is_multisite() | 211–218 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_check_filetype_and_ext(), current_user_can(), wp_upload_dir(), wp_unique_filename(), apply_filters(), move_uploaded_file(), stat(), chmod(), is_multisite(), clean_dirsize_cache(), file() |
function_exists() && !isset($overrides) && !isset($file) && !empty($wp_filetype) && $move_new_file === null && $move_new_file !== false && is_multisite() | 211–218 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_check_filetype_and_ext(), wp_upload_dir(), wp_unique_filename(), apply_filters(), copy(), unlink(), stat(), chmod(), is_multisite(), clean_dirsize_cache(), file() |
function_exists() && !isset($overrides) && !isset($file) && $action !== "wp_handle_upload" && current_user_can() && $move_new_file === null && $move_new_file !== false && !is_multisite() | 213–225 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_check_filetype_and_ext(), current_user_can(), wp_upload_dir(), wp_unique_filename(), apply_filters(), copy(), unlink(), stat(), chmod(), is_multisite(), file() |
function_exists() && !isset($overrides) && !isset($file) && current_user_can() && $move_new_file === null && $move_new_file !== false && is_multisite() | 213–225 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_check_filetype_and_ext(), current_user_can(), wp_upload_dir(), wp_unique_filename(), apply_filters(), move_uploaded_file(), stat(), chmod(), is_multisite(), clean_dirsize_cache(), file() |
function_exists() && !isset($overrides) && !isset($file) && $action !== "wp_handle_upload" && $move_new_file === null && $move_new_file !== false && is_multisite() | 213–224 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_check_filetype_and_ext(), wp_upload_dir(), wp_unique_filename(), apply_filters(), copy(), unlink(), stat(), chmod(), is_multisite(), clean_dirsize_cache(), file() |
function_exists() && !isset($overrides) && !isset($file) && !empty($wp_filetype) && current_user_can() && $move_new_file === null && $move_new_file !== false && is_multisite() | 214–221 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), wp_check_filetype_and_ext(), current_user_can(), wp_upload_dir(), wp_unique_filename(), apply_filters(), copy(), unlink(), stat(), chmod(), is_multisite(), clean_dirsize_cache(), file() |
function_exists() && !isset($overrides) && !isset($file) && $action !== "wp_handle_upload" && current_user_can() && $move_new_file === null && $move_new_file !== false && is_multisite() | 216–228 | function_exists(), apply_filters(), apply_filters(), __(), sprintf(), __(), sprintf(), __(), __(), __(), __(), __(), is_readable(), filesize(), wp_check_filetype_and_ext(), current_user_can(), wp_upload_dir(), wp_unique_filename(), apply_filters(), copy(), unlink(), stat(), chmod(), is_multisite(), clean_dirsize_cache(), file() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 386 | 121–228 | 39 | |
| 8.5 | 386 | 121–228 | 39 | |
| 8.4 | 386 | 121–228 | 39 | 10 fewer instructions than PHP 8.3 |
| 8.3 | 396 | 121–230 | 39 | |
| 8.2 | 396 | 121–230 | 39 | |
| 8.1 | 396 | 121–230 | 39 | 5 fewer instructions than PHP 7.4 |
| 7.4 | 401 | 124–230 | 39 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 4
4 hooks fire while _wp_handle_upload() runs, in this order:
- apply_filters( {$action}_prefilter )filterline 833 (+31 into the body)
Filters the data for a file before it is uploaded to WordPress.
- apply_filters( {$action}_overrides )filterline 859 (+57 into the body)
Filters the override parameters for a file before it is uploaded to WordPress.
- apply_filters( pre_move_uploaded_file )filterline 1010 (+208 into the body)
Filters whether to short-circuit moving the uploaded file after passing all checks.
- apply_filters( wp_handle_upload )filterline 1066 (+264 into the body)
Filters the data array for the uploaded file.
Uses · 9
- apply_filters()Calls the callback functions that have been added to a filter hook.
- __()Retrieves the translation of $text.
- is_multisite()Determines whether Multisite is enabled.
- wp_check_filetype_and_ext()Attempts to determine the real file type of a file.
- current_user_can()Returns whether the current user has the specified capability.
- wp_upload_dir()Returns an array containing the current upload directory's path and URL.
- wp_unique_filename()Gets a filename that is sanitized and unique for the given directory.
- str_starts_with()Polyfill for `str_starts_with()` function added in PHP 8.0.
- clean_dirsize_cache()Cleans directory size cache used by recurse_dirsize().
Used by · 2
- wp_handle_sideload()Wrapper for _wp_handle_upload().
- wp_handle_upload()Wrapper for _wp_handle_upload().
Source code
function _wp_handle_upload( &$file, $overrides, $time, $action ) { // The default error handler. if ( ! function_exists( 'wp_handle_upload_error' ) ) { function wp_handle_upload_error( &$file, $message ) { return array( 'error' => $message ); } } /** * Filters the data for a file before it is uploaded to WordPress. * * The dynamic portion of the hook name, `$action`, refers to the post action. * * Possible hook names include: * * - `wp_handle_sideload_prefilter` * - `wp_handle_upload_prefilter` * * @since 2.9.0 as 'wp_handle_upload_prefilter'. * @since 4.0.0 Converted to a dynamic hook with `$action`. * * @param array $file { * Reference to a single element from `$_FILES`. * * @type string $name The original name of the file on the client machine. * @type string $type The mime type of the file, if the browser provided this information. * @type string $tmp_name The temporary filename of the file in which the uploaded file was stored on the server. * @type int $size The size, in bytes, of the uploaded file. * @type int $error The error code associated with this file upload. * } */ $file = apply_filters( "{$action}_prefilter", $file ); /** * Filters the override parameters for a file before it is uploaded to WordPress. * * The dynamic portion of the hook name, `$action`, refers to the post action. * * Possible hook names include: * * - `wp_handle_sideload_overrides` * - `wp_handle_upload_overrides` * * @since 5.7.0 * * @param array|false $overrides An array of override parameters for this file. Boolean false if none are * provided. See {@see _wp_handle_upload()}. * @param array $file { * Reference to a single element from `$_FILES`. * * @type string $name The original name of the file on the client machine. * @type string $type The mime type of the file, if the browser provided this information. * @type string $tmp_name The temporary filename of the file in which the uploaded file was stored on the server. * @type int $size The size, in bytes, of the uploaded file. * @type int $error The error code associated with this file upload. * } */ $overrides = apply_filters( "{$action}_overrides", $overrides, $file ); // You may define your own function and pass the name in $overrides['upload_error_handler']. $upload_error_handler = 'wp_handle_upload_error'; if ( isset( $overrides['upload_error_handler'] ) ) { $upload_error_handler = $overrides['upload_error_handler']; } // You may have had one or more 'wp_handle_upload_prefilter' functions error out the file. Handle that gracefully. if ( isset( $file['error'] ) && ! is_numeric( $file['error'] ) && $file['error'] ) { return call_user_func_array( $upload_error_handler, array( &$file, $file['error'] ) ); } // Install user overrides. Did we mention that this voids your warranty? // You may define your own function and pass the name in $overrides['unique_filename_callback']. $unique_filename_callback = null; if ( isset( $overrides['unique_filename_callback'] ) ) { $unique_filename_callback = $overrides['unique_filename_callback']; } /* * This may not have originally been intended to be overridable,Changelog
Introduced in 4.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-admin/includes/file.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.