Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
2  
Hey, Mr. Elliot, you made the Question, you have an Answer, now you gotta write it up as such (explain why and mark as accepted in two days), instead of a small Comment ;) –  brasofilo Jan 16 '13 at 4:02
add comment

2 Answers

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 :)

share|improve this answer
1  
Make sure your answers are more than just links to avoid the risk of getting down-voted! –  mrwweb Jan 16 '13 at 3:51
1  
Bronson, not sure if I selected the best snippet for Brady Vercher's article, please modify as you see fit. Nice links, thx +1 ;) –  brasofilo Jan 16 '13 at 3:56
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.