[wp-trac] [WordPress Trac] #43009: Create Video/Audio Playlist hooks not working as expected
WordPress Trac
noreply at wordpress.org
Wed Apr 11 18:39:26 UTC 2018
#43009: Create Video/Audio Playlist hooks not working as expected
--------------------------+------------------------------
Reporter: iforrest | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version: 4.9.1
Severity: normal | Resolution:
Keywords: needs-patch | Focuses: administration
--------------------------+------------------------------
Changes (by birgire):
* keywords: => needs-patch
* focuses: => administration
Comment:
@iforrest thanks for the ticket and welcome to Trac.
That sounds like a bug.
The
[attachment:with_media_library_show_audio_playlist_filter_set_to_zero.gif]
screen-cast shows the issue, given the filtering:
{{{
add_filter( 'media_library_show_audio_playlist', '__return_false' );
}}}
When a new audio file is uploaded, then the "Create Audio Playlist" link
shows up, regardless of the above filtering.
The reason for this comes within the {{{bindHandlers}}} function here:
https://core.trac.wordpress.org/browser/tags/4.9.5/src/wp-includes/js
/media-views.js#L3391
For example the audio/video playlist menu items are hidden/displayed via:
https://core.trac.wordpress.org/browser/tags/4.9.5/src/wp-includes/js
/media-views.js#L3452
{{{
activate: function() {
// Hide menu items for states tied to particular media
types if there are no items
_.each( this.counts, function( type ) {
if ( type.count < 1 ) {
this.menuItemVisibility( type.state,
'hide' );
}
}, this );
},
mediaTypeCounts: function( model, attr ) {
if ( typeof this.counts[ attr ] !== 'undefined' &&
this.counts[ attr ].count < 1 ) {
this.counts[ attr ].count++;
this.menuItemVisibility( this.counts[ attr
].state, 'show' );
}
},
}}}
where e.g. the count is updated via this event listener:
https://core.trac.wordpress.org/browser/tags/4.9.5/src/wp-includes/js
/media-views.js#L3403
{{{
if ( typeof checkCounts !== 'undefined' ) {
this.listenTo( wp.media.model.Attachments.all, 'change:type',
this.mediaTypeCounts );
}
}}}
The {{{attachmentCounts}}} settings comes from:
{{{
'attachmentCounts' => array(
'audio' => ( $show_audio_playlist ) ? 1 : 0,
'video' => ( $show_video_playlist ) ? 1 : 0,
),
}}}
https://core.trac.wordpress.org/browser/tags/4.9.5/src/wp-
includes/media.php#L3451
This shows that there are two state-values possible for {{{audio}}} and
{{{video}}} in {{{attachmentCounts}}}, but we have possible 3 state-values
from the filtering (e.g. audio):
{{{
$show_audio_playlist = apply_filters( 'media_library_show_audio_playlist',
true );
if ( null === $show_audio_playlist ) {
$show_audio_playlist = $wpdb->get_var(...);
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/43009#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list