Created
August 4, 2020 18:33
-
-
Save sinebeef/e66593c7716b50b4c1ff52fb9b466cec to your computer and use it in GitHub Desktop.
Message filter hooks
This file contains hidden or 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
add_filter( 'wpcf7_validate_text*', 'custom_phone_confirmation_validation_filter', 20, 2 ); | |
function custom_phone_confirmation_validation_filter( $result, $tag ) { | |
if ( 'your-phone' == $tag->name ) { | |
$your_phone = isset( $_POST['your-phone'] ) ? trim( $_POST['your-phone'] ) : ''; | |
if ( !preg_match('/^0/', $your_phone ) ){ | |
$result->invalidate( $tag, "Needs to start with a zero, are you a bot?" ); | |
} | |
} | |
return $result; | |
} | |
add_filter( 'wpcf7_validate_textarea*', 'textarea_confirmation_validation_filter', 20, 2 ); | |
function textarea_confirmation_validation_filter( $result, $tag ) { | |
if ( 'your-message' == $tag->name ) { | |
$your_message = isset( $_POST['your-message'] ) ? trim( $_POST['your-message'] ) : ''; | |
if ( preg_match('/google|seo|http|latex|gloves/i', $your_message ) ){ | |
$result->invalidate( $tag, "Your message contains invalid words that are not allowed, we are trying to weed out spam bots, please rephrase. No links etc." ); | |
} | |
} | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment