*
'; // question (hidden with js) [aria-required="true" required="required"]
$antispam_form_part .= '
'; // empty field (hidden with css)
echo $antispam_form_part;
}
}
add_action( 'comment_form', 'antispam_form_part' ); // add anti-spam input to the comment form
endif; // end of antispam_form_part()
if ( ! function_exists( 'antispam_check_comment' ) ) :
function antispam_check_comment( $commentdata ) {
global $antispam_send_spam_comment_to_admin;
extract( $commentdata );
$antispam_pre_error_message = 'Go back and try again.';
$antispam_error_message = '';
if ( ! is_user_logged_in() && $comment_type != 'pingback' && $comment_type != 'trackback' ) { // logged in user is not a spammer
$spam_flag = false;
if ( trim( $_POST['anti-spam-q'] ) != date('Y') ) { // answer is wrong - maybe spam
$spam_flag = true;
if ( empty( $_POST['anti-spam-q'] ) ) { // empty answer - maybe spam
$antispam_error_message .= '
Error: empty answer. ';
} else {
$antispam_error_message .= '
Error: answer is wrong. ';
}
}
if ( ! empty( $_POST['anti-spam-e-email-url'] ) ) { // field is not empty - maybe spam
$spam_flag = true;
$antispam_error_message .= '
Error: field should be empty. ';
}
if ( $spam_flag ) { // if we have spam
if ( $antispam_send_spam_comment_to_admin ) { // if sending email to admin is enabled
$post = get_post( $comment->comment_post_ID );
$antispam_admin_email = get_option('admin_email'); // admin email
$antispam_subject = 'Spam comment on site "'.get_bloginfo( 'name' ).'" '; // email subject
$antispam_message = 'Spam comment on "'.$post->post_title.'"' . "\r\n";
$antispam_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n";
$antispam_message .= 'IP : ' . $_SERVER['REMOTE_ADDR'] . "\r\n";
$antispam_message .= 'User agent : ' . $_SERVER['HTTP_USER_AGENT'] . "\r\n";
$antispam_message .= 'Referer : ' . $_SERVER['HTTP_REFERER'] . "\r\n\r\n";
$antispam_message .= 'Errors: ' . $antispam_error_message . "\r\n\r\n";
$antispam_message .= 'Post vars:'."\r\n"; // lets see what post vars spammers try to submit
foreach ( $_POST as $key => $value ) {
$antispam_message .= '$_POST['.$key. '] = '.$value."\r\n"; // .chr(13).chr(10)
}
$antispam_message .= "\r\n\r\n";
$antispam_message .= 'Cookie vars:'."\r\n"; // lets see what cookie vars spammers try to submit
foreach ( $_COOKIE as $key => $value ) {
$antispam_message .= '$_COOKIE['.$key. '] = '.$value."\r\n"; // .chr(13).chr(10)
}
$antispam_message .= "\r\n\r\n";
$antispam_message .= '-----------------------------'."\r\n";
$antispam_message .= 'This is spam comment rejected by Anti-spam plugin. wordpress.org/extend/plugins/anti-spam/' . "\r\n";
$antispam_message .= 'You may edit "anti-spam.php" file and disable this notification.' . "\r\n";
$antispam_message .= 'You should find "$antispam_send_spam_comment_to_admin" and make it equal to "false".' . "\r\n";
@wp_mail( $antispam_admin_email, $antispam_subject, $antispam_message ); // send spam comment to admin email
}
wp_die( $antispam_pre_error_message . $antispam_error_message ); // die - do not send comment and show errors
}
}
//if ( $comment_type == 'trackback' || $comment_type == 'pingback' ) { // check spam in trackbacks - http://web-profile.com.ua/web/trackback-vs-pingback/
// $debug_message = print_r( $commentdata, true );
// @wp_mail( 'vitalymylo@gmail.com', 'antispam trackback debug info', $debug_message ); // debug info
//}
return $commentdata;
}
if( ! is_admin() ) {
add_filter( 'preprocess_comment', 'antispam_check_comment', 1 );
}
endif; // end of antispam_check_comment()
if ( ! function_exists( 'antispam_plugin_meta' ) ) :
function antispam_plugin_meta( $links, $file ) { // add 'Plugin page' and 'Donate' links to plugin meta row
if ( strpos( $file, 'anti-spam.php' ) !== false ) {
$links = array_merge( $links, array( '' . __('Anti-spam') . '' ) );
$links = array_merge( $links, array( '' . __('Donate') . '' ) );
}
return $links;
}
add_filter( 'plugin_row_meta', 'antispam_plugin_meta', 10, 2 );
endif; // end of antispam_plugin_meta()