0

I'm following the advice found in several places to remove tabs by using the following filter. However, the same number of tabs appear, the last one is simply displayed x number of times. I'm running Multisite, 4.0

The filter:

function remove_media_editor_tabs( $strings ) {
    $user_id = get_current_user_id();
    $user = get_userdata( $user_id );

    $user_has_role = array_intersect( $user->roles, array(
        'role_one', 
        'role_two' 
    ) );

    if ( $user_has_role ) {
        // remove "Create New Gallery"
        unset( $strings["createGalleryTitle"] );

        // remove "Set Featured Image"
        unset( $strings["setFeaturedImageTitle"] );

        // remove "Create Video Playlist"
        unset( $strings["createVideoPlaylistTitle"] );
    }

    return $strings;
}
add_filter('media_view_strings', 'remove_media_editor_tabs');

The screenshot:

Duplicate Media Tabs when attempting to remove tabs

2 Answers 2

1

Changing strings to null or to empty strings removes items from left menu of the uploader and corresponding tabs. Paste this code in functions.php:

function remove_media_tab( $strings ) {
    if( !current_user_can( 'administrator' ) ) {
         $strings["createGalleryTitle"] = "";
         $strings["setFeaturedImageTitle"] = "";
         $strings["insertFromUrlTitle"] = "";
         $strings['createPlaylistTitle'] = "";
         $strings['createVideoPlaylistTitle'] = "";
    }
    return $strings;
}
add_filter( 'media_view_strings', 'remove_media_tab' );

You can also get rid of "create audio playlist" and "create video playlist" buttons with filters:

add_filter( 'media_library_show_audio_playlist', function(){ 
    return false; 
}, 10, 1 );

add_filter( 'media_library_show_video_playlist', function(){ 
    return false; 
}, 10, 1 );

This would additionally save you from running default query that checks if there are any video/audio files in the media library.

2
  • Please format your code and add some explanation. Commented May 22, 2015 at 9:01
  • Unfortunately these filters don't seem to work any more, trying to find a way of removing these links myself and have tried the filters and also unsetting but nothing seems to work.
    – Adrian
    Commented May 17, 2022 at 15:54
0

This is the closest I've been able to get, but if anyone has any other ideas, that would be great. I don't have a firm grasp on the Backbone part of WP just yet, and have never used it, so I'm not sure extending entire objects is the way to override default functionality. Any feedback would be helpful.

/**
 * Replace the 'insert media into post' frame with 
 * one that hides featured image, gallery, and other states
 */
var originalPostMediaFrame = wp.media.view.MediaFrame.Post;

wp.media.view.MediaFrame.Post = originalPostMediaFrame.extend({

    activate: function() {
        originalPostMediaFrame.prototype.activate.apply(this,arguments);

        this.menuItemVisibility( 'featured-image', 'hide' );
        this.menuItemVisibility( 'video-playlist', 'hide' );
        this.menuItemVisibility( 'playlist', 'hide' );
        this.menuItemVisibility( 'gallery', 'hide' );
    }
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.