WordPress Add Context to the Media Uploader

I’m implementing a custom media uploader for a custom post type in the latest version of WordPress (3.5.1).

I have a bare bones version of the media uploader working fine with the following JS attached to my custom media button which is injected via the media_buttons action.

Read More
jQuery(document).ready(function($) {

(function() {
   var file_frame = false;

    $('.vp-upload-product').click(function(e) {
        event.preventDefault();

        if(!file_frame) {
            file_frame = wp.media.frames.file_frame = wp.media({
                title: $(this).data( 'uploader_title' ),
                button: {
                    text: jQuery( this ).data( 'Upload' )
                },
                multiple: false
            });
        }

        file_frame.open();
    });

    })();
});

The Problem:
I want to send the files to a different directory on the server only when using this particular media uploader. I don’t want this to happen for all uploads of this post type or even file types of a certain type.

I’m using the 'upload_dir' filter but I can’t figure out how to get some context available to that function so I know where it was called from. A GET parameter would be enough.

I did find a few things like this: http://shibashake.com/wordpress-theme/how-to-hook-into-the-media-upload-popup-interface but they’re using the old media upload from what I see.

Any suggestions would be great.

Related posts

Leave a Reply