Home / Admin / Donation Form Email Check (Advanced)
Duplicate Snippet

Embed Snippet on Your Site

Donation Form Email Check (Advanced)

If you need to do manual validation of an email when a donation is being submitted (only accepting emails from certain domains or manually blocking for spam reasons). This script is slightly more advanced, showing a valid email check and searching for a domain in the email.

Code Preview
php
<?php
add_filter('charitable_validate_donation_form_submission_email_check', 'charitable_test_for_email', 10, 2 );
function charitable_test_for_email( $valid, $submitted ) {
	$email = $submitted->get_submitted_value( 'email' );
    if ( ! is_valid_email( $email ) ) {
	   return false;
	}
	return $valid;
}
function is_valid_email($email) {
    // Use PHP's built-in function to split the email into local and domain parts
    $parts = explode('@', $email);
    
    // Check if the email has a domain part
    if (count($parts) !== 2) {
        return false;  // Invalid email format
    }
    
    $domain = $parts[1];
	
    // Check if the word "baddomain" is in the domain
    if (strpos($domain, 'baddomain') !== false) {
        return false;
    }
    return true;
}

Comments

Add a Comment