{$action}_overrides
云策文档标注
概述
此文档介绍了一个动态过滤器钩子,用于在文件上传到 WordPress 前修改其覆盖参数。钩子名称基于 $action 动态生成,例如 wp_handle_sideload_overrides 或 wp_handle_upload_overrides。
关键要点
- 过滤器钩子名称为 {$action}_overrides,其中 $action 是动态部分,对应不同的上传操作。
- 参数包括 $overrides(覆盖参数数组或 false)和 $file($_FILES 数组中的单个文件元素)。
- 文件元素包含 name、type、tmp_name、size 和 error 等属性,用于描述上传文件的信息。
- 此钩子在 _wp_handle_upload() 函数中被调用,用于处理上传逻辑。
- 从 WordPress 5.7.0 版本开始引入。
代码示例
$overrides = apply_filters( "{$action}_overrides", $overrides, $file );
原文内容
Filters the override parameters for a file before it is uploaded to WordPress.
Description
The dynamic portion of the hook name, $action, refers to the post action.
Possible hook names include:
wp_handle_sideload_overrideswp_handle_upload_overrides
Parameters
$overridesarray|false-
An array of override parameters for this file. Boolean false if none are provided. See _wp_handle_upload().
$filearray-
Reference to a single element from
$_FILES.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.
Source
$overrides = apply_filters( "{$action}_overrides", $overrides, $file );
Changelog
| Version | Description |
|---|---|
| 5.7.0 | Introduced. |