• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Custom New Thread/Post Listener

#1
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
#2
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.
 

Jeremy

Well-known member
#4
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.
 
#5
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
#6
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.
 
#8
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
#11
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.
 
#13
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
#14
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
#16
The code is well documented, and resources exist to explain nearly everything. The resource listed above will walk you through it.