1
我有一个帖子类型,用于在wordpress中上传横幅。使用自定义字段名称,图像/视频和网址。默认的媒体上传工作正常上传图片/视频,但我的问题是我无法获得视频基地网址到自定义字段。如何使用wordpress上传媒体上传视频文件?
这是我的代码,无法获取视频网址。它只给我视频文件名称。
window.send_to_editor = function(html) {
var imgurlar = html.match(/<img[^>]+src=\"([^\"]+)\"/);
var imgurl = imgurlar[1];
//image
if(imgurl.length){
jQuery('#wsp_media').val(imgurl);
jQuery('#preview-wsp-media').html('<img src="'+imgurl+'" style="max-width:30px; max-height:50px"/><input type="button" value="Remove" class="button" onclick="removeUspMedia()"/>');
}
//video
else{
var fileurl = jQuery(html);
//above "html" carries only video name if I click on "none" button in media library
//check if fileurl is a video ??
var fName = jQuery(fileurl).attr('href');
ext = fName.split('.').pop().toLowerCase();
var validVideos = [<?php echo "'" . implode("','", explode(' ', $this->validVideos)) . "'"?>];
if(jQuery.inArray(ext, validVideos) == -1){
alert('invalid video file selected');
}else{
jQuery('#wsp_media').val(fName);
jQuery('#preview-wsp-media').html('<img src="<?php bloginfo('url')?>/wp-includes/images/crystal/video.png" style="max-width:30px; max-height:50px"/><input type="button" value="Remove" class="button" onclick="removeUspMedia()"/>');
}
}
tb_remove();
}