diff --git a/includes/sp-formatting-functions.php b/includes/sp-formatting-functions.php index 4735164f..66fee2e2 100644 --- a/includes/sp-formatting-functions.php +++ b/includes/sp-formatting-functions.php @@ -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; } }