wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren
sanitize_html_class › WordPress Function
Seit2.8.0
Veraltetn/v
› sanitize_html_class ( $classname, $fallback = '' )
Parameter: (2) |
|
Gibt zurück: |
|
Definiert in: |
|
Codex: |
Sanitizes an HTML classname to ensure it only contains valid characters.
Strips the string down to A-Z,a-z,0-9,_,-. If this results in an empty string then it will return the alternative value supplied.Ähnliche Funktionen: sanitize_hex_color, sanitize_term, sanitize_meta, sanitize_term_field, sanitize_hex_color_no_hash
Quellcode
function sanitize_html_class( $classname, $fallback = '' ) { // Strip out any percent-encoded characters. $sanitized = preg_replace( '|%[a-fA-F0-9][a-fA-F0-9]|', '', $classname ); // Limit to A-Z, a-z, 0-9, '_', '-'. $sanitized = preg_replace( '/[^A-Za-z0-9_-]/', '', $sanitized ); if ( '' === $sanitized && $fallback ) { return sanitize_html_class( $fallback ); } /** * Filters a sanitized HTML class string. * * @since 2.8.0 * * @param string $sanitized The sanitized HTML class. * @param string $classname HTML class before sanitization. * @param string $fallback The fallback string. */ return apply_filters( 'sanitize_html_class', $sanitized, $classname, $fallback ); }