SidXSpam-sidxspam.php代码详解

sidxspam.php是这个插件的主文件

  1. <?php
  2. /*
  3. Plugin Name: SidXSpam
  4. Version: 1.0
  5. Plugin URI: http://photozero.net
  6. Author: Neekey
  7. Author URI: http://photozero.net
  8. Description: Anti-Spam by check code.
  9. */
  10.  
  11. //获取插件URL
  12. $sxs_dir = get_bloginfo('wpurl').'/wp-content/plugins/sidxspam';
  13.  
  14. //验证码错误时输出信息。
  15. $sxs_lang_error = '
  16. <h1 style="color:red">Error:</h1>
  17. Sorry!Your Check Code is wrong.Please go back and try again!
  18. ';
  19.  
  20. //输入验证码的表格
  21. $sxs_lang_msg = '
  22. <br /><abbr title="Just check you are a person not a robot :)">Check Code</abbr>  <img alt="If you cannot see the CheckCode image,please refresh the page again!" src="'.$sxs_dir.'/image.php" />
  23. <input type="text" name="sxscode" maxlength="4" style="width:60px" title="Type here what you see in the left image" />
  24. ';
  25.  
  26.  
  27. @session_start();
  28.  
  29. //将插件载入WP
  30. add_action('comment_form','show_sxs');
  31. add_filter('preprocess_comment','check_sxs');
  32.  
  33.  
  34. //在回复框处显示验证码
  35. function show_sxs(){
  36.     global $sxs_lang_msg;
  37. echo $sxs_lang_msg;
  38. }
  39.  
  40. //发表评论时确认验证码
  41. function check_sxs($commentdata){
  42. if ($_POST['sxscode'] != $_SESSION['sxscode'] || time() > $_SESSION['sxscode_offtime']) {
  43. unset($_SESSION['sxscode']);unset($_SESSION['sxscode_offtime']);
  44. global $sxs_lang_error;
  45. die(__($sxs_lang_error));
  46. }
  47.     return $commentdata;
  48. }
  49. ?>
该文章发布在 PHP, wordpress。收藏该永久链接

评论功能被关闭。