[wp-hackers] Calling the Edit Gallery/Playlist modals via JS

Eric Andrew Lewis eric.andrew.lewis at gmail.com
Tue May 6 12:43:10 UTC 2014

The modal has default frame workflows you can use by passing different `frame` attributes into the wp.media() arguments object.   


var myFrame = wp.media( { frame: ‘select’ } );

Select will allow the user to choose one attachment from the library, although you can make it multiple by setting the `multiple` flag in the attributes object.  

var myFrame = wp.media( { frame: ‘select’, multple: true } );

There is a separate frame called “Post,” which is intended for inserting content into an editor. It is invoked via var myFrame = wp.media( { frame: ‘post’ } ); To utilize this in a WP editor you can use the wp.media.editor.open() method to open a modal and bind it to an editor element, so when the “insert” button is clicked, everything is wired up for you automatically and you don’t need to write more handler code.

When you’re creating a gallery or a playlist, you are within a “state” of the Post frame workflow (hold on to your seat). Depending on your needs, you might be able to just use the Post frame workflow. For anything else, you’re going to want to look into creating a custom frame workflow and duplicating the states you want from the Post frame workflow, and modifying according to your needs.

Eric Andrew Lewis

On Monday, May 5, 2014 at 11:28 PM, Funkatron wrote:

> Playing around with the code of the new media modals. Thanks to some help,
> I've found out how to call the modals related to editing the audio and
> video shortcodes (via wp.media() ) but I can't figure out how to call the
> ones for gallery and playlists. Been digging through the code and I can't
> seem to find any info. Can anyone help me?
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com (mailto:wp-hackers at lists.automattic.com)
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list