如何在Wordpress中使用媒体上传功能上传视频文件? [英] How to upload video file using media upload in wordpress?

查看:561
本文介绍了如何在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中使用媒体上传功能上传视频文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆