Remove attachment fields from custom media uploader

I’ve got a custom media uploader setup and trying to remove attachment fields from only this uploader, while leaving the fields intact for the default WP post/page media uploader. Everything works great except getting the fields to be excluded behaves oddly.

Here’s a bit of code on how it works:

Read More

First, open uploader thickbox with this js tb_show(box_title, 'media-upload.php?post_id=0&custom_uploader=1&TB_iframe=1' );

Next, add the custom_uploader value to the form action URL

function upload_request_hook( $form_action_url, $type ) {
    $form_action_url = $form_action_url . '&custom_uploader=1';

    return $form_action_url;
}

The iframe url for my custom uploader now looks like: media-upload.php?type=image&tab=type&post_id=0&custom_uploader=1 and the form action is something of the same. So it’s all good there.

For testing purposes, I’m removing all attachment fields

function image_attachment_settings( $form_fields, $post ) {
    unset( $form_fields );

    return $form_fields;
}

Then adding the filter and action:

function image_upload_options() {
    add_filter( 'media_upload_form_url', 'upload_request_hook', 10, 2 );
}

if ( isset( $_GET['custom_uploader'] ) || isset( $_POST['custom_uploader'] ) ) {
    add_action( 'admin_init', 'image_upload_options' );
}

So I’m trying to use the if ( isset( $_GET['custom_uploader'] ) || isset( $_POST['custom_uploader'] ) ) to only apply the filter/action for my custom uploader, based on the form action.

But here is the first odd bit. It works how I’m expecting if I use the HTML upload method. If I use the Flash uploader, none of the fields are removed.

And the second odd bit … If I remove the IF statement, where it basically removse the attachment fields for every upload type (custom and default WP), it works with both the flash and HTML uploader. But thats defeating the purpose.

The question here is; what can I setup here to exclude the attachment fields for only the custom uploader, where it works with the Flash and HTML uploader? Any type of IF statement to apply? Any other hooks I could setup or latch on to?

Appreciate any help that could be given here. Thanks!

Related posts

Leave a Reply

1 comment

  1. I know this isn’t an in depth answer (I’m at work and can’t really test any code) but, maybe you need to look at directly creating hooks for your upload – which should mean that the flash uploader will act as you expect.

    The hook for the flash loader is: pre-flash-upload-ui

    You can see where this hook appears here:

    http://adambrown.info/p/wp_hooks/hook/pre-flash-upload-ui

    Some other stems/hooks to look at are these:

    • post-html-upload-ui
    • post-plupload-upload-ui
    • post-upload-ui
    • pre-flash-upload-ui

    Also regarding the media uploader and $GET in one of your conditions – I think $REQUEST is preferred.

    Sorry for the vague answer but inspecting these hooks may help you find a solution to your problem – hopefully I’ll be able to expand and test later tonight and help out a bit more

    Craig