diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index 78cad542cf..55661dd692 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -2156,7 +2156,7 @@ function wp_ajax_query_attachments() { $query = isset( $_REQUEST['query'] ) ? (array) $_REQUEST['query'] : array(); $query = array_intersect_key( $query, array_flip( array( 's', 'order', 'orderby', 'posts_per_page', 'paged', 'post_mime_type', - 'post_parent', 'post__in', 'post__not_in', + 'post_parent', 'post__in', 'post__not_in', 'year', 'monthnum' ) ) ); $query['post_type'] = 'attachment'; @@ -2713,7 +2713,7 @@ function wp_ajax_parse_media_shortcode() { if ( ! empty( $wp_scripts ) ) { $wp_scripts->done = array(); } - + if ( 'playlist' === $_REQUEST['type'] ) { wp_underscore_playlist_templates(); diff --git a/src/wp-includes/js/media-grid.js b/src/wp-includes/js/media-grid.js index a1f2e30ef1..449680b1ec 100644 --- a/src/wp-includes/js/media-grid.js +++ b/src/wp-includes/js/media-grid.js @@ -448,7 +448,7 @@ /** * Render the EditImage view into the frame's content region. - * + * * @param {Object} contentRegion Basic object with a `view` property, which * should be set with the proper region view. */ @@ -649,4 +649,33 @@ } }); + /** + * A filter dropdown for month/dates. + */ + media.view.DateFilter = media.view.AttachmentFilters.extend({ + id: 'media-attachment-date-filters', + + createFilters: function() { + var filters = {}; + _.each( media.view.settings.months || {}, function( value, index ) { + filters[ index ] = { + text: value.text, + props: { + year: value.year, + monthnum: value.month + } + }; + }); + filters.all = { + text: l10n.allDates, + props: { + monthnum: false, + year: false + }, + priority: 10 + }; + this.filters = filters; + } + }); + }(jQuery, _, Backbone, wp)); \ No newline at end of file diff --git a/src/wp-includes/js/media-views.js b/src/wp-includes/js/media-views.js index ce8eadfdb6..ef3e787ade 100644 --- a/src/wp-includes/js/media-views.js +++ b/src/wp-includes/js/media-views.js @@ -5506,13 +5506,19 @@ this.select(); }, + /** + * @abstract + */ createFilters: function() { this.filters = {}; }, + /** + * When the selection changes, set the Query properties + * accordingly for the selected filter. + */ change: function() { var filter = this.filters[ this.el.value ]; - if ( filter ) { this.model.set( filter.props ); } @@ -5742,10 +5748,15 @@ priority: -90 }).render() ); - this.toolbar.set( 'BulkSelection', new media.view.BulkSelection({ + this.toolbar.set( 'bulkSelection', new media.view.BulkSelection({ controller: this.controller, priority: -70 }).render() ); + this.toolbar.set( 'dateFilter', new media.view.DateFilter({ + controller: this.controller, + model: this.collection.props, + priority: -75 + }).render() ); } filters = this.options.filters; diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index fea3c34a18..cd32ae1c6c 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -2772,7 +2772,7 @@ function wp_enqueue_media( $args = array() ) { if ( did_action( 'wp_enqueue_media' ) ) return; - global $content_width, $wpdb; + global $content_width, $wpdb, $wp_locale; $defaults = array( 'post' => null, @@ -2825,6 +2825,15 @@ function wp_enqueue_media( $args = array() ) { AND post_mime_type LIKE 'video%' LIMIT 1 " ); + $months = $wpdb->get_results( $wpdb->prepare( " + SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month + FROM $wpdb->posts + WHERE post_type = %s + ORDER BY post_date DESC + ", 'attachment' ) ); + foreach ( $months as $month_year ) { + $month_year->text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month_year->month ), $month_year->year ); + } $settings = array( 'tabs' => $tabs, @@ -2846,6 +2855,7 @@ function wp_enqueue_media( $args = array() ) { 'embedExts' => $exts, 'embedMimes' => $ext_mimes, 'contentWidth' => $content_width, + 'months' => $months, ); $post = null; @@ -2904,6 +2914,7 @@ function wp_enqueue_media( $args = array() ) { 'returnToLibrary' => __( '← Return to library' ), 'allMediaItems' => __( 'All media items' ), 'allMediaTypes' => __( 'All media types' ), + 'allDates' => __( 'All dates' ), 'noItemsFound' => __( 'No items found.' ), 'insertIntoPost' => $hier ? __( 'Insert into page' ) : __( 'Insert into post' ), 'uploadedToThisPost' => $hier ? __( 'Uploaded to this page' ) : __( 'Uploaded to this post' ),