Created
December 12, 2013 09:48
-
-
Save Dimasmagadan/7925557 to your computer and use it in GitHub Desktop.
Quick&simple anti-spam for WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: OS Spam Comments Filter | |
Description: antispam | |
Author: dimas@odminstudios.ru | |
Version: 1.1 | |
*/ | |
function verify_comment_meta_data( $commentdata ) { | |
if ( !is_user_logged_in() && (!isset( $_POST['city'] ) || $_POST['city']!='Москва') ){ | |
wp_die( 'Вы не прошли проверку на спам.' ); | |
} | |
return $commentdata; | |
} | |
add_filter( 'preprocess_comment', 'verify_comment_meta_data' ); | |
function verify_comment_meta_data_field(){ | |
if( !is_user_logged_in() ) { | |
?><p class="check_field"> | |
<label for="city">Антиспам: столица нашей страны? (Москва) | |
<input class="city" name="city" type="text" value="" /> | |
</label> | |
</p> | |
<script type="text/javascript"> | |
jQuery(document).ready(function(){ | |
jQuery('.check_field input').val('Москва'); | |
jQuery('.check_field').hide(); | |
}); | |
</script> | |
<?php | |
} | |
} | |
add_action( 'comment_form', 'verify_comment_meta_data_field' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment