Jquery 如何在wordpress中使用媒体上传上传上传视频文件?
我有一个帖子类型,用于在wordpress中上传横幅。为名称、图像/视频和url使用自定义字段。默认的媒体上传可以很好地上传图像/视频,但我的问题是我无法将视频基url获取到自定义字段 这是我无法获取视频url的代码。它只给我视频文件名Jquery 如何在wordpress中使用媒体上传上传上传视频文件?,jquery,wordpress,Jquery,Wordpress,我有一个帖子类型,用于在wordpress中上传横幅。为名称、图像/视频和url使用自定义字段。默认的媒体上传可以很好地上传图像/视频,但我的问题是我无法将视频基url获取到自定义字段 这是我无法获取视频url的代码。它只给我视频文件名 window.send_to_editor = function(html) { var imgurlar = html.match(/<img[^>]+src=\"([^\"]+)\"/); var imgurl = imgurl
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();
}
window.send\u to\u editor=函数(html){
var imgurlar=html.match(/);
}
//录像带
否则{
var fileurl=jQuery(html);
//若我点击媒体库中的“无”按钮,上面的“html”只包含视频名称
//检查fileurl是否为视频??
var fName=jQuery(fileurl).attr('href');
ext=fName.split('.').pop().toLowerCase();
var validVideos=[我自己找到了解决方案
在“媒体发送到编辑器”中添加过滤器
在输出html中附加视频url
function media_editor($html, $send_id, $attachment ){
//get the media's guid and append it to the html
$post = get_post($send_id);
$html .= '<media>'.$post->guid.'</media>';
return $html;
}
函数媒体编辑器($html、$send\u id、$attachment){
//获取媒体的guid并将其附加到html
$post=获取发布($send\u id);
$html.=''.$post->guid';
返回$html;
}
像这样获取媒体url
window.send_to_editor = function(html) {
.......
.......
var pathArray = html.match(/<media>(.*)<\/media>/);
var mediaUrl = pathArray != null && typeof pathArray[1] != 'undefined' ? pathArray[1] : '';
jQuery('#wsp_media').val(mediaUrl);
.......
.......
}
window.send\u to\u editor=函数(html){
.......
.......
var pathArray=html.match(/(.*)/);
var mediaUrl=pathArray!=null&&typeof pathArray[1]!=“未定义”?pathArray[1]:“”;
jQuery('wsp#u media').val(mediaUrl);
.......
.......
}
window.send_to_editor = function(html) {
.......
.......
var pathArray = html.match(/<media>(.*)<\/media>/);
var mediaUrl = pathArray != null && typeof pathArray[1] != 'undefined' ? pathArray[1] : '';
jQuery('#wsp_media').val(mediaUrl);
.......
.......
}