sanitize_user()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
sanitize_user( string $username, bool $strict = false ): string
Описание
Удаляет теги, символы в процентном кодировании, HTML-сущности, а если включён строгий режим, оставляет только буквы, цифры, _, пробел, ., - и @. После очистки передаёт имя пользователя, исходное имя пользователя (переданное в параметре) и значение $strict в качестве параметров фильтра ‘sanitize_user’.
Оригинал (английский)
Removes tags, percent-encoded characters, HTML 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.
Параметры
$username
string
обязательный
$strict
bool
необязательный
= false
Возвращаемое значение
string
Исходный код
wp-includes/formatting.php:2149
function sanitize_user( $username, $strict = false ) {
$raw_username = $username;
$username = wp_strip_all_tags( $username );
$username = remove_accents( $username );
// Remove percent-encoded characters.
$username = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '', $username );
// Remove HTML entities.
$username = preg_replace( '/&.+?;/', '', $username );
// 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 );
/**
* Filters a sanitized username string.
*
* @since 2.0.1
*
* @param string $username Sanitized username.
* @param string $raw_username The username prior to sanitization.
* @param bool $strict Whether to limit the sanitization to specific characters.
*/
return apply_filters( 'sanitize_user', $username, $raw_username, $strict );
}
История изменений
| Версия | Описание |
|---|---|
| 2.0.0 | Introduced. |

