$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>core - How to overwriteextent wordpress function is_email|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

core - How to overwriteextent wordpress function is_email

matteradmin8PV0评论

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?[^\\x5C\\x22]\\x22?)){255,})(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){65,}@)(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22))(?:\\.(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\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!

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?[^\\x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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!

Share Improve this question asked Jan 28, 2019 at 9:40 SamSam 1972 silver badges13 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 1

is_email is a native WP function. As you can see here (https://core.trac.wordpress/browser/tags/5.0.3/src/wp-includes/formatting.php#L2886) it allows you to modify it with filter is_email.

So yes - anytime the function is_email will be called, it will run, and at the end it will run your filters allowing you to modify the result.

But... The filter should take 3 params:

$is_email (bool) Whether the email address has passed the is_email() checks. Default false.

$email (string) The email address being checked.

$context (string) Context under which the email was tested.

function my_email_validation( $is_email, $email, $context )
{
    if ( <MY CONDITION> ) {  // check if it is an email
        return true;
    }

    return false;
}
add_filter( 'is_email', 'my_email_validation', 99, 3 );

So your code doesn't work, because you use this filter incorrectly (you register it as it should take 4 params and your filter function takes only one, and so on).

Post a comment

comment list (0)

  1. No comments so far