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!

Read More

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

Related posts

Leave a Reply

2 comments

  1. 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

  2. Looks like you’ve figured it out but seeing I use ACF all the time I figured I could link you to a couple of awesome posts about the media uploader in 3.5 as the codex still aren’t updated yet.

    Check out: Using the WordPress 3.5 Media Uploader within plugins

    This week whilst working on WooCommerce 2.0 beta I was faced with the task of rewriting the media unloaders to use the fancy new interface in 3.5 instead of the tired old thickbox modal windows used in earlier versions.

    This was no easy task mainly due to the lack of documentation available for the new system, but I persevered and wanted to share my experiences in this post.

    and Building a Better Image Widget with the New WordPress Media Manager

    I decided to build a better image widget — something seemingly simple that’s not too different from the featured image workflow and could be used as a starting point. I was fairly satisfied with my initial effort, but the code in the post thumbnail meta box didn’t resemble an API and it was eventually reverted to maintain compatibility.

    Keep up the great work with ACF 🙂