The media_library_show_audio_playlist WordPress PHP filter allows you to control the visibility of the “Create Audio Playlist” button in the media library.
Usage
add_filter( 'media_library_show_audio_playlist', 'your_custom_function' ); function your_custom_function( $show ) { // your custom code here return $show; }
Parameters
$show
(bool|null): Whether to show the button, or null to decide based on whether any audio files exist in the media library.
More information
See WordPress Developer Resources: media_library_show_audio_playlist
Examples
Always show the “Create Audio Playlist” button
function always_show_audio_playlist( $show ) { return true; } add_filter( 'media_library_show_audio_playlist', 'always_show_audio_playlist' );
Always hide the “Create Audio Playlist” button
function always_hide_audio_playlist( $show ) { return false; } add_filter( 'media_library_show_audio_playlist', 'always_hide_audio_playlist' );
Show the “Create Audio Playlist” button only for admins
function show_audio_playlist_for_admins( $show ) { return current_user_can( 'manage_options' ) ? true : false; } add_filter( 'media_library_show_audio_playlist', 'show_audio_playlist_for_admins' );
Show the “Create Audio Playlist” button only if there are more than 10 audio files
function show_audio_playlist_if_enough_files( $show ) { $audio_count = get_posts( array( 'post_type' => 'attachment', 'post_mime_type' => 'audio', 'numberposts' => -1 ) ); return count( $audio_count ) > 10 ? true : false; } add_filter( 'media_library_show_audio_playlist', 'show_audio_playlist_if_enough_files' );
Show the “Create Audio Playlist” button only for specific user roles
function show_audio_playlist_for_specific_roles( $show ) { $user = wp_get_current_user(); $allowed_roles = array( 'editor', 'author' ); return array_intersect( $allowed_roles, $user->roles ) ? true : false; } add_filter( 'media_library_show_audio_playlist', 'show_audio_playlist_for_specific_roles' );