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".
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.