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.

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:

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!

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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

share|improve this answer
    
Changed out the IF statement to $_REQUEST. Just to test again if it was working, I put a disable tabs function in there. The tabs are being disabled based on the IF statement, so I know that it's working. Here's my new code stuff here: pastebin.com/bYeFUbha - I changed the thickbox and form action to be context=custom_uploader, which I changed in the IF statement. Saw something similar in WP includes/media.php. Not sure how to setup the hooks you provided here for this ... –  Ryan Palmer Aug 3 '12 at 15:01
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.