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

Alert users in addon?

Liam W

Well-known member
OK, I'm going around in circles with headaches here...

Is there a guide or can someone tell me exactly how to alert users, just with plain text, in an addon?

There's no specific content with it - it's just plain text and a link.

I've looked through the code, and I created an entry in `xf_content_type_field` and it still doesn't work. The alert 'alerts', as in it says I have a new alert, but when I go to view it it says I have no alert.

I added a few var_dumps, and it looks like it can't find the alert handler for my content type - even though I put it in that table.

Do I have to add another db entry somewhere?



XenForo moderator
Staff member
There are quite a few steps to getting alerts implemented.
Very briefly, you will need:
  • An alert handler class
  • A datawriter (optional)
  • Data in the xf_content_type and xf_content_type_field tables
  • A specifically named template, e.g. alert_content_type_action
It sounds like you missed the xf_content_type table.

Chris D

XenForo developer
Staff member
There needs to be an entry in xf_content_type which contains a cache of all the available content type fields ... this is rebuilt automatically. You just need to insert the content_type name and the add-on ID.

During rebuild, matching fields in xf_content_type_field are serialised and stored in the "fields" field of xf_content_type.

So once you have that, and the bits Brogan mentions above, you need to rebuild the content types cache. Otherwise you get the exact problem you describe. Easiest way to rebuild the cache is just to install an add-on (e.g. export your add-on XML and upgrade with it).

Things should start working then.

Liam W

Well-known member
@Brogan @Chris D

Perfect! I had everything except the xf_content_type entry. I added it, upgraded the addon to rebuild everything, and it works :)

I'm not using a datawriter however, I'm just using the XenForo_Model_Alert model to alert users - there's no data associated with the alert, so there's nothing I need to store.

Thanks :)


Daniel Hood

Well-known member
Easiest way to rebuild the cache is just to install an add-on (e.g. export your add-on XML and upgrade with it).
I generally just delete the xf data registry row for content types. Is there a downside to this? It rebuilds exactly what I want on the next page load.

Daniel Hood

Well-known member

Liam W

Well-known member
No, you're right. That's fine too.

I forgot about that approach because I actually use this:


Still unsure why something like this isn't in the core - but with improvements where the content types are included in the add-on XML.
I was surprised something like that wasn't in the addon XML, especially as the xf_content_type table has an addon_id column...

This addon will make it much easier :p Thanks for the link! (And damn me for not searching for it sooner!)