我已经在我的主题中创建了一个自定义站点选项页面作为顶级管理页面。这些选项非常基本,但包括一些图像。
我最初在选项页面上找到了很多使用Media Uploader上载或选择图像的示例。它很容易实现,工作起来很有魅力,但却产生了严重的不良后果。
尽管我可以调用media uploader模式并将图像添加回我的自定义选项页面,但“插入到帖子”打破了WP的所有其他方面。当我单击“插入帖子”时,所有帖子、自定义帖子和页面都无法再从媒体上传程序返回任何字符串。
我认为这一定与window.send_to_editor
函数,下面是我用来调用媒体上传器的javascript(我在许多网站上都找到了):
jQuery(document).ready(function($) {
$(\'#upload_header_img_button\').click(function() {
formfield = $(\'#header_image\');
tb_show(\'\', \'media-upload.php?type=image&TB_iframe=true\');
return false;
});
$(\'#upload_branding_img_button\').click(function() {
formfield = $(\'#branding_image\');
tb_show(\'\', \'media-upload.php?type=image&TB_iframe=true\');
return false;
});
window.send_to_editor = function(html) {
imgurl = $(html).attr(\'href\');
$(formfield).val(imgurl);
tb_remove();
var img_preview = $(formfield).parent().find(\'img\');
console.log(img_preview);
img_preview.attr(\'src\',imgurl);
}
});
经过大量挖掘(阅读:评论搜索)I found this function 一位读者提供了一个可能的解决方案:https://dpaste.de/T8ji 在我的window.send_to_editor
作用它起到了作用,因为我的所有帖子和页面都恢复了“插入帖子”功能,但现在媒体上传器在我的自定义选项页面上坏了。有人碰到过这个吗?