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:
parent
0464ec77b5
commit
dd3cd96bac
|
@ -157,7 +157,8 @@
|
||||||
icontag: 'dt',
|
icontag: 'dt',
|
||||||
captiontag: 'dd',
|
captiontag: 'dd',
|
||||||
columns: 3,
|
columns: 3,
|
||||||
size: 'thumbnail'
|
size: 'thumbnail',
|
||||||
|
orderby: 'menu_order ID'
|
||||||
},
|
},
|
||||||
|
|
||||||
attachments: function( shortcode ) {
|
attachments: function( shortcode ) {
|
||||||
|
@ -170,12 +171,17 @@
|
||||||
if ( result )
|
if ( result )
|
||||||
return 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 = _.pick( attrs, 'orderby', 'order' );
|
||||||
|
|
||||||
args.type = 'image';
|
args.type = 'image';
|
||||||
args.perPage = -1;
|
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.
|
// Map the `ids` param to the correct query args.
|
||||||
if ( attrs.ids ) {
|
if ( attrs.ids ) {
|
||||||
args.post__in = attrs.ids.split(',');
|
args.post__in = attrs.ids.split(',');
|
||||||
|
@ -204,14 +210,21 @@
|
||||||
|
|
||||||
shortcode: function( attachments ) {
|
shortcode: function( attachments ) {
|
||||||
var props = attachments.props.toJSON(),
|
var props = attachments.props.toJSON(),
|
||||||
attrs = _.pick( props, 'include', 'exclude', 'orderby', 'order' ),
|
attrs = _.pick( props, 'orderby', 'order' ),
|
||||||
shortcode, clone;
|
shortcode, clone;
|
||||||
|
|
||||||
if ( attachments.gallery )
|
if ( attachments.gallery )
|
||||||
_.extend( attrs, attachments.gallery.toJSON() );
|
_.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');
|
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
|
// If the `ids` attribute is set and `orderby` attribute
|
||||||
// is the default value, clear it for cleaner output.
|
// is the default value, clear it for cleaner output.
|
||||||
if ( attrs.ids && 'post__in' === attrs.orderby )
|
if ( attrs.ids && 'post__in' === attrs.orderby )
|
||||||
|
@ -272,7 +285,12 @@
|
||||||
selection.props.unset('orderby');
|
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',
|
frame: 'post',
|
||||||
state: 'gallery-edit',
|
state: 'gallery-edit',
|
||||||
title: wp.media.view.l10n.editGalleryTitle,
|
title: wp.media.view.l10n.editGalleryTitle,
|
||||||
|
@ -280,6 +298,8 @@
|
||||||
multiple: true,
|
multiple: true,
|
||||||
selection: selection
|
selection: selection
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return this.frame;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}());
|
}());
|
||||||
|
|
|
@ -659,18 +659,20 @@ window.wp = window.wp || {};
|
||||||
},
|
},
|
||||||
|
|
||||||
orderby: {
|
orderby: {
|
||||||
allowed: [ 'name', 'author', 'date', 'title', 'modified', 'uploadedTo', 'id', 'post__in' ],
|
allowed: [ 'name', 'author', 'date', 'title', 'modified', 'uploadedTo', 'id', 'post__in', 'menuOrder' ],
|
||||||
valuemap: {
|
valuemap: {
|
||||||
'id': 'ID',
|
'id': 'ID',
|
||||||
'uploadedTo': 'parent'
|
'uploadedTo': 'parent',
|
||||||
|
'menuOrder': 'menu_order ID'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
propmap: {
|
propmap: {
|
||||||
'search': 's',
|
'search': 's',
|
||||||
'type': 'post_mime_type',
|
'type': 'post_mime_type',
|
||||||
'parent': 'post_parent',
|
'parent': 'post_parent',
|
||||||
'perPage': 'posts_per_page'
|
'perPage': 'posts_per_page',
|
||||||
|
'menuOrder': 'menu_order'
|
||||||
},
|
},
|
||||||
|
|
||||||
// Caches query objects so queries can be easily reused.
|
// Caches query objects so queries can be easily reused.
|
||||||
|
|
|
@ -2898,7 +2898,9 @@
|
||||||
all: {
|
all: {
|
||||||
text: l10n.allMediaItems,
|
text: l10n.allMediaItems,
|
||||||
props: {
|
props: {
|
||||||
parent: null
|
parent: null,
|
||||||
|
orderby: 'date',
|
||||||
|
order: 'DESC'
|
||||||
},
|
},
|
||||||
priority: 10
|
priority: 10
|
||||||
},
|
},
|
||||||
|
@ -2906,7 +2908,9 @@
|
||||||
uploaded: {
|
uploaded: {
|
||||||
text: l10n.uploadedToThisPost,
|
text: l10n.uploadedToThisPost,
|
||||||
props: {
|
props: {
|
||||||
parent: media.view.settings.postId
|
parent: media.view.settings.postId,
|
||||||
|
orderby: 'menuOrder',
|
||||||
|
order: 'ASC'
|
||||||
},
|
},
|
||||||
priority: 20
|
priority: 20
|
||||||
}
|
}
|
||||||
|
@ -2921,8 +2925,10 @@
|
||||||
filters[ key ] = {
|
filters[ key ] = {
|
||||||
text: text,
|
text: text,
|
||||||
props: {
|
props: {
|
||||||
type: key,
|
type: key,
|
||||||
parent: null
|
parent: null,
|
||||||
|
orderby: 'date',
|
||||||
|
order: 'DESC'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -2930,8 +2936,10 @@
|
||||||
filters.all = {
|
filters.all = {
|
||||||
text: l10n.allMediaItems,
|
text: l10n.allMediaItems,
|
||||||
props: {
|
props: {
|
||||||
type: null,
|
type: null,
|
||||||
parent: null
|
parent: null,
|
||||||
|
orderby: 'date',
|
||||||
|
order: 'DESC'
|
||||||
},
|
},
|
||||||
priority: 10
|
priority: 10
|
||||||
};
|
};
|
||||||
|
@ -2939,8 +2947,10 @@
|
||||||
filters.uploaded = {
|
filters.uploaded = {
|
||||||
text: l10n.uploadedToThisPost,
|
text: l10n.uploadedToThisPost,
|
||||||
props: {
|
props: {
|
||||||
type: null,
|
type: null,
|
||||||
parent: media.view.settings.postId
|
parent: media.view.settings.postId,
|
||||||
|
orderby: 'menuOrder',
|
||||||
|
order: 'ASC'
|
||||||
},
|
},
|
||||||
priority: 20
|
priority: 20
|
||||||
};
|
};
|
||||||
|
|
|
@ -1327,6 +1327,7 @@ function wp_prepare_attachment_for_js( $attachment ) {
|
||||||
'uploadedTo' => $attachment->post_parent,
|
'uploadedTo' => $attachment->post_parent,
|
||||||
'date' => strtotime( $attachment->post_date_gmt ) * 1000,
|
'date' => strtotime( $attachment->post_date_gmt ) * 1000,
|
||||||
'modified' => strtotime( $attachment->post_modified_gmt ) * 1000,
|
'modified' => strtotime( $attachment->post_modified_gmt ) * 1000,
|
||||||
|
'menuOrder' => $attachment->menu_order,
|
||||||
'mime' => $attachment->post_mime_type,
|
'mime' => $attachment->post_mime_type,
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'subtype' => $subtype,
|
'subtype' => $subtype,
|
||||||
|
|
Loading…
Reference in New Issue