以下是链接解决方案的一个版本,可以覆盖galleryAddToolbar
有一个额外的按钮(insertTop
) 要想做你想做的事情(在“functions.php”中):
add_filter( \'media_view_strings\', function ( $strings, $post ) {
$strings[\'addToGallery\'] = __( \'Add to end of gallery\' );
$strings[\'addToGalleryTop\'] = __( \'Add to start of gallery\' );
return $strings;
}, 10, 2 );
add_action( \'admin_footer\' , function () {
?>
<script>
jQuery(document).ready(function() {
(function ($) {
if (typeof wp.media !== \'undefined\') {
wp.media.view.MediaFrame.Post.prototype.galleryAddToolbar = function () {
var media = wp.media, l10n = media.view.l10n;
this.toolbar.set( new media.view.Toolbar({
controller: this,
items: {
insert: {
style: \'secondary\',
text: l10n.addToGallery,
priority: 70,
requires: { selection: true },
/**
* @fires wp.media.controller.State#reset
*/
click: function() {
var controller = this.controller,
state = controller.state(),
edit = controller.state(\'gallery-edit\');
edit.get(\'library\').add( state.get(\'selection\').models );
state.trigger(\'reset\');
controller.setState(\'gallery-edit\');
}
},
insertTop: {
style: \'primary\',
text: l10n.addToGalleryTop,
priority: 80,
requires: { selection: true },
/**
* @fires wp.media.controller.State#reset
*/
click: function() {
var controller = this.controller,
state = controller.state(),
edit = controller.state(\'gallery-edit\');
edit.get(\'library\').unshift( state.get(\'selection\').models );
state.trigger(\'reset\');
controller.setState(\'gallery-edit\');
}
}
}
}) );
};
}
})(jQuery);
});
</script>
<?php
} );