Support » Developing with WordPress » Unset media view strings

  • Hi
    I am trying to remove the “create gallery”, “create audio playlist” and “creat video playlist” links from within the media library.
    I have added the following in to functions.php:

    function remove_media_library_links( $strings, $post ) {
    	return $strings;
    add_filter( 'media_view_strings', 'remove_media_library_links', 10, 2 );

    But only the “insertFromUrlTitle” one worked, the other 3 didn’t, although I have confirmed that the string is correct from the array.
    Any ideas?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The media_view_strings filter hook is for the text strings. I think there are other hooks you need to target.

    I believe the following should disable the audio and video playlists (I’m not sure about galleries yet):

    add_action( 'init', function() {
    	if ( ! current_user_can( 'manage_options' ) ) {
    		add_filter( 'media_library_show_audio_playlist', '__return_false' );
    		add_filter( 'media_library_show_video_playlist', '__return_false' );
    } );

    I’m just poking around the filter hooks in this function:

    Thread Starter adejones


    Thanks Justin, unfortunately those didn’t seem to work 🙁

    Moderator bcworkz


    Curiously, the filters do what they are supposed to do, set media counts to zero. At some time in the past I think a zero count would suppress the associated playlist links. But since one may want to upload new media into a playlist, that behavior doesn’t make sense. I speculate the behavior was subsequently modified, which in turn made the filter’s purpose fail to work as intended.

    I don’t have a solution, I just wanted to report what little more I found out. I think we need to find the code that actually outputs the links in order to find a way to suppress the links.

    I’ve another idea though. Could you simply hide the links with CSS? You could conditionally output some inline CSS from the “admin_print_styles” action. Hook with a very large priority arg so the styles are output after all others. If a user happened to know the proper URL, they could still create a playlist, but the lack of a link will deter nearly everyone.

    Thread Starter adejones


    Thanks, so would this be something like:

    function remove_media_links(){ ?>
    .media-frame-menu {display: none;}
    <?php }
    Moderator bcworkz


    Yeah, that’s the idea. Did you really want to hide all links? If so, you may want to hide the “Actions” title as well. Looks weird in an otherwise empty side panel 🙂

    Wouldn’t you still want to manage style output with a ! current_user_can( 'manage_options' ) conditional so mods can still easily access the links?

    I’d add a , 9999 parameter to the add_action() call to help ensure the style is output after all others.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.