Version Description
- 2012-10-14 =
- sending answer from server to client into hidden field (because client year and server year could mismatch)
Download this release
Release Info
Developer | webvitaly |
Plugin | Anti-spam |
Version | 1.1 |
Comparing to | |
See all releases |
Version 1.1
- anti-spam.php +117 -0
- js/anti-spam.js +7 -0
- readme.txt +49 -0
anti-spam.php
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Anti-spam
|
4 |
+
Plugin URI: http://web-profile.com.ua/wordpress/plugins/anti-spam/
|
5 |
+
Description: No spam in comments. No captcha.
|
6 |
+
Version: 1.1
|
7 |
+
Author: webvitaly
|
8 |
+
Author URI: http://web-profile.com.ua/wordpress/
|
9 |
+
License: GPLv2 or later
|
10 |
+
*/
|
11 |
+
|
12 |
+
/*
|
13 |
+
future to do list:
|
14 |
+
- block spam in trackbacks and pingbacks
|
15 |
+
- show spam counter in admin section
|
16 |
+
- include js only on singular pages with comments enabled
|
17 |
+
- add options page if it will be needed
|
18 |
+
- also check year+1 and year-1 to be equal year for users could leave comments in the end of the year
|
19 |
+
*/
|
20 |
+
|
21 |
+
$antispam_unqprfx_send_spam_comment_to_admin = false; // if true, than rejected spam comments will be sent to admin email
|
22 |
+
|
23 |
+
$antispam_unqprfx_version = '1.1';
|
24 |
+
|
25 |
+
|
26 |
+
function antispam_unqprfx_scripts_styles_init() {
|
27 |
+
global $antispam_unqprfx_version;
|
28 |
+
if ( !is_admin() ) { // && is_singular() && comments_open() && get_option( 'thread_comments' )
|
29 |
+
//wp_enqueue_script('jquery');
|
30 |
+
wp_enqueue_script( 'anti-spam-script', plugins_url( '/js/anti-spam.js', __FILE__ ), array('jquery'), $antispam_unqprfx_version );
|
31 |
+
}
|
32 |
+
}
|
33 |
+
add_action('init', 'antispam_unqprfx_scripts_styles_init');
|
34 |
+
|
35 |
+
|
36 |
+
function antispam_unqprfx_form_part() {
|
37 |
+
$antispam_unqprfx_form_part = '
|
38 |
+
<p class="comment-form-anti-spam" style="clear:both;">
|
39 |
+
<label for="anti-spam">Current ye@r</label> <span class="required">*</span>
|
40 |
+
<input type="hidden" name="anti-spam-0" id="anti-spam-0" value="'.date('Y').'" />
|
41 |
+
<input type="text" name="anti-spam" id="anti-spam" size="30" value="" />
|
42 |
+
</p>
|
43 |
+
'; // question (hidden with js) [aria-required="true" required="required"]
|
44 |
+
$antispam_unqprfx_form_part .= '
|
45 |
+
<p class="comment-form-anti-spam-2" style="display:none;">
|
46 |
+
<label for="anti-spam-2">Leave this field empty</label> <span class="required">*</span>
|
47 |
+
<input type="text" name="anti-spam-2" id="anti-spam-2" size="30" value=""/>
|
48 |
+
</p>
|
49 |
+
'; // empty field (hidden with css)
|
50 |
+
echo $antispam_unqprfx_form_part;
|
51 |
+
}
|
52 |
+
add_action( 'comment_form', 'antispam_unqprfx_form_part' ); // add anti-spam input to the comment form
|
53 |
+
|
54 |
+
|
55 |
+
function antispam_unqprfx_check_comment( $commentdata ) {
|
56 |
+
global $antispam_unqprfx_send_spam_comment_to_admin;
|
57 |
+
extract( $commentdata );
|
58 |
+
$antispam_unqprfx_pre_error_message = '<strong><a href="javascript:window.history.back()">Go back</a></strong> and try again.';
|
59 |
+
$antispam_unqprfx_error_message = '';
|
60 |
+
if( !is_user_logged_in() && $comment_type != 'pingback' && $comment_type != 'trackback' /* && !current_user_can( 'publish_posts' ) */ ) { // logged in user is not a spammer
|
61 |
+
$error_flag = false;
|
62 |
+
|
63 |
+
if ( trim( $_POST['anti-spam'] ) != date('Y') ) { // answer is wrong - maybe spam
|
64 |
+
$error_flag = true;
|
65 |
+
if ( empty( $_POST['anti-spam'] ) ) { // empty answer - maybe spam
|
66 |
+
$antispam_unqprfx_error_message .= '<br> Error: empty answer. ';
|
67 |
+
}else{
|
68 |
+
$antispam_unqprfx_error_message .= '<br> Error: answer is wrong. ';
|
69 |
+
}
|
70 |
+
}
|
71 |
+
if ( !empty( $_POST['anti-spam-2'] ) ) { // field is not empty - maybe spam
|
72 |
+
$error_flag = true;
|
73 |
+
$antispam_unqprfx_error_message .= '<br> Error: field should be empty. ';
|
74 |
+
}
|
75 |
+
if( $error_flag ){ // if we have an error
|
76 |
+
if ( $antispam_unqprfx_send_spam_comment_to_admin ) { // if sending email to admin is enabled
|
77 |
+
$post = get_post($comment->comment_post_ID);
|
78 |
+
|
79 |
+
$antispam_unqprfx_admin_email = get_option('admin_email'); // admin email
|
80 |
+
$antispam_unqprfx_subject = 'Spam comment on site "'.get_bloginfo('name').'" '; // email subject
|
81 |
+
$antispam_unqprfx_message = 'Spam comment on "'.$post->post_title.'"' . "\r\n";
|
82 |
+
$antispam_unqprfx_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
|
83 |
+
|
84 |
+
$antispam_unqprfx_message .= 'IP : ' . $_SERVER['REMOTE_ADDR'] . "\r\n";
|
85 |
+
$antispam_unqprfx_message .= 'User agent : ' . $_SERVER['HTTP_USER_AGENT'] . "\r\n";
|
86 |
+
$antispam_unqprfx_message .= 'Referer : ' . $_SERVER['HTTP_REFERER'] . "\r\n\r\n";
|
87 |
+
|
88 |
+
$antispam_unqprfx_message .= 'Errors: ' . $antispam_unqprfx_error_message . "\r\n\r\n";
|
89 |
+
|
90 |
+
$antispam_unqprfx_message .= 'Post vars:'."\r\n"; // lets see what post vars spammers try to submit
|
91 |
+
foreach ($_POST as $key => $value) {
|
92 |
+
$antispam_unqprfx_message .= '$_POST['.$key. '] = '.$value."\r\n"; // .chr(13).chr(10)
|
93 |
+
}
|
94 |
+
$antispam_unqprfx_message .= "\r\n\r\n";
|
95 |
+
|
96 |
+
$antispam_unqprfx_message .= 'Cookie vars:'."\r\n"; // lets see what cookie vars spammers try to submit
|
97 |
+
foreach ($_COOKIE as $key => $value) {
|
98 |
+
$antispam_unqprfx_message .= '$_COOKIE['.$key. '] = '.$value."\r\n"; // .chr(13).chr(10)
|
99 |
+
}
|
100 |
+
$antispam_unqprfx_message .= "\r\n\r\n";
|
101 |
+
|
102 |
+
$antispam_unqprfx_message .= '-----------------------------'."\r\n";
|
103 |
+
$antispam_unqprfx_message .= 'This is spam comment rejected by Anti-spam plugin. wordpress.org/extend/plugins/anti-spam/' . "\r\n";
|
104 |
+
$antispam_unqprfx_message .= 'You may edit "anti-spam.php" file and disable this notification.' . "\r\n";
|
105 |
+
$antispam_unqprfx_message .= 'You should find "$antispam_unqprfx_send_spam_comment_to_admin" and make it equal to "false".' . "\r\n";
|
106 |
+
|
107 |
+
@wp_mail( $antispam_unqprfx_admin_email, $antispam_unqprfx_subject, $antispam_unqprfx_message ); // send comment to admin email
|
108 |
+
}
|
109 |
+
wp_die( $antispam_unqprfx_pre_error_message . $antispam_unqprfx_error_message ); // die and show errors
|
110 |
+
}
|
111 |
+
}
|
112 |
+
return $commentdata;
|
113 |
+
}
|
114 |
+
|
115 |
+
if( ! is_admin() ) {
|
116 |
+
add_filter( 'preprocess_comment', 'antispam_unqprfx_check_comment', 1 );
|
117 |
+
}
|
js/anti-spam.js
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* Anti-spam plugin. No spam in comments. No captcha. wordpress.org/extend/plugins/anti-spam/ */
|
2 |
+
|
3 |
+
jQuery(function($){
|
4 |
+
$('.comment-form-anti-spam, .comment-form-anti-spam-2').hide(); // hide inputs from users
|
5 |
+
var answer = $('.comment-form-anti-spam input#anti-spam-0').val(); // get answer
|
6 |
+
$('.comment-form-anti-spam input#anti-spam').val( answer ); // set answer into other input
|
7 |
+
});
|
readme.txt
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.4.2
|
7 |
+
Stable tag: 1.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 |
+
Plugin will block spam in comments. Users hate spam in comments and also they hate captcha.
|
16 |
+
So Anti-spam plugin will block spam automatically without moderation and silently for site visitors.
|
17 |
+
|
18 |
+
[Anti-spam plugin page](http://web-profile.com.ua/wordpress/plugins/anti-spam/ "Need help with the plugin? Try to find it here.")
|
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 |
+
* ["Login-Logout" - default Meta widget replacement](http://wordpress.org/extend/plugins/login-logout/ "default Meta widget replacement")
|
24 |
+
|
25 |
+
== Installation ==
|
26 |
+
|
27 |
+
1. install and activate the plugin on the Plugins page
|
28 |
+
2. enjoy life without spam in comments
|
29 |
+
|
30 |
+
== Frequently Asked Questions ==
|
31 |
+
|
32 |
+
= How does it work? =
|
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 "$antispam_unqprfx_send_spam_comment_to_admin" and make it "true".
|
42 |
+
|
43 |
+
== Changelog ==
|
44 |
+
|
45 |
+
= 1.1 - 2012-10-14 =
|
46 |
+
* sending answer from server to client into hidden field (because client year and server year could mismatch)
|
47 |
+
|
48 |
+
= 1.0 =
|
49 |
+
* initial release
|