I ended up using the following code in extend.php file.
Not sure if its the best way or not.
use Flarum\Extend;
use Flarum\Post\Event\Saving;
use Flarum\Post\Exception\InvalidPostException;
use Flarum\User\User;
use Illuminate\Contracts\Events\Dispatcher;
return [
(new Extend\Event())
->listen(Saving::class, function (Saving $event) {
$minWordLimit = 5; // Change this to your desired minimum word limit
$content = $event->post->content;
// Remove HTML tags to get the plain text content
$plainTextContent = strip_tags($content);
// Split the plain text content into words
$words = preg_split('/\s+/', $plainTextContent);
// Exclude enforcement for administrator and moderator groups
$user = $event->actor;
if ($user instanceof User && ($user->isAdmin() || $user->isModerator())) {
return;
}
if (count($words) < $minWordLimit) {
$event->post->addError('content', 'Posts must have at least '.$minWordLimit.' words.');
throw new InvalidPostException;
}
})
];
Only thing i'd like to change is the error even tho I try to force to Post must have... error it comes up with oops something is wrong error, need to look into why that is.