Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.
function validate_username( $username ) {
    $sanitized = sanitize_user( $username, true );
    $valid = ( $sanitized == $username );

    return apply_filters( 'validate_username', $valid, $username );
}

in wp-includes/registration.php i want to change

$sanitized = sanitize_user( $username, true );

to

$sanitized = sanitize_user( $username, false );

I couldnt success to write add_filter in there, somehow its not working. Can you write a filter for this please?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Like so:

function my_validate_username( $valid, $username ) {
    $sanitized = sanitize_user( $username, false );
    $valid = ( $sanitized == $username );

    return $valid;
}

add_filter('validate_username', 'my_validate_username', 10, 2);
share|improve this answer
    
i am adding this change to core for turkish chars: core.trac.wordpress.org/ticket/15248 but when i use this add_filter i am getting error: Catchable fatal error: Object of class WP_Error could not be converted to string in wp-includes\formatting.php on line 2785 How can i fix this any idea? –  Ünsal Korkmaz Dec 10 '10 at 12:20
    
Add some error checking in that case. The general idea is what is highlighted above: override the WP function entirely using the filter. –  Denis de Bernardy Dec 10 '10 at 12:48

So the problem is caused by this line in wp-includes/user.php:

$user_login = sanitize_user($user_login, true);

which causes sanitize_true to be strict, which reduced to ascii.

Change to false to work around, who knows what other bugs this will cause since apparently non-latin logins in wordpress is not supported, see this thread:

http://bbpress.org/forums/topic/accents-in-username#post-19037

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.