Validate hex input close #151
This commit is contained in:
@@ -268,12 +268,15 @@ if ( ! function_exists( 'sp_format_hex' ) ) {
|
||||
*/
|
||||
function sp_format_hex( $hex ) {
|
||||
|
||||
$hex = preg_replace( '/[^A-Fa-f0-9]/', '', $hex );
|
||||
$hex = trim( str_replace( '#', '', $hex ) );
|
||||
|
||||
if ( strlen( $hex ) == 3 ) {
|
||||
$hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
|
||||
}
|
||||
|
||||
$hex = substr( $hex, 0, 6 );
|
||||
|
||||
if ( $hex ) return '#' . $hex;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user