Skip to content

Instantly share code, notes, and snippets.

@xnau
Last active April 25, 2021 20:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save xnau/f98cb9bffc07fde03ce841fa150a6f72 to your computer and use it in GitHub Desktop.
Shows how to check a Participants Database signup submission for a valid email address
<?php
/**
* checks a signup submission for a valid email
*
* @return bool true to accept the submission, false to reject it
*/
add_filter( 'pdb-check_submission', function() {
// this check is only applied to signups
if ( filter_input( INPUT_POST, 'action', FILTER_SANITIZE_STRING ) === 'signup' ) {
if ( ! filter_input( INPUT_POST, 'email', FILTER_VALIDATE_EMAIL ) ) {
return false;
}
}
return true;
} );
@xnau
Copy link
Author

xnau commented Apr 25, 2021

This filter is checked immediately after the submission to minimize resources spent on invalid submissions. It's primary purpose is filtering spam.

Be sure to check for the type of submission (line 10) because almost every submission Participants Database receives goes through this filter.

The very simple function can be elaborated to include several data integrity checks if desired. It is also useful for rejecting identifiable types of human-generated spam.

This example checks the "email" field in a signup submission for a valid email address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment