Creating an Addon.

Yeah, would be interested, too.
Specially explaining the architecture (listeners, hooks, php-xen relation, etc.).
So like for real beginners :P.
 
I've picked up a few things throughout my journey so far. I plan to write tutorials once I'm confident of my skills.
That would be great because there is no "Starting Guide" for beginners, and I mean beginners. All those developers have background in programming and they just need to adapt their skills to Xenforo/different language whereas real beginners don't understand the system. Sure all starters need at least basic programming knowledge like conditionals or functions and object-oriented programming, and stuff but that is not enough to see the "big picture". Specially when you are someone outside of this IT business. At least I feel like that and I would like to understand the "inside" stuff. I would appreciate that a lot.
 
Last edited:
Part 1

This walk-through will take you step-by-step through the process of creating a working XenForo Add-on.

The Add-on created will allow Admins to prevent the editing of signatures for members with less than a specified amount of posts, and who belong to a particular group. To accomplish this we will need to set up a Listener, an Admin Options Page, and create the PHP files.

I decided to not use screen shots in this walk-through as I want to give the feel that you already know XenForo's Model View Controller (MVC) concept and are about to write your Add-on. Each step will be explained in detailed.

The working Add-on will be available at the end of this walk-through for coders to reference, or for licensed members to use.

If you plan on building the Add-on step by step you will need to enable Debug Mode. It is recommended that you first make a back-up of your config.php file before editing it. To enable debug mode:

open: yourForo -> library -> config.php

And add at the bottom: $config['debug'] = true;

At this time you may also want to add:

// $config['enableListeners'] = false;

Save your config.php file.

Creating the Add-on

Log into your AdminCP, and navigate to: Development -> Create Add-on

The following fields for this Add-on need to be filled with the following information:

Add-on ID: limitSigs
Title: Limit Signatures for new Members
Version String: 1.0
Version ID: 1

The Version ID is used internally to keep track of revisions. Increase this number for each revision.

The rest of the fields we do not need for this Add-on.

Click the Save Add-on button.

As the purpose of our Add-on is to not allow new members to edit (create) a signature, we must locate where members can edit their signature within XenForo, so we can Listen for the class being called. This is handled by a Controller. There are four Controller directories: Admin, Helper, Public, and Response. Editing a signature is not an Admin function. Nor is it a Helper, or a Response, that leaves us with Public. From your filemanager navigate to ControllerPublic. As editing a signature is part of a members account look for Account.php. Open this file and search for signature. The first word highlighted is just above: public function actionSignature(). This is the function we want to override.

Now we must listen for the class which this function belongs to be called (XenForo_ControllerPublic_Account).

XenForo comes with quite a few Listeners that we can choose from. Navigate to: Development -> Code Event Listeners. Click on the Create New Code Event Listener.

The first drop down allows you to select which event to listen to. As we want to listen to a class from the controller being loaded, from the drop down, select Load_Class_Controller.

The load_class_controller listener is tricky, but it is powerful and provides the most flexibility of all the Listeners. When you select this listener you will notice in the explanation of the load_class_controller that the class must be defined as: class My_Class_Name extends XFCP_My_Class_Name. This is true, but it can not be loaded directly. Loading this class directly will result in the AutoLoader to generate this exception: Cannot load class using XFCP. Load the class using the correct loader first.

What the error means is that the new class you want to create must be loaded before it can be resolved. But the question is, where does it get loaded, and how? This is the purpose of the $extend array argument.
Thanks for the tutorial. How can I locate ControllerPublic? I can't find it on my cPanel, nor on XenForo admin panel and nor in the file manager. What am I missing?
 
Also, I second the things about having a development tutorial for beginners. It would be awesome. I am a complete newbie myself, but would love to know more about how XenForo forums are programmed (and how to develop addons myself to be cost effective haha).
 
Thanks for the tutorial. How can I locate ControllerPublic? I can't find it on my cPanel, nor on XenForo admin panel and nor in the file manager. What am I missing?

For the example in this tutorial, XenForo_ControllerPublic_Account is located here:
yourXenForo/library/XenForo/ControllerPublic/Account

The class reflects the directory structure

Also, I second the things about having a development tutorial for beginners. It would be awesome. I am a complete newbie myself, but would love to know more about how XenForo forums are programmed (and how to develop add-ons myself to be cost effective haha).

There are numerous free add-ons that are small enough so that you can go through them after reading this guide, to see what is going on. When you feel comfortable enough, download free larger ones, and walk through those. That is the best way to add to your knowledge after this guide, :)

Also, if you have any coding questions, post it in the development forum, and some members may help point you in the right direction.
 
This is a great tutorial.

But it is still a bit over my head, as a non-coder.
However, as the prime mover of a growing site (16,000 members and growing), I realize that I need to know some coding, some PHP, some SQL, and how to make add ons. This is NOT meant to be criticism, but, other than the official XF addons, I cannot depend on support from the paid addons. I need to know how to work on them myself. It's like owning a car- you really need to know a thing or two about maintenance.

With that in mind, I am asking you coders, where do I go to start learning about all this?
I haven't coded since Basic in high school 30+ years ago.
Is there a reference that will get me enough up to speed so that a tutorial like this isn't Greek to me.
(For example, what is a Listener? I see it mentioned, but have no idea what that is).

Any help would be greatly appreciated.
 
Hi, the best thing to do to get started is to download some simple add-ons and go through them. I recently uploaded a few add-ons that are small in size, and fairly straight-forward to navigate through, that would be a good pace to start, :)

Listeners are places you can hook into to run your custom code, or extend other methods to retrieve your data. Some listeners have event hints, where your listener won't run until a certain class is loaded, for example: you want to add in a listener for controller_post_dispatch to retrieve some data for forum home through your own code, so you use the hint of XenForo_ControllerPublic_Forum. Your code won't be executed until XenForo_ControllerPublic_Forum has been loaded.
 
Lawrence, thanks for your suggestion. I don't even know what a 'class" is. Don't I need to know these these things before I can parse an already written addon?

Is there a source for me that language that I can look up these things?
 
Lawrence, thanks for your suggestion. I don't even know what a 'class" is. Don't I need to know these these things before I can parse an already written addon?

Is there a source for me that language that I can look up these things?
If you're not familiar with PHP, there are various sources of information:

PHP manual: https://secure.php.net/manual/en/index.php

Some simple tutorials to start with:
http://php.net/manual/en/tutorial.php
http://www.w3schools.com/php/
https://www.codecademy.com/learn/php

There are also more courses on the likes of Udemy (mostly paid-for but not expensive) that may help.

You'd need to be familiar with not just procedural PHP (which is what the basic tutorials cover) but also then on to Object Orientated Programming (OOP) in PHP and then the Model-View-Controller (MVC) design pattern in PHP.
 
@Nelson T. you should also consider purchasing a book on PHP/MySql. It's pretty convenient for referencing. I have one I purchased a few years ago, and still look things up with it instead of searching on the internet; it's faster, and gives you the exact answer (or example) you are looking for, :)
 
Back
Top Bottom