3 * HTML/XHTML filter that only allows some elements and attributes
5 * Added wp_ prefix to avoid conflicts with existing kses users
8 * @copyright (C) 2002, 2003, 2005
9 * @author Ulf Harnhammar <metaur@users.sourceforge.net>
15 * *** CONTACT INFORMATION ***
16 * E-mail: metaur at users dot sourceforge dot net
17 * Web page: http://sourceforge.net/projects/kses
18 * Paper mail: Ulf Harnhammar
23 * [kses strips evil scripts!]
27 * You can override this in your my-hacks.php file You can also override this
28 * in a plugin file. The my-hacks.php is deprecated in its usage.
32 if (!defined('CUSTOM_TAGS'))
33 define('CUSTOM_TAGS', false);
37 * Kses global for default allowable HTML tags.
39 * Can be override by using CUSTOM_TAGS constant.
41 * @global array $allowedposttags
44 $allowedposttags = array(
62 'blockquote' => array(
67 'xml:lang' => array()),
71 'disabled' => array (),
88 'charoff' => array (),
95 'datetime' => array ()),
103 'xml:lang' => array()),
107 'fieldset' => array(),
113 'action' => array (),
114 'accept' => array (),
115 'accept-charset' => array (),
116 'enctype' => array (),
117 'method' => array (),
119 'target' => array ()),
122 'class' => array ()),
125 'class' => array ()),
128 'class' => array ()),
131 'class' => array ()),
134 'class' => array ()),
137 'class' => array ()),
141 'noshade' => array (),
143 'width' => array ()),
148 'border' => array (),
150 'height' => array (),
151 'hspace' => array (),
152 'longdesc' => array (),
153 'vspace' => array (),
156 'width' => array ()),
158 'datetime' => array (),
164 'align' => array ()),
167 'class' => array ()),
174 'xml:lang' => array()),
177 'width' => array ()),
188 'xml:lang' => array()),
195 'bgcolor' => array (),
196 'border' => array (),
197 'cellpadding' => array (),
198 'cellspacing' => array (),
204 'summary' => array (),
205 'width' => array ()),
209 'charoff' => array (),
210 'valign' => array ()),
215 'bgcolor' => array (),
217 'charoff' => array (),
219 'colspan' => array (),
221 'headers' => array (),
222 'height' => array (),
223 'nowrap' => array (),
224 'rowspan' => array (),
227 'valign' => array (),
228 'width' => array ()),
232 'disabled' => array (),
234 'readonly' => array ()),
239 'charoff' => array (),
240 'valign' => array ()),
245 'bgcolor' => array (),
247 'charoff' => array (),
249 'colspan' => array (),
250 'headers' => array (),
251 'height' => array (),
252 'nowrap' => array (),
253 'rowspan' => array (),
255 'valign' => array (),
256 'width' => array ()),
260 'charoff' => array (),
262 'valign' => array ()),
266 'bgcolor' => array (),
268 'charoff' => array (),
271 'valign' => array ()),
286 * Kses allowed HTML elements.
288 * @global array $allowedtags
291 $allowedtags = array(
294 'title' => array ()),
296 'title' => array ()),
298 'title' => array ()),
300 'blockquote' => array(
306 'datetime' => array ()),
310 'em' => array (), 'i' => array (),
311 // 'ins' => array('datetime' => array(), 'cite' => array()),
327 * Filters content and keeps only allowable HTML elements.
329 * This function makes sure that only the allowed HTML element names, attribute
330 * names and attribute values plus only sane HTML entities will occur in
331 * $string. You have to remove any slashes from PHP's magic quotes before you
332 * call this function.
334 * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news',
335 * 'irc', 'gopher', 'nntp', 'feed', and finally 'telnet. This covers all common
336 * link protocols, except for 'javascript' which should not be allowed for
341 * @param string $string Content to filter through kses
342 * @param array $allowed_html List of allowed HTML elements
343 * @param array $allowed_protocols Optional. Allowed protocol in links.
344 * @return string Filtered content with only allowed HTML elements
346 function wp_kses($string, $allowed_html, $allowed_protocols = array ('http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet')) {
347 $string = wp_kses_no_null($string);
348 $string = wp_kses_js_entities($string);
349 $string = wp_kses_normalize_entities($string);
350 $allowed_html_fixed = wp_kses_array_lc($allowed_html);
351 $string = wp_kses_hook($string, $allowed_html_fixed, $allowed_protocols); // WP changed the order of these funcs and added args to wp_kses_hook
352 return wp_kses_split($string, $allowed_html_fixed, $allowed_protocols);
356 * You add any kses hooks here.
358 * There is currently only one kses WordPress hook and it is called here. All
359 * parameters are passed to the hooks and expected to recieve a string.
363 * @param string $string Content to filter through kses
364 * @param array $allowed_html List of allowed HTML elements
365 * @param array $allowed_protocols Allowed protocol in links
366 * @return string Filtered content through 'pre_kses' hook
368 function wp_kses_hook($string, $allowed_html, $allowed_protocols) {
369 $string = apply_filters('pre_kses', $string, $allowed_html, $allowed_protocols);
374 * This function returns kses' version number.
378 * @return string KSES Version Number
380 function wp_kses_version() {
385 * Searches for HTML tags, no matter how malformed.
387 * It also matches stray ">" characters.
391 * @param string $string Content to filter
392 * @param array $allowed_html Allowed HTML elements
393 * @param array $allowed_protocols Allowed protocols to keep
394 * @return string Content with fixed HTML tags
396 function wp_kses_split($string, $allowed_html, $allowed_protocols) {
397 global $pass_allowed_html, $pass_allowed_protocols;
398 $pass_allowed_html = $allowed_html;
399 $pass_allowed_protocols = $allowed_protocols;
400 return preg_replace_callback('%((<!--.*?(-->|$))|(<[^>]*(>|$)|>))%',
401 create_function('$match', 'global $pass_allowed_html, $pass_allowed_protocols; return wp_kses_split2($match[1], $pass_allowed_html, $pass_allowed_protocols);'), $string);
405 * Callback for wp_kses_split for fixing malformed HTML tags.
407 * This function does a lot of work. It rejects some very malformed things like
408 * <:::>. It returns an empty string, if the element isn't allowed (look ma, no
409 * strip_tags()!). Otherwise it splits the tag into an element and an attribute
412 * After the tag is split into an element and an attribute list, it is run
413 * through another filter which will remove illegal attributes and once that is
414 * completed, will be returned.
418 * @uses wp_kses_attr()
420 * @param string $string Content to filter
421 * @param array $allowed_html Allowed HTML elements
422 * @param array $allowed_protocols Allowed protocols to keep
423 * @return string Fixed HTML element
425 function wp_kses_split2($string, $allowed_html, $allowed_protocols) {
426 $string = wp_kses_stripslashes($string);
428 if (substr($string, 0, 1) != '<')
430 # It matched a ">" character
432 if (preg_match('%^<!--(.*?)(-->)?$%', $string, $matches)) {
433 $string = str_replace(array('<!--', '-->'), '', $matches[1]);
434 while ( $string != $newstring = wp_kses($string, $allowed_html, $allowed_protocols) )
435 $string = $newstring;
438 // prevent multiple dashes in comments
439 $string = preg_replace('/--+/', '-', $string);
440 // prevent three dashes closing a comment
441 $string = preg_replace('/-$/', '', $string);
442 return "<!--{$string}-->";
444 # Allow HTML comments
446 if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9]+)([^>]*)>?$%', $string, $matches))
448 # It's seriously malformed
450 $slash = trim($matches[1]);
452 $attrlist = $matches[3];
454 if (!@isset($allowed_html[strtolower($elem)]))
456 # They are using a not allowed HTML element
459 return "<$slash$elem>";
460 # No attributes are allowed for closing elements
462 return wp_kses_attr("$slash$elem", $attrlist, $allowed_html, $allowed_protocols);
466 * Removes all attributes, if none are allowed for this element.
468 * If some are allowed it calls wp_kses_hair() to split them further, and then
469 * it builds up new HTML code from the data that kses_hair() returns. It also
470 * removes "<" and ">" characters, if there are any left. One more thing it does
471 * is to check if the tag has a closing XHTML slash, and if it does, it puts one
472 * in the returned code as well.
476 * @param string $element HTML element/tag
477 * @param string $attr HTML attributes from HTML element to closing HTML element tag
478 * @param array $allowed_html Allowed HTML elements
479 * @param array $allowed_protocols Allowed protocols to keep
480 * @return string Sanitized HTML element
482 function wp_kses_attr($element, $attr, $allowed_html, $allowed_protocols) {
483 # Is there a closing XHTML slash at the end of the attributes?
486 if (preg_match('%\s/\s*$%', $attr))
489 # Are any attributes allowed at all for this element?
491 if (@ count($allowed_html[strtolower($element)]) == 0)
492 return "<$element$xhtml_slash>";
496 $attrarr = wp_kses_hair($attr, $allowed_protocols);
498 # Go through $attrarr, and save the allowed attributes for this element
503 foreach ($attrarr as $arreach) {
504 if (!@ isset ($allowed_html[strtolower($element)][strtolower($arreach['name'])]))
505 continue; # the attribute is not allowed
507 $current = $allowed_html[strtolower($element)][strtolower($arreach['name'])];
509 continue; # the attribute is not allowed
511 if (!is_array($current))
512 $attr2 .= ' '.$arreach['whole'];
513 # there are no checks
516 # there are some checks
518 foreach ($current as $currkey => $currval)
519 if (!wp_kses_check_attr_val($arreach['value'], $arreach['vless'], $currkey, $currval)) {
525 $attr2 .= ' '.$arreach['whole']; # it passed them
526 } # if !is_array($current)
529 # Remove any "<" or ">" characters
531 $attr2 = preg_replace('/[<>]/', '', $attr2);
533 return "<$element$attr2$xhtml_slash>";
537 * Builds an attribute list from string containing attributes.
539 * This function does a lot of work. It parses an attribute list into an array
540 * with attribute data, and tries to do the right thing even if it gets weird
541 * input. It will add quotes around attribute values that don't have any quotes
542 * or apostrophes around them, to make it easier to produce HTML code that will
543 * conform to W3C's HTML specification. It will also remove bad URL protocols
544 * from attribute values. It also reduces duplicate attributes by using the
545 * attribute defined first (foo='bar' foo='baz' will result in foo='bar').
549 * @param string $attr Attribute list from HTML element to closing HTML element tag
550 * @param array $allowed_protocols Allowed protocols to keep
551 * @return array List of attributes after parsing
553 function wp_kses_hair($attr, $allowed_protocols) {
557 $uris = array('xmlns', 'profile', 'href', 'src', 'cite', 'classid', 'codebase', 'data', 'usemap', 'longdesc', 'action');
559 # Loop through the whole attribute list
561 while (strlen($attr) != 0) {
562 $working = 0; # Was the last operation successful?
565 case 0 : # attribute name, href for instance
567 if (preg_match('/^([-a-zA-Z]+)/', $attr, $match)) {
568 $attrname = $match[1];
569 $working = $mode = 1;
570 $attr = preg_replace('/^[-a-zA-Z]+/', '', $attr);
575 case 1 : # equals sign or valueless ("selected")
577 if (preg_match('/^\s*=\s*/', $attr)) # equals sign
581 $attr = preg_replace('/^\s*=\s*/', '', $attr);
585 if (preg_match('/^\s+/', $attr)) # valueless
589 if(FALSE === array_key_exists($attrname, $attrarr)) {
590 $attrarr[$attrname] = array ('name' => $attrname, 'value' => '', 'whole' => $attrname, 'vless' => 'y');
592 $attr = preg_replace('/^\s+/', '', $attr);
597 case 2 : # attribute value, a URL after href= for instance
599 if (preg_match('/^"([^"]*)"(\s+|$)/', $attr, $match))
602 $thisval = $match[1];
603 if ( in_array($attrname, $uris) )
604 $thisval = wp_kses_bad_protocol($thisval, $allowed_protocols);
606 if(FALSE === array_key_exists($attrname, $attrarr)) {
607 $attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname=\"$thisval\"", 'vless' => 'n');
611 $attr = preg_replace('/^"[^"]*"(\s+|$)/', '', $attr);
615 if (preg_match("/^'([^']*)'(\s+|$)/", $attr, $match))
618 $thisval = $match[1];
619 if ( in_array($attrname, $uris) )
620 $thisval = wp_kses_bad_protocol($thisval, $allowed_protocols);
622 if(FALSE === array_key_exists($attrname, $attrarr)) {
623 $attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname='$thisval'", 'vless' => 'n');
627 $attr = preg_replace("/^'[^']*'(\s+|$)/", '', $attr);
631 if (preg_match("%^([^\s\"']+)(\s+|$)%", $attr, $match))
634 $thisval = $match[1];
635 if ( in_array($attrname, $uris) )
636 $thisval = wp_kses_bad_protocol($thisval, $allowed_protocols);
638 if(FALSE === array_key_exists($attrname, $attrarr)) {
639 $attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname=\"$thisval\"", 'vless' => 'n');
641 # We add quotes to conform to W3C's HTML spec.
644 $attr = preg_replace("%^[^\s\"']+(\s+|$)%", '', $attr);
650 if ($working == 0) # not well formed, remove and try again
652 $attr = wp_kses_html_error($attr);
657 if ($mode == 1 && FALSE === array_key_exists($attrname, $attrarr))
658 # special case, for when the attribute list ends with a valueless
659 # attribute like "selected"
660 $attrarr[$attrname] = array ('name' => $attrname, 'value' => '', 'whole' => $attrname, 'vless' => 'y');
666 * Performs different checks for attribute values.
668 * The currently implemented checks are "maxlen", "minlen", "maxval", "minval"
669 * and "valueless" with even more checks to come soon.
673 * @param string $value Attribute value
674 * @param string $vless Whether the value is valueless or not. Use 'y' or 'n'
675 * @param string $checkname What $checkvalue is checking for.
676 * @param mixed $checkvalue What constraint the value should pass
677 * @return bool Whether check passes (true) or not (false)
679 function wp_kses_check_attr_val($value, $vless, $checkname, $checkvalue) {
682 switch (strtolower($checkname)) {
684 # The maxlen check makes sure that the attribute value has a length not
685 # greater than the given value. This can be used to avoid Buffer Overflows
686 # in WWW clients and various Internet servers.
688 if (strlen($value) > $checkvalue)
693 # The minlen check makes sure that the attribute value has a length not
694 # smaller than the given value.
696 if (strlen($value) < $checkvalue)
701 # The maxval check does two things: it checks that the attribute value is
702 # an integer from 0 and up, without an excessive amount of zeroes or
703 # whitespace (to avoid Buffer Overflows). It also checks that the attribute
704 # value is not greater than the given value.
705 # This check can be used to avoid Denial of Service attacks.
707 if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value))
709 if ($value > $checkvalue)
714 # The minval check checks that the attribute value is a positive integer,
715 # and that it is not smaller than the given value.
717 if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value))
719 if ($value < $checkvalue)
724 # The valueless check checks if the attribute has a value
725 # (like <a href="blah">) or not (<option selected>). If the given value
726 # is a "y" or a "Y", the attribute must not have a value.
727 # If the given value is an "n" or an "N", the attribute must have one.
729 if (strtolower($checkvalue) != $vless)
738 * Sanitize string from bad protocols.
740 * This function removes all non-allowed protocols from the beginning of
741 * $string. It ignores whitespace and the case of the letters, and it does
742 * understand HTML entities. It does its work in a while loop, so it won't be
743 * fooled by a string like "javascript:javascript:alert(57)".
747 * @param string $string Content to filter bad protocols from
748 * @param array $allowed_protocols Allowed protocols to keep
749 * @return string Filtered content
751 function wp_kses_bad_protocol($string, $allowed_protocols) {
752 $string = wp_kses_no_null($string);
753 $string = preg_replace('/\xad+/', '', $string); # deals with Opera "feature"
754 $string2 = $string.'a';
756 while ($string != $string2) {
758 $string = wp_kses_bad_protocol_once($string, $allowed_protocols);
765 * Removes any NULL characters in $string.
769 * @param string $string
772 function wp_kses_no_null($string) {
773 $string = preg_replace('/\0+/', '', $string);
774 $string = preg_replace('/(\\\\0)+/', '', $string);
780 * Strips slashes from in front of quotes.
782 * This function changes the character sequence \" to just ". It leaves all
783 * other slashes alone. It's really weird, but the quoting from
784 * preg_replace(//e) seems to require this.
788 * @param string $string String to strip slashes
789 * @return string Fixed strings with quoted slashes
791 function wp_kses_stripslashes($string) {
792 return preg_replace('%\\\\"%', '"', $string);
796 * Goes through an array and changes the keys to all lower case.
800 * @param array $inarray Unfiltered array
801 * @return array Fixed array with all lowercase keys
803 function wp_kses_array_lc($inarray) {
804 $outarray = array ();
806 foreach ( (array) $inarray as $inkey => $inval) {
807 $outkey = strtolower($inkey);
808 $outarray[$outkey] = array ();
810 foreach ( (array) $inval as $inkey2 => $inval2) {
811 $outkey2 = strtolower($inkey2);
812 $outarray[$outkey][$outkey2] = $inval2;
820 * Removes the HTML JavaScript entities found in early versions of Netscape 4.
824 * @param string $string
827 function wp_kses_js_entities($string) {
828 return preg_replace('%&\s*\{[^}]*(\}\s*;?|$)%', '', $string);
832 * Handles parsing errors in wp_kses_hair().
834 * The general plan is to remove everything to and including some whitespace,
835 * but it deals with quotes and apostrophes as well.
839 * @param string $string
842 function wp_kses_html_error($string) {
843 return preg_replace('/^("[^"]*("|$)|\'[^\']*(\'|$)|\S)*\s*/', '', $string);
847 * Sanitizes content from bad protocols and other characters.
849 * This function searches for URL protocols at the beginning of $string, while
850 * handling whitespace and HTML entities.
854 * @param string $string Content to check for bad protocols
855 * @param string $allowed_protocols Allowed protocols
856 * @return string Sanitized content
858 function wp_kses_bad_protocol_once($string, $allowed_protocols) {
859 global $_kses_allowed_protocols;
860 $_kses_allowed_protocols = $allowed_protocols;
862 $string2 = preg_split('/:|:|:/i', $string, 2);
863 if ( isset($string2[1]) && !preg_match('%/\?%', $string2[0]) )
864 $string = wp_kses_bad_protocol_once2($string2[0]) . trim($string2[1]);
866 $string = preg_replace_callback('/^((&[^;]*;|[\sA-Za-z0-9])*)'.'(:|:|&#[Xx]3[Aa];)\s*/', 'wp_kses_bad_protocol_once2', $string);
872 * Callback for wp_kses_bad_protocol_once() regular expression.
874 * This function processes URL protocols, checks to see if they're in the
875 * white-list or not, and returns different data depending on the answer.
880 * @param mixed $matches string or preg_replace_callback() matches array to check for bad protocols
881 * @return string Sanitized content
883 function wp_kses_bad_protocol_once2($matches) {
884 global $_kses_allowed_protocols;
886 if ( is_array($matches) ) {
887 if ( ! isset($matches[1]) || empty($matches[1]) )
890 $string = $matches[1];
895 $string2 = wp_kses_decode_entities($string);
896 $string2 = preg_replace('/\s/', '', $string2);
897 $string2 = wp_kses_no_null($string2);
898 $string2 = preg_replace('/\xad+/', '', $string2);
899 # deals with Opera "feature"
900 $string2 = strtolower($string2);
903 foreach ( (array) $_kses_allowed_protocols as $one_protocol)
904 if (strtolower($one_protocol) == $string2) {
916 * Converts and fixes HTML entities.
918 * This function normalizes HTML entities. It will convert "AT&T" to the correct
919 * "AT&T", ":" to ":", "&#XYZZY;" to "&#XYZZY;" and so on.
923 * @param string $string Content to normalize entities
924 * @return string Content with normalized entities
926 function wp_kses_normalize_entities($string) {
927 # Disarm all entities by converting & to &
929 $string = str_replace('&', '&', $string);
931 # Change back the allowed entities in our entity whitelist
933 $string = preg_replace('/&([A-Za-z][A-Za-z0-9]{0,19});/', '&\\1;', $string);
934 $string = preg_replace_callback('/&#0*([0-9]{1,5});/', 'wp_kses_normalize_entities2', $string);
935 $string = preg_replace_callback('/&#([Xx])0*(([0-9A-Fa-f]{2}){1,2});/', 'wp_kses_normalize_entities3', $string);
941 * Callback for wp_kses_normalize_entities() regular expression.
943 * This function helps wp_kses_normalize_entities() to only accept 16 bit values
944 * and nothing more for &#number; entities.
949 * @param array $matches preg_replace_callback() matches array
950 * @return string Correctly encoded entity
952 function wp_kses_normalize_entities2($matches) {
953 if ( ! isset($matches[1]) || empty($matches[1]) )
957 return ( ( ! valid_unicode($i) ) || ($i > 65535) ? "&#$i;" : "&#$i;" );
961 * Callback for wp_kses_normalize_entities() for regular expression.
963 * This function helps wp_kses_normalize_entities() to only accept valid Unicode
964 * numeric entities in hex form.
968 * @param array $matches preg_replace_callback() matches array
969 * @return string Correctly encoded entity
971 function wp_kses_normalize_entities3($matches) {
972 if ( ! isset($matches[2]) || empty($matches[2]) )
975 $hexchars = $matches[2];
976 return ( ( ! valid_unicode(hexdec($hexchars)) ) ? "&#x$hexchars;" : "&#x$hexchars;" );
980 * Helper function to determine if a Unicode value is valid.
982 * @param int $i Unicode value
983 * @return bool true if the value was a valid Unicode number
985 function valid_unicode($i) {
986 return ( $i == 0x9 || $i == 0xa || $i == 0xd ||
987 ($i >= 0x20 && $i <= 0xd7ff) ||
988 ($i >= 0xe000 && $i <= 0xfffd) ||
989 ($i >= 0x10000 && $i <= 0x10ffff) );
993 * Convert all entities to their character counterparts.
995 * This function decodes numeric HTML entities (A and A). It doesn't do
996 * anything with other entities like ä, but we don't need them in the URL
997 * protocol whitelisting system anyway.
1001 * @param string $string Content to change entities
1002 * @return string Content after decoded entities
1004 function wp_kses_decode_entities($string) {
1005 $string = preg_replace_callback('/&#([0-9]+);/', create_function('$match', 'return chr($match[1]);'), $string);
1006 $string = preg_replace_callback('/&#[Xx]([0-9A-Fa-f]+);/', create_function('$match', 'return chr(hexdec($match[1]));'), $string);
1012 * Sanitize content with allowed HTML Kses rules.
1015 * @uses $allowedtags
1017 * @param string $data Content to filter
1018 * @return string Filtered content
1020 function wp_filter_kses($data) {
1021 global $allowedtags;
1022 return addslashes( wp_kses(stripslashes( $data ), $allowedtags) );
1026 * Sanitize content for allowed HTML tags for post content.
1028 * Post content refers to the page contents of the 'post' type and not $_POST
1032 * @uses $allowedposttags
1034 * @param string $data Post content to filter
1035 * @return string Filtered post content with allowed HTML tags and attributes intact.
1037 function wp_filter_post_kses($data) {
1038 global $allowedposttags;
1039 return addslashes ( wp_kses(stripslashes( $data ), $allowedposttags) );
1043 * Strips all of the HTML in the content.
1047 * @param string $data Content to strip all HTML from
1048 * @return string Filtered content without any HTML
1050 function wp_filter_nohtml_kses($data) {
1051 return addslashes ( wp_kses(stripslashes( $data ), array()) );
1055 * Adds all Kses input form content filters.
1057 * All hooks have default priority. The wp_filter_kses() function is added to
1058 * the 'pre_comment_content' and 'title_save_pre' hooks.
1060 * The wp_filter_post_kses() function is added to the 'content_save_pre',
1061 * 'excerpt_save_pre', and 'content_filtered_save_pre' hooks.
1064 * @uses add_filter() See description for what functions are added to what hooks.
1066 function kses_init_filters() {
1067 // Normal filtering.
1068 add_filter('pre_comment_content', 'wp_filter_kses');
1069 add_filter('title_save_pre', 'wp_filter_kses');
1072 add_filter('content_save_pre', 'wp_filter_post_kses');
1073 add_filter('excerpt_save_pre', 'wp_filter_post_kses');
1074 add_filter('content_filtered_save_pre', 'wp_filter_post_kses');
1078 * Removes all Kses input form content filters.
1080 * A quick procedural method to removing all of the filters that kses uses for
1081 * content in WordPress Loop.
1083 * Does not remove the kses_init() function from 'init' hook (priority is
1084 * default). Also does not remove kses_init() function from 'set_current_user'
1085 * hook (priority is also default).
1089 function kses_remove_filters() {
1090 // Normal filtering.
1091 remove_filter('pre_comment_content', 'wp_filter_kses');
1092 remove_filter('title_save_pre', 'wp_filter_kses');
1095 remove_filter('content_save_pre', 'wp_filter_post_kses');
1096 remove_filter('excerpt_save_pre', 'wp_filter_post_kses');
1097 remove_filter('content_filtered_save_pre', 'wp_filter_post_kses');
1101 * Sets up most of the Kses filters for input form content.
1103 * If you remove the kses_init() function from 'init' hook and
1104 * 'set_current_user' (priority is default), then none of the Kses filter hooks
1107 * First removes all of the Kses filters in case the current user does not need
1108 * to have Kses filter the content. If the user does not have unfiltered html
1109 * capability, then Kses filters are added.
1111 * @uses kses_remove_filters() Removes the Kses filters
1112 * @uses kses_init_filters() Adds the Kses filters back if the user
1113 * does not have unfiltered HTML capability.
1116 function kses_init() {
1117 kses_remove_filters();
1119 if (current_user_can('unfiltered_html') == false)
1120 kses_init_filters();
1123 add_action('init', 'kses_init');
1124 add_action('set_current_user', 'kses_init');