I'm trying to figure out a better way to pass a parameter to the function I am using with the upload_dir filter. Currently I have only gotten it to work by using sessions and/or cookie that I erase after I use them.

I have a URL like the following: /wp-admin/admin.php?page=my-plugin.php&parameter=apple

I want to upload the file into a directory called /apple/ (inside of the default upload directory) so that I can better categorize the images.

This may be too much info, but figured it might help understand my end goal. I built out the page in the plugin using the following so that I could use the media uploader from there. This basically just lets you pick images and once you click 'insert' it drops the image IDs as a comma sep list into a hidden variable.

$('#uploadGalleryButton').click(function(e) {

    //If the uploader object has already been created, reopen the dialog
    if (plugin_gallery_uploader) {

    //Extend the wp.media object
    plugin_gallery_uploader = wp.media({
        multiple: true

    plugin_gallery_uploader.on('select', function() {
        selectedImages = '';
            selectedImages += item.id+',';

        selectedImages = selectedImages.slice(0,-1);

    plugin_gallery_uploader.on('open',function() {
      var selection = plugin_gallery_uploader.state().get('selection');
      ids = $('#imageList').val().split(',');
        ids.forEach(function(id) {
          attachment = wp.media.attachment(id);
          selection.add( attachment ? [ attachment ] : [] );

    //Open the uploader dialog

I had found the media_upload_form_url filter, and I figured perhaps I could append the parameter name/value to the form URL and pass it along in that manner, but I can't seem to get it to work (or perhaps it doesn't even work to override what I think it does).

add_filter('plugin_upload_form_url', 'plugin_upload_form_url', 9);

function plugin_upload_form_url($form_action_url, $type) {
    return '/test/';

If I run the above it doesn't seem to alter the upload form URL. Am I misinterpreting what that filter is supposed to do, or am I using it incorrectly? That filter is defined in /wp-admin/includes/media.php

Thanks so much!

  • the function name you've assigned to your filter, awesome_upload_form_url, is not the name of the function you've created, is that a typo here? – Milo Jul 27 '13 at 2:35
  • oh yes, that was a typo here and not in the plugin, i renames things when i pasted them in. Sorry about that. – Levi Jul 27 '13 at 2:49
  • maybe you can set the UPLOADS constant on admin page init based on $_GET('parameter') – gmazzap Jul 27 '13 at 13:27
  • I just gave that a try and it does work to override the upload dir on the page the gallery popup is on, but the media popup POSTS the file to a different page (async-upload.php) and the $_GET param doesn't get passed along to that. Thanks for the tip and info on the UPLOADS constant though. – Levi Jul 27 '13 at 22:14
  • @Levi, were you able to resolve this? – Duane Jan 10 '15 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.