Info
- 3 posts
- 2 voices
- Started 3 years ago by _ck_
- Latest reply from _ck_
- This topic is not a support question
Here's how to strip bad markup instead of encoding it
-
- Posted 3 years ago #
On some forums you might want to remove bad html markup that's not allowed instead of encoding it into text. Here's a mini-plugin to do just that. It also converts
<b>into<strong>and<i>into<em>It only runs when posts are saved instead of each time they are displayed to keep things at full speed. Posts by Moderators and Administrators are not stripped.
(note: for now it doesn't obey backticks and will strip inside them)
<?php /* Plugin Name: Strip Bad Markup Plugin URI: http://bbpress.org/plugins/topic/ Description: removes tags that are not allowed in posts instead of encoding them Author: _ck_ Author URI: http://bbShowcase.org Version: 0.0.1 */ add_filter('pre_post', 'strip_bad_markup',9); function strip_bad_markup($text) { if (!bb_current_user_can('moderate')) { $tags=bb_allowed_tags(); $tags['br']=true; $tags['p']=true; $tags = implode('|',array_keys($tags)); $text=preg_replace(array("/<(\/)?b>/si","/<(\/)?i>/si"),array("<strong>","<em>"),$text); $text=preg_replace("/<\/?(?!($tags)).*?>/sim","", $text); } return $text; } ?> -
- Posted 3 years ago #
This looks awesome! I am going to try it out tomorrow... I noticed that some nbsp's were being "encoded" in my bbPress installs tonight, and was wondering how I was gonna strip them out. Looking forward to trying this out :-).
Will report back with results.
-
- Posted 3 years ago #
Ah I didn't think of handling
But I thought bbpress allowed htmlentities. Maybe only some of them. -
You must log in to post.