admin管理员组文章数量:1122832
I have been using a custom code to upload images to Wordpress using custom metaboxes. Here is the code:
<script type="text/javascript">
jQuery(document).ready(function( $ ) {
var formfield;
$('.upload_button').click(function() {
$('html').addClass('Image');
formfield = $(this).prev('.upload_image'); // .attr('name');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
return false;
});
// user inserts file into post. only run custom if user started process using the above process
// window.send_to_editor(html) is how wp would normally handle the received data
window.original_send_to_editor = window.send_to_editor;
window.send_to_editor = function(html){
if (formfield) {
fileurl = jQuery('img',html).attr('src');
$(formfield).val(fileurl);
tb_remove();
formfield = '';
$('html').removeClass('Image');
} else {
window.original_send_to_editor(html);
}
};
});
</script>
My actual problem is that I have to upload now a PDF. I have try to use the .urlfield input in the media uploader with keeps the URL of the uploaded file.
I have changed fileurl = jQuery('img',html).attr('src'); to fileurl = jQuery('.urlfield',html).val(); but it does not work.
What can I do please?
An alternative tip I would like to know is how can I change the "Insert button" value text to something like "Use this file".
Thanks in advance.
I have been using a custom code to upload images to Wordpress using custom metaboxes. Here is the code:
<script type="text/javascript">
jQuery(document).ready(function( $ ) {
var formfield;
$('.upload_button').click(function() {
$('html').addClass('Image');
formfield = $(this).prev('.upload_image'); // .attr('name');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
return false;
});
// user inserts file into post. only run custom if user started process using the above process
// window.send_to_editor(html) is how wp would normally handle the received data
window.original_send_to_editor = window.send_to_editor;
window.send_to_editor = function(html){
if (formfield) {
fileurl = jQuery('img',html).attr('src');
$(formfield).val(fileurl);
tb_remove();
formfield = '';
$('html').removeClass('Image');
} else {
window.original_send_to_editor(html);
}
};
});
</script>
My actual problem is that I have to upload now a PDF. I have try to use the .urlfield input in the media uploader with keeps the URL of the uploaded file.
I have changed fileurl = jQuery('img',html).attr('src'); to fileurl = jQuery('.urlfield',html).val(); but it does not work.
What can I do please?
An alternative tip I would like to know is how can I change the "Insert button" value text to something like "Use this file".
Thanks in advance.
Share Improve this question edited Oct 18, 2012 at 21:35 DeryckOE asked Oct 18, 2012 at 21:22 DeryckOEDeryckOE 158 bronze badges 1- This was answered here: wordpress.stackexchange.com/questions/20530/… – Wyck Commented Oct 18, 2012 at 22:24
1 Answer
Reset to default 0please use this code....
(function( $ ) {
$( '#uploadpdf' ).on( 'click', function() {
tb_show('Upload the pdf', 'media-upload.php?type=file&TB_iframe=1');
window.send_to_editor = function( html )
{
fileurl = $(html).attr('href');
if(/\.pdf\b/.test(fileurl)){
$('#pdf').val(fileurl);
}else{
alert('Not a valid pdf file');
}
tb_remove();
}
return false;
});
})(jQuery);
</script>
本文标签: custom fieldUploading PDF using Media Uploader
版权声明:本文标题:custom field - Uploading PDF using Media Uploader 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736281629a1926379.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论