不堪垃圾评论.新增图形验证码插件 wp-imgcode

插件下载地址:http://blog.chweng.idv.tw/wordpress/wp-imgcode-mod/

安装并进入后台启用插件

修改模板 comments.php

  1. <!--<p><textarea name="comment" id="comment" cols="60%" rows="10" tabindex="4"></textarea></p>
  2. <p><input name="submit" class="s" type="submit" id="submit"  tabindex="5" value="发表留言" />
  3. <input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
  4. </p>
  5. <?php do_action('comment_form', $post->ID); ?>-->
  6.  
  7.  
  8. <p><textarea name='comment' id='comment' cols='60%' rows='10' tabindex='5'></textarea></p>
  9. <?php do_action('comment_form', $post->ID); ?>
  10. <p><input name='submit' type='submit' class="s" id='submit' tabindex='5' value='发表留言' />
  11. <input type='hidden' name='comment_post_ID' value='<?php echo $id; ?>' />
  12. </p>

NOTE:注释部分为原有的模板部分

装上后不太好看..改改吧

打开插件文件 wp-imgcode.php

修改 wp_imgcode 类

修改后的代码如下:
(新增点击刷新验证码.错误页面显示..)

  1. class wp_imgcode
  2. {
  3.     var $version = '1.0.0';
  4.     var $plugin_dir = '/wp-content/plugins/wp-imgcode';
  5.  
  6.     function wp_imgcode() {
  7.         @session_start();
  8.         add_action('comment_form', array(& $this, 'edit_comment_blog'));
  9.         add_filter('preprocess_comment', array(& $this, 'preprocess_comment'));
  10.     }
  11.  
  12.     function edit_comment_blog() {
  13.         echo <<<END
  14. <p style="margin:12px 0;">验证码:<input type="text" name="imgcode" class='c' id="imgcode" size="6" tabindex="4" /> <img src="{$this->plugin_dir}/imgcode.php" id="codeimg" style="vertical-align:middle;margin-right:12px;" /><a href="" onclick='getimgcode();return false;'>验证码看不清发泄点这里</a></p>
  15. <p>&nbsp;</p>
  16. <script type="text/javascript">
  17. function getimgcode()
  18. {
  19.     var randomnum = Math.random();
  20.     var getimagecode = document.getElementById("codeimg");
  21.     getimagecode.src = "{$this->plugin_dir}/imgcode.php?"+randomnum;
  22. }
  23. </script>
  24. END;
  25.     }
  26.  
  27.     function preprocess_comment($commentdata) {
  28.         if ($_POST['imgcode'] != $_SESSION['IMGCODE'] || time() >= $_SESSION['IMGCODE_EXPIRED']) {
  29.             wp_die( __('Error: please enter a valid imgcode.') );
  30.         }
  31.         unset($_SESSION['IMGCODE']);
  32.         unset($_SESSION['IMGCODE_EXPIRED']);
  33.         return $commentdata;
  34.     }
  35. }

1 条评论

  1. seo

    谢谢,收下了

发表评论

验证码: 验证码看不清发泄点这里

 

浏览最多的10篇日志

评论最多的10篇日志

随机显示的10篇日志