Introduce sanitize_key().

git-svn-id: https://develop.svn.wordpress.org/trunk@13718 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2010-03-16 19:19:32 +00:00
parent 39d8739a81
commit 35236d8291
1 changed files with 25 additions and 0 deletions

View File

@ -750,6 +750,31 @@ function sanitize_user( $username, $strict = false ) {
return apply_filters('sanitize_user', $username, $raw_username, $strict);
}
/**
* Sanitize a string key.
*
* Keys are used as internal identifiers. They should be lowercase ASCII. Dashes and underscores are allowed.
*
* @since 3.0.0
*
* @param string $key String key
* @return string Sanitized key
*/
function sanitize_key( $key ) {
$raw_key = $key;
$key = wp_strip_all_tags($key);
// Kill octets
$key = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '', $key);
$key = preg_replace('/&.+?;/', '', $key); // Kill entities
$key = preg_replace('|[^a-z0-9 _.\-@]|i', '', $key);
// Consolidate contiguous whitespace
$key = preg_replace('|\s+|', ' ', $key);
return apply_filters('sanitize_key', $key, $raw_key);
}
/**
* Sanitizes title or use fallback title.
*