I am using custom media upload
in my plugin. In my previous (before 4.0) WordPress
versions its working perfectly. When I upload audio or image file its upload successfully
and when i click on "Insert Into Post"
the path of uploaded file shown in the text field.
But when I upgrade my WordPress into 4.4.2
and upload any file its upload successfully
and when I click on “Insert Into Post” the file path of uploaded file not shown in my text field.
In both WordPress’s the code is 100% same.
Here is my HTML Code:
<input type="text" size="50" name="mp3" id="mp3" class="upload-url" />
<input id="st_upload_button" class="st_upload_button" type="button" name="upload_button" value="Upload">
And here is my Functions.php Code:
function pro_scripts_method() {
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');
wp_register_script( 'custom-js', plugin_dir_url( __FILE__ )."js/custom.js");
wp_enqueue_script( 'custom-js' );
}
add_action('admin_enqueue_scripts', 'pro_scripts_method');
And here is my JS Code:
jQuery('.st_upload_button').click(function() {
targetfield = jQuery(this).prev('.upload-url');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
return false;
});
window.send_to_editor = function(html) {
fileurl = jQuery(html).attr('href');
//alert(fileurl);
jQuery(targetfield).val(fileurl);
tb_remove();
}
I alert fileurl
variable but it gives me undefined value. So please help me for fix that problem
The change that new WordPress made to their media upload is the empty Link URL field.
But if you click
file url
button below that field and then clickInsert Into Post
your code works well 🙂So we need a simple way to automatically put the
file url
value in the Link URL. I don’t know about it whether there is a setting for that in wordpress or not but there is a simple code I wrote in jQuery to achieve it and it works really well for me.What I’m really doing is:
When user hit the
Insert into Post
button. My jQuery check the parent of thatInsert into Post
button and find thefile url
value and insert it into Link URL field. That’s it! Simple right?So try it out and let me know 🙂
Why aren’t you using
wp.media
?Try with this:
This will open the media screen on button click, and put the url to the input field.
Their is a new version of the wordpress uploader since WordPress 3.5. Maybe the way you did it is not available in WordPress 4.0
You could find a basic tutorial here:
http://www.webmaster-source.com/