RSS feed

Nutsmuggling

How to allow tags in WordPress comments unobtrusively

Scenario: I am using the tinymcecomments plugin to give some formatting capabilities to commenters.
With the latest WP update I realised the span tag was removed from comments; colors attributes are filtered by the kses filter.

Hum.

After investigating I come across this suggestion in the Codex:

Acceptance of HTML tags in the comments field is managed in the file kses.php, located in the wp-includes folder.

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.

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.

That’s 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’mon, we can do better than that!

In the kses source code I find this:

 
if (!defined('CUSTOM_TAGS'))
	define('CUSTOM_TAGS', false);
 
if (!CUSTOM_TAGS) {     
	etc

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…

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.

add_filter('preprocess_comment','fa_allow_tags_in_comments');
 
function fa_allow_tags_in_comments($data) {
	global $allowedtags; 
	$allowedtags['span'] = array('style'=>array());
	$allowedtags['p'] = array();   
	return $data;
}

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.

Cheers,
Davide

Be Sociable, Share!

64 responses to “How to allow tags in WordPress comments unobtrusively”

  1. madearcaria says:

    moUupS7tZ3 GQUodsS9U4 &nbsp&nbsp<a href=http://dns-davidebenini.it > moUupS7tZ3 GQUodsS9U4 </a> のみによる最低支払を作るとき、あなたはその後負っ残高に対する利息をお支払いいただきます。これはまたあなたのクレジットカードの債務残高が増加します。あなたが唯一の原因で毎月最低支払額を作っている場合は、新しい毎月の利息は、前ヶ月バランスに計算されます。

    mcm 財布 mcm バッグ 新作 クロエ 長財布 新作 シャネル チェーンウォレット mcm アウトレット mcm バッグ トート 時計 ブランド

    クロムハーツ 財布 激安 グッチ 長財布 エムシーエム キーケース

    人は何のオプションを持っていないことを検知するが、統合するために、これらのローンのプロバイダは、ローンの統合のために高い手数料を決定。彼らはあなたの標準金利よりも高い金利を請求する場合があります。あなたはオプションを見て回るために多くの時間を持っていないので、そして、あなたは簡単に犠牲者かもしれません。

    chanel 時計 トリーバーチ バッグ 激安 marc by marc jacobs バッグ ミュウミュウ リボン 財布 ルイヴィトン バッグ 女性 miumiu アウトレット moncler モンクレール エルメス 激安

    ミュウミュウ リボン 財布 ミュウミュウ メンズ 財布

    tb moncler jp out

  2. Obat Alami Asam Urat says:

    kapayunan eung nu ieu mah :-)

  3. Obat Serangan Jantung says:

    I agree :-)

  4. Obat Leher Bengkak says:

    it was Amazing Obat Radang Otak Pada Anak

  5. Obat Angin Duduk says:

    April Wish ? Obat Kanker Kandung Kemih

  6. Obat Penyempitan Pembuluh Darah says:

    thank you for this very useful information. I am very interested in posting your articles. every article that you write very educational and beneficial for the wider community.

  7. Customized Youth San Diego Chargers Blue new jerseys sale says:

    Authentic nfl jerseys Ravens throwback jerseys sale

  8. Vacheron Constantin Watches Online says:

    The added comfort which comes with employing a touch screen watch isn’t only limited to devoid of to press physical buttons to get things done on it. In addition, this is also an effective methods to remind each other from the love they share even when they are physically apart. Most people think Italian watches are just for men, as watches are one of the few products acceptable among men. There a wide range of watches designed particularly for girls through the very young to adolescence. He is incredibly well acknowledged for his reliable, chic and historical designs that attract the buyers as well as satisfies the flavour of any category he explains.

  9. rea says:

    Have youu ever thought about publishing an e-book or guest authoring on other websites?

    I have a blog based upon on the same information you discuss and would really like to have you share some stories/information. I know my subscribers would appreciate your work. If you are even remotely interested, feel frese to shoot me an email.

    Also visit my webpage: rea

  10. ruletka97 says:

    азартные игры смс [url=http://arab5.amerikanskaja-ruletka.ru/theme468.html]казино онлайн на рубли гривны[/url] онлайн казино играть бесплатно шарики, [url=http://arab5.amerikanskaja-ruletka.ru/theme1512.html]казино пополнить webmoney[/url]

  11. lose weight fast pills over the counter says:

    I like it when people get together and share ideas. Great site, stick with it!

  12. quadri famosi says:

    These stands assistance the products to be eye catching and encourages good company. It operates great for your trade.

    stampe su tela This is a link to a website on the World Wide Web.

    dipinti quadri famosi

  13. nike free run 3 heel to toe drop says:

    mbt shoes stores las vegas nike free run zebra karen millen official outlet lululemon black and white hoodie discount mbt shoes fitflop original walkstar where to buy mbt shoes in australia mbt garissa women white blue shoes tiffany and co sets nike free run 3 womens sale karen millen fashion designer tiffany s rings tiffany & co in new york tiffany co dubai walking in vibram five fingers mbt M.Walk Peachblow Shoes nike free 5.0 v4 leopard mbt chapa men shoes pumpkin black nike free run 2 shoes for sale nike free run mens white

  14. ケイトスペード gold coast says:

    ケイトスペード gold coast…

    私ダウン|テーマ、どこうあなたは入手するには、崇拝負荷を通して|それはからを手に入れる?…

Leave a Reply

You must be logged in to post a comment.