我的插件中有这个jQuery代码,用于显示媒体框,最好是上载图像或从媒体库中选择图像:
(function($){
jQuery(document).ready(function() {
$(\'#upload_image_button\').click(function(e) {
e.preventDefault();
//If the uploader object has already been created, reopen the dialog
if (custom_uploader) {
custom_uploader.open();
return;
}
//Extend the wp.media object
custom_uploader = wp.media.frames.file_frame = wp.media({
title: \'Choose Image\',
button: {
text: \'Choose Image\'
},
multiple: false
});
//When a file is selected, grab the URL and set it as the text field\'s value
custom_uploader.on(\'select\', function() {
attachment = custom_uploader.state().get(\'selection\').first().toJSON();
$(\'#upload_image\').val(attachment.url);
});
//Open the uploader dialog
custom_uploader.open();
});
});
})(jQuery);
e是我的插件选项中与jQuery代码绑定的以下元素:
<input class="nput" id="upload_image" type="text" name="the_box[authorpic]" value="<?php echo $options[\'authorpic\']; ?>" /> <input class="button-primary" id="upload_image_button" type="button" value="Pick From Gallery" />
但现在它不起作用了,我的意思是现在单击或按下按钮时不会发生任何事情,因为它应该像以前一样显示媒体框(我现在使用的是WordPress 3.8.1),并且我确信我加载了jQuery脚本(我测试了它)。
是什么原因导致此操作不再有效?如有任何想法、建议和建议,我们将不胜感激。提前谢谢。