Version Description
- 2013-04-13 =
- code refactor
- renaming empty field to "*-email-url" to trap more spam
Download this release
Release Info
Developer | webvitaly |
Plugin | Anti-spam |
Version | 1.4 |
Comparing to | |
See all releases |
Code changes from version 1.0 to 1.4
- anti-spam.php +102 -85
- js/anti-spam.js +8 -3
- readme.txt +50 -14
anti-spam.php
CHANGED
@@ -1,118 +1,135 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Anti-spam
|
4 |
-
Plugin URI: http://
|
5 |
-
Description: No spam in comments. No captcha.
|
6 |
-
Version: 1.
|
7 |
Author: webvitaly
|
8 |
-
Author URI: http://web-profile.com.ua/wordpress/
|
|
|
9 |
*/
|
10 |
|
11 |
-
|
12 |
-
to do list:
|
13 |
-
- show spam counter in admin section
|
14 |
-
- include js only on singular pages with comments enabled
|
15 |
-
- block spam in trackbacks and pingbacks
|
16 |
-
- add options page
|
17 |
-
*/
|
18 |
-
|
19 |
-
$antispam_unqprfx_send_spam_comment_to_admin = false; // if true, than rejected spam comments will be sent to admin email
|
20 |
|
21 |
-
$
|
22 |
|
23 |
|
24 |
-
|
25 |
-
|
|
|
26 |
if ( !is_admin() ) { // && is_singular() && comments_open() && get_option( 'thread_comments' )
|
27 |
//wp_enqueue_script('jquery');
|
28 |
-
wp_enqueue_script( 'anti-spam-script', plugins_url( '/js/anti-spam.js', __FILE__ ), array('jquery'), $
|
29 |
}
|
30 |
}
|
31 |
-
add_action('init', '
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
<
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
48 |
}
|
49 |
-
add_action( 'comment_form', '
|
|
|
50 |
|
51 |
|
52 |
-
|
53 |
-
|
|
|
54 |
extract( $commentdata );
|
55 |
-
|
56 |
-
$
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
66 |
}
|
67 |
}
|
68 |
-
if ( !empty( $_POST['anti-spam-
|
69 |
-
$
|
70 |
-
$
|
71 |
}
|
72 |
-
if( $
|
73 |
-
if ( $
|
74 |
-
$
|
75 |
-
|
76 |
-
$
|
77 |
-
$
|
78 |
-
$
|
79 |
-
$
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
$
|
86 |
-
|
87 |
-
$
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
$antispam_unqprfx_message .= 'Post vars:'."\r\n"; // lets see what post vars spammers try to submit
|
92 |
-
foreach ($_POST as $key => $value) {
|
93 |
-
$antispam_unqprfx_message .= '$_POST['.$key. '] = '.$value."\r\n"; // .chr(13).chr(10)
|
94 |
}
|
95 |
-
$
|
96 |
|
97 |
-
$
|
98 |
-
foreach ($_COOKIE as $key => $value) {
|
99 |
-
$
|
100 |
}
|
101 |
-
$
|
102 |
|
103 |
-
$
|
104 |
-
$
|
105 |
-
$
|
106 |
-
$
|
107 |
|
108 |
-
@wp_mail( $
|
109 |
}
|
110 |
-
wp_die( $
|
111 |
}
|
112 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
return $commentdata;
|
114 |
}
|
115 |
|
116 |
if( ! is_admin() ) {
|
117 |
-
add_filter( 'preprocess_comment', '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.4
|
7 |
Author: webvitaly
|
8 |
+
Author URI: http://web-profile.com.ua/wordpress/plugins/
|
9 |
+
License: GPLv2 or later
|
10 |
*/
|
11 |
|
12 |
+
$antispam_send_spam_comment_to_admin = false; // if true, than rejected spam comments will be sent to admin email
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
$antispam_version = '1.4';
|
15 |
|
16 |
|
17 |
+
if ( ! function_exists( 'antispam_scripts_styles_init' ) ) :
|
18 |
+
function antispam_scripts_styles_init() {
|
19 |
+
global $antispam_version;
|
20 |
if ( !is_admin() ) { // && is_singular() && comments_open() && get_option( 'thread_comments' )
|
21 |
//wp_enqueue_script('jquery');
|
22 |
+
wp_enqueue_script( 'anti-spam-script', plugins_url( '/js/anti-spam.js', __FILE__ ), array( 'jquery' ), $antispam_version );
|
23 |
}
|
24 |
}
|
25 |
+
add_action('init', 'antispam_scripts_styles_init');
|
26 |
+
endif; // end of antispam_scripts_styles_init()
|
27 |
+
|
28 |
+
|
29 |
+
if ( ! function_exists( 'antispam_form_part' ) ) :
|
30 |
+
function antispam_form_part() {
|
31 |
+
if ( ! is_user_logged_in() ) { // add anti-spam fields only for not logged in users
|
32 |
+
$antispam_form_part = '
|
33 |
+
<p class="comment-form-anti-spam" style="clear:both;">
|
34 |
+
<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>
|
35 |
+
<input type="hidden" name="anti-spam-a" id="anti-spam-a" value="'.date('Y').'" />
|
36 |
+
<input type="text" name="anti-spam-q" id="anti-spam-q" size="30" value="1980" />
|
37 |
+
</p>
|
38 |
+
'; // question (hidden with js) [aria-required="true" required="required"]
|
39 |
+
$antispam_form_part .= '
|
40 |
+
<p class="comment-form-anti-spam-2" style="display:none;">
|
41 |
+
<label for="anti-spam-e-email-url">Leave this field empty</label> <span class="required">*</span>
|
42 |
+
<input type="text" name="anti-spam-e-email-url" id="anti-spam-e-email-url" size="30" value=""/>
|
43 |
+
</p>
|
44 |
+
'; // empty field (hidden with css)
|
45 |
+
echo $antispam_form_part;
|
46 |
+
}
|
47 |
}
|
48 |
+
add_action( 'comment_form', 'antispam_form_part' ); // add anti-spam input to the comment form
|
49 |
+
endif; // end of antispam_form_part()
|
50 |
|
51 |
|
52 |
+
if ( ! function_exists( 'antispam_check_comment' ) ) :
|
53 |
+
function antispam_check_comment( $commentdata ) {
|
54 |
+
global $antispam_send_spam_comment_to_admin;
|
55 |
extract( $commentdata );
|
56 |
+
|
57 |
+
$antispam_pre_error_message = '<strong><a href="javascript:window.history.back()">Go back</a></strong> and try again.';
|
58 |
+
$antispam_error_message = '';
|
59 |
+
if ( ! is_user_logged_in() && $comment_type != 'pingback' && $comment_type != 'trackback' ) { // logged in user is not a spammer
|
60 |
+
$spam_flag = false;
|
61 |
+
|
62 |
+
if ( trim( $_POST['anti-spam-q'] ) != date('Y') ) { // answer is wrong - maybe spam
|
63 |
+
$spam_flag = true;
|
64 |
+
if ( empty( $_POST['anti-spam-q'] ) ) { // empty answer - maybe spam
|
65 |
+
$antispam_error_message .= '<br> Error: empty answer. ';
|
66 |
+
} else {
|
67 |
+
$antispam_error_message .= '<br> Error: answer is wrong. ';
|
68 |
}
|
69 |
}
|
70 |
+
if ( ! empty( $_POST['anti-spam-e-email-url'] ) ) { // field is not empty - maybe spam
|
71 |
+
$spam_flag = true;
|
72 |
+
$antispam_error_message .= '<br> Error: field should be empty. ';
|
73 |
}
|
74 |
+
if ( $spam_flag ) { // if we have spam
|
75 |
+
if ( $antispam_send_spam_comment_to_admin ) { // if sending email to admin is enabled
|
76 |
+
$post = get_post( $comment->comment_post_ID );
|
77 |
+
|
78 |
+
$antispam_admin_email = get_option('admin_email'); // admin email
|
79 |
+
$antispam_subject = 'Spam comment on site "'.get_bloginfo( 'name' ).'" '; // email subject
|
80 |
+
$antispam_message = 'Spam comment on "'.$post->post_title.'"' . "\r\n";
|
81 |
+
$antispam_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n";
|
82 |
+
|
83 |
+
$antispam_message .= 'IP : ' . $_SERVER['REMOTE_ADDR'] . "\r\n";
|
84 |
+
$antispam_message .= 'User agent : ' . $_SERVER['HTTP_USER_AGENT'] . "\r\n";
|
85 |
+
$antispam_message .= 'Referer : ' . $_SERVER['HTTP_REFERER'] . "\r\n\r\n";
|
86 |
+
|
87 |
+
$antispam_message .= 'Errors: ' . $antispam_error_message . "\r\n\r\n";
|
88 |
+
|
89 |
+
$antispam_message .= 'Post vars:'."\r\n"; // lets see what post vars spammers try to submit
|
90 |
+
foreach ( $_POST as $key => $value ) {
|
91 |
+
$antispam_message .= '$_POST['.$key. '] = '.$value."\r\n"; // .chr(13).chr(10)
|
|
|
|
|
|
|
|
|
92 |
}
|
93 |
+
$antispam_message .= "\r\n\r\n";
|
94 |
|
95 |
+
$antispam_message .= 'Cookie vars:'."\r\n"; // lets see what cookie vars spammers try to submit
|
96 |
+
foreach ( $_COOKIE as $key => $value ) {
|
97 |
+
$antispam_message .= '$_COOKIE['.$key. '] = '.$value."\r\n"; // .chr(13).chr(10)
|
98 |
}
|
99 |
+
$antispam_message .= "\r\n\r\n";
|
100 |
|
101 |
+
$antispam_message .= '-----------------------------'."\r\n";
|
102 |
+
$antispam_message .= 'This is spam comment rejected by Anti-spam plugin. wordpress.org/extend/plugins/anti-spam/' . "\r\n";
|
103 |
+
$antispam_message .= 'You may edit "anti-spam.php" file and disable this notification.' . "\r\n";
|
104 |
+
$antispam_message .= 'You should find "$antispam_send_spam_comment_to_admin" and make it equal to "false".' . "\r\n";
|
105 |
|
106 |
+
@wp_mail( $antispam_admin_email, $antispam_subject, $antispam_message ); // send spam comment to admin email
|
107 |
}
|
108 |
+
wp_die( $antispam_pre_error_message . $antispam_error_message ); // die - do not send comment and show errors
|
109 |
}
|
110 |
}
|
111 |
+
|
112 |
+
//if ( $comment_type == 'trackback' || $comment_type == 'pingback' ) { // check spam in trackbacks - http://web-profile.com.ua/web/trackback-vs-pingback/
|
113 |
+
// $debug_message = print_r( $commentdata, true );
|
114 |
+
// @wp_mail( 'vitalymylo@gmail.com', 'antispam trackback debug info', $debug_message ); // debug info
|
115 |
+
//}
|
116 |
+
|
117 |
return $commentdata;
|
118 |
}
|
119 |
|
120 |
if( ! is_admin() ) {
|
121 |
+
add_filter( 'preprocess_comment', 'antispam_check_comment', 1 );
|
122 |
+
}
|
123 |
+
endif; // end of antispam_check_comment()
|
124 |
+
|
125 |
+
|
126 |
+
if ( ! function_exists( 'antispam_plugin_meta' ) ) :
|
127 |
+
function antispam_plugin_meta( $links, $file ) { // add 'Plugin page' and 'Donate' links to plugin meta row
|
128 |
+
if ( strpos( $file, 'anti-spam.php' ) !== false ) {
|
129 |
+
$links = array_merge( $links, array( '<a href="http://web-profile.com.ua/wordpress/plugins/anti-spam/" title="Plugin page">' . __('Anti-spam') . '</a>' ) );
|
130 |
+
$links = array_merge( $links, array( '<a href="http://web-profile.com.ua/donate/" title="Support the development">' . __('Donate') . '</a>' ) );
|
131 |
+
}
|
132 |
+
return $links;
|
133 |
}
|
134 |
+
add_filter( 'plugin_row_meta', 'antispam_plugin_meta', 10, 2 );
|
135 |
+
endif; // end of antispam_plugin_meta()
|
js/anti-spam.js
CHANGED
@@ -1,6 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
jQuery(function($){
|
2 |
$('.comment-form-anti-spam, .comment-form-anti-spam-2').hide(); // hide inputs from users
|
3 |
-
var
|
4 |
-
|
5 |
-
$('.comment-form-anti-spam input').val(year); // automatically fill answer with javascript
|
6 |
});
|
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
CHANGED
@@ -1,26 +1,33 @@
|
|
1 |
=== Anti-spam ===
|
2 |
Contributors: webvitaly
|
3 |
Donate link: http://web-profile.com.ua/donate/
|
4 |
-
Tags: spam, spammer, spammers, comment, comments
|
5 |
Requires at least: 3.0
|
6 |
-
Tested up to: 3.
|
7 |
-
Stable tag: 1.
|
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 |
-
|
16 |
-
|
17 |
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
= Useful plugins: =
|
21 |
* ["Page-list" - show list of pages with shortcodes](http://wordpress.org/extend/plugins/page-list/ "list of pages with shortcodes")
|
22 |
* ["Iframe" - embed iframe with shortcode](http://wordpress.org/extend/plugins/iframe/ "embed iframe")
|
23 |
-
* ["
|
24 |
|
25 |
== Installation ==
|
26 |
|
@@ -29,18 +36,47 @@ So Anti-spam plugin will block spam automatically without moderation and silentl
|
|
29 |
|
30 |
== Frequently Asked Questions ==
|
31 |
|
32 |
-
= How does
|
33 |
|
34 |
-
Two extra fields are added to comments form. First is the question about the current year. Second should be empty.
|
35 |
-
If the user visits site, than first field is answered automatically with javascript, second field left blank and both fields are hidden and invisible for the user.
|
36 |
-
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 rejected.
|
37 |
|
38 |
= How to test what spam comments are rejected? =
|
39 |
|
40 |
You may enable sending all rejected spam comments to admin email.
|
41 |
-
You should edit "anti-spam.php" file and find "$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
== Changelog ==
|
44 |
|
45 |
-
= 1.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
* initial release
|
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.4
|
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 |
|
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_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 |
+
= How to reduce the amount of spam? =
|
62 |
+
Do not order spam-newsletters because people hate spam and people will not like products received from spam.
|
63 |
+
Do not order products from spam. If spam will be less effective than spammers will stop sending it.
|
64 |
+
|
65 |
|
66 |
== Changelog ==
|
67 |
|
68 |
+
= 1.4 - 2013-04-13 =
|
69 |
+
* code refactor
|
70 |
+
* renaming empty field to "*-email-url" to trap more spam
|
71 |
+
|
72 |
+
= 1.3 - 2013-04-10 =
|
73 |
+
* changing the input names and add some more traps because some spammers are passing the plugin
|
74 |
+
|
75 |
+
= 1.2 - 2012-10-28 =
|
76 |
+
* minor changes
|
77 |
+
|
78 |
+
= 1.1 - 2012-10-14 =
|
79 |
+
* sending answer from server to client into hidden field (because client year and server year could mismatch)
|
80 |
+
|
81 |
+
= 1.0 - 2012-09-06 =
|
82 |
* initial release
|