2014-10-19 1 views
0

을 포함하여 문제 WordPress 기능을 활용하는 사용자 정의 인터페이스를 만들고 있으며 활용하려는 특정 영역은 WordPress의 미디어 섹션입니다. 내가 먼저 워드 프레스의 핵심 파일을 포함하고있다 : 내가 사용하고 내 미디어 파일 내에서보다wp_enqueue_media - WordPress

$location = $_SERVER['DOCUMENT_ROOT'] . "/wordpress"; 

include($location.'/wp-config.php'); 
include($location.'/wp-load.php'); 
include($location.'/wp-includes/pluggable.php'); 
global $wpdb; 
if(!isset($wpdb)) 
{ 
    include($location.'/wp-config.php'); 
    include($location.'/wp-includes/wp-db.php'); 
} 

: wp_enqueue_media() 날은 사용자가 자신의 계정에서 미디어를 업로드 할 때의 미디어 뷰어에 액세스 할 수 있도록.

내 나는 다음과 같은 요청이있는 미디어를 실행하는 데 사용하고 JS 스크립트 다음 add-media 이벤트를 실행할 때

여기 IS
$('.add-media').on('click', function(event){ 
    var file_frame; 
    var wp_media_post_id = wp.media.model.settings.post.id; // Store the old id 
    event.preventDefault(); 

    // If the media frame already exists, reopen it. 
    if (file_frame) { 
     file_frame.open(); 
     return; 
    } 

    // Create the media frame. 
    file_frame = wp.media.frames.file_frame = wp.media({ 
     title: jQuery(this).data('uploader_title'), 
     button: { 
     text: jQuery(this).data('uploader_button_text'), 
     }, 
     multiple: true // Set to true to allow multiple files to be selected 
    }); 

    // When an image is selected, run a callback. 
    file_frame.on('select', function() { 

     var selection = file_frame.state().get('selection'); 

     selection.map(function(attachment) { 

      attachment = attachment.toJSON(); 
      // Do something with attachment.id and/or attachment.url here 

      $(".load-attachments").append('<div class="singleImg"><a href="'+attachment.url+'" class="shadowbox"><img src="'+attachment.url+'" width="100px" height="100px"/></a><input type="hidden" class="fileURL load-single-attachment" value="'+attachment.id+'"/><span class="removeImg remove"> X </span></div>'); 
      $(".removeImg").bind('click', function(){ 
      $(this).parent().remove(); 
      }); 

     }); 

    }); 

    // Finally, open the modal 
    file_frame.open(); 
}); 

문제, wp가 정의되어 있지 않습니다. 이제는 왜 그런지 확신 할 수 없습니다. 어떤 생각이나 제안?

답변

0

문서를 살펴본 후 왜 이런 일이 발생했는지 알 수 없었습니다. 하지만 그 해결책을 찾았습니다. wp_footer()을 사용할 때 일부 최종 파일이 호출됩니다. 그리고 이것 없이는 JavaScript 파일이 실행되지 않습니다.

그래서 당신은 응용 프로그램을 개발하고 워드 프레스의 핵심 기능을 사용하려면 미래에 당신이 js에 정의되지 wp으로 실행되지 않습니다 확인하기 위해 응용 프로그램의 마지막에 wp_footer()를 포함 할 수 있는지 확인하십시오.

관련 문제