How to upload video file using media upload in wordpress?

前端 未结 1 1438
难免孤独
难免孤独 2021-01-15 16:43

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/video

相关标签:
1条回答
  • 2021-01-15 17:04

    I have found the solution myself.

    Add a filter in "media_send_to_editor"

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

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

    Get the media url like this

    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);
            .......
            .......
        }
    
    0 讨论(0)
提交回复
热议问题