Skip to content

Commit

Permalink
New function wfx_allowed_simple_tags()
Browse files Browse the repository at this point in the history
Returns array of limited HTML tags to be used with kses or similar.
- You shouldn't use wp_kses() much - it can be a-little intensive!
- However, sometimes we need it to clean user input to only allow certain tags so there is no funny business!
  • Loading branch information
Jonnyauk committed Jun 22, 2016
1 parent 6630c4f commit ac92e3c
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 5 deletions.
27 changes: 25 additions & 2 deletions functions.php
Expand Up @@ -447,19 +447,42 @@

/**
* Returns array of common HTML tags to be used with kses or similar.
* Use filter 'wflux_allowed_tags' to mainpulate allowed tags
* You shouldn't use wp_kses() much - it can be a-little intensive!
* However, sometimes we need it to clean user input to only allow certain tags so there is no funny business!
*
* Filters available:
* wflux_allowed_tags - Array containing allowed tags
*
* @since 1.1
* @version 1.1
*
* @param none
* @return [array] Allowed tags array
* @return [array] Allowed tags
*/
if ( !function_exists( 'wfx_allowed_tags' ) ) : function wfx_allowed_tags() {
global $wfx_data_manage; return $wfx_data_manage->allowed_tags();
} endif;


/**
* Returns array of limited HTML tags to be used with kses or similar.
* You shouldn't use wp_kses() much - it can be a-little intensive!
* However, sometimes we need it to clean user input to only allow certain tags so there is no funny business!
*
* @since 2.3
* @version 2.3
*
* @param [string] $type Required - Type of tags to return text/simple/headings [text]
* - text => Sutable for wrapping inside your own block level elements - a, br, span, b, strong and i
* - simple => Similar to 'text' param, much more limited, no links or text styling tags = span, br
* - headings => Just headings, nothing else = h1, h2, h3, h4, h5, h6
* @return [array] Allowed tags
*/
if ( !function_exists( 'wfx_allowed_simple_tags' ) ) : function wfx_allowed_simple_tags($input) {
global $wfx_data_manage; return $wfx_data_manage->allowed_simple_tags($input);
} endif;


/**
* Strips white space and other cruft in html type output
*
Expand Down
124 changes: 122 additions & 2 deletions wf-includes/wf-data-management.php
Expand Up @@ -5,14 +5,20 @@
*/
class wflux_data_manage {


/**
* Returns array of common HTML tags to be used with kses or similar.
* Use filter 'wflux_allowed_tags' to mainpulate allowed tags
* You shouldn't use wp_kses() much - it can be a-little intensive!
* However, sometimes we need it to clean user input to only allow certain tags so there is no funny business!
*
* Filters available:
* wflux_allowed_tags - Array containing allowed tags
*
* @since 1.1
* @version 1.1
*
* @return [array] Allowed tags array
* @param none
* @return [array] Allowed tags
*/
function wf_allowed_tags(){

Expand Down Expand Up @@ -409,6 +415,120 @@ function wf_allowed_tags(){
}


/**
* Returns array of limited HTML tags to be used with kses or similar.
* You shouldn't use wp_kses() much - it can be a-little intensive!
* However, sometimes we need it to clean user input to only allow certain tags so there is no funny business!
*
* @since 2.3
* @version 2.3
*
* @param [string] $type Required - Type of tags to return text/simple/headings [text]
* - text => Sutable for wrapping inside your own block level elements - a, br, span, b, strong and i
* - simple => Similar to 'text' param, much more limited, no links or text styling tags = span, br
* - headings => Just headings, nothing else = h1, h2, h3, h4, h5, h6
* @return [array] Allowed tags
*/
function wf_allowed_simple_tags( $input='text' ) {

// Default is first in array
$types = array(
'text',
'notags',
'simple',
'headings'
);

$input = ( !isset($input) ) ? $types[0] : $input;

$type = ( !in_array($input, $types) ) ? $types[0] : $input;

switch ( $type ) {

case 'simple':

$output = array (
'span' => array(
'class'=>array(),
'id'=>array()
),
'br' => array()
);

break;

case 'headings':

$output = array (
'h1' => array(
'align' => true,
'class' => true,
'id' => true,
'style' => true
),
'h2' => array (
'align' => true,
'class' => true,
'id' => true,
'style' => true
),
'h3' => array (
'align' => true,
'class' => true,
'id' => true,
'style' => true
),
'h4' => array (
'align' => true,
'class' => true,
'id' => true,
'style' => true
),
'h5' => array (
'align' => true,
'class' => true,
'id' => true,
'style' => true
),
'h6' => array (
'align' => true,
'class' => true,
'id' => true,
'style' => true
)
);

break;

default:

// text
$output = array(
'a' => array(
'href'=> array(),
'title'=> array(),
'class'=>array(),
'id'=>array()
),
'span' => array(
'class'=>array(),
'id'=>array()
),
'br' => array(),
'b' => array(),
'strong' => array(),
'i' => array()
);

break;

}

return $output;

}


/**
* Strips white space and other cruft in html type output
*
Expand Down
3 changes: 2 additions & 1 deletion wf-includes/wf-engine.php
Expand Up @@ -122,13 +122,14 @@ function wflux_capacitor_data_manage() {

/**
* @since 1.1
* @updated 2.2
* @updated 2.3
* Creates all Wonderflux core data handling/cleaning functions
*/
class wflux_data_manage_all {
public $wflux_data_manage_do;
function __construct(){ $this->wflux_data_manage_do = new wflux_data_manage; }
function allowed_tags(){ return $this->wflux_data_manage_do->wf_allowed_tags(); }
function allowed_simple_tags($input){ return $this->wflux_data_manage_do->wf_allowed_simple_tags($input); }
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); }
Expand Down

0 comments on commit ac92e3c

Please sign in to comment.