Jump to content

Recommended Posts

Hi guys.

 

As per usual when the official forums of software like Wordpress gives you no help whatsoever i come to the only community that always gave me great help in the past!

 

This time i'm trying to get WP to allow hyphens and underscores in the username. There is one topic in their forum explaining that commenting some code could help, but it didn't for me in the latest version.

 

I have no idea what this code is or how it works (or even if it's there to allow or disallow), but as i've seen many other requests for help for this type of code in this board i try here:

 

/**
* Sanitize username stripping out unsafe characters.
*
* Removes tags, octets, entities, and if strict is enabled, will only keep
* alphanumeric, _, space, ., -, @. After sanitizing, it passes the username,
* raw username (the username in the parameter), and the value of $strict as
* parameters for the 'sanitize_user' filter.
*
* @since 2.0.0
* @uses apply_filters() Calls 'sanitize_user' hook on username, raw username,
*		and $strict parameter.
*
* @param string $username The username to be sanitized.
* @param bool $strict If set limits $username to specific characters. Default false.
* @return string The sanitized username, after passing through filters.
*/
function sanitize_user( $username, $strict = false ) {
$raw_username = $username;
$username = wp_strip_all_tags( $username );
$username = remove_accents( $username );
// Kill octets
$username = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '', $username );
$username = preg_replace( '/&.+?;/', '', $username ); // Kill entities

// If strict, reduce to ASCII for max portability.
if ( $strict )
	$username = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $username );

$username = trim( $username );
// Consolidate contiguous whitespace
$username = preg_replace( '|\s+|', ' ', $username );

return apply_filters( 'sanitize_user', $username, $raw_username, $strict );
}

 

The wierd thing is that it clearly states that.. "will only keep alphanumeric, _, space, ., -, @." , which it obviously doesn't. The code that i think is what you can modify to allow hyphens and underscores is the one under "//Kill octets". Does anyone have any idea what i could add there to make this happen? Simply commenting out that code for some reason still only allows numbers and letters in usernames during the registration on my website.

The code removing hyphens and underscores is somewhere else, not in this function. Probably, in filters (apply_filters).

 

Hmm, but all the other "functions" or whatever are in the parenthesis of apply_filters, like here:

return apply_filters( 'sanitize_html_class', $sanitized, $class, $fallback );

 

So doesn't that mean that apply_filters just is a function that starts the other functions?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.