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
是不确定的。现在我不确定这是为什么。任何想法或建议?