media_library_months_with_files
云策文档标注
概述
media_library_months_with_files 是一个 WordPress 过滤器,允许开发者覆盖媒体库中显示的月份列表。默认情况下,WordPress 会运行查询来确定有媒体项的月份,但对于大型媒体库,此查询可能性能开销较大,因此该过滤器可用于优化此行为。
关键要点
- 这是一个过滤器,用于自定义媒体库中显示的月份列表。
- 默认行为会运行查询来获取月份,可能对大型媒体库造成性能问题。
- 参数 $months 可以是一个包含 month 和 year 属性的对象数组,或 null 以使用默认行为。
- 过滤器在 wp_enqueue_media() 函数中被使用,用于媒体相关脚本和样式的加载。
- 该过滤器自 WordPress 4.7.4 版本引入。
代码示例
$months = apply_filters( 'media_library_months_with_files', null );
原文内容
Allows overriding the list of months displayed in the media library.
Description
By default (if this filter does not return an array), a query will be run to determine the months that have media items. This query can be expensive for large media libraries, so it may be desirable for sites to override this behavior.
Parameters
$monthsstdClass[]|null-
An array of objects with
monthandyearproperties, ornullfor default behavior.
Source
$months = apply_filters( 'media_library_months_with_files', null );
Changelog
| Version | Description |
|---|---|
| 4.7.4 | Introduced. |