让我用最简单的方式回答。这取决于具体情况,有时您可能想创建自己的MediaFrame,但我认为这将稍微超出问题的范围,需要更多的解释:
假设所有附件都有一个要编辑的ID,下面的代码将打开详细信息。要在内置编辑屏幕之外进行此操作,您需要自己将媒体内容排队(请参阅wp_enqueue_media )
// we only want to query "our" image attachment
// value of post__in must be an array
var queryargs = {post__in: [385]};
wp.media.query(queryargs) // set the query
.more() // execute the query, this will return an deferred object
.done(function(){ // attach callback, executes after the ajax call succeeded
// inside the callback \'this\' refers to the result collection
// there should be only one model, assign it to a var
var attachment = this.first();
// this is a bit odd: if you want to access the \'sizes\' in the modal
// and if you need access to the image editor / replace image function
// attachment_id must be set.
// see media-models.js, Line ~370 / PostImage
attachment.set(\'attachment_id\', attachment.get(\'id\'));
// create a frame, bind \'update\' callback and open in one step
wp.media({
frame: \'image\', // alias for the ImageDetails frame
state: \'image-details\', // default state, makes sense
metadata: attachment.toJSON(), // the important bit, thats where the initial informations come from
}).on(\'update\', function(attachmentObj){ // bind callback to \'update\'
console.log(attachmentObj); // attachment object is passed to the callback, do whatever you want from here
}).open(); // finally open the frame
});
基本上就是这样。玩得高兴