如何在Wordpress中使用媒体上传功能上传视频文件?

编程入门 行业动态 更新时间:2024-10-06 09:24:17
本文介绍了如何在Wordpress中使用媒体上传功能上传视频文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个帖子类型,用于在wordpress中上传横幅.使用自定义字段输入名称,图像/视频和网址.默认的媒体上传可以很好地上传图像/视频,但是我的问题是我无法将视频基本URL转到自定义字段.

I have a post type which is used to upload banners in wordpress. Using custom fields for name, image/video and url. The default media upload works fine to upload image/videos, but my problem is I cannot get the video base url to the custom field.

这是我的代码,无法获取视频网址.它只给我视频文件名.

Here is my code that is not able to get the video url. It only gives me video file name.

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(); }

推荐答案

我自己找到了解决方案.

I have found the solution myself.

在"media_send_to_editor"中添加过滤器

Add a filter in "media_send_to_editor"

add_filter('media_send_to_editor', 'media_editor', 1, 3);

在输出html中添加视频网址

Append the video url in output html

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; }

像这样获取媒体网址

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); ....... ....... }

更多推荐

如何在Wordpress中使用媒体上传功能上传视频文件?

本文发布于:2023-11-26 18:53:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634773.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上传   视频文件   功能   媒体   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!