wysiwyg - How to remove commenters ability to add hyperlinks to comments?

I'd like to be able to filter out a commenters ability to add hyperlinks in their comment text.I removed the &quo

I'd like to be able to filter out a commenters ability to add hyperlinks in their comment text.

I removed the "websites" field from the mix to reduce the amount of spammage already (see: Removing the "Website" Field from Comments and Replies?") which has helped a lot.

By default, they can use the '< a '> tag to do so in the comment box text, which allows spammers to embed hyperlinks to their sites.

Is there a way to filter out that capability in the wysiwyg editor for comment fields?

I'd like to be able to filter out a commenters ability to add hyperlinks in their comment text.

I removed the "websites" field from the mix to reduce the amount of spammage already (see: Removing the "Website" Field from Comments and Replies?") which has helped a lot.

By default, they can use the '< a '> tag to do so in the comment box text, which allows spammers to embed hyperlinks to their sites.

Is there a way to filter out that capability in the wysiwyg editor for comment fields?

Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 1 asked Jan 3, 2011 at 17:01 cpugurucpuguru 2771 gold badge3 silver badges10 bronze badges 1
  • nice idea, p.s.: codex.wordpress/Function_Reference/wp_filter_comment – edelwater Commented Jan 3, 2011 at 17:14
Add a comment  | 

2 Answers 2

Reset to default 9

WP runs so many prettifying filters on this stuff that it's easy to get lost.

Here is what I ended up with:

remove_filter('comment_text', 'make_clickable', 9);
add_filter('pre_comment_content', 'strip_comment_links');

function strip_comment_links($content) {

    global $allowedtags;

    $tags = $allowedtags;
    unset($tags['a']);
    $content = addslashes(wp_kses(stripslashes($content), $tags));

    return $content;
}

This scrubs out clearly defined links and removes filter that turns plain text links into properly tagged ones.

Another solution -

The function that will remove all <a>...</a> from a text (Probably it's better to use strip_tags instead of regex here):

     function strip_links($content){
       return preg_replace('/<a[^>]*>(.*)<\/a>/iU','', $content);
     }

Remove links from all new comments permanently, before they are insterted in the db:

     add_filter('preprocess_comment', 'new_comment_strip_links');
     function new_comment_strip_links($commentdata){
       $commentdata['comment_content'] = strip_links($commentdata['comment_content']);
       return $commentdata;
     }

Or, remove links before we output them to the screen (Your theme should run the 'comment_text' filter somewhere in a template file):

     add_filter('comment_text', 'display_comment_strip_links');
     function display_comment_strip_links($content){
       return strip_links($content);
     }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745089535a4610609.html

相关推荐

  • wysiwyg - How to remove commenters ability to add hyperlinks to comments?

    I'd like to be able to filter out a commenters ability to add hyperlinks in their comment text.I removed the &quo

    14小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信