Skip to content

Commit

Permalink
New function wfx_valid_hex_colour()
Browse files Browse the repository at this point in the history
Helper function to validate hex colour value input.
  • Loading branch information
Jonnyauk committed May 22, 2016
1 parent 8b103f5 commit 1d0d90f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
17 changes: 17 additions & 0 deletions functions.php
Expand Up @@ -492,6 +492,23 @@
} endif;


/**
* Check if input is valid 6 character hexidecimal colour value (plus additional #)
* Output escaping example $bg_colour = strip_tags( stripslashes( $bg_colour ) );
*
* @since 2.2
* @version 2.2
*
* @param [string] $input Text string including #
* @return [bool] true/false
*/
if ( !function_exists( 'wfx_valid_hex_colour' ) ) : function wfx_valid_hex_colour( $input ) {

global $wfx_data_manage; return $wfx_data_manage->valid_hex_colour( $input );

} endif;


/**
* Check if input starts with a string
*
Expand Down
17 changes: 17 additions & 0 deletions wf-includes/wf-data-management.php
Expand Up @@ -442,6 +442,23 @@ function wf_valid_url($input){
}


/**
* Check if input is valid 6 character hexidecimal colour value (plus additional #)
* Output escaping example $bg_colour = strip_tags( stripslashes( $bg_colour ) );
*
* @since 2.2
* @version 2.2
*
* @param [string] $input Text string including #
* @return [bool] true/false
*/
function wf_valid_hex_colour($input){

return ( preg_match( '/^#[a-f0-9]{6}$/i', $input ) ) ? true : false;

}


/**
* Check if input starts with a string
*
Expand Down
1 change: 1 addition & 0 deletions wf-includes/wf-engine.php
Expand Up @@ -131,6 +131,7 @@ function __construct(){ $this->wflux_data_manage_do = new wflux_data_manage; }
function allowed_tags(){ return $this->wflux_data_manage_do->wf_allowed_tags(); }
function strip_whitespace($input){ return $this->wflux_data_manage_do->wf_strip_whitespace($input); }
function valid_url($input){ return $this->wflux_data_manage_do->wf_valid_url($input); }
function valid_hex_colour($input){ return $this->wflux_data_manage_do->wf_valid_hex_colour($input); }
function starts_with($needle, $haystack){ return $this->wflux_data_manage_do->wf_starts_with($needle, $haystack); }
function ends_with($needle, $haystack){ return $this->wflux_data_manage_do->wf_ends_with($needle, $haystack); }
}
Expand Down

0 comments on commit 1d0d90f

Please sign in to comment.