Here is a short reference of some points in source code, which should help you to create XenForo 2 add-on. At first, I recommend you follow the official tutorial with an add-on sample.

You can find it here:

Below you will find additional information I discovered during writing my add-on.

Prepare environment

I usually use Docker for such kind of app. I worked on an app with Memcached, so you will see it in the files below.

Here is the content of Dockerfile:

FROM php:7.2-apache

RUN apt-get update \
    && apt-get install -y \
    zip \
    zlib1g-dev \
    libz-dev \
    libmemcached-dev \
    libpng-dev \
    libfreetype6-dev \
    libjpeg62-turbo-dev \

RUN a2enmod rewrite \
    && pecl install memcache xdebug-2.6.1 \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install gd mysqli zip \
    && docker-php-ext-enable memcache xdebug \
    && echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini

And the content of docker-compose.yml file:

version: '3'

    build: ./docker/php #path to 
    container_name: php_container
      XDEBUG_CONFIG: "remote_host= remote_port=9000"
      PHP_IDE_CONFIG: serverName=localhost
      - ./app:/var/www/html
      - 80:80

    image: mariadb:10.4
      MYSQL_DATABASE: database_name
      - db:/var/lib/mysql
      - 3306:3306

    image: memcached:alpine
      - 11211:11211


If you want to use HTTPS locally read the tutorial How to get HTTPS working on localhost to know more.

XenForo 2 console commands

Enter a Docker container with command:

docker exec -it -u www-data php_container bash

Then you can list all commands and filter them:

$ php cmd.php | grep addon

Add-on commands located in src/XF/Cli/Command/AddOn folder.

Add-on data

All add-ons stored in src/addons folder and xf_addon table in the database.

Setup script

If you change tables with alters, use available data types from here: src/XF/Db/Schema/Column.php::type.
Change tables with SchemaManager. See available methods in src/XF/Db/SchemaManager.php, i.e. tableExists(), columnExists() etc.

Extend entity

The simplest way to extend an entity is to add it in the admin panel. See Development - Class extensions menu in the admin control panel.

It will write data to xf_class_extension table. Classes extensions will be processed here: src/XF/Extension.php::extendClass. XenForo extends with class_alias PHP function. As a parent class, you should specify a class name with “XFCP_” prefix, see how it works here: forum/src/XF/Extension.php:243 (resolveExtendedClassToRoot method).

Event listeners

XenForo 2 sends a lot of events through request processing. See the list of events and event listeners in Development - Code events and Code event listeners in the admin control panel. Data will be stored in database in tables xf_code_event and xf_code_event_listener.

In order to see all events, you could use Xdebug. Set a breakpoint in src/XF/Extension.php::fire function and see event names and hints which you could use.

Use composer packages

Here is a good tutorial on how to use it:

Template functions

See the list of default functions you can use in templates in file src/XF/Template/Templater.php:152 (variable $defaultFunctions).