I'm trying to adjust my plugin a bit. I'd like to change the file name of an upload as I'm adding a new product. My current solutions - I've disabled the tb_show image upload box from appearing if the name input has not been filled out. This way we'll have that value. In my init.php file I have this which seems to be what I'm looking for. A way to edit the file name :
add_filter('wp_handle_upload_prefilter', 'custom_upload_filter' );
function custom_upload_filter( $file ){
$fileNameHere = $_POST["bv_product_num"];
$file['name'] = 'new value';
//return $files;
exit(var_dump($fileNameHere));
$fileNameHere = $_POST["bv_product"];
}
in my create.php file which is for the user I have :
<script type="text/javascript">
//tb_show('', 'media-upload.php?TB_iframe=true');
/*----------------------------------------------*/
jQuery(document).ready(function() {
jQuery('.upload_image_button').click(function() {
original_send_to_editor = window.send_to_editor;
window.send_to_editor = function(html) {
hrefurl = jQuery(html).attr('href');
jQuery('#'+formfieldID).val(hrefurl);
tb_remove();
window.send_to_editor = original_send_to_editor;
}
// loads thickbox
upload_image_button =true;
formfieldID=jQuery(this).prev().attr("id");
formfield = jQuery("#"+formfieldID).attr('name');
/*
* Get values of above boxes
*/
//bv_product_num=jQuery('#bv_product_num').val();
bv_product_num=jQuery('#bv_product_num').val();
bv_product_num="this";
bv_product_iw_bulk=jQuery('#bv_product_iw_bulk').val();
bv_wg_lf_rf=jQuery('#bv_wg_lf_rf').val();//not necessary str.replace(',','.').replace(' ','')
bv_product_name=jQuery('#bv_product_name').val();
bv_pack_oz=jQuery('#bv_pack_oz').val();
fileNameHere = bv_product_num+"_"+bv_wg_lf_rf+"_"+bv_product_name+"_"+bv_pack_oz+"_oz";
//if(bv_product_num && bv_product_iw_bulk && bv_wg_lf_rf && bv_product_name && bv_pack_oz)
if(bv_product_num)
{
/*-------------------------
----------------------------
------------------------------
------------------------------
----------------------------
------------------------------
*/
/*------------------------------------------------
-------------------------------------------------
--------------------------------------------------
--------------------------------------------------
------------------------------------------------*/
tb_show('', 'media-upload.php?bv_product=+'+fileNameHere+'&type=image&TB_iframe=true');
return false;
}else{
alert("nothing");
}
//formfield = jQuery("#"+formfieldID).attr('name');
/**/
});
})
//old----------------------------------
/*jQuery(document).ready(function() {
jQuery('.upload_image_button').click(function() {
original_send_to_editor = window.send_to_editor;
window.send_to_editor = function(html) {
hrefurl = jQuery(html).attr('href');
jQuery('#'+formfieldID).val(hrefurl);
tb_remove();
window.send_to_editor = original_send_to_editor;
}
loads thickbox
upload_image_button =true;
formfieldID=jQuery(this).prev().attr("id");
formfield = jQuery("#"+formfieldID).attr('name');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
return false;
});
})*/
</script>
What I'm trying to do is pass the variables from my main plugin page to my init file so that I can manipulate them. What is the correct flow for communicating these variables in this way?