Steve Taylor photo

Anyone know their way around the WordPress 3.5+ media upload API?

Version 1.0 of the Developer’s Custom Fields plugin is in development. I’d hoped that the core Metadata UI API would have made progress enough for me to revamp DCF in light of the new core functionality, but that’s not looking likely. DCF 1.0 won’t be a major update, but I’m hoping to get some significant things sorted out.

The most important, I think, is getting the file field type working with the new (well, introduced in WordPress 3.5) media upload API. It’s pretty much there, but I’m looking for some help with it. Does anyone know the media upload API well?

I’ve followed Thomas Griffin’s nice example. You can download the current development code to try it out.

Here’s the issues I’d love some input on:

  1. The main thing I’m stuck on is, how to control whether or not the files uploaded through the media upload dialog are attached to the current post or not? DCF has a field parameter for this, file_attach_to_post. Previously, I just had to append a post_id query string parameter (or not) to the media iframe URL. Now, I’m not sure. Any ideas?
  2. A related issue is how to restrict the files listed in the dialog to those attached to the current post. I’m using library: { type: 'image' } to restrict the files to images (or audio, or video). In the main media library there’s a drop-down which offers this filtering, which also includes ‘Uploaded to this post’ (option value uploaded). But passing library: { type: 'uploaded' } to wp.media doesn’t seem to work. And I can’t find another option. Is this possible?
  3. While we’re on that one – how about being able to restrict to documents (i.e. everything except images, audio and video)?

Issue 1 is the main problem, because there’s already a field parameter for this, and I need to get this working in this new version so it doesn’t break sites out there that are using that parameter.

Any ideas welcome!

4 comments

  1. Aghiad avatar Aghiad

    Hi Steve,

    I know it is an old post, but I really searched a lot and I couldn’t find a good answer for my issue which has something in common with yours in this post.

    In the media library uploader popup I want to have a filter like in the main media library with the option ‘Uploaded to this post’, any idea how to do that?
    note: the uploader is for a custom pod file field.

  2. Steve Taylor avatar Steve Taylor

    I’m not sure – I have a vague memory of trying to do that, but if I did, I obviously failed, as that feature’s not in my plugin! Search my plugin source for file_dialog_title and file_restrict_to_type, they were the main customisations I managed. But no ‘uploaded to this post’ filter I’m afraid. Let me know if you crack it!

  3. Aghiad avatar Aghiad

    It turned out that the pods plugin uses media library by inheriting from it with all its default values and the “Uploaded to this post” filter is disabled by default
    I needed the change the value “filterable” from false to 'uploaded' in wp.media.controller.Library, I couldn’t pass the value in the plugin so I had to change it in WordPress core in the file media-views.js or media.views.min.js and it’s working now.
    I ‘ll keep it like that for now until I find a way to pass this value or maybe I need to build a custom plugin to change this value without hacking WordPress core.

    Thanks for your time :)

Comments are closed.