From dd3cd96bac54316b5c1cf5d44627dbecb9b8b156 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Tue, 27 Nov 2012 23:20:12 +0000 Subject: [PATCH] When editing a plain, legacy [gallery] shortcode, ensure we are sorting its contents using menu_order. When attachments are sorted, we convert the shortcode to [gallery ids=""], as before. props koopersmith. fixes #22608. git-svn-id: http://core.svn.wordpress.org/trunk@22882 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/media-editor.js | 28 ++++++++++++++++++++++++---- wp-includes/js/media-models.js | 14 ++++++++------ wp-includes/js/media-views.js | 26 ++++++++++++++++++-------- wp-includes/media.php | 3 ++- 4 files changed, 52 insertions(+), 19 deletions(-) diff --git a/wp-includes/js/media-editor.js b/wp-includes/js/media-editor.js index 315940a28a..6f346d583e 100644 --- a/wp-includes/js/media-editor.js +++ b/wp-includes/js/media-editor.js @@ -157,7 +157,8 @@ icontag: 'dt', captiontag: 'dd', columns: 3, - size: 'thumbnail' + size: 'thumbnail', + orderby: 'menu_order ID' }, attachments: function( shortcode ) { @@ -170,12 +171,17 @@ if ( result ) return result; - attrs = shortcode.attrs.named; + // Fill the default shortcode attributes. + attrs = _.defaults( shortcode.attrs.named, wp.media.gallery.defaults ); args = _.pick( attrs, 'orderby', 'order' ); args.type = 'image'; args.perPage = -1; + // Map the `orderby` attribute to the corresponding model property. + if ( ! attrs.orderby || /^menu_order(?: ID)?$/i.test( attrs.orderby ) ) + args.orderby = 'menuOrder'; + // Map the `ids` param to the correct query args. if ( attrs.ids ) { args.post__in = attrs.ids.split(','); @@ -204,14 +210,21 @@ shortcode: function( attachments ) { var props = attachments.props.toJSON(), - attrs = _.pick( props, 'include', 'exclude', 'orderby', 'order' ), + attrs = _.pick( props, 'orderby', 'order' ), shortcode, clone; if ( attachments.gallery ) _.extend( attrs, attachments.gallery.toJSON() ); + // Convert all gallery shortcodes to use the `ids` property. + // Ignore `post__in` and `post__not_in`; the attachments in + // the collection will already reflect those properties. attrs.ids = attachments.pluck('id'); + // Copy the `parent` post ID. + if ( props.parent ) + attrs.id = props.parent; + // If the `ids` attribute is set and `orderby` attribute // is the default value, clear it for cleaner output. if ( attrs.ids && 'post__in' === attrs.orderby ) @@ -272,7 +285,12 @@ selection.props.unset('orderby'); }); - return wp.media({ + // Destroy the previous gallery frame. + if ( this.frame ) + this.frame.dispose(); + + // Store the current gallery frame. + this.frame = wp.media({ frame: 'post', state: 'gallery-edit', title: wp.media.view.l10n.editGalleryTitle, @@ -280,6 +298,8 @@ multiple: true, selection: selection }); + + return this.frame; } }; }()); diff --git a/wp-includes/js/media-models.js b/wp-includes/js/media-models.js index 7da7327a1d..8207645788 100644 --- a/wp-includes/js/media-models.js +++ b/wp-includes/js/media-models.js @@ -659,18 +659,20 @@ window.wp = window.wp || {}; }, orderby: { - allowed: [ 'name', 'author', 'date', 'title', 'modified', 'uploadedTo', 'id', 'post__in' ], + allowed: [ 'name', 'author', 'date', 'title', 'modified', 'uploadedTo', 'id', 'post__in', 'menuOrder' ], valuemap: { 'id': 'ID', - 'uploadedTo': 'parent' + 'uploadedTo': 'parent', + 'menuOrder': 'menu_order ID' } }, propmap: { - 'search': 's', - 'type': 'post_mime_type', - 'parent': 'post_parent', - 'perPage': 'posts_per_page' + 'search': 's', + 'type': 'post_mime_type', + 'parent': 'post_parent', + 'perPage': 'posts_per_page', + 'menuOrder': 'menu_order' }, // Caches query objects so queries can be easily reused. diff --git a/wp-includes/js/media-views.js b/wp-includes/js/media-views.js index 5ef57ceba4..d7e35f8175 100644 --- a/wp-includes/js/media-views.js +++ b/wp-includes/js/media-views.js @@ -2898,7 +2898,9 @@ all: { text: l10n.allMediaItems, props: { - parent: null + parent: null, + orderby: 'date', + order: 'DESC' }, priority: 10 }, @@ -2906,7 +2908,9 @@ uploaded: { text: l10n.uploadedToThisPost, props: { - parent: media.view.settings.postId + parent: media.view.settings.postId, + orderby: 'menuOrder', + order: 'ASC' }, priority: 20 } @@ -2921,8 +2925,10 @@ filters[ key ] = { text: text, props: { - type: key, - parent: null + type: key, + parent: null, + orderby: 'date', + order: 'DESC' } }; }); @@ -2930,8 +2936,10 @@ filters.all = { text: l10n.allMediaItems, props: { - type: null, - parent: null + type: null, + parent: null, + orderby: 'date', + order: 'DESC' }, priority: 10 }; @@ -2939,8 +2947,10 @@ filters.uploaded = { text: l10n.uploadedToThisPost, props: { - type: null, - parent: media.view.settings.postId + type: null, + parent: media.view.settings.postId, + orderby: 'menuOrder', + order: 'ASC' }, priority: 20 }; diff --git a/wp-includes/media.php b/wp-includes/media.php index 1612b80d2e..efd9a19182 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -1254,7 +1254,7 @@ function wp_plupload_default_settings() { 'multipart' => true, 'urlstream_upload' => true, ); - + // Multi-file uploading doesn't currently work in iOS Safari, // single-file allows the built-in camera to be used as source for images if ( wp_is_mobile() ) @@ -1327,6 +1327,7 @@ function wp_prepare_attachment_for_js( $attachment ) { 'uploadedTo' => $attachment->post_parent, 'date' => strtotime( $attachment->post_date_gmt ) * 1000, 'modified' => strtotime( $attachment->post_modified_gmt ) * 1000, + 'menuOrder' => $attachment->menu_order, 'mime' => $attachment->post_mime_type, 'type' => $type, 'subtype' => $subtype,