Custom New Thread/Post Listener

viaBowl

Member
Where's the best place or best practice in creating a listener to execute code when a new thread is created?

Does some examples exist?
 
You need to use load_class_controller and extend XenForo_ControllerPublic_Thread / XenForo_ControllerPublic_Forum.

Several add-ons have done it, I believe [bd] Bank does it.
 
grr. More specifically... I'm wanting to copy the first post in a new thread to another database after its created.
 
You should read through the classes, and you'll figure out how XenForo is adding posts. You can then quickly and easily learn how to copy them.
 
maybe i'm missing something. My add-on is quite basic, and here's the code:

PHP:
class XFtoWP_ControllerPublic_Forum extends XFCP_ControllerPublic_Forum
{
    public function actionAddThread()
    {
        $response = parent::actionAddThread();
       // do something here...

    }
}
 
And what's wrong with it? Without more code and a specific error, it's slightly difficult to advise you on which way to go.
 
well... for testing purposes, i tried an email function to see what i get, and even junk code to trigger an error, nothing happens.
 
No, your class is XFtoWP_ControllerPublic_Forum. You'll change the underscores to slashes and add .php. So, XFtoWP/ControllerPublic/Forum.php. However, your problem is in your XFCP class.
 
ok... /library/XFtoWP/Forum.php

PHP:
class XFtoWP_ControllerPublic_Forum extends Xenforo_ControllerPublic_Forum
{
    public function actionAddThread()
    {
        $response = parent::actionAddThread();
        // my custom code here....
    }
}

and nothing still.
 
Reread my post. You have placed the file in the wrong location. You also do not extend XenForo classes directly. You need to use the XenForo Class Proxy system as described in my resource. Have you created a listener?
 
The code is well documented, and resources exist to explain nearly everything. The resource listed above will walk you through it.
 
Then you'll need to post the code you are using, it's location and any errors you're getting.
 
Back
Top Bottom