Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the Comment Blacklist to check Contact Form submissions for spam. #11037

Merged
merged 1 commit into from
Jan 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions modules/contact-form/grunion-contact-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ function __construct() {
) {
add_filter( 'widget_text', array( $this, 'widget_shortcode_hack' ), 5 );
}

add_filter( 'jetpack_contact_form_is_spam', array( $this, 'is_spam_blacklist' ), 10, 2 );

// Akismet to the rescue
if ( defined( 'AKISMET_VERSION' ) || function_exists( 'akismet_http_post' ) ) {
Expand Down Expand Up @@ -618,6 +620,29 @@ function widget_shortcode_hack( $text ) {

return $text;
}

/**
* Check if a submission matches the Comment Blacklist.
* The Comment Blacklist is a means to moderate discussion, and contact
* forms are 1:1 discussion forums, ripe for abuse by users who are being
* removed from the public discussion.
* Attached to `jetpack_contact_form_is_spam`
*
* @param bool $is_spam
* @param array $form
* @return bool TRUE => spam, FALSE => not spam
*/
function is_spam_blacklist( $is_spam, $form = array() ) {
if ( $is_spam ) {
return $is_spam;
}

if ( wp_blacklist_check( $form['comment_author'], $form['comment_author_email'], $form['comment_author_url'], $form['comment_content'], $form['user_ip'], $form['user_agent'] ) ) {
return true;
}

return false;
}

/**
* Populate an array with all values necessary to submit a NEW contact-form feedback to Akismet.
Expand Down