Checking employee suggestions & comments for bad words

Checking employee suggestions & comments for bad words

When we tell people about mplyees and how it allows employees to leave public anonymous suggestions, one of their first responses is about abuse. And rightfully so, abuse has always been a hot topic for many semi anonymous sites like

reddit and twitter. This is why mplyees has put checking employee suggestions & comments for bad words as one of our core features.

Flagging employee suggestions and comments

One of the first things that we programmed into mplyees was a flagging system for employee suggestions and comments. It’s a very basic system, but has the ability to be customized if we get a large flux of users using mplyees in the future. This is just one small first step to mitigate abuse, so we came up with another way to help stop abuse.

Checking employee suggestions & comments for bad words

As a first defense against abuse, we built a system that handles checking both employee suggestions & comments for bad words. We started by putting together a list of over 200 bad words.

When someone adds a suggestion or comment we take their input and send it off to a Laravel Queue. The queue is always running and checking for jobs to process. The queue will then take the input and remove the punctuation and extract each individual word.

With the words extracted we check each word against the words in our library of bad words. We also take each bad word and add the proper plural form and check it against the user input words.

Here is our code that checks for bad words.


$badWords = (new GetAllBadWordsController)->arrayOfBadWords();

$titleNoPunctuation = preg_replace("#[[:punct:]]#", "", $this->input['title']);

$descriptionNoPunctuation = preg_replace("#[[:punct:]]#", "", $this->input['description']);

$allWordsNoPunctuation = "{$titleNoPunctuation} {$descriptionNoPunctuation}";

$allInputWords = explode(" ", $allWordsNoPunctuation);

$suggestionStatus = 'public';

foreach ( $allInputWords as $inputWord )
{
    $inputWord = strtolower($inputWord);

    foreach ( $badWords as $badWord )
    {
        $badWord = strtolower($badWord);

        // here we check the singular version of the word
        if ( $inputWord === $badWord )
        {
            $suggestionStatus = 'draft';
        }

        $lastLetter = substr($badWord, -1);
        $secondToLastLetter = substr($badWord, -2, 1);
        $lastTwoLetters = substr($badWord, -2);

        // check for plurals, but which kind??!! :P
        if (
                $lastTwoLetters === "ss" ||
                $lastLetter === "s" ||
                $lastLetter === "x" ||
                $lastTwoLetters === "ch" ||
                $lastTwoLetters === "sh"
            )
        {
            if ( $inputWord === "{$badWord}es" )
            {
                $suggestionStatus = 'draft';
            }
        }

        // y's are dumb
        elseif ( $lastLetter === "y" )
        {
            if ( in_array($secondToLastLetter, ['a', 'e', 'i', 'o', 'u']) )
            {
                if ( $inputWord === "{$badWord}s" )
                {
                    $suggestionStatus = 'draft';
                }
            }
            else
            {
                $badWordWithoutY = substr($badWord, 0, -1);

                if ( $inputWord === "{$badWordWithoutY}ies" )
                {
                    $suggestionStatus = 'draft';
                }
            }

        }
        else
        {
            if ( $inputWord === "{$badWord}s" )
            {
                $suggestionStatus = 'draft';
            }
        }
    }

}

We plan on continuing our efforts to stay ahead of any abuse that may happen on our software.

Please, start making your work culture better today and try out mplyees.

Also, if you have a story about a successful suggestion you’ve made at work, tell us your story!

Leave a Reply

Your email address will not be published. Required fields are marked *