Anti-spam - Version 1.3

Version Description

  • 2013-04-10 =
  • changing the input names and add some more traps because some spammers are passing the plugin
Download this release

Release Info

Developer webvitaly
Plugin Icon 128x128 Anti-spam
Version 1.3
Comparing to
See all releases

Version 1.3

Files changed (3) hide show
  1. anti-spam.php +118 -0
  2. js/anti-spam.js +11 -0
  3. readme.txt +73 -0
anti-spam.php ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Anti-spam
4
+ Plugin URI: http://wordpress.org/extend/plugins/anti-spam/
5
+ Description: No spam in comments. No captcha.
6
+ Version: 1.3
7
+ Author: webvitaly
8
+ Author URI: http://web-profile.com.ua/wordpress/plugins/
9
+ License: GPLv2 or later
10
+ */
11
+
12
+ $antispam_unqprfx_send_spam_comment_to_admin = false; // if true, than rejected spam comments will be sent to admin email
13
+
14
+ $antispam_unqprfx_version = '1.3';
15
+
16
+
17
+ function antispam_unqprfx_scripts_styles_init() {
18
+ global $antispam_unqprfx_version;
19
+ if ( !is_admin() ) { // && is_singular() && comments_open() && get_option( 'thread_comments' )
20
+ //wp_enqueue_script('jquery');
21
+ wp_enqueue_script( 'anti-spam-script', plugins_url( '/js/anti-spam.js', __FILE__ ), array('jquery'), $antispam_unqprfx_version );
22
+ }
23
+ }
24
+ add_action('init', 'antispam_unqprfx_scripts_styles_init');
25
+
26
+
27
+ function antispam_unqprfx_form_part() {
28
+ $antispam_unqprfx_form_part = '
29
+ <p class="comment-form-anti-spam" style="clear:both;">
30
+ <label for="anti-spam-q">Current <span style="display:none;">month</span> <span style="display:inline;">ye@r</span> <span style="display:none;">day</span></label> <span class="required">*</span>
31
+ <input type="hidden" name="anti-spam-a" id="anti-spam-a" value="'.date('Y').'" />
32
+ <input type="text" name="anti-spam-q" id="anti-spam-q" size="30" value="1980" />
33
+ </p>
34
+ '; // question (hidden with js) [aria-required="true" required="required"]
35
+ $antispam_unqprfx_form_part .= '
36
+ <p class="comment-form-anti-spam-2" style="display:none;">
37
+ <label for="anti-spam-e">Leave this field empty</label> <span class="required">*</span>
38
+ <input type="text" name="anti-spam-e" id="anti-spam-e" size="30" value=""/>
39
+ </p>
40
+ '; // empty field (hidden with css)
41
+ echo $antispam_unqprfx_form_part;
42
+ }
43
+ add_action( 'comment_form', 'antispam_unqprfx_form_part' ); // add anti-spam input to the comment form
44
+
45
+
46
+ function antispam_unqprfx_check_comment( $commentdata ) {
47
+ global $antispam_unqprfx_send_spam_comment_to_admin;
48
+ extract( $commentdata );
49
+ $antispam_unqprfx_pre_error_message = '<strong><a href="javascript:window.history.back()">Go back</a></strong> and try again.';
50
+ $antispam_unqprfx_error_message = '';
51
+ if( !is_user_logged_in() && $comment_type != 'pingback' && $comment_type != 'trackback' /* && !current_user_can( 'publish_posts' ) */ ) { // logged in user is not a spammer
52
+ $error_flag = false;
53
+
54
+ if ( trim( $_POST['anti-spam-q'] ) != date('Y') ) { // answer is wrong - maybe spam
55
+ $error_flag = true;
56
+ if ( empty( $_POST['anti-spam-q'] ) ) { // empty answer - maybe spam
57
+ $antispam_unqprfx_error_message .= '<br> Error: empty answer. ';
58
+ }else{
59
+ $antispam_unqprfx_error_message .= '<br> Error: answer is wrong. ';
60
+ }
61
+ }
62
+ if ( ! empty( $_POST['anti-spam-e'] ) ) { // field is not empty - maybe spam
63
+ $error_flag = true;
64
+ $antispam_unqprfx_error_message .= '<br> Error: field should be empty. ';
65
+ }
66
+ if( $error_flag ){ // if we have an error
67
+ if ( $antispam_unqprfx_send_spam_comment_to_admin ) { // if sending email to admin is enabled
68
+ $post = get_post($comment->comment_post_ID);
69
+
70
+ $antispam_unqprfx_admin_email = get_option('admin_email'); // admin email
71
+ $antispam_unqprfx_subject = 'Spam comment on site "'.get_bloginfo('name').'" '; // email subject
72
+ $antispam_unqprfx_message = 'Spam comment on "'.$post->post_title.'"' . "\r\n";
73
+ $antispam_unqprfx_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
74
+
75
+ $antispam_unqprfx_message .= 'IP : ' . $_SERVER['REMOTE_ADDR'] . "\r\n";
76
+ $antispam_unqprfx_message .= 'User agent : ' . $_SERVER['HTTP_USER_AGENT'] . "\r\n";
77
+ $antispam_unqprfx_message .= 'Referer : ' . $_SERVER['HTTP_REFERER'] . "\r\n\r\n";
78
+
79
+ $antispam_unqprfx_message .= 'Errors: ' . $antispam_unqprfx_error_message . "\r\n\r\n";
80
+
81
+ $antispam_unqprfx_message .= 'Post vars:'."\r\n"; // lets see what post vars spammers try to submit
82
+ foreach ($_POST as $key => $value) {
83
+ $antispam_unqprfx_message .= '$_POST['.$key. '] = '.$value."\r\n"; // .chr(13).chr(10)
84
+ }
85
+ $antispam_unqprfx_message .= "\r\n\r\n";
86
+
87
+ $antispam_unqprfx_message .= 'Cookie vars:'."\r\n"; // lets see what cookie vars spammers try to submit
88
+ foreach ($_COOKIE as $key => $value) {
89
+ $antispam_unqprfx_message .= '$_COOKIE['.$key. '] = '.$value."\r\n"; // .chr(13).chr(10)
90
+ }
91
+ $antispam_unqprfx_message .= "\r\n\r\n";
92
+
93
+ $antispam_unqprfx_message .= '-----------------------------'."\r\n";
94
+ $antispam_unqprfx_message .= 'This is spam comment rejected by Anti-spam plugin. wordpress.org/extend/plugins/anti-spam/' . "\r\n";
95
+ $antispam_unqprfx_message .= 'You may edit "anti-spam.php" file and disable this notification.' . "\r\n";
96
+ $antispam_unqprfx_message .= 'You should find "$antispam_unqprfx_send_spam_comment_to_admin" and make it equal to "false".' . "\r\n";
97
+
98
+ @wp_mail( $antispam_unqprfx_admin_email, $antispam_unqprfx_subject, $antispam_unqprfx_message ); // send comment to admin email
99
+ }
100
+ wp_die( $antispam_unqprfx_pre_error_message . $antispam_unqprfx_error_message ); // die and show errors
101
+ }
102
+ }
103
+ return $commentdata;
104
+ }
105
+
106
+ if( ! is_admin() ) {
107
+ add_filter( 'preprocess_comment', 'antispam_unqprfx_check_comment', 1 );
108
+ }
109
+
110
+
111
+ function antispam_unqprfx_plugin_meta( $links, $file ) { // add 'Plugin page' and 'Donate' links to plugin meta row
112
+ if ( strpos( $file, 'anti-spam.php' ) !== false ) {
113
+ $links = array_merge( $links, array( '<a href="http://web-profile.com.ua/wordpress/plugins/anti-spam/" title="Plugin page">' . __('Anti-spam') . '</a>' ) );
114
+ $links = array_merge( $links, array( '<a href="http://web-profile.com.ua/donate/" title="Support the development">' . __('Donate') . '</a>' ) );
115
+ }
116
+ return $links;
117
+ }
118
+ add_filter( 'plugin_row_meta', 'antispam_unqprfx_plugin_meta', 10, 2 );
js/anti-spam.js ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Anti-spam plugin
3
+ No spam in comments. No captcha.
4
+ wordpress.org/extend/plugins/anti-spam/
5
+ */
6
+
7
+ jQuery(function($){
8
+ $('.comment-form-anti-spam, .comment-form-anti-spam-2').hide(); // hide inputs from users
9
+ var answer = $('.comment-form-anti-spam input#anti-spam-a').val(); // get answer
10
+ $('.comment-form-anti-spam input#anti-spam-q').val( answer ); // set answer into other input
11
+ });
readme.txt ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Anti-spam ===
2
+ Contributors: webvitaly
3
+ Donate link: http://web-profile.com.ua/donate/
4
+ Tags: spam, spammer, spammers, comment, comments, antispam, anti-spam, block-spam, spamfree, spam-free, spambot, spam-bot, bot
5
+ Requires at least: 3.0
6
+ Tested up to: 3.5.1
7
+ Stable tag: 1.3
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ No spam in comments. No captcha.
12
+
13
+ == Description ==
14
+
15
+ [Anti-spam](http://web-profile.com.ua/wordpress/plugins/anti-spam/ "Plugin page") |
16
+ [Donate](http://web-profile.com.ua/donate/ "Support the development")
17
+
18
+ Anti-spam plugin blocks spam in comments automatically, invisibly for users and for admins.
19
+
20
+ * **no captcha**, because spam is not users' problem
21
+ * **no moderation queues**, because spam is not administrators' problem
22
+ * **no options**, because it is great to forget about spam completely
23
+
24
+ Plugin is easy to use: just install it and it just works.
25
+ Need [more info about the plugin](http://wordpress.org/extend/plugins/anti-spam/faq/)?
26
+
27
+ = Useful plugins: =
28
+ * ["Page-list" - show list of pages with shortcodes](http://wordpress.org/extend/plugins/page-list/ "list of pages with shortcodes")
29
+ * ["Iframe" - embed iframe with shortcode](http://wordpress.org/extend/plugins/iframe/ "embed iframe")
30
+ * ["Filenames to latin" - sanitize filenames to latin during upload](http://wordpress.org/extend/plugins/filenames-to-latin/ "sanitize filenames to latin")
31
+
32
+ == Installation ==
33
+
34
+ 1. install and activate the plugin on the Plugins page
35
+ 2. enjoy life without spam in comments
36
+
37
+ == Frequently Asked Questions ==
38
+
39
+ = How does Anti-spam plugin work? =
40
+
41
+ Two extra hidden fields are added to comments form. First field is the question about the current year. Second field should be empty.
42
+ If the user visits site, than first field is answered automatically with javascript, second field left blank and both fields are hidden by javascript and css and invisible for the user.
43
+ If the spammer tries to submit comment form, he will make a mistake with answer on first field or tries to submit an empty field and spam comment will be automatically rejected.
44
+
45
+ = How to test what spam comments are rejected? =
46
+
47
+ You may enable sending all rejected spam comments to admin email.
48
+ You should edit "anti-spam.php" file and find "$antispam_unqprfx_send_spam_comment_to_admin" and make it "true".
49
+
50
+ = What is the percentage of spam blocked? =
51
+
52
+ Anti-spam plugin blocks about 99.9% of automatic spam messages (sent by spam-bots via post requests).
53
+ But Anti-spam plugin will pass the messages which were submitted by spammers manually via browser. But such messages happens very rarely.
54
+
55
+ = Not enough information about the plugin? =
56
+
57
+ You may check out the [source code of the plugin](http://plugins.trac.wordpress.org/browser/anti-spam/trunk/anti-spam.php).
58
+ The plugin has about 100 lines of code and pretty easy to read. I was trying my best to make plugin's code clean.
59
+ Plugin is small but it makes all the dirty work against spam pretty good. You may give it a try.
60
+
61
+ == Changelog ==
62
+
63
+ = 1.3 - 2013-04-10 =
64
+ * changing the input names and add some more traps because some spammers are passing the plugin
65
+
66
+ = 1.2 - 2012-10-28 =
67
+ * minor changes
68
+
69
+ = 1.1 - 2012-10-14 =
70
+ * sending answer from server to client into hidden field (because client year and server year could mismatch)
71
+
72
+ = 1.0 - 2012-09-06 =
73
+ * initial release