简体   繁体   中英

How to use WordPress 3.5 media manager gallery tool for my own plugin

In the WordPress 3.5 media manager under the "Create Gallery" tab, users can choose multiple images and then have the ability to reorder images in a second page. When done, it inserts a shortcode such as: [gallery ids="895,1007,986"]

I would like to use this same interface so that users can select and reorder images. However, instead of returning a shortcode, I would like to return just a list of ID's of the images like so: 895,1007,986

Another important thing is that my button will be in a metabox and the list of ID's will not be placed inside TinyMCE post edit area.

How can I achieve this?

Thank You.

You can call a = wp.media.gallery.edit('[gallery ids="2,1,3..."]'); like Wordpress does in media-editor.js.

I wasn't sure what event can catch the update, I found it with a.on('all',function(n,a) {console.log(n); console.log(a)})

Notice "update" in the log, and an object with a models array with the images. So, the quickest solutions using the gallery selector would be:

wp.media.gallery.edit('[gallery ids="numberlist"]').on('update',function(obj)
  { do something with obj.models)})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM