Skip to content

Instantly share code, notes, and snippets.

@ChrisFlannagan
Created May 31, 2016 16:03
Show Gist options
  • Save ChrisFlannagan/ce8c3152552e7156ad2c892bcc7e85cb to your computer and use it in GitHub Desktop.
Save ChrisFlannagan/ce8c3152552e7156ad2c892bcc7e85cb to your computer and use it in GitHub Desktop.
<?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