elegantthemes / Divi-Beta

8 stars 0 forks source link

How to Implement Email Address Filtering in the Contact Form Module of Divi 5 #76

Closed UmerCheema-WPD closed 4 months ago

UmerCheema-WPD commented 4 months ago

To filter email addresses or perform actions before sending contact form emails in Divi 4, we can achieve this using add_filter('et_contact_page_email_to','my_callback_function').

How can we achieve this in Divi 5.0? Is there any alternate hook for this?

Hook

apply_filters( 'et_contact_page_email_to', $et_email_to )

Code Example

 /**
 * Handle the contact form submission and filter out spam email addresses.
 *
 * @param string $et_email_to The email address to send the contact form submission to.
 *
 * @return string|null The original email address or null if it is identified as spam.
 */
if (!function_exists('filter_spam_email_from_contact_form')):
    function filter_spam_email_from_contact_form($et_email_to)
    {
        // Simple regex check for common spam patterns
        if (preg_match('/spam|junk|test/i', $et_email_to)) {
            return null;
        }

        // Return the email address if it doesn't look like spam
        return $et_email_to;
    }

    add_filter('et_contact_page_email_to', 'filter_spam_email_from_contact_form', 10, 1);
endif;
UmerCheema-WPD commented 4 months ago

Hook is available and working