[wp-trac] [WordPress Trac] #55465: Fix hiding playlist buttons from Add Media modal dialog

WordPress Trac noreply at wordpress.org
Fri Mar 25 17:31:46 UTC 2022


#55465: Fix hiding playlist buttons from Add Media modal dialog
-------------------------------------+-----------------------------
 Reporter:  erengy                   |      Owner:  (none)
     Type:  defect (bug)             |     Status:  new
 Priority:  normal                   |  Milestone:  Awaiting Review
Component:  Media                    |    Version:  5.9.2
 Severity:  minor                    |   Keywords:
  Focuses:  ui, css, administration  |
-------------------------------------+-----------------------------
 ==== How to reproduce

 On a fresh installation of WordPress 5.9.2 with
 [[https://wordpress.org/plugins/classic-editor/|Classic Editor]] plugin
 enabled, add the following lines to the default theme's `functions.php`:

 {{{#!php
 <?php
 add_filter('media_library_show_audio_playlist', '__return_false');
 add_filter('media_library_show_video_playlist', '__return_false');
 }}}

 Then go to `/wp-admin/post-new.php` and click the Add Media button.

 These filters are supposed to allow hiding the
 [[https://developer.wordpress.org/reference/hooks/media_library_show_audio_playlist/|Create
 Audio Playlist]] and
 [[https://developer.wordpress.org/reference/hooks/media_library_show_video_playlist/|Create
 Video Playlist]] buttons, which is not the case. The buttons are still
 visible in the Add Media modal dialog.

 Workarounds include filtering `media_view_strings` instead, or enqueing
 additional styles to hide the buttons.

 The discussion at Ticket [ticket:43009] focuses on the behavior //after//
 uploading an audio/video file rather than the initial state, hence the new
 ticket.

 ==== Reason

 ✅ **PHP:**
 [[https://developer.wordpress.org/reference/functions/wp_enqueue_media/|wp_enqueue_media]]
 function sets `attachmentCounts` according to the filter results.

 ✅ **JavaScript:** `menuItemVisibility` function is called, which adds
 `hidden` class to the elements.

 ❌ **CSS:** In `media-views.css`, `.media-menu .media-menu-item` selector
 wins over `.media-frame .hidden`, setting the elements' `display` property
 to `block` instead of `none`.

 ==== Proposed fix

 Since there are similar rules of higher specificity (e.g. `.attachments-
 browser .uploader-inline.hidden`, `.media-embed .setting input.hidden`) in
 the same CSS file, I thought adding the following rule would be
 appropriate:

 {{{#!css
 .media-menu .media-menu-item.hidden {
         display: none;
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/55465>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list