Make WordPress Core


Ignore:
Timestamp:
03/16/2010 07:19:32 PM (15 years ago)
Author:
ryan
Message:

Introduce sanitize_key().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/formatting.php

    r13673 r13718  
    749749
    750750    return apply_filters('sanitize_user', $username, $raw_username, $strict);
     751}
     752
     753/**
     754 * Sanitize a string key.
     755 *
     756 * Keys are used as internal identifiers. They should be lowercase ASCII.  Dashes and underscores are allowed.
     757 *
     758 * @since 3.0.0
     759 *
     760 * @param string $key String key
     761 * @return string Sanitized key
     762 */
     763function sanitize_key( $key ) {
     764    $raw_key = $key;
     765    $key = wp_strip_all_tags($key);
     766    // Kill octets
     767    $key = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '', $key);
     768    $key = preg_replace('/&.+?;/', '', $key); // Kill entities
     769
     770    $key = preg_replace('|[^a-z0-9 _.\-@]|i', '', $key);
     771
     772    // Consolidate contiguous whitespace
     773    $key = preg_replace('|\s+|', ' ', $key);
     774
     775    return apply_filters('sanitize_key', $key, $raw_key);
    751776}
    752777
Note: See TracChangeset for help on using the changeset viewer.