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?
 

Jeremy

Well-known member
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.
 

viaBowl

Member
grr. More specifically... I'm wanting to copy the first post in a new thread to another database after its created.
 

Jeremy

Well-known member
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.
 

viaBowl

Member
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...

    }
}
 

Jeremy

Well-known member
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.
 

viaBowl

Member
well... for testing purposes, i tried an email function to see what i get, and even junk code to trigger an error, nothing happens.
 

Jeremy

Well-known member
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.
 

viaBowl

Member
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.
 

Jeremy

Well-known member
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?
 

Jeremy

Well-known member
The code is well documented, and resources exist to explain nearly everything. The resource listed above will walk you through it.
 

Jeremy

Well-known member
Then you'll need to post the code you are using, it's location and any errors you're getting.
 
Top