Skip to content

Instantly share code, notes, and snippets.

@richardW8k
Created July 23, 2021 12:46
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 richardW8k/3d42464184003ee8d799bc2ef7e47a68 to your computer and use it in GitHub Desktop.
Save richardW8k/3d42464184003ee8d799bc2ef7e47a68 to your computer and use it in GitHub Desktop.
/**
* Performs spam check and returns result to Gravity Forms.
*
* @param bool $is_spam Indicates if the entry is to be marked as spam.
* @param array $form The form currently being processed.
* @param array $entry The entry being evaluated.
*
* @return bool
*/
function your_gform_entry_is_spam_callback( $is_spam, $form, $entry ) {
// Return early if the entry has already been marked as spam by another plugin.
if ( $is_spam ) {
return $is_spam;
}
// Perform your spam check here; populating $is_spam with the result.
if ( $is_spam ) {
add_action( 'gform_entry_created', 'your_gform_entry_created_callback' );
}
return $is_spam;
}
add_filter( 'gform_entry_is_spam', 'your_gform_entry_is_spam_callback', 11, 3 );
/**
* Adds a note to the entry once the spam status is set (GF 2.4.18+).
*
* @param array $entry The entry that was created.
*/
function your_gform_entry_created_callback( $entry ) {
if ( rgar( $entry, 'status' ) !== 'spam' || ! method_exists( 'GFAPI', 'add_note' ) ) {
return;
}
GFAPI::add_note( $entry['id'], 0, 'Your plugin short name', __( 'This entry has been marked as spam.', 'your-plugin-domain' ), 'your-plugin-slug', 'success' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment