删除新WordPress媒体集中的其他选项卡

时间:2013-02-11 作者:rjx44

我最近将我的WordPress网站更新为WordPress的最新版本,并在functions.php 这将增加订阅者使用WordPress media upload上传的功能。我成功地删除了WordPress更高版本上的媒体库选项卡,但当我更新版本时,代码似乎不再有效。有没有办法解决这个问题?

这是我之前在google上搜索过的代码:

function remove_medialibrary_tab($tabs){
  if ( !current_user_can( \'administrator\' ) || !current_user_can( \'editor\' ) || !current_user_can( \'contibutor\' ) || !current_user_can( \'author\' ) ) {
    unset($tabs[\'library\']);
    return $tabs;
  } else {
    return $tabs;
  }
}
add_filter(\'media_upload_tabs\',\'remove_medialibrary_tab\');

if ( !current_user_can(\'upload_files\') ){
    add_action(\'init\', \'allow_user_to_upload\');
}

function allow_user_to_upload() {
    $subscriber = get_role(\'subscriber\');
    $subscriber->add_cap(\'upload_files\');
}

1 个回复
最合适的回答,由SO网友:birgire 整理而成

如果要隐藏媒体库子菜单:

Media Library submenu

您可以通过admin_menu 措施:

function wpse85351_hide_submenus() {
      if(!current_user_can(\'edit_posts\')){
           global $submenu;
           unset($submenu[\'upload.php\'][5]); // hide the Media Library
      }
}
add_action(\'admin_menu\', \'wpse85351_hide_submenus\');
如果要更改/删除媒体字符串:

Media strings

您可以使用media_view_strings 过滤器:

function wpse85351_media_strings($strings) {
    // only for subscribers:
    if(!current_user_can(\'edit_posts\')){
        // remove "mediaLibraryTitle"
        unset($strings["mediaLibraryTitle"]);
    }
    return $strings;
}
add_filter(\'media_view_strings\',\'wpse85351_media_strings\');
您可以使用

!current_user_can(\'edit_posts\')
而不是

!current_user_can( \'administrator\' ) || !current_user_can( \'editor\' ) || !current_user_can( \'contibutor\' ) || !current_user_can( \'author\' )
仅限于“订阅者”。

以下是所有媒体视图字符串的数组,您可以根据需要取消设置或更改这些字符串:

Array
(
    [url] => URL
    [addMedia] => Add Media
    [search] => Search
    [select] => Select
    [cancel] => Cancel
    [selected] => %d selected
    [dragInfo] => Drag and drop to reorder images.
    [uploadFilesTitle] => Upload Files
    [uploadImagesTitle] => Upload Images
    [mediaLibraryTitle] => Media Library
    [insertMediaTitle] => Insert Media
    [createNewGallery] => Create a new gallery
    [returnToLibrary] => ← Return to library
    [allMediaItems] => All media items
    [noItemsFound] => No items found.
    [insertIntoPost] => Insert into post
    [uploadedToThisPost] => Uploaded to this post
    [warnDelete] => You are about to permanently delete this item.
  \'Cancel\' to stop, \'OK\' to delete.
    [insertFromUrlTitle] => Insert from URL
    [setFeaturedImageTitle] => Set Featured Image
    [setFeaturedImage] => Set featured image
    [createGalleryTitle] => Create Gallery
    [editGalleryTitle] => Edit Gallery
    [cancelGalleryTitle] => ← Cancel Gallery
    [insertGallery] => Insert gallery
    [updateGallery] => Update gallery
    [addToGallery] => Add to gallery
    [addToGalleryTitle] => Add to Gallery
    [reverseOrder] => Reverse order
)

结束

相关推荐

Apply_Filters()和_Excerpt提供了意外的结果

我觉得我一定错过了一些显而易见的东西,但我似乎无法让WordPress合作。我正在用一个函数生成Facebook OG标签。除了摘录,一切都很好。自get_the_excerpt($post->ID), 有没有其他方法可以创建摘录而不必创建一个全新的循环?我觉得这太过分了。我的第一反应是apply_filters():$description = apply_filters(\'the_excerpt\', get_post($post->ID)->post_content);