Creating WordPress Plugins

Somehow this last year I have jumped into the world of WordPress plugin creation. I’m actually enjoying it. I have been a WordPress user since around version 2.0, or whatever version was out in April 2006. I have run very quiet blogs, like this, as well as a couple of higher traffic blogs such as my gadget block from 2006 to 2011. During this time I have modified plugins, fixed plugins, and become familiar with them from a distance. It turns out when there’s a million page views to a blog in a month that you start to see problems with some plugins. What I like about WordPress plugins is that you can fix them up, make them run more efficiently, and keep the site reliability high.

Back in February this year I took the opportunity to held a friend on a project to build a WordPress plugin. This was the first I had built. Although I can’t speak about what it does as its not my own news to share right now, I can say that I had to learn how plugins actually work.

Some of what I have learned includes the following:

  • Plugin structure and setup. I learned how to set up a plugin with a header, metadata, as well as using ABSPATH to prevent direct access.
  • WooCommerce work. The plugin I created works with WooCommerce and adds certain custom enhancements. Rather than taking off the shelf plugins, we opted to write from scratch so that the code only does exactly what we need it to and nothing more. Working with WooCommerce led me to working with hooks and filters, order meta, as well as using AJAX to make the features better to use.
  • Admin dashboard enhancements were made. I created a number of widgets that allow users to interact in a custom way and to hide the complexity of wp-admin by only showing the data that they will need on the custom sites that are being built.
  • Making use of environemnt variables in Docker to be read in by the site so that quick setups could be used.
  • Custom meta fields were added so that custom post types could be used. This meant understanding serialising and deserialising data stored in tables such as wp_options.
  • Webhooks were used to create endpoints for external services to use.
  • Usual security type features were used to make sure that data was escaped and input was sanitised.
  • A custom roles plugin was created, one of the roles extending one of the WooCommerce roles. As well as implenting a roles plugin from a template someone shated, I also created helper functions to only allow UI to appear to those that need access.
  • Debugging was also used heavily to check outputs at certainly steps in the code. WordPress makes it very easy to enable debugging.
  • I also created a child theme and made some light edits to the default UI that the Twenty Twenty Five presents.
  • I learned that using ChatGPT can be both incredibly helpful at speeding up creating code, but on the flip side, it can also be a royal pain and slow you down. I learned that you need to understand what you are asking it and seek answers for perhaps explaning this, or doing repetitive work. One example was using it for test data. Rather than write 20 or so test items myself, I could share the model with ChatGPT and explain that I wanted 20 of these in an array that I can copy and paste into my code. It does great at that, as well as finding some bugs.

All of the work was stored in a wp-content/plugins and wp-content/themes as expected.

To allow for quick testing from a clean slate I created a docker-compose file that contained WordPress, Adminer, MariaDB, WPCLI, and some environment variables as mentioned earlier.

docker compose down -v && docker compose up

Using CTRL+C in the terminal would take the site on localhost down, and then running the command above would create the containers and run commands in the WPCLI to delete the standard plugins that are not needed and also activate the ones I added to my shared folder.

In doing this, it takes about 30 seconds to spin up a clean site for testing.

Overall I like the progress I have made this year. I do not know if I will stick to WordPress plugin development full time as I am also working on a C# .NET project for one of my own companies, toolshare.uk, as well as a SwiftUI project for iPad and iPhone (and Mac eventually) called Notic Meet, but I do like the new skills I have learned which will be very useful when I need to do my own WordPress work.

If you need any help with development work then please reach out. Contact details can be found on my iOS dev blog.

 

Leave a Reply