This page redirects to an external site: https://developer.wordpress.org/reference/hooks/sanitize_key/
The "sanitize_key" filter is used to filter the key from the sanitize_key() function output. That function sanitize a string key which are used as internal identifiers.
<?php add_filter( 'sanitize_key', 'filter_function_name' ); ?>
By default, lowercase alphanumeric characters, dashes and underscores are allowed. Uppercase characters will be converted to lowercase. After `sanitize_key()` has done its work, it passes the sanitized key through this `sanitize_key` filter.
This filter accepts two parameters, but at least one.
The `sanitize_key()` function done its work, then you want to remove the dashes inside the key.
add_filter( 'sanitize_key', 'remove_dashes_from_keys' );
function remove_dashes_from_keys( $key ) {
return preg_replace( '/-/s', '', $key );;
}
You can interact with the raw key as second parameter of that filter. The raw key is the exact value passed to the function. You could use it to make your own sanitization of the original key.
add_filter( 'sanitize_key', 'do_something_with_rawkeys', 10, 2 );
function do_something_with_rawkeys( $key, $rawkey ) {
// do domething with $rawkey
return $rawkey;
}
sanitize_key() is located in wp-includes/formatting.php#L1231.