sanitize_key( string $key )

Sanitizes a string key.


Description Description

Keys are used as internal identifiers. Lowercase alphanumeric characters, dashes and underscores are allowed.


Parameters Parameters

$key

(string) (Required) String key


Top ↑

Return Return

(string) Sanitized key


Top ↑

Source Source

File: wp-includes/formatting.php

function sanitize_key( $key ) {
	$raw_key = $key;
	$key = strtolower( $key );
	$key = preg_replace( '/[^a-z0-9_\-]/', '', $key );

	/**
	 * Filters a sanitized key string.
	 *
	 * @since 3.0.0
	 *
	 * @param string $key     Sanitized key.
	 * @param string $raw_key The key prior to sanitization.
	 */
	return apply_filters( 'sanitize_key', $key, $raw_key );
}

Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.