是否可以重复使用图像详细信息弹出窗口?

时间:2014-10-18 作者:s_ferdie

我想用“编辑图像详细信息”按钮扩展我的小部件中的图像字段。是否可以以某种方式重新使用tinyMCE编辑器中的弹出窗口?

enter image description here

例如,我可以使用大小设置。

2 个回复
最合适的回答,由SO网友:ungestaltbar 整理而成

让我用最简单的方式回答。这取决于具体情况,有时您可能想创建自己的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
  });
基本上就是这样。玩得高兴

SO网友:Chief Alchemist

CMB2插件允许您添加图像,看看这个?

有几个插件可以将图像添加到分类术语中,我相信它们也可以使用媒体管理器,也许也可以看看这些插件?

结束