Introduce sanitize_key().

git-svn-id: http://svn.automattic.com/wordpress/trunk@13718 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2010-03-16 19:19:32 +00:00
parent a237b80e0b
commit 6f27182cf1
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.
*