wordpress的評論這塊,有人憂愁有人喜,憂愁的是頻繁的廣告好鬧心,喜的各種限制操作已經讓評論很安靜,比如大叔,哈哈,前幾天墨手說奶子的站存在評論XSS漏洞。。。我急忙的說,來試試我的呢,他盡然告訴我,“不行,你的限制太多了”,那么是什么黑科技讓評論如何的安心呢?請進《wordpress垃圾評論的新戰術》,但是,今天說的,是wordpress評論字數限制,從而更加嚴格的規范了評論者的行為!

那么直接上今天的黑科技吧,將下列代碼插入到主題的functions.php內,
wordpress默認評論方式:
- function?set_comments_length($commentdata)?{
- ????$minCommentlength?=?3;??????
- ????$maxCommentlength?=?1000;???
- ????$pointCommentlength?=?mb_strlen($commentdata['comment_content'],'UTF8');????
- ????if?($pointCommentlength?<?$minCommentlength){
- ????????header("Content-type:?text/html;?charset=utf-8");
- ????????wp_die('抱歉,您的評論字數過少,請至少輸入'?.?$minCommentlength?.'個字(目前字數:'.?$pointCommentlength?.'個字)');
- ????????exit;
- ????}
- ????if?($pointCommentlength?>?$maxCommentlength){
- ????????header("Content-type:?text/html;?charset=utf-8");
- ????????wp_die('對不起,您的評論字數過多,請少於'?.?$maxCommentlength?.'個字(目前字數:'.?$pointCommentlength?.'個字)');
- ????????exit;
- ????}
- ????return?$commentdata;
- }
- add_filter('preprocess_comment',?'set_comments_length');
Ajax評論方式:
- function?set_comments_length($commentdata)?{
- ????$minCommentlength?=?3;??????
- ????$maxCommentlength?=?1000;???
- ????$pointCommentlength?=?mb_strlen($commentdata['comment_content'],'UTF8');????
- ????if?($pointCommentlength?<?$minCommentlength){
- ????????err('抱歉,您的評論字數過少,請至少輸入'?.?$minCommentlength?.'個字(目前字數:'.?$pointCommentlength?.'個字)');
- ????????exit;
- ????}
- ????if?($pointCommentlength?>?$maxCommentlength){
- ????????err('對不起,您的評論字數過多,請少於'?.?$maxCommentlength?.'個字(目前字數:'.?$pointCommentlength?.'個字)');
- ????????exit;
- ????}
- ????return?$commentdata;
- }
- add_filter('preprocess_comment',?'set_comments_length');
區分自己的評論方式,然后創作吧,騷年!
支持下吧,好文章、、、、
2015-08-07 上午 11:55