WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/sanitize user

Description

Sanitize username stripping out unsafe characters.

If $strict is true, only alphanumeric characters plus these: _, space, ., -, *, and @ are returned.

Removes tags, octets, entities, and if strict is enabled, will remove all non-ASCII characters. After sanitizing, it passes the username, raw username (the username in the parameter), and the strict parameter as parameters for the sanitize_user filter.

Usage

<?php sanitize_user$username$strict ?>

Parameters

$username
(string) (required) The username to be sanitized.
Default: None
$strict
(boolean) (optional) If set limits $username to specific characters.
Default: false

Return Values

(string) 
The sanitized username, after passing through filters.

Examples

Notes

  • Uses: apply_filters() Calls 'sanitize_user' hook on username, raw username, and $strict parameter.

Change Log

Source File

sanitize_user() is located in wp-includes/formatting.php.

Related

Functions

sanitize_user() is in a class of functions that help you sanitize potentially unsafe data which allow you to pass an arbitrary variable and receive the clean version based on data type. Others include:

Filters

See also index of Function Reference and index of Template Tags.