Don't create topic based on post text?

Plugin Development
  • #1

    I am working on making a profanity filter type plugin that disallows certain words from being posted.

    I'm hooking on to these hooks and returning an error if profanity exists in the data.

            { "hook": "filter:topic.create", "method": "profanityHook" },
            { "hook": "filter:topic.reply", "method": "profanityHook" },
            { "hook": "filter:post.edit", "method": "profanityHook" },
            { "hook": "", "method": "profanityHook" }

    and here's how my hook works:

                if (!data){
                    return next(null,data);//no data no profanity lol
                //check content
                if (data.content){
                        return next(new Error('Profanity found'),data);
                //check topic title
                if (data.topic && data.topic.title){
                    if( hasProfanity(data.topic.title) ){
                         return next(new Error('Profanity found'),data);
                //all ok I guess
                return next(null,data);

    So here's the problem: if there's profanity in the post, but not in the topic title, the topic still gets created with 0 posts in it.

    So, how can I stop the topic from being created with 0 posts?

  • Plugin & Theme Dev

    Observing this code I'd say you should use the and check its title and content payload.

    Using the filter:topic.create would be more or less obsolete then since it might only catch topics created by bad plugins that don't respect this line.

  • #3

    Wow awesome, that seems to have done the trick 👍

    Thank you so much for the help.

Suggested Topics

| | | |