Skip to content

Instantly share code, notes, and snippets.

@Dimasmagadan
Created December 12, 2013 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dimasmagadan/7925557 to your computer and use it in GitHub Desktop.
Save Dimasmagadan/7925557 to your computer and use it in GitHub Desktop.
Quick&simple anti-spam for WordPress
<?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