r/PHPhelp • u/Unable-Series-4196 • Aug 31 '25
How to create a plugin system like wordpress
I couldn't post this on the laravel sub because I don't have enough engagement, so I just gotta ask here.
I want to create a big project, and I want the functionality of the application to be extendable by plugins/modules. I plan to use Laravel & livewire. Ideally, users will get the core functionality of the app by default. Then, there's a plugin/module marketplace where they can find plugins, buy them, install and get more functionality.
I don't know how to get this done though. If you know how I can get this done, please help me out. I would love to hear your thoughts and suggestions, plus any resources you know of. Thanks!
16
u/Pechynho Aug 31 '25
Use a tons of events in your application, so plugins can hook into the process and modify its outcome.
And ofc make everything as a interface, so plugin can potentially override base implementation with its own.
Strategy pattern will probably be your best friend.
3
u/[deleted] Aug 31 '25
Events would be a good approach. Trigger an event when the plugin could be run, and a listener runs the plugin code if the user has permission to use it.
3
u/Wilko_The_Maintainer Sep 01 '25
Check out Winter CMS, it is Laravel based and supports plugins & modules, it may provide some inspiration :)
7
u/HolyGonzo Aug 31 '25
The short of it is a place to store / register plugins, pre-defined times to run certain methods, and plugins that correspond to those times.
A VERY simple / rough example (just to illustrate mechanics) would look like this:
So you can see that the code at the bottom defines the points at which a plugin can run, and then it's simply a matter of using call_user_func() to run the corresponding method if it exists.
The above is nowhere near complete and is missing things such as defining orders of priority, or any kind of performance optimization, type-hinting/interfaces, etc. But it gives you the gist of how it can work.
2
u/tonygoboy Aug 31 '25
You might check akaunting system and documentation. It is a good start
2
u/RetaliateX Aug 31 '25
I've not done this myself, but if I were going to start somewhere, I'd begin with Filament and how their plugin system works. You'll want a simple way for your app to know about which plugins the user has added and then load those plugins for use.
2
u/equilni Sep 01 '25
https://blog.ircmaxell.com/2012/03/handling-plugins-in-php.html
Older blog post on this, but architecture is still relevant. Wordpress uses the Mediator pattern here.
1
u/ajbapps Sep 02 '25
What you are describing is possible in Laravel, but it requires some upfront architecture planning. The general approach is:
The hard part is not just loading code but also handling versioning, migrations, and making sure one plugin does not break the whole system. Start small by making a basic Hello World plugin that can be installed and enabled, then expand from there.
1
u/AcanthisittaBig6667 Sep 03 '25
Check Freescout on GitHub. They make modules for Laravel like WordPress plugins. I like it.
0
u/__kkk1337__ Aug 31 '25
What stops you from looking into Wordpress source code ?