sidxspam.php是这个插件的主文件
- <?php
- /*
- Plugin Name: SidXSpam
- Version: 1.0
- Plugin URI: http://photozero.net
- Author: Neekey
- Author URI: http://photozero.net
- Description: Anti-Spam by check code.
- */
- //获取插件URL
- $sxs_dir = get_bloginfo('wpurl').'/wp-content/plugins/sidxspam';
- //验证码错误时输出信息。
- $sxs_lang_error = '
- <h1 style="color:red">Error:</h1>
- Sorry!Your Check Code is wrong.Please go back and try again!
- ';
- //输入验证码的表格
- $sxs_lang_msg = '
- <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" />
- <input type="text" name="sxscode" maxlength="4" style="width:60px" title="Type here what you see in the left image" />
- ';
- @session_start();
- //将插件载入WP
- add_action('comment_form','show_sxs');
- add_filter('preprocess_comment','check_sxs');
- //在回复框处显示验证码
- function show_sxs(){
- global $sxs_lang_msg;
- echo $sxs_lang_msg;
- }
- //发表评论时确认验证码
- function check_sxs($commentdata){
- if ($_POST['sxscode'] != $_SESSION['sxscode'] || time() > $_SESSION['sxscode_offtime']) {
- unset($_SESSION['sxscode']);unset($_SESSION['sxscode_offtime']);
- global $sxs_lang_error;
- die(__($sxs_lang_error));
- }
- return $commentdata;
- }
- ?>