From d8d477c41729cfdbef85f771fe885768c5e6a189 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Wed, 14 Oct 2015 15:32:55 +1100 Subject: [PATCH] Validate hex input close #151 --- includes/sp-formatting-functions.php | 3 +++ 1 file changed, 3 insertions(+) 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; } }