Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
sanitize_hex_color
/**
* Duplicate the sanitize_hex_color function, which is generally
* only available to the theme customizer.
*/
if ( !function_exists( 'sanitize_hex_color' ) ) {
function sanitize_hex_color( $color ) {
if ( '' === $color )
return '';
// 3 or 6 hex digits, or the empty string.
if ( preg_match('|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) )
return $color;
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.