钩子文档

media_library_show_audio_playlist

💡 云策文档标注

概述

media_library_show_audio_playlist 是一个 WordPress 过滤器,用于控制媒体库中“创建音频播放列表”按钮的显示或隐藏。默认情况下按钮始终显示,但可通过过滤器调整行为,以避免在大型媒体库中执行昂贵的查询。

关键要点

  • 过滤器名称:media_library_show_audio_playlist
  • 参数:$show,布尔值或 null,决定是否显示按钮或基于音频文件存在性自动判断
  • 默认值:从 WordPress 4.8.0 起为 true,之前版本为 null
  • 用途:优化性能,避免在大型媒体库中运行不必要的查询

代码示例

$show_audio_playlist = apply_filters( 'media_library_show_audio_playlist', true );

注意事项

  • 返回 null 会触发查询以检查媒体库中是否有音频文件,这在大型媒体库中可能影响性能
  • 从版本 4.8.0 开始,默认值改为 true,以提升效率

📄 原文内容

Allows showing or hiding the “Create Audio Playlist” button in the media library.

Description

By default, the “Create Audio Playlist” button will always be shown in the media library. If this filter returns null, a query will be run to determine whether the media library contains any audio items. This was the default behavior prior to version 4.8.0, but this query is expensive for large media libraries.

Parameters

$showbool|null
Whether to show the button, or null to decide based on whether any audio files exist in the media library.

Source

$show_audio_playlist = apply_filters( 'media_library_show_audio_playlist', true );

Changelog

Version Description
4.8.0 The filter’s default value is true rather than null.
4.7.4 Introduced.