mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
Username sanitization cleanups.
git-svn-id: https://develop.svn.wordpress.org/trunk@3481 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -265,13 +265,18 @@ function remove_accents($string) {
|
||||
return $string;
|
||||
}
|
||||
|
||||
function sanitize_user( $username ) {
|
||||
function sanitize_user( $username, $strict = false ) {
|
||||
$raw_username = $username;
|
||||
$username = strip_tags($username);
|
||||
// Kill octets
|
||||
$username = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '', $username);
|
||||
$username = preg_replace('/&.+?;/', '', $username); // Kill entities
|
||||
return apply_filters('sanitize_user', $username, $raw_username);
|
||||
|
||||
// If strict, reduce to ASCII for max portability.
|
||||
if ( $strict )
|
||||
$username = preg_replace('|[^a-z0-9 _.-@]|i', '', $username);
|
||||
|
||||
return apply_filters('sanitize_user', $username, $raw_username, $strict);
|
||||
}
|
||||
|
||||
function sanitize_title($title, $fallback_title = '') {
|
||||
|
||||
@@ -10,6 +10,16 @@ function username_exists( $username ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function validate_username( $username ) {
|
||||
$name = sanitize_user($username, true);
|
||||
$valid = true;
|
||||
|
||||
if ( $name != $username )
|
||||
$valid = false;
|
||||
|
||||
return apply_filters('validate_username', $valid, $username);
|
||||
}
|
||||
|
||||
function wp_insert_user($userdata) {
|
||||
global $wpdb;
|
||||
|
||||
@@ -24,6 +34,8 @@ function wp_insert_user($userdata) {
|
||||
$user_pass = md5($user_pass);
|
||||
}
|
||||
|
||||
$user_login = sanitize_user($user_login, true);
|
||||
|
||||
if ( empty($user_nicename) )
|
||||
$user_nicename = sanitize_title( $user_login );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user