您可以使用wp_enqueue_media()
在您的admin_enqueue_scripts
钩
在javascript文件中,将其挂接到按钮并使用insert
事件以捕获所选图像的详细信息
$(\'.media-button\').click(function() {
var media_uploader = wp.media({
frame: "post",
text : "Add image",
state: "insert",
multiple: false
});
media_uploader.on("insert", function(){
var json = media_uploader.state().get("selection").first().toJSON();
var image_name = json.filename;
var image_url = json.url;
var image_caption = json.caption;
var image_title = json.title;
});
});