1 图形验证码

下载连接:wp-imgcode.zip

安装方法:

下载后解压缩到 的 /wp-content/plugins/ 目录中。然后在 后台启用该插件。

wp_imgcode_01.png

接下来修改当前使用主题的评论模版(comments.php),将

<p><textarea name=”comment” id=”comment” cols=”100%” rows=”10″ tabindex=”5″></textarea></p><p><input name=”submit” type=”submit” id=”submit” tabindex=”5″ value=”Submit Comment” />
<input type=”hidden” name=”comment_post_ID” value=”<?php echo $id; ?>” />
</p>

<?php do_action(’comment_form’, $post->ID); ?>

</form>

改为

<p><textarea name=”comment” id=”comment” cols=”100%” rows=”10″ tabindex=”5″></textarea></p><?php do_action(’comment_form’, $post->ID); ?>

<p><input name=”submit” type=”submit” id=”submit” tabindex=”5″ value=”Submit Comment” />
<input type=”hidden” name=”comment_post_ID” value=”<?php echo $id; ?>” />
</p>

</form>

也就是修改 do_action 代码的位置。

保存模版后,刷新页面就能看到验证码了。

wp_imgcode_02.png

此插件出处:http://www.dualface.com/blog/?p=194

2 Peter’s Custom Anti-Spam Image Plugin

目前的版本是V2.1,可以自定义图片大小(修改$cas_imgwidth、$cas_imgheight值)和图片文字(修改$cas_text[])内容。前提是你的系统必须支持imagettftext函数,不过一般安装GD库的都没问题。

安装很简单,下载v2.1版本,解压缩到“\wp-content\plugins”目录,三个字体文件也放在custom-anti-spam目录下,在后台插件启用之后,就可使用了。已经注册或留言的用户不会看到这个验证码,只有游客才需要输入验证码。

世事并非一帆风顺,我安装之后怎么都不显示,使用下列代码检查imagettftext函数,也支持。

<?
$function = “imagettftext”;
if(function_exists($function)) {
print “Yes, the function $function is installed.”;
}
else {
print “Nope, the function $function is not installed.”;
}
?>

折腾了半天,后来才在留言中发现,原来这是Windows系统路径问题:

找到 $abspath = dirname(__FILE__).’/’;

使用以下代码替换:
if (DIRECTORY_SEPARATOR==’/’){
$abspath = dirname(__FILE__).’/’;
}
else{
$abspath = str_replace(’\\’, ‘/’, dirname(__FILE__)).’/’;
}

找到以下代码:

// Determine the url to this script
$tmp1 = strpos( __FILE__, ABSPATH );
$tmp2 = strlen( ABSPATH);
$cas_myurl = get_settings(‘siteurl’) . “/” . substr( __FILE__, $tmp1 + $tmp2 );

用以下代码更换:

$tmpfile=str_replace(’\\’, ‘/’, __FILE__);
$tmp1 = strpos( $tmpfile, ABSPATH );
$tmp2 = strlen( ABSPATH);
$cas_myurl = get_settings(’siteurl’) . “/” . substr( $tmpfile, $tmp1 + $tmp2 );

(注意:实际使用时,将以上的全角引号改为半角引号。)

如此这般后就可以正常使用,以后也可以远离垃圾留言了,推荐wp用户安装。