media_upload_library()
云策文档标注
概述
media_upload_library() 函数用于在 iframe 中检索旧版媒体库表单,处理表单提交并返回结果或错误。
关键要点
- 函数返回类型为 string|null,可能返回字符串或 null 值。
- 如果 POST 请求非空,会调用 media_upload_form_handler() 处理表单,并根据返回类型处理结果或错误。
- 最终通过 wp_iframe() 输出 media_upload_library_form 表单,并传递错误数组。
代码示例
function media_upload_library() {
$errors = array();
if ( ! empty( $_POST ) ) {
$return = media_upload_form_handler();
if ( is_string( $return ) ) {
return $return;
}
if ( is_array( $return ) ) {
$errors = $return;
}
}
return wp_iframe( 'media_upload_library_form', $errors );
}注意事项
- 此函数自 WordPress 2.5.0 版本引入,属于旧版媒体上传系统的一部分。
- 相关函数包括 media_upload_form_handler() 和 wp_iframe(),分别用于处理表单提交和输出 iframe。
原文内容
Retrieves the legacy media library form in an iframe.
Source
function media_upload_library() {
$errors = array();
if ( ! empty( $_POST ) ) {
$return = media_upload_form_handler();
if ( is_string( $return ) ) {
return $return;
}
if ( is_array( $return ) ) {
$errors = $return;
}
}
return wp_iframe( 'media_upload_library_form', $errors );
}
Changelog
| Version | Description |
|---|---|
| 2.5.0 | Introduced. |