-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathantispam.php
54 lines (51 loc) · 1.94 KB
/
antispam.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/*
This module handles simple form field anti-spam. It works by inserting two hidden
fields into the comment form. The first should be blank. The second should contain
a specified value. If one or the other doesn't match, we consider it spam.
*/
function gci_antispam_head() {
echo '<style type="text/css"><!-- .gcias-fields { display:none; } --></style>'."\n";
}
function gci_antispam_comment_form() {
global $gci_tools_options;
$blankfld=$gci_tools_options['antispam-blankfld'];
$filledfld=$gci_tools_options['antispam-filledfld'];
$filledval=$gci_tools_options['antispam-filledval'];
echo '<div class="gcias-fields"><input type="text" name="'.$filledfld.'" value="'.$filledval.'">'."\n".'<input type="text" name="'.$blankfld.'" value=""></div>'."\n";
}
function gci_antispam_check_comment($comment) {
global $gci_tools_options;
$blankfld=$gci_tools_options['antispam-blankfld'];
$filledfld=$gci_tools_options['antispam-filledfld'];
$filledval=$gci_tools_options['antispam-filledval'];
$gci_isspam=false;
if ($_POST[$filledfld]!=$filledval) {
$comment['comment_content'] .= "\n\n[GCI AntiSpam] Field value for $filledfld does not match and so is spam. [".$_POST[$filledfld]."]!=[$filledval]\n\n".print_r($_POST,true);
$gci_isspam=true;
}
if ($_POST[$blankfld]!='') {
$comment['comment_content'] .= "\n\n[GCI AntiSpam] Field value not empty and so is spam.";
$gci_isspam=true;
}
if ($gci_isspam) {
if(function_exists('akismet_init')) {
add_filter('pre_comment_approved', function($a) {
return 'spam';
});
} else {
add_filter('comment_post', function($id) {
wp_delete_comment($id);
die('This comment has been deleted by GCI-AntiSpam');
});
}
}
return $comment;
}
global $gci_tools_options;
if ($gci_tools_options['antispam-enable']=='1') {
add_action('wp_head', 'gci_antispam_head');
add_action('comment_form', 'gci_antispam_comment_form');
add_filter('preprocess_comment', 'gci_antispam_check_comment');
}
?>