<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[12125] trunk/wp-includes: Introduce wp_kses_post() and wp_kses_data()
  for filtering unescaped data.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12125">12125</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2009-10-29 17:15:58 +0000 (Thu, 29 Oct 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>Introduce wp_kses_post() and wp_kses_data() for filtering unescaped data. Fixes slashing of displayed fields. fixes <a href="http://trac.wordpress.org/ticket/10949">#10949</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesdefaultfiltersphp">trunk/wp-includes/default-filters.php</a></li>
<li><a href="#trunkwpincludesksesphp">trunk/wp-includes/kses.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesdefaultfiltersphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/default-filters.php (12124 => 12125)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/default-filters.php        2009-10-28 21:58:15 UTC (rev 12124)
+++ trunk/wp-includes/default-filters.php        2009-10-29 17:15:58 UTC (rev 12125)
</span><span class="lines">@@ -26,11 +26,16 @@
</span><span class="cx">         add_filter( $filter, '_wp_specialchars', 30 );
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-// Kses only for textarea saves and displays
-foreach ( array( 'pre_term_description', 'term_description', 'pre_link_description', 'link_description', 'pre_link_notes', 'link_notes', 'pre_user_description', 'user_description' ) as $filter ) {
</del><ins>+// Kses only for textarea saves
+foreach ( array( 'pre_term_description', 'pre_link_description', 'pre_link_notes', 'pre_user_description' ) as $filter ) {
</ins><span class="cx">         add_filter( $filter, 'wp_filter_kses' );
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+// Kses only for textarea saves displays
+foreach ( array( 'term_description', 'link_description', 'link_notes', 'user_description' ) as $filter ) {
+        add_filter( $filter, 'wp_kses_data' );
+}
+
</ins><span class="cx"> // Email saves
</span><span class="cx"> foreach ( array( 'pre_comment_author_email', 'pre_user_email' ) as $filter ) {
</span><span class="cx">         add_filter( $filter, 'trim'           );
</span></span></pre></div>
<a id="trunkwpincludesksesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/kses.php (12124 => 12125)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/kses.php        2009-10-28 21:58:15 UTC (rev 12124)
+++ trunk/wp-includes/kses.php        2009-10-29 17:15:58 UTC (rev 12125)
</span><span class="lines">@@ -1059,7 +1059,7 @@
</span><span class="cx">  * @since 1.0.0
</span><span class="cx">  * @uses $allowedtags
</span><span class="cx">  *
</span><del>- * @param string $data Content to filter
</del><ins>+ * @param string $data Content to filter, expected to be escaped with slashes
</ins><span class="cx">  * @return string Filtered content
</span><span class="cx">  */
</span><span class="cx"> function wp_filter_kses($data) {
</span><span class="lines">@@ -1068,6 +1068,20 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><ins>+ * Sanitize content with allowed HTML Kses rules.
+ *
+ * @since 2.9.0
+ * @uses $allowedtags
+ *
+ * @param string $data Content to filter, expected to not be escaped
+ * @return string Filtered content
+ */
+function wp_kses_data($data) {
+        global $allowedtags;
+        return wp_kses( $data , $allowedtags );
+}
+
+/**
</ins><span class="cx">  * Sanitize content for allowed HTML tags for post content.
</span><span class="cx">  *
</span><span class="cx">  * Post content refers to the page contents of the 'post' type and not $_POST
</span><span class="lines">@@ -1076,7 +1090,7 @@
</span><span class="cx">  * @since 2.0.0
</span><span class="cx">  * @uses $allowedposttags
</span><span class="cx">  *
</span><del>- * @param string $data Post content to filter
</del><ins>+ * @param string $data Post content to filter, expected to be escaped with slashes
</ins><span class="cx">  * @return string Filtered post content with allowed HTML tags and attributes intact.
</span><span class="cx">  */
</span><span class="cx"> function wp_filter_post_kses($data) {
</span><span class="lines">@@ -1085,6 +1099,23 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><ins>+ * Sanitize content for allowed HTML tags for post content.
+ *
+ * Post content refers to the page contents of the 'post' type and not $_POST
+ * data from forms.
+ *
+ * @since 2.9.0
+ * @uses $allowedposttags
+ *
+ * @param string $data Post content to filter
+ * @return string Filtered post content with allowed HTML tags and attributes intact.
+ */
+function wp_kses_post($data) {
+        global $allowedposttags;
+        return wp_kses( $data , $allowedposttags );
+}
+
+/**
</ins><span class="cx">  * Strips all of the HTML in the content.
</span><span class="cx">  *
</span><span class="cx">  * @since 2.1.0
</span></span></pre>
</div>
</div>

</body>
</html>