0
我正在構建一個自定義界面,利用WordPress的功能和我試圖利用的特定領域是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').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();
});
問題這裏,運行add-media
事件時,wp
是不確定的。現在我不確定這是爲什麼。任何想法或建議?