We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

Code: Autosubscribe To Forum Posts When You Reply | Forum

Musik
Musik May 22 '16
I see this requested a lot, especially with recent updates, and I found a buried, hard-to-find thread on the forums on the topic. However, because the thread was originally on a different topic, it's very easy to miss. The core code has also changed so the modification is slightly different. So I decided to make a new thread, name it accordingly, and post the updated custom code here in hopes it'll make life far easier for forum searchers.


What This Modification Does

With this modification, when a user replies to a forum thread, they are automatically subscribed to that thread and will receive notifications when new replies are added. The base functionality for Oxwall requires users to manually subscribe to threads, even if they've posted in them previously. The only time a user is automatically subscribed to a thread is if they're the OP. This modification is more intuitive and provides a smoother user experience.


Original thread/credit here.


----


Find the following file: 

/ow_plugins/forum/classes/event_handler.php


----


Locate the following lines:

$event = new OW_Event('notifications.add', $params, $data);

        OW::getEventManager()->trigger($event);

    }


----


Add this code immediately after:

$subscribeService = FORUM_BOL_SubscriptionService::getInstance();

    $userId = OW::getUser()->getId();

    $topicId = $post->topicId;


    if ( OW::getUser()->isAuthorized('forum', 'subscribe') && !$subscribeService->isUserSubscribed($userId, $topicId) )

    {

        $subscription = new FORUM_BOL_Subscription;

        $subscription->userId = $userId;

        $subscription->topicId = $topicId;

        $subscribeService->addSubscription($subscription);

    }


Best of luck!

The Forum post is edited by Musik May 23 '16