wp_handle_upload
云策文档标注
概述
wp_handle_upload 是一个 WordPress 过滤器,用于修改上传文件的数据数组,包括文件路径、URL 和 MIME 类型。
关键要点
- 过滤器名称:wp_handle_upload
- 参数:$uploadarray(上传数据数组)、$context(上传操作类型,如 'upload' 或 'sideload')
- 返回数组包含 'file'、'url' 和 'type' 键
- 相关函数:_wp_handle_upload() 和 wp_upload_bits()
- 引入版本:2.1.0
代码示例
return apply_filters(
'wp_handle_upload',
array(
'file' => $new_file,
'url' => $url,
'type' => $type,
),
'wp_handle_sideload' === $action ? 'sideload' : 'upload'
);
原文内容
Filters the data array for the uploaded file.
Parameters
$uploadarray-
Array of upload data.
filestringFilename of the newly-uploaded file.urlstringURL of the newly-uploaded file.typestringMime type of the newly-uploaded file.
$contextstring-
The type of upload action. Values include
'upload'or'sideload'.
Source
return apply_filters(
'wp_handle_upload',
array(
'file' => $new_file,
'url' => $url,
'type' => $type,
),
'wp_handle_sideload' === $action ? 'sideload' : 'upload'
);
Changelog
| Version | Description |
|---|---|
| 2.1.0 | Introduced. |