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
This commit is contained in:
Andrew Nacin 2012-11-27 23:20:12 +00:00
parent 0464ec77b5
commit dd3cd96bac
4 changed files with 52 additions and 19 deletions

View File

@ -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;
}
};
}());

View File

@ -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.

View File

@ -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
};

View File

@ -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,