media_upload_tabs()
云策文档标注
概述
media_upload_tabs() 函数定义了旧版(3.5.0 之前)媒体上传弹窗的默认标签页,返回一个数组,包含标签页的处理器后缀和文本。该函数通过 apply_filters 钩子允许开发者过滤这些标签页。
关键要点
- 函数返回一个数组,键为处理器后缀(如 'type'、'type_url'),值为翻译后的标签文本(如 'From Computer'、'From URL')。
- 使用 apply_filters('media_upload_tabs', $_default_tabs) 钩子,允许通过过滤器修改标签页数组。
- 此函数适用于 WordPress 2.5.0 及以上版本,但注意它是旧版媒体上传界面的一部分,新版(3.5.0 后)推荐使用 media_view_settings 钩子。
代码示例
add_filter('media_view_settings', 'addTab');
function addTab($settings) {
$settings['tabs'] = array('photogrid' => 'Photogrid');
return $settings;
}注意事项
- media_upload_tabs() 主要用于旧版媒体上传界面,现代开发中应考虑使用 media_view_settings 钩子进行扩展。
- 函数内部使用 __() 进行文本翻译,确保国际化支持。
原文内容
Defines the default media upload tabs.
Source
function media_upload_tabs() {
$_default_tabs = array(
'type' => __( 'From Computer' ), // Handler action suffix => tab text.
'type_url' => __( 'From URL' ),
'gallery' => __( 'Gallery' ),
'library' => __( 'Media Library' ),
);
/**
* Filters the available tabs in the legacy (pre-3.5.0) media popup.
*
* @since 2.5.0
*
* @param string[] $_default_tabs An array of media tabs.
*/
return apply_filters( 'media_upload_tabs', $_default_tabs );
}
Hooks
- apply_filters( ‘media_upload_tabs’, string[] $_default_tabs )
-
Filters the available tabs in the legacy (pre-3.5.0) media popup.
Changelog
| Version | Description |
|---|---|
| 2.5.0 | Introduced. |
Skip to note 2 content
publicJorn
This is a 2.5.0 filter. You can also use a newer filter (3.5.0) to achieve the same:
https://developer.wordpress.org/reference/hooks/media_view_settings/
So for example use:
add_filter('media_view_settings', 'addTab'); function addTab($settings) { $settings['tabs'] = array('photogrid' => 'Photogrid'); return $settings; }