I have a validation function that uses wp_kses
, and it works as expected to remove code from the input if it is relatively simple code HOWEVER using kses is also removing semicolons from inline styles. (in <h1 style="color: red;">the name</h1>
, the semicolon after the word 'red' is removed)
Documentation makes no mention of this behavior, is it a bug? My actual code using kses is below. Can anyone tell me how to change my code so that kses does not remove the semicolon?
function sanitize_name($valid, $value, $field, $input) {
if( $valid !== true ) {
return $valid;
}
$allowed = array(
'h1' => array(
'style' => array(),
),
'h2' => array(),
'h3' => array(),
'h4' => array(),
'h5' => array(),
'h6' => array(),
'p' => array(),
'br' => array(),
'strong' => array(),
'b' => array(),
'em' => array(),
'ul' => array(),
'li' => array(),
'ol' => array(),
'div' => array(),
'span' => array(),
'pre' => array(),
'button' => array(),
'svg' => array(),
'blockquote' => array(),
'a' => array(),
'i' => array(),
'sup' => array(),
'sub' => array()
);
$value2 = wp_kses( $value, $allowed );
if ( strcmp( stripslashes( $value ), $value2) !== 0 ) {
return 'Please remove the disallowed HTML from this field to submit.<br />
Entered:' . stripslashes($value) . '<br />
Cleaned:<br />' . $value2;
}
return $valid;
}
strcmp
which gives a false negative because of the missing semicolon. Do you know of a way around that?validate_name
<h1 style="color: red;">Photo Challenge 1</h1>
and the output is<h1 style="color: red">Photo Challenge 1</h1>
or<h1 style="color: red; text-decoration: underline;">Photo Challenge 1</h1>
and<h1 style="color: red;text-decoration: underline">Photo Challenge 1</h1>
so there is no HTML mistake that I see. The last style attribute doesnt have the semicolon on both... Is that a bug withwp_kses
?