Version Description
- initial release
Download this release
Release Info
Developer | webvitaly |
Plugin | Anti-spam |
Version | 1.0 |
Comparing to | |
See all releases |
Version 1.0
- anti-spam.php +118 -0
- js/anti-spam.js +6 -0
- readme.txt +46 -0
anti-spam.php
ADDED
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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. No moderation.
|
6 |
+
Version: 1.0
|
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 |
+
$antispam_unqprfx_version = '1.0';
|
22 |
+
|
23 |
+
|
24 |
+
function antispam_unqprfx_scripts_styles_init() {
|
25 |
+
global $antispam_unqprfx_version;
|
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'), $antispam_unqprfx_version );
|
29 |
+
}
|
30 |
+
}
|
31 |
+
add_action('init', 'antispam_unqprfx_scripts_styles_init');
|
32 |
+
|
33 |
+
|
34 |
+
function antispam_unqprfx_form_part() {
|
35 |
+
$antispam_unqprfx_form_part = '
|
36 |
+
<p class="comment-form-anti-spam" style="clear:both;">
|
37 |
+
<label for="anti-spam">Current ye@r</label> <span class="required">*</span>
|
38 |
+
<input type="text" name="anti-spam" id="anti-spam" size="30" value="" placeholder="" />
|
39 |
+
</p>
|
40 |
+
'; // question (hide with js later) [aria-required="true" required="required"]
|
41 |
+
$antispam_unqprfx_form_part .= '
|
42 |
+
<p class="comment-form-anti-spam-2" style="display:none;">
|
43 |
+
<label for="anti-spam-2">Leave this field empty</label> <span class="required">*</span>
|
44 |
+
<input type="text" name="anti-spam-2" id="anti-spam-2" size="30" value="" placeholder="" />
|
45 |
+
</p>
|
46 |
+
'; // empty field (hide with css later)
|
47 |
+
echo $antispam_unqprfx_form_part;
|
48 |
+
}
|
49 |
+
add_action( 'comment_form', 'antispam_unqprfx_form_part' ); // add anti-spam input to the comment form
|
50 |
+
|
51 |
+
|
52 |
+
function antispam_unqprfx_check_comment( $commentdata ) {
|
53 |
+
global $antispam_unqprfx_send_spam_comment_to_admin;
|
54 |
+
extract( $commentdata );
|
55 |
+
$antispam_unqprfx_pre_error_message = '<strong><a href="javascript:window.history.back()">Go back</a></strong> and try again.';
|
56 |
+
$antispam_unqprfx_error_message = '';
|
57 |
+
if( !is_user_logged_in() && $comment_type != 'pingback' && $comment_type != 'trackback' /* && !current_user_can( 'publish_posts' ) */ ) { // logged in user is not a spammer
|
58 |
+
$error_flag = false;
|
59 |
+
|
60 |
+
if ( trim( $_POST['anti-spam'] ) != date('Y') ) { // answer is wrong - maybe spam
|
61 |
+
$error_flag = true;
|
62 |
+
if ( empty( $_POST['anti-spam'] ) ) { // empty answer - maybe spam
|
63 |
+
$antispam_unqprfx_error_message .= '<br> Error: empty answer. ';
|
64 |
+
}else{
|
65 |
+
$antispam_unqprfx_error_message .= '<br> Error: answer is wrong. ';
|
66 |
+
}
|
67 |
+
}
|
68 |
+
if ( !empty( $_POST['anti-spam-2'] ) ) { // field is not empty - maybe spam
|
69 |
+
$error_flag = true;
|
70 |
+
$antispam_unqprfx_error_message .= '<br> Error: field should be empty. ';
|
71 |
+
}
|
72 |
+
if( $error_flag ){ // if we have error
|
73 |
+
if ( $antispam_unqprfx_send_spam_comment_to_admin ) { // if sending email to admin is enabled
|
74 |
+
$comment = get_comment($comment_id);
|
75 |
+
$post = get_post($comment->comment_post_ID);
|
76 |
+
$user = get_userdata( $post->post_author );
|
77 |
+
$antispam_unqprfx_admin_email = get_option('admin_email'); // admin email
|
78 |
+
$antispam_unqprfx_subject = 'Spam comment rejected by Anti-spam plugin'; // email subject
|
79 |
+
$antispam_unqprfx_message = 'Spam comment on "'.$post->post_title.'"' . "\r\n";
|
80 |
+
$antispam_unqprfx_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
|
81 |
+
//$antispam_unqprfx_message .= 'Author : ' . $comment->comment_author . "\r\n";
|
82 |
+
//$antispam_unqprfx_message .= 'Author domain : ' . $comment_author_domain . "\r\n";
|
83 |
+
//$antispam_unqprfx_message .= 'E-mail : ' . $comment->comment_author_email . "\r\n";
|
84 |
+
//$antispam_unqprfx_message .= 'URL : ' . $comment->comment_author_url . "\r\n";
|
85 |
+
$antispam_unqprfx_message .= 'IP : ' . $_SERVER['REMOTE_ADDR'] . "\r\n"; // $comment->comment_author_IP
|
86 |
+
$antispam_unqprfx_message .= 'User agent : ' . $_SERVER['HTTP_USER_AGENT'] . "\r\n";
|
87 |
+
$antispam_unqprfx_message .= 'Referer : ' . $_SERVER['HTTP_REFERER'] . "\r\n\r\n";
|
88 |
+
//$antispam_unqprfx_message .= 'Comment: ' . "\r\n" . $comment->comment_content . "\r\n\r\n";
|
89 |
+
$antispam_unqprfx_message .= 'Errors: ' . $antispam_unqprfx_error_message . "\r\n\r\n";
|
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 |
+
$antispam_unqprfx_message .= "\r\n\r\n";
|
96 |
+
|
97 |
+
$antispam_unqprfx_message .= 'Cookie vars:'."\r\n"; // lets see what cookie vars spammers try to submit
|
98 |
+
foreach ($_COOKIE as $key => $value) {
|
99 |
+
$antispam_unqprfx_message .= '$_COOKIE['.$key. '] = '.$value."\r\n"; // .chr(13).chr(10)
|
100 |
+
}
|
101 |
+
$antispam_unqprfx_message .= "\r\n\r\n";
|
102 |
+
|
103 |
+
$antispam_unqprfx_message .= '-----------------------------'."\r\n";
|
104 |
+
$antispam_unqprfx_message .= 'This email was generated by Anti-spam plugin.' . "\r\n";
|
105 |
+
$antispam_unqprfx_message .= 'You may edit "anti-spam.php" file and disable this notification.' . "\r\n";
|
106 |
+
$antispam_unqprfx_message .= 'You should find "$antispam_unqprfx_send_spam_comment_to_admin" and make it "false".' . "\r\n";
|
107 |
+
|
108 |
+
@wp_mail( $antispam_unqprfx_admin_email, $antispam_unqprfx_subject, $antispam_unqprfx_message ); // send comment to admin email
|
109 |
+
}
|
110 |
+
wp_die( $antispam_unqprfx_pre_error_message . $antispam_unqprfx_error_message ); // die and show errors
|
111 |
+
}
|
112 |
+
}
|
113 |
+
return $commentdata;
|
114 |
+
}
|
115 |
+
|
116 |
+
if( ! is_admin() ) {
|
117 |
+
add_filter( 'preprocess_comment', 'antispam_unqprfx_check_comment', 1 );
|
118 |
+
}
|
js/anti-spam.js
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
jQuery(function($){
|
2 |
+
$('.comment-form-anti-spam, .comment-form-anti-spam-2').hide(); // hide inputs from users
|
3 |
+
var date = new Date();
|
4 |
+
var year = date.getFullYear(); // get current year
|
5 |
+
$('.comment-form-anti-spam input').val(year); // automatically fill answer with javascript
|
6 |
+
});
|
readme.txt
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.1
|
7 |
+
Stable tag: 1.0
|
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. No moderation.
|
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.0 =
|
46 |
+
* initial release
|