Skip to content

Instantly share code, notes, and snippets.

@marcelotorres
Created September 6, 2022 14:05
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 marcelotorres/b31b5eea542aec1618e3ab02b8349075 to your computer and use it in GitHub Desktop.
Save marcelotorres/b31b5eea542aec1618e3ab02b8349075 to your computer and use it in GitHub Desktop.
function is_spam_akismet($args){
global $akismet_api_host, $akismet_api_port;
$query['user_ip'] = preg_replace( '/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR'] );
$query['user_agent'] = (isset( $_SERVER['HTTP_USER_AGENT'] )) ? $_SERVER['HTTP_USER_AGENT'] : '';
$query['referrer'] = (isset( $_SERVER['HTTP_REFERER'] )) ? $_SERVER['HTTP_REFERER'] : '';
$query['blog'] = get_option( 'home' );
$query['blog_lang'] = get_locale(); // default 'en_US'
$query['blog_charset'] = get_option( 'blog_charset' );
$query['comment_type'] = 'forum-post'; //For more info http://bit.ly/2bVOMay
$query['comment_content'] = $args["post_content"];
$query['permalink'] = $args['referrer'];
$query['comment_author'] = $args["user_name"];
$query['comment_author_email'] = $args["user_email"];
//$query['is_test'] = "1"; // uncomment this when testing spam detection
//$query['comment_author'] = "viagra-test-123"; // uncomment this to test spam detection
$query_string = http_build_query($query);
$spam = false;
if ( is_callable( array( 'Akismet', 'http_post' ) ) ) { //Akismet v3.0+
$response = Akismet::http_post( $query_string, 'comment-check' );
} else {
$response = akismet_http_post( $query_string, $akismet_api_host,
'/1.1/comment-check', $akismet_api_port );
}
if ( 'true' == $response[1] ) {
$spam = true;
}
return $spam;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment