
其实也没必要,我是比较折腾的人,爱折腾
1.首先需要给wordpress评论模板comments.php加上一个上传代码,css自己美化
2.在wordpress functions.php写上函数,处理评论图片的短代码,第二行代码里a链接可以自己处理,我是加了fancybox插件点击放大图片
function boxmoe_comment_upload_img($content) {
$content = preg_replace('/[img=?]*(.*?)([/img)?]/i', '
', $content);
return $content;
}
add_filter('comment_text', 'boxmoe_comment_upload_img');
3.加入js代码json post上传图片
jQuery('#upload_img_api').change(function() {
window.wpActiveEditor = null;
for (var i = 0; i Uploading...');
},
success:function(res){
$('textarea[name="comment"]').val($('textarea[name="comment"]').val()+'[img]'+res.data.url+'[/img]').focus();
jQuery("#upload_img_label").html(' 上传成功,继续上传');
},
error: function (){
jQuery("#upload_img_label").html(' 上传失败,重新上传');
}
});
}
});
到处就结束了,这里需要你自己去美化CSS,和自己安排上wordpress评论传按钮的位置
文章来源于互联网:给wordpress的评论加上图片上传按钮并用图床api上传




