XF 1.5 Hooks are deprecated, but for everything?

Hi. New the developing for XenForo.

We recently started using XenForo because we were on an old version of VB (3.7) and it didn't seem smart to upgrade to VB 4 or 5. Honestly, VB lost their mojo. So we've switched to XenForo, which is truly 100x better, especially for developing on.

We bought a license to XenForo over a year ago, but just finally getting to developing and moving the old forum over. So we're on 1.5 (but we've renewed and will likely move to 2.0 sooner than later.)

To business: :D

I'm writing a plugin that gets information from a couple 3rd party APIs. Both of which are done in PHP via cURL. While I was writing it, I noticed that hooks are being deprecated. But in PHP I'm using the hook name and contents to modify the contents. I'm not doing HTML work in the PHP (I get the HTML from custom templates I've made), but assign the properties of a dict object for the templates inside the PHP. (i.e. $template->create('template_name', $dataFromCURL) ).

That being said, now that I see hooks are being deprecated, I'm trying to understand at what level? Are <xen:hook> tags being removed completely?

If so, how do we get PHP classes/functionality into XenForo?

Thanks in advance!

Chris D

XenForo developer
Staff member
Template hooks, and therefore the <xen:hook> tags have all been removed from 2.0.

Since the release of XenForo 1.2 back in 2012, we have been recommending the use of the "Template Modifications" system which you can find under "Appearance" in the Admin CP.

It's a find and replace system. You pick a template, specify a string to search for, provide a string to replace it with and that then gets applied to the compiled template without affecting the original template code.
I see. I'll read more into this. Thanks for the quick response. This will probably be a lot easier to implement once I fully understand how it works with the PHP callback.

Chris D

XenForo developer
Staff member
I missed a part from my previous message (the most important part probably). Template modifications won't work for your use case because the changes are compiled into the template at save time. So if you did a cURL request that would only be performed once, and its result would be compiled into the template, rather than running on every request which is what I assume is roughly desired.

Instead I'd recommend you use a <xen:callback> tag. You can read more about that here:

This is a special tag which calls a PHP class and function, so that's where you'd put your code. You'd then just use "Template Modifications" to place your callback tag in whichever template you want.
Got it working like a charm. :) Thanks for your help.

The one thing that took me a while to find was the callback signature. I eventually found it, but it's good to know that the callback signature is:
function ($content, $params, XenForo_Template_Abstract $template)
This is good to know if you need to bring in templates. You also don't have to use the func_get_args() to get the parameters.