Long answer:查看wp包括/js/媒体模型。js,我看到了:
if ( \'select\' === attributes.frame && MediaFrame.Select ) {
frame = new MediaFrame.Select( attributes );
} else if ( \'post\' === attributes.frame && MediaFrame.Post ) {
frame = new MediaFrame.Post( attributes );
} else if ( \'manage\' === attributes.frame && MediaFrame.Manage ) {
frame = new MediaFrame.Manage( attributes );
} else if ( \'image\' === attributes.frame && MediaFrame.ImageDetails ) {
frame = new MediaFrame.ImageDetails( attributes );
} else if ( \'audio\' === attributes.frame && MediaFrame.AudioDetails ) {
frame = new MediaFrame.AudioDetails( attributes );
} else if ( \'video\' === attributes.frame && MediaFrame.VideoDetails ) {
frame = new MediaFrame.VideoDetails( attributes );
} else if ( \'edit-attachments\' === attributes.frame && MediaFrame.EditAttachments ) {
frame = new MediaFrame.EditAttachments( attributes );
}
所以有人认为你可以做到这一点:
var frame = wp.media.frames.frame = wp.media({
title: \'Select Image\',
button: { text: \'Select\' },
multiple: false,
frame: \'edit-attachments\',
controller: {
gridRouter: {}
}
});
frame.open();
但这行不通。您遇到的第一个问题是需要一些脚本。可以这样处理:
add_action( \'admin_enqueue_scripts\', function() {
wp_enqueue_media();
wp_enqueue_script( \'media-grid\' );
wp_enqueue_script( \'media\' );
});
但还是没有雪茄。
这个问题可以在wp-includes/js/media-grid中找到。js公司:
EditAttachments = MediaFrame.extend({
initialize: function() {
this.controller = this.options.controller;
this.gridRouter = this.controller.gridRouter;
这表明EditAttachments需要选项中提供的控制器,并且该控制器必须具有属性“gridRouter”。这样的话:
var frame = wp.media.frames.frame = wp.media({
frame: \'edit-attachments\',
controller: {
gridRouter: {}
}
});
但这行不通,因为您需要一个有效的gridRouter。
这都与底层网格相关。
了解更多关于wp的信息。media,我可以推荐此插件:https://github.com/ericandrewlewis/wp-media-javascript-guide
当然,还有这一页:https://codex.wordpress.org/Javascript_Reference/wp.media
相关问题: