Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
T5 Extend Email Checks
<?php # -*- coding: utf-8 -*-
/*
Plugin Name: T5 Extend Email Checks
Description: Overrides the results of the functions <code>is_email()</code> and <code>sanitize_email()</code>. Allows for example <code>me@localhost</code> or punycode encoded email adresses by using PHP’s internal filter function.
Version: 2012.08.29
Plugin URI: http://toscho.de/?p=2195
Author: Thomas Scholz
Author URI: http://toscho.de
License: MIT
*/
! defined( 'ABSPATH' ) and exit;
if ( ! function_exists( 't5_extend_email_checks' ) )
{
add_filter( 'is_email', 'extend_email_checks', 10, 2 );
add_filter( 'sanitize_email', 'extend_email_checks', 10, 2 );
function t5_extend_email_checks( $result, $email )
{
return filter_var( $email, FILTER_VALIDATE_EMAIL );
}
}
@hakre

This comment has been minimized.

Show comment Hide comment
@hakre

hakre May 15, 2011

Is there a reason you don't return the filtered $email if the filter_var did not false?

hakre commented May 15, 2011

Is there a reason you don't return the filtered $email if the filter_var did not false?

@thefuxia

This comment has been minimized.

Show comment Hide comment
@thefuxia

thefuxia May 15, 2011

Uhm … but I do exactly this!?

Owner

thefuxia commented May 15, 2011

Uhm … but I do exactly this!?

@hakre

This comment has been minimized.

Show comment Hide comment
@hakre

hakre May 15, 2011

filtered in the meaning of filter_var(), e.g.: return filter_var( $email, FILTER_VALIDATE_EMAIL ); -- filter_var will either return FALSE or the filtered value of $email. In your gist you return $email unfiltered.

hakre commented May 15, 2011

filtered in the meaning of filter_var(), e.g.: return filter_var( $email, FILTER_VALIDATE_EMAIL ); -- filter_var will either return FALSE or the filtered value of $email. In your gist you return $email unfiltered.

@thefuxia

This comment has been minimized.

Show comment Hide comment
@thefuxia

thefuxia May 16, 2011

Oh, I see. :) Changed.

Owner

thefuxia commented May 16, 2011

Oh, I see. :) Changed.

@swinhoe

This comment has been minimized.

Show comment Hide comment
@swinhoe

swinhoe Sep 14, 2011

Ive tested this and it still errors on an apostrophe.. is it working for you ?

swinhoe commented Sep 14, 2011

Ive tested this and it still errors on an apostrophe.. is it working for you ?

@thefuxia

This comment has been minimized.

Show comment Hide comment
@thefuxia

thefuxia Sep 14, 2011

Do you mean an apostrophe in a mail address or a parse error?

Owner

thefuxia commented Sep 14, 2011

Do you mean an apostrophe in a mail address or a parse error?

@swinhoe

This comment has been minimized.

Show comment Hide comment
@swinhoe

swinhoe Sep 15, 2011

no, no parse error, but the address is still rejected.

does the PHP filter not allow apostrophes ?

swinhoe commented Sep 15, 2011

no, no parse error, but the address is still rejected.

does the PHP filter not allow apostrophes ?

@thefuxia

This comment has been minimized.

Show comment Hide comment
@thefuxia

thefuxia Sep 16, 2011

The filter allows apostrophes, at least the fake apostrophe '. Hm, the WordPress functions should allow it too. I’m not sure what happens here.

Owner

thefuxia commented Sep 16, 2011

The filter allows apostrophes, at least the fake apostrophe '. Hm, the WordPress functions should allow it too. I’m not sure what happens here.

@swinhoe

This comment has been minimized.

Show comment Hide comment
@swinhoe

swinhoe Sep 16, 2011

They, dont, its a logged issue in WP Trac. Im trying to find the easiest workaround...

swinhoe commented Sep 16, 2011

They, dont, its a logged issue in WP Trac. Im trying to find the easiest workaround...

@swinhoe

This comment has been minimized.

Show comment Hide comment
@swinhoe

swinhoe Apr 23, 2012

Are we going to get this change pushed into a future release ?

https://wordpress.org/support/topic/writing-a-plugin-to-amend-the-core-possible?replies=9#post-2769861

It would be handy to support email address's properly...

swinhoe commented Apr 23, 2012

Are we going to get this change pushed into a future release ?

https://wordpress.org/support/topic/writing-a-plugin-to-amend-the-core-possible?replies=9#post-2769861

It would be handy to support email address's properly...

@thefuxia

This comment has been minimized.

Show comment Hide comment
@thefuxia

thefuxia Apr 23, 2012

There is an open ticket: http://core.trac.wordpress.org/ticket/17433

Go, vote for it, add Unit tests. Then it may become part of the core.

Owner

thefuxia commented Apr 23, 2012

There is an open ticket: http://core.trac.wordpress.org/ticket/17433

Go, vote for it, add Unit tests. Then it may become part of the core.

@swinhoe

This comment has been minimized.

Show comment Hide comment
@swinhoe

swinhoe Apr 23, 2012

swinhoe commented Apr 23, 2012

@thefuxia

This comment has been minimized.

Show comment Hide comment
@thefuxia

thefuxia Apr 23, 2012

Ask on Trac. I have no influence to core development.

Owner

thefuxia commented Apr 23, 2012

Ask on Trac. I have no influence to core development.

@tcbarrett

This comment has been minimized.

Show comment Hide comment
@tcbarrett

tcbarrett Oct 3, 2013

The callback functions need the t5_ prefix - have forked a working example.

Note that apostrophes are escaped by WordPress, so they are still invalid.

The callback functions need the t5_ prefix - have forked a working example.

Note that apostrophes are escaped by WordPress, so they are still invalid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment