明光正能量 發表於 2023-10-1 00:00:00

wordpress教程防wordpress广告的方法 评论中包含过多链接不可提交

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
写了一年多WordPress,除了感受到它的强大,还有spam… <br>
虽然Akismet阻挡了四五K的spam,但是一条一条审核还是太过麻烦,写个方法来处理一下</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
 </p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span>
</div>
代码如下:</div>
<div id="phpcode1" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
function spamCheck( $incoming_comment ) {<br>
$pattern = '/[一-龥]/u';<br>
if(!preg_match($pattern, $incoming_comment['comment_content'])) {<br>
wp_die( 'You should type some Chinese word!' );<br>
}<br>
if(substr_count($incoming_comment['comment_content'],'http') &gt; 3) {<br>
wp_die( '请勿在您的评论中包含过多链接!' );<br>
}<br>
return( $incoming_comment );<br>
}<br>
add_filter('preprocess_comment', 'spamCheck');</div>
頁: [1]
查看完整版本: wordpress教程防wordpress广告的方法 评论中包含过多链接不可提交