WordPress.org

Forums

[resolved] Disabling HTML tags in comments (14 posts)

  1. fterh
    Member
    Posted 4 years ago #

    I hacked the kses.php and added // before the undesired HTML tags in the variable $allowedtags. However when I tried posting:

    <b>Test comment</b>

    the "Test commment" is bolded.

    Why doesn't it work?

  2. Mark / t31os
    Moderator
    Posted 4 years ago #

    Plonk this in your theme's functions.php file.

    Eg. wp-content/your-theme/functions.php

    add_filter( 'comment_text', 'wp_filter_nohtml_kses' );
    add_filter( 'comment_text_rss', 'wp_filter_nohtml_kses' );
    add_filter( 'comment_excerpt', 'wp_filter_nohtml_kses' );

    After the opening PHP tag, ie. <?php ...so it looks like this..

    <?php
    add_filter( 'comment_text', 'wp_filter_nohtml_kses' );
    add_filter( 'comment_text_rss', 'wp_filter_nohtml_kses' );
    add_filter( 'comment_excerpt', 'wp_filter_nohtml_kses' );
  3. fterh
    Member
    Posted 4 years ago #

    I get this:

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'wp_filter_normal_kses' not found or invalid function name in E:\Software\xampp\htdocs\wordpress\wp-includes\plugin.php on line 166

  4. Mark / t31os
    Moderator
    Posted 4 years ago #

    Any plugins currently active?

  5. fterh
    Member
    Posted 4 years ago #

    No, except the default ones. I'll try again, sometimes a couple days' rest helps speed things up :)

  6. Mark / t31os
    Moderator
    Posted 4 years ago #

    I've tested the code in two installations, one running 2.9.2 and another running the latest SVN of 3.0, it worked without errors in both cases.

    Perhaps it would help to paste your complete functions.php into a pastebin so i can see how you've pasted the code and where..

  7. fterh
    Member
    Posted 4 years ago #

    Okay now here's the weird thing:

    After adding the 3 lines of add_filter(); it works, no errors whatsoever, but in my kses.php I did not have the <b> tag commented out but yet the comment is not bolded.

  8. Mark / t31os
    Moderator
    Posted 4 years ago #

    Well yeah all tags will be stripped out, that's what you asked for..

    Disabling HTML tags in comments

    If you want to limit the tags available you'd need a different solution, i assumed from the title you wanted all tags stripped.

  9. fterh
    Member
    Posted 4 years ago #

    Oh sorry for the unclear title. What I wanted was to disable certain tags, but not all.

    I followed this solution: http://codex.wordpress.org/Answers-Configuration#Stopping_HTML_in_Comments but it doesn't work.

  10. Mark / t31os
    Moderator
    Posted 4 years ago #

    The approach does work, just ensure you edit the $allowedtags array, not the preceeding $allowedposttags array which is for posts.

  11. fterh
    Member
    Posted 4 years ago #

    It doesn't for me :X

    Just checking, that approach doesn't require any adding of lines to the functions file, right?

  12. Mark / t31os
    Moderator
    Posted 4 years ago #

    So you're editting kses.php as indicated on the above link right?

    If won't strip any existing comments if that's what you're expecting, once the changes are made it will only effect new comments being posted. Dealing with existing comments would require a different approach.

  13. fterh
    Member
    Posted 4 years ago #

    I was just about to post that it didn't work, new comments with the commented-out-tags still appear as if the tags were working. Then I had a thought and realized that the moderation only applies to "visitors". I, as the admin, can post comments with the disallowed tags :X

  14. chadrew
    Member
    Posted 4 years ago #

    This is exactly what I was looking for. Just a small note, Firefox seems to still show HTML formatting and hyperlinks in the RSS feed; comments on site are OK, and viewing in IE the comments in RSS feed are OK too. I'm not sure why Firefox is different.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.