Skip to content

Instantly share code, notes, and snippets.

@devinsays
Last active September 10, 2015 18:14
Show Gist options
  • Save devinsays/ea3b18acc2eccf02a927 to your computer and use it in GitHub Desktop.
Save devinsays/ea3b18acc2eccf02a927 to your computer and use it in GitHub Desktop.
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