2012-01-19 3 views
1

나는 Wordpress에서 배너를 업로드하는 데 사용되는 게시 유형이 있습니다. 이름, 이미지/비디오 및 URL에 사용자 정의 필드 사용. 기본 미디어 업로드는 이미지/비디오를 업로드하는 데는 잘 작동하지만 내 문제는 사용자 정의 필드에 비디오 기본 URL을 가져올 수 없다는 것입니다.wordpress에서 미디어 업로드를 사용하여 비디오 파일을 업로드하는 방법은 무엇입니까?

여기에 비디오 URL을 가져올 수없는 코드가 있습니다. 그것은 단지 나에게 비디오 파일 이름을 준다.

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

} 

답변

1

직접 해결책을 찾았습니다.

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

출력 HTML에서 비디오 URL을 추가 "media_send_to_editor"에 필터를 추가

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); 
     ....... 
     ....... 
    } 
같은 미디어 URL
관련 문제