In your extend.php
between return [
and ];
:
(new Extend\Event)
// Add a user to a specific group after number of approved posts, requires flarum/approval.
->listen(\Flarum\Post\Event\Posted::class, function (\Flarum\Post\Event\Posted $event) {
$needsApprovedPosts = 5; // number of approved posts to add group to user
$addGroup = 5; // use the Id of the group you want to add
$user = $event->post->user;
// Skip if user is already part of group
if ($user->groups->find($addGroup) !== null) return;
if ($user->posts()->where('is_approved')->count() >= $needsApprovedPosts) {
$user->groups()->attach($addGroup);
}
}),
Update $needsApprovedPosts
for the amount of posts the user needs before getting the group acccess.
Update $addGroup
to the group Id of the group you want to give access to.
This is untested code, if it errors, just remove the lines from the extend.php
.