I need to apply an add_filter from my functions.php but only if the user has opened media-upload.php from my custom function. Is it possible to send a variable when opening media-upload.php that I could then test for existence of before executing add_filter?
Example: Here is my code in which I’m opening the media uploader from my custom icon…
//Custom upload launcher for custom attachments
function wpe_customImages($initcontext)
{
global $post;
?>
<script type="text/javascript">
jQuery(document).ready(function() {
var fileInput="";
jQuery('#customAttachments').click(function() {
fileInput = jQuery(this).prev('input');
formfield = jQuery('#upload_image').attr('name');
post_id = jQuery('#post_ID').val();
tb_show('', 'media-upload.php?post_id='+post_id+'&type=image&TB_iframe=true');
return false;
});
});
</script>
<?php
return $initcontext.
'<input type="hidden" id="post_ID" value="'. $post->ID .'" />
Product Images:<a id="customAttachments" href="https://wordpress.stackexchange.com/questions/4302/javascript:;"
class="mceButton mceButtonEnabled" onmousedown="return false;"
onclick="return false;">
<img src="'.get_bloginfo('template_directory') .'/img/upload-icon.gif"" /></a>';
}
add_filter('media_buttons_context', 'wpe_customImages');
Inside the above code, would it be possible to set a global variable or some marker that I can test for in order to execute my add_filter code?
if(isset($myMarker)){
add_filter("attachment_fields_to_save", "rt_image_attachment_fields_to_save", null , 2);
}