要从计算机中删除选项卡标题,请取消设置the type
key from that array. 但是,这不会(令人困惑地)删除选项卡内容,而且因为这是默认选项卡,即使其选项卡标题不存在,也会显示它。
要更改默认选项卡,必须挂接到the media_upload_default_tab
filter. 这在多个地方被调用,我没有研究在什么情况下调用哪一个,所以我将附件检查移到了一个单独的函数,并像这样重写代码:
add_filter(\'media_upload_tabs\',\'wpse13567_media_upload_tabs\', 99);
function wpse13567_media_upload_tabs( $tabs ) {
if ( wpse13567_post_has_attachments() ) {
unset( $tabs[\'type\'] );
}
unset( $tabs[\'type_url\'] );
unset( $tabs[\'library\'] );
return $tabs;
}
add_filter( \'media_upload_default_tab\', \'wpse13567_media_upload_default_tab\' );
function wpse13567_media_upload_default_tab( $tab )
{
if ( wpse13567_post_has_attachments() ) {
return \'gallery\';
}
return $tab;
}
function wpse13567_post_has_attachments()
{
static $post_has_attachments = null;
if ( null === $post_has_attachments && $post_id = (isset($_REQUEST[\'post_id\']) ? $_REQUEST[\'post_id\'] : false) ) {
$post_has_attachments = count(get_posts("post_type=attachment&post_parent={$post_id}"))>0;
}
return $post_has_attachments;
}