XF 2.0 Censoring add-on

AndyB

Well-known member
I would like to create an add-on that would essentially disable the Censoring function for logged in members. So when a Unregistered / Unconfirmed visitor is viewing the forum, the Censoring will be in effect. If a logged in member is viewing the forum, the Censoring will not be in effect.

The part of the code that I need to override is located in the following file:

XF/App.php

The line of code that reads the censoring options is this:
PHP:
$formatter->setCensorRules($options->censorWords, $options->censorCharacter);

What would be the best way to extend the following method?

protected function initialize()

Thank you.
 
Last edited:
I got it!

Here's what I did.

1511458102750.webp

The PHP code:
PHP:
<?php

namespace Andy\Censoring;

class Listener
{
    public static function appPubSetup(\XF\Pub\App $app) 
	{
		$userCookie = \XF::app()->request->getCookie('user');
		
		if ($userCookie != '')
		{
			$formatter = $app->stringFormatter();
			$formatter->setCensorRules(array(), array());
		}
    }
}
 
Last edited:
Hey Andy, is there any chance of making this into an add-on where users could choose whether they want content to be censored? We have a swear filter on our board to keep it family friendly but I’d love to have the option to turn it off for myself.
 
Top Bottom