How to overwrite / extent wordpress function is_email

so wordpress’ core isn’t really up to date with email allowances of unicode domains. Even simple special characters like the german umlauts (äÄöÖüÜß) aren’t allowed in the domain part of the name.

So I’ve been thinking to add a filter to the is_email function with high priority and simply return the result. But it doesn’t seem to function as I’ve intended to. Here’s what I’ve tried:

// Code written in my themes functions.php
function kk_email_validation_override( $email )
{
$pattern = ‘/^(?!(?:(?:x22?x5C[x00-x7E]x22?)|(?:x22?[^x5Cx22]x22?)){255,})(?!(?:(?:x22?x5C[x00-x7E]x22?)|(?:x22?[^x5Cx22]x22?)){65,}@)(?:(?:[x21x23-x27x2Ax2Bx2Dx2F-x39x3Dx3Fx5E-x7E]+)|(?:x22(?:[x01-x08x0Bx0Cx0E-x1Fx21x23-x5Bx5D-x7F]|(?:x5C[x00-x7F]))*x22))(?:.(?:(?:[x21x23-x27x2Ax2Bx2Dx2F-x39x3Dx3Fx5E-x7E]+)|(?:x22(?:[x01-x08x0Bx0Cx0E-x1Fx21x23-x5Bx5D-x7F]|(?:x5C[x00-x7F]))*x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-+[a-z0-9äÄüÜöÖß]+)*.){1,126}){1,}(?:(?:[a-z][a-z0-9äÄüÜöÖß]*)|(?:(?:xn--)[a-z0-9äÄüÜöÖß]+))(?:-+[a-z0-9äÄüÜöÖß]+)*)|(?:[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))]))$/iD’;

if (preg_match($pattern, $email)) {
return trim(strtolower($email));
}

return false;
}
add_filter(‘is_email’, ‘kk_email_validation_override’, 99, 4);

For some reason though, the original wordpress’ is_email() is still being called. Am I applying my filter wrong or what else am I missing to not go down the filter chain of wordpress’ filtering?

Thanks in advance!

Read more here:: How to overwrite / extent wordpress function is_email

Leave a Reply

Your email address will not be published. Required fields are marked *