@@ -4866,7 +4866,25 @@ function wp_enqueue_media( $args = array() ) {
48664866 );
48674867 }
48684868
4869- $ months = wp_get_media_library_attachment_months ();
4869+ /**
4870+ * Allows overriding the list of months displayed in the media library.
4871+ *
4872+ * By default (if this filter does not return an array), a query will be
4873+ * run to determine the months that have media items. This query can be
4874+ * expensive for large media libraries, so it may be desirable for sites to
4875+ * override this behavior.
4876+ *
4877+ * @since 4.7.4
4878+ *
4879+ * @link https://core.trac.wordpress.org/ticket/31071
4880+ *
4881+ * @param stdClass[]|null $months An array of objects with `month` and `year`
4882+ * properties, or `null` for default behavior.
4883+ */
4884+ $ months = apply_filters ( 'media_library_months_with_files ' , null );
4885+ if ( ! is_array ( $ months ) ) {
4886+ $ months = wp_get_media_library_attachment_months ();
4887+ }
48704888
48714889 foreach ( $ months as $ month_year ) {
48724890 $ month_year ->text = sprintf (
@@ -5130,6 +5148,9 @@ function wp_enqueue_media( $args = array() ) {
51305148/**
51315149 * Retrieves the months that have media library attachments.
51325150 *
5151+ * Results are cached in a transient and automatically invalidated when
5152+ * attachments are created, updated, or deleted.
5153+ *
51335154 * Example:
51345155 *
51355156 * $months = wp_get_media_library_attachment_months();
@@ -5147,26 +5168,6 @@ function wp_enqueue_media( $args = array() ) {
51475168function wp_get_media_library_attachment_months (): array {
51485169 global $ wpdb ;
51495170
5150- /**
5151- * Allows overriding the list of months displayed in the media library.
5152- *
5153- * By default (if this filter does not return an array), a query will be
5154- * run to determine the months that have media items. This query can be
5155- * expensive for large media libraries, so it may be desirable for sites to
5156- * override this behavior.
5157- *
5158- * @since 4.7.4
5159- *
5160- * @link https://core.trac.wordpress.org/ticket/31071
5161- *
5162- * @param array<int, object{year: string, month: string}>|null $months An array of objects with `month` and `year`
5163- * properties, or `null` for default behavior.
5164- */
5165- $ months = apply_filters ( 'media_library_months_with_files ' , null );
5166- if ( is_array ( $ months ) ) {
5167- return $ months ;
5168- }
5169-
51705171 return $ wpdb ->get_results (
51715172 $ wpdb ->prepare (
51725173 "SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
0 commit comments