我已经将媒体上传器添加到我们的插件中,但不知怎么的,它正在创建多个实例。模型创建两次。一个是配置,另一个是默认实例。我不知道这是从哪里煽动出来的。这是我的JS:
/**
* Load media uploader on pages with our custom metabox
*/
jQuery(document).ready(function($){
\'use strict\';
var file_frame = null;
function showMediaUploader(e) {
var self = this;
var title = ( $(self).attr(\'id\') == \'listListingImages\' ) ? \'Select Multiple Images\' : \'Select Image\';
var text = ( $(self).attr(\'id\') == \'listListingImages\' ) ? \'Add Images\' : \'Add Image\';
// If the media frame already exists, reopen it.
if ( file_frame ) {
file_frame.open();
return;
}
// Create the media frame, if applicable.
if (!file_frame) {
file_frame = wp.media.frames.file_frame = wp.media({
title: title, // Translated string
button: {
text: text //Translated string
},
multiple: false
});
file_frame.off("select");
file_frame.on("select", function() {
setCustomImage(self);
});
file_frame.open();
}
}
function setCustomImage(btn) {
var attachment = file_frame.state().get("selection").first().toJSON();
$(btn).prev().val(attachment.url);
}
$(".wp-upload-button").on("click", showMediaUploader);
});
这是HTML
echo \'<input type="text" name="\'. $this->element_name() .\'" id="listListingImages" value="\'. $this->element_value() .\'">\';
echo \'<a href="#" class="button button-primary exopite-sof-button wp-upload-button" id="listListingImages" data-media-uploader-target="#listListingImages">\'. $add .\'</a>\';
查看此gif中的错误
如果这不是我的代码中的错误,而是来自其他地方的媒体上传程序的另一个实例,那么我应该如何确定它在哪里?