Trek15 Posted January 12, 2012 Share Posted January 12, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/254867-how-do-i-allow-hyphens-and-underscores-in-this-code/ Share on other sites More sharing options...
abareplace Posted January 12, 2012 Share Posted January 12, 2012 The code removing hyphens and underscores is somewhere else, not in this function. Probably, in filters (apply_filters). Quote Link to comment https://forums.phpfreaks.com/topic/254867-how-do-i-allow-hyphens-and-underscores-in-this-code/#findComment-1306944 Share on other sites More sharing options...
Trek15 Posted January 12, 2012 Author Share Posted January 12, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/254867-how-do-i-allow-hyphens-and-underscores-in-this-code/#findComment-1306957 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.