Created
May 31, 2016 16:03
-
-
Save ChrisFlannagan/ce8c3152552e7156ad2c892bcc7e85cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function __construct() { | |
// register actions | |
add_action( 'init', array( &$this, 'init' ) ); | |
} | |
//Sanitizers | |
public function cplh_hexcolor_sanitize( $new_value, $old_value ) { | |
$new_value = sanitize_hex_color( $new_value ); | |
return $new_value; | |
} | |
public function init() { | |
add_filter( 'pre_update_option_cplh_highlight_color', array( &$this, 'cplh_hexcolor_sanitize' ), 10, 2 ); | |
} | |
if ( ! function_exists( 'sanitize_hex_color' ) ) { | |
function sanitize_hex_color( $color ) { | |
if ( '' === $color ) | |
return ''; | |
// 3 or 6 hex digits, or the empty string. | |
if ( preg_match('|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) | |
return $color; | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment