wp.media update options and force render on uploader

Elliot here from the “Advanced Custom Fields” plugin.

I’m working on integrating the new WP 3.5 uploader into the ACF plugin and can’t find much documentation about the new uploader at all!

Creating an uploader frame is easy, that can be done like this:

// Create the media frame.
acf.media = wp.media({
    title : 'title',
    button : {
        text: 'button',
    },
    multiple: true
});

However, what if you want to change multiple to false and for another field?
Basically, I would like to create only 1 wp.media object, but then update the options when needed (when you click “upload image”, etc) and force a render refresh on the uploader.

I’ve played around with stuff like this:

acf.media.title.get().refresh()

But that doesn’t work…

Any help will be greatly apreciated

Cheers
Elliot

2 s
2

Solved!

Not sure if this is the correct method, but after hours of console logging I discovered that this code:

acf.media.content.get().options.selection.multiple = false

will update the multiple option and therefore change how many images can be selected in the new uploader.

If someone finds a nicer way, I’d love to hear it

Leave a Comment