Last active
April 25, 2021 20:15
Star
You must be signed in to star a gist
Shows how to check a Participants Database signup submission for a valid email address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.