XF 2.2 Easiest way to create a very simple XF 2 addon? Can I edit an existing addon template, or do I have to create it using a developer environment?

MaximilianKohler

Well-known member
I've seen a few guides that all have different directions, possibly because some of them are for older versions of Xenforo.

I don't want to learn php, javascript, etc. I want to know the simplest way I can implement a few db and file changes to increase the length of titles: https://xenforo.com/community/threa...acter-thread-title-limit.215208/#post-1666121

This is one of the most simple guides I found https://xenforo.com/community/threads/creating-an-addon.5416/, but it's for an older version and still probably more complicated than I need it to be. I didn't find an XF v2.x version of it. I downloaded it to compare to XF 2.2 addons and it has a different file structure & format, so it doesn't seem applicable.

I found a video tutorial but it was missing information and also very old.

The XF 2.2 addons have a hashes.json file, which seems to indicate that I can't just edit the files directly, I need to use the developer UI to generate and update the addon. Is that correct?

The official Xenforo documentation & videos are meant for developers who already know the multiple computer languages involved, and want to develop complex addons.
 
Very difficult to create or modify any add-ons if you do not wish to put forth any effort.
I think it's a little ridiculous to expect users to learn computer languages or dole out $20+ to someone each time they want to make a minor change to their forum.

In the 10 years I spent on reddit, I never had to do any such thing, and it was FREE. There were a total of two addons needed. Whereas with Xenforo there are over a dozen that seem essential, and loads of other important tweaks that either require you to learn multiple computer languages or pay someone $20+ for each change. Not to mention, all those addons make it quite a pain in the *** to upgrade to new versions of Xenforo.

A simple override system, or a template that we could copy-paste or change values in would be much more user-friendly. Yet even simple template modifications seem extremely complicated.
 
They seem extremely complicated to the uneducated (no insult intended here) but they are extremely efficient for the performance of the software and the stability. It's a tradeoff. It isn't as simple as pasting some code into a box using event hooks like the old vbulletin days. Software evolves.
 
I think it's a little ridiculous to expect users to learn computer languages or dole out $20+ to someone each time they want to make a minor change to their forum.

In the 10 years I spent on reddit, I never had to do any such thing, and it was FREE. There were a total of two addons needed. Whereas with Xenforo there are over a dozen that seem essential, and loads of other important tweaks that either require you to learn multiple computer languages or pay someone $20+ for each change. Not to mention, all those addons make it quite a pain in the *** to upgrade to new versions of Xenforo.

A simple override system, or a template that we could copy-paste or change values in would be much more user-friendly. Yet even simple template modifications seem extremely complicated.
You sound like a alienated and discruntled Gen Z who wants everything handed to them. Do your work and earn respect.
 
The XF 2.2 addons have a hashes.json file, which seems to indicate that I can't just edit the files directly, I need to use the developer UI to generate and update the addon. Is that correct?
Addressing this issue alone. You can modify any add on to make slight changes, say make a number 100 instead of 50 in a file for a completely different result.

Changing the add on file will accomplish what you want, but the hashes.json is there to tell you that the file was changed (a warning in ACP). I suppose it's for security purposes, but it doesn't quite make sense to me as if a hacker could change a file to run malicious code, they probably would know about hashes.json and update the md5 checksum (either by hand or rebuilding the add on in command line) in it so that the error doesn't show up. It could also be for development purposes so that a developer knows when a file has been changed. Not certain...

That said,
Very difficult to create or modify any add-ons if you do not wish to put forth any effort.
This hits.

You're going to need to understand why the add on (in the example) has a number of 100 instead of 50 and what it will do by changing it.
 
Hashes.json is just another verification tool - I'm not sure if it's still the case now but there are many sources citing that you can literally skip/delete the hash file and an addon will still install. I feel like this is just a secondary tool to check if files are modified post-installation (eg malicious code insertion) as opposed to being the absolute be-all-and-end-all of software security.
 
Thanks for the info about the hashes.json file.

You sound like a alienated and discruntled Gen Z who wants everything handed to them. Do your work and earn respect.
Reacting to a legitimate comparison to a popular competitor with insults/ridicule is very foolish. At this point, I'm thinking AI tools will be the only way the average person would be able to use Xenforo as a legitimate alternative to Reddit. As is, the difficulty level is far too much higher than creating a subreddit, and the software itself even lags behind.
 
A very simple add on can be done with ChatGPT.

Code:
Build me a Xenforo 2.3 add on that will post a reply to thread ID 1 as user_id 1 and username Admin with the text "This is a reply to thread ID 1 by Admin" when it is installed through the ACP.


Package it in the root folder upload to be installed in the ACP. Give me a downloadable package.

It'll zip the add on in the /upload folder (as required to be installed through the ACP) and include addon.json and Setup.php. Once installed, it will reply to thread id 1 under Admin with the text "This is a reply to thread ID 1 by Admin".

1739874893428.webp

For some reason it used ForumDiscovery as the username even though username was set to Admin. I ran into issues on XF 2.2 (when learning, and the coding method seemed to have changed when I instructed it to make it for XF 2.3, to which I have since adapted) where both $post->user_id = 1; and $post->username = 'Admin'; were required, but it looks like something in 2.3 changed where it queries the user_id and ignores username now.

Suffice it to say, you can build a really simple add on in ChatGPT. However, I would take it as a learning experience, as it understands the coding structure of XenForo, and remember what it gave you before so you can use it as a learning experience and type it out quicker to do what you want instead of querying ChatGPT it over and over to get something more complex done right.

If it errors out on install, copy/paste the error into ChatGPT and it'll fix it. Maybe the 2nd time will still error, but the 3rd or 4th time will give you a simple working add on if you can instruct it clearly enough for it to understand what you want to accomplish.

I've done enough in ChatGPT to now feel confident enough to invest in a PHP IDE and use XenForo type hints on a local machine to get what I want to be done without relying on AI.

I'm just researching phpStorm over other IDEs and trying to figure out which one is best for XenForo development before I pull the trigger as it'd be quite a costly mistake to get something that won't work, to learn it, and have to choose another IDE.

PHP:
<?php
namespace MyAddon\AutoReply;

use XF\AddOn\AbstractSetup;
use XF\Entity\Post;
use XF\Entity\Thread;
use XF\Repository\Thread as ThreadRepo;
use XF\Service\Thread\Replier;

class Setup extends AbstractSetup
{
    public function install(array $stepParams = [])
    {
        $this->postReplyToThread1();
    }

    public function upgrade(array $stepParams = [])
    {
        // No upgrade logic required for now
    }

    public function uninstall(array $stepParams = [])
    {
        // No uninstall logic required for now
    }

    protected function postReplyToThread1()
    {
        /** @var \XF\App $app */
        $app = \XF::app();
        $em = $app->em();

        // Check if thread ID 1 exists
        $thread = $em->find('XF:Thread', 1);
        if (!$thread) {
            return; // Exit if the thread does not exist
        }

        // Create a new post entity
        $post = $em->create('XF:Post');
        $post->thread_id = 1;
        $post->user_id = 1;
        $post->username = 'Admin';
        $post->message = 'This is a reply to thread ID 1 by Admin';
        $post->post_date = time();
        $post->position = 0; // Ensuring position field is set
        $post->save();

        // Update thread last post info
        $thread->reply_count += 1;
        $thread->last_post_id = $post->post_id;
        $thread->last_post_date = time();
        $thread->last_post_user_id = 1;
        $thread->last_post_username = 'Admin';
        $thread->save();
    }
}

(I'm unsure if that code is "proper", but it does work (installed and tested))

Go line by line of your simple add on, once it works, and learn why it's doing what it's doing, and you'll be far better off developing more complex add ons as time goes on, especially if you want to use XenForo for a forum and see a lack of a feature that you'd want, and could either hammer it out on your own or pay $20-200 to get it done.

You can also open all the free add ons in the Resources section and take note of what they are doing to accomplish the add on functionality to carry over into your own work (to do something different).

@Sim helped me out by posting this:
https://xenforo.com/docs/dev/

As I was unaware if you are in developer mode and create phrases/cron jobs, building the add on will create the necessary cron.xml and phrases.xml files, as I took other add ons' files as templates and was doing it by hand editing my own XML files that XenForo would recognize on install.

Also this:
https://xenforo.com/docs/dev/development-tools/

You also need to have a basic understanding of PHP. I first started PHP on version 3 and quit to pursue a different career right after 4 was released, which was more of a procedural language at the time. I might be wrong here, but XenForo uses an object-oriented approach, which threw me for a loop at first because I had no background in that and it looked foreign to what I was doing before. But because I had a base, I picked it up relatively quickly.

I'm far from where I would like to be in development, and should've taken @Bob up on his "challenge" to learn in 2018~ (a post he made on his forum way back when), but I fell back to trying to do everything through template edits, which can be a pain with XF, style, and add on updates. Now, I'm focusing on implementing template changes with add ons to find what sections I want to be changed and to change them with an add on, which still might need updated with changes, but would be less complex when it comes to merging templates.

With my background in (depreciated) PHP functions, it helped me learn a bit quicker than if I started from scratch. But, if your goal is to have a community last 10+ years, and want to develop features for it, you have plenty of time to take an hour or two of your day to learn PHP and how to apply those principles to XenForo development.

Heck. I had 6 years since @Bob posted the challenge to learn XenForo development, and I squandered that time on template edits vs. getting in the code; I still probably wouldn't be at his level over those 6 years, but I'm sure I could crank out some more complex add ons that have cost me upwards of $750 in the past through taking it one step at a time until it could be ready for live deployment.

XenForo is developer friendly and you can get it to do pretty much whatever you want to do (within reason) with its framework. There are so many resources to help you get where you need, and you could even start with AI, but it's broken up all over to piece together and learn yourself as there's not a 1-fits all developer documentation to follow like a book on PHP that takes you step by step. I want to say @Kirby posted a resource before that is a separate application that scans XenForo for all the functions and then breaks them up in a "wiki" like page where you can go function by function to see which one you need to make your stuff work with the required inputs they need to work. I think I have it bookmarked, but I can't find it, and might be wrong with who posted it. I'll need to do that at one point, but hoped that someone (maybe XF) would publish a new version of the compiled "documentation" for each release.

So the real question is: Do you want to learn or do you want to complain about the outsourcing costs?

All it takes is time and dedication to learn.
 
I think it's a little ridiculous to expect users to learn computer languages or dole out $20+ to someone each time they want to make a minor change to their forum.
You don't need to for every change, only adding new functionality or making database changes.
At this point, I'm thinking AI tools will be the only way the average person would be able to use Xenforo as a legitimate alternative to Reddit. As is, the difficulty level is far too much higher than creating a subreddit, and the software itself even lags behind.
Most users aren't trying to build new functionality in or make changes like this though. Changing database schema isn't minor and isn't something the overwhelming majority of site owners have any need to do unless it's part of a larger new feature being built. If most forum admins started arbitrarily changing code or making database schema changes without knowing what they were doing, they would just break things.

Reddit and XenForo are quite significantly different, XenForo is PHP software so you'd need to know PHP to work with it (the same way that Discourse is written in Ruby). You can edit HTML templates with XenForo, but adding new functionality would have to be written in PHP, and database changes would need to be made via an addon too, you can't do that with some sort of template file. Reddit isn't set up anything like forum software written in PHP/Ruby etc. All forum software would require some degree of programming knowledge to make deeper functional changes beyond editing templates and styles.
 
Last edited:
A very simple add on can be done with ChatGPT.
Hmm, I tried that with something even more simple than an addon and it did not work: https://xenforo.com/community/threa...a-template-and-adding-them-to-another.229230/

an addon too, you can't do that with some sort of template file
According to the replies so far, you CAN use an existing addon as a template and simply change values in it. But that's definitely very limited since most addons are more complex, and there needs to be guides & examples for stuff like that.

I would say changing the length of titles is minor. I know of other forum software that let you do it in the options. Reddit isn't forum software, but it functions as a forum. There are even open-source versions you could use. I just prefer this type of software for my forum.

All it takes is time and dedication to learn.
I have my hands full.
 
According to the replies so far, you CAN use an existing addon as a template and simply change values in it.
That's a different use of the term "template". In XenForo a template is HTML used to render a part of the page, using an existing addon as a "template" for how to build one is a different concept (and would still require development knowledge).
I would say changing the length of titles is minor. I know of other forum software that let you do it in the options. Reddit isn't forum software, but it functions as a forum.
But there would still be an upper limit as the length is defined in the database schema - XenForo will allow titles that fit in the length defined in the database, to increase that would need a database change which is the same for all software with a database, there will be a hard limit somewhere. Even Reddit would likely have an upper limit at some point.
 
Last edited:
But there would still be an upper limit as the length is defined in the database schema - XenForo will allow titles that fit in the length defined in the database, to increase that would need a database change which is the same for all software with a database, there will be a hard limit somewhere. Even Reddit would likely have an upper limit at some point.
That reminded me of this suggestion that I made to extend the length in the Database.

https://xenforo.com/community/threa...anner-text-max-chars-limit-to-reflect.228566/

I contemplated making an add on to change it myself (or do a direct DB change), and don't want to throw this thread too far off topic (but still slightly on topic as the OP is suggesting to extend lengths for titles), but would that be advisable or could it have a "damaging" effect in that an upgrade (if they don't implement it) would error out if there were values greater than 100 characters?
 
Back
Top Bottom