I have been working on a project where I wanted to push some information to the administrator’s Panel.
I had to figure out an easy way to send “push notifications” to multiple Kirby CMS installations at once — to send information such as the current version of a plugin and important announcements.
What I came up with is this:
a widget that reads a public hosted JSON which I can modify anytime
This way I would be able to send important updates and check if the current Kirby Plugin installation has a newer version and needs to be updated.
Now, let’s dive into the details.
1. Create a Kirby Dashboard Widget
You can read more about Widgets on the Kirby Docs.
This widget has the following structure:
The first template should contain the Widget’s logic. The second one is the template where this logic should be printed. My structure is a bit messy, though, because I have some logic in the .html.php file (read the disclaimer :).
2. Create and host the JSON
The second and last step (wow) is to create the JSON file we are going to push on a public URL that will serve as an API.
Now you have to upload it on your public server, which you have already defined in the raport-version.html.php file on line 5.
Room for improvement
Now that you have to update your JSON file by hand and upload it via FTP every time you’d like to push a new message, it can easily get out of hand.
One way to improve the method above is to generate the JSON dynamically on your hosting. For example, you can install Kirby CMS on your example.com/ website, create an invisible page (or even better — use a route) and generate a JSON file on every update of that page from the Panel.
Also, there is no errors handler, which you would probably like to have in a real-life project.
I am not a PHP developer but a designer, so bear with me and my might-be-a-bit-messy code.
If you have any tips for better implementation of the code above, I’ll be happy to hear. ✌️
Edit: Many thanks to Sonja Broda for the improvement tips!