Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#55465 new defect (bug)

Fix hiding playlist buttons from Add Media modal dialog

Reported by: erengy's profile erengy Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version: 5.9.2
Component: Media Keywords: has-patch
Focuses: ui, css, administration Cc:

Description

How to reproduce

On a fresh installation of WordPress 5.9.2 with Classic Editor plugin enabled, add the following lines to the default theme's functions.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 Create Audio Playlist and 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 43009 focuses on the behavior after uploading an audio/video file rather than the initial state, hence the new ticket.

Reason

PHP: 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:

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

Change History (1)

This ticket was mentioned in PR #2461 on WordPress/wordpress-develop by erengy.


2 years ago
#1

  • Keywords has-patch added

### How to reproduce

On a fresh installation of WordPress 5.9.2 with Classic Editor plugin enabled, add the following lines to the default theme's functions.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 Create Audio Playlist and 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 43009 focuses on the behavior *after* uploading an audio/video file rather than the initial state, hence the new ticket.

### Reason

PHP: 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;

}
}}}

Trac ticket: https://core.trac.wordpress.org/ticket/55465

Note: See TracTickets for help on using tickets.