Codex

Function Reference/sanitize user

Contents

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 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

Since: 2.0.0

Source File

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

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.

Related

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