of_validate_hex

Is a given string a color formatted in hexidecimal notation?.

Description

of_validate_hex( (string) $hex ); 

Parameters (1)

0. $hex (string)
Color in hexidecimal notation. # may or may not be prepended to the string.

Usage

  1. if ( !function_exists( 'of_validate_hex' ) ) { 
  2. require_once '/admin/includes/class-options-sanitization.php'; 
  3.  
  4. // Color in hexidecimal notation. "#" may or may not be prepended to the string. 
  5. $hex = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = of_validate_hex($hex); 
  9.  

Defined (1)

The function is defined in the following location(s).

/admin/includes/class-options-sanitization.php  
  1. function of_validate_hex( $hex ) { 
  2. $hex = trim( $hex ); 
  3. /** Strip recognized prefixes. */ 
  4. if ( 0 === strpos( $hex, '#' ) ) { 
  5. $hex = substr( $hex, 1 ); 
  6. elseif ( 0 === strpos( $hex, '%23' ) ) { 
  7. $hex = substr( $hex, 3 ); 
  8. /** Regex match. */ 
  9. if ( 0 === preg_match( '/^[0-9a-fA-F]{6}$/', $hex ) ) { 
  10. return false; 
  11. else { 
  12. return true;