of_sanitize_hex

Sanitize a color represented in hexidecimal notation.

Description

(string) of_sanitize_hex( (string) $hex, (string) $default = '' ); 

Returns (string)

Parameters (2)

0. $hex (string)
Color in hexidecimal notation. # may or may not be prepended to the string.
1. $default — Optional. (string) => ''
The value that this function should return if it cannot be recognized as a color.

Usage

  1. if ( !function_exists( 'of_sanitize_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. // The value that this function should return if it cannot be recognized as a color. 
  8. $default = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = of_sanitize_hex($hex, $default); 
  12.  

Defined (1)

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

/admin/includes/class-options-sanitization.php  
  1. function of_sanitize_hex( $hex, $default = '' ) { 
  2. if ( of_validate_hex( $hex ) ) { 
  3. return $hex; 
  4. return $default;