{"id":574,"date":"2010-12-10T00:19:56","date_gmt":"2010-12-09T22:19:56","guid":{"rendered":"http:\/\/www.kavdesign.net\/blog\/?p=574"},"modified":"2010-12-10T00:49:45","modified_gmt":"2010-12-09T22:49:45","slug":"how-to-allow-more-html-tags-in-the-wordpress-comments","status":"publish","type":"post","link":"https:\/\/www.kavdesign.net\/blog\/coding\/how-to-allow-more-html-tags-in-the-wordpress-comments\/","title":{"rendered":"How to allow more html tags in the wordpress comments?"},"content":{"rendered":"<p>Scenario: I am using the <a href=\"http:\/\/wordpress.org\/extend\/plugins\/tinymcecomments\/\">tinymcecomments<\/a> plugin to give some formatting capabilities to commenters. Also <a href=\"http:\/\/wordpress.org\/extend\/plugins\/oembed-for-comments\/\" target=\"_blank\">oEmbed for Comments<\/a>\ufeff is nice one &#8211; when you put a link to youtube or vimeo it automatically embeds the video.<br \/>\nWith the latest WP update I realised the <code>span<\/code> tag was removed from comments; colors attributes are filtered by the kses filter.<\/p>\n<p><!--more-->Hum.<\/p>\n<p>After investigating I come across <a href=\"http:\/\/codex.wordpress.org\/FAQ_Working_with_WordPress#How_do_I_stop_people_from_posting_HTML_in_comments.3F\">this suggestion<\/a> in the Codex:<\/p>\n<blockquote><p>Acceptance of HTML tags in the comments field is managed in the file kses.php, located in the wp-includes folder.<\/p>\n<p>Open this file in a text editor, and locate the list of HTML tags  near the top of the file. Each HTML tag is listed on a separate line, in  the construction of a PHP array of allowed tags. Lines which begin with  \/\/ are commented-out, or disabled, so lines which begin with \/\/  designate HTML tags that are not allowed in comments.<\/p>\n<p>To stop people from posting HTML in comments, edit your kses.php file  as desired to allow or disallow specific HTML tags in comments, by  adding \/\/ to the very beginning of the appropriate lines of the list. To  exclude all HTML tags, comment out all lines which allow HTML tags. Be  sure to save your file when done.<\/p><\/blockquote>\n<p>That\u2019s a start but hey, is the Codex really suggesting that I alter  the WP core? Next update my all precious settings will go away. C\u2019mon,  we can do better than that!<\/p>\n<p>In the kses source code I find this:<\/p>\n<div>\n<div>\n<pre>if (!defined('CUSTOM_TAGS'))\r\n\tdefine('CUSTOM_TAGS', false);\r\n\r\nif (!CUSTOM_TAGS) {\r\n\tetc<\/pre>\n<\/div>\n<\/div>\n<p>So basically I can redefine all the allowed tags structure in a  constant. Not bad. But hey, do I really want to redefine  both the  $allowedposttags and the $allowedtags variables? Naaah\u2026<\/p>\n<p>So I scavenged in the source code and I came across a fit filter. I  wrote a little function for my functions.php file; needless to say, this  could have gone into a plugin.<\/p>\n<div>\n<div>\n<pre>add_filter('preprocess_comment','fa_allow_tags_in_comments');\r\n\r\nfunction fa_allow_tags_in_comments($data) {\r\n\tglobal $allowedtags;\r\n\t$allowedtags['span'] = array('style'=&gt;array());\r\n\t$allowedtags['p'] = array();\r\n\treturn $data;\r\n}<\/pre>\n<\/div>\n<\/div>\n<p>See? Much more concise than overwriting the variables. And more  future-proof: if subsequent versions of WordPress change the variable  there is no constant barring the changes.<\/p>\n<p>Cheers,<br \/>\nDavide<\/p>\n<p>Original post: http:\/\/davidebenini.it\/2010\/04\/29\/how-to-allow-tags-in-wordpress-comments-unobtrusively\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Scenario: I am using the tinymcecomments plugin to give some formatting capabilities to commenters. Also oEmbed for Comments\ufeff is nice one &#8211; when you put<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/www.kavdesign.net\/blog\/coding\/how-to-allow-more-html-tags-in-the-wordpress-comments\/\">Continue reading<span class=\"screen-reader-text\">How to allow more html tags in the wordpress comments?<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[9,82],"tags":[118,142,143,103,418],"class_list":["post-574","post","type-post","status-publish","format-standard","hentry","category-coding","category-wordpress","tag-comments","tag-html","tag-tag","tag-tags","tag-wordpress","entry"],"_links":{"self":[{"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/posts\/574","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/comments?post=574"}],"version-history":[{"count":3,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/posts\/574\/revisions"}],"predecessor-version":[{"id":576,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/posts\/574\/revisions\/576"}],"wp:attachment":[{"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/media?parent=574"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/categories?post=574"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/tags?post=574"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}