Fort Collins WordPress Meetup: How To Build A Plugin
If you missed the latest Meetup, find the highlights here!
Have you ever wondered how to build a plugin for WordPress? Last Saturday, I teamed up with Jeremy Green of Endo Creative, David Hayes of WP Shout, and Mike Selander & Michael Launer of Old Town Media to teach a plugin workshop through the Fort Collins WordPress Meetup. The four hour workshop was held at Galvanize in Fort Collins and was a great success! In case you missed it, here’s a run down of what we taught…
Plugin Development Workshop Overview
The plugin workshop was broken into four segments with Jeremy, myself, David, and Mike each taking a part of the plugin building lesson, which was centered around the development of a testimonials plugin. Prior to the workshop, the four of us collaborated to build a prototype for the testimonials plugin, using a GitHub repository. It’s much easier to teach people how to build a plugin if you can walk them through building their own, and we decided that a testimonials plugin might be something that could be commonly useful to a large group of Fort Collins WordPress users.
On the day of the workshop, participants were introduced to general concepts related to plugins, how they function within WordPress, and plugin development. Then, we created a testimonial plugin together, walking through the process from the beginning to the end so that each participant left with a functioning WordPress plugin they had built on their own.
Key Topics Covered
The key topics that we covered included:
- How plugins operate in the WordPress ecosystem
- How to create your own custom plugins for clients or personal use
- Plugin development best practices
- When you should build a plugin instead of adding code to your theme’s functions.php file
- How to use actions and filters to create your own extensions for plugins like Gravity Forms, WooCommerce, and Yoast SEO
- How to create a custom post type, taxonomy and custom meta fields
- How to create a shortcode
- How to create a widget
- How to add styles to a plugin, and when to do so
- How to create an admin settings page
How To Build A Plugin for WordPress Basics
and three examples of very extensive, more complicated WordPress plugins:
Then, he discussed the differences between plugins, which add functionality, and themes, which control styling. A big reason why things should be added to plugins rather than themes is because you want the user to be able to change themes without losing any functionality. And, of course, it is always very important to not modify core WordPress files or all your changes will be lost when WordPress updates. Finally, adding functionality through a plugin allows for that functionality to be easily reused from project to project.
The downsides to plugins is that they have limited access to the theme files and output is limited to shortcodes or widgets. If not coded properly, plugins can conflict with one another and cause very bad things to happen on your site or hosting environment.
A repeating concept in our workshop was the usefulness of the WordPress Codex, and Jeremy introduced the Plugin API, Widgets API, Shortcode API, HTTP API, and Settings API. Core concepts he introduced included:
Actions: trigger performed by WordPress at a certain time. When triggered, WordPress will find all functions that have been attached to this action and execute them in the correct order.
Filters: accepts a variable or series of variables, modifies them, and returns them back.
Basic Plugin Requirements:
- Create a folder to store your plugin files. This will be your plugin’s slug. It should be unique through the WP repo.
- Create a file that has the same slug as your folder
- Add plugin comments to the beginning of the file
- Display plugin in Plugins screen
Digital Marketing Insights & Strategy
Delivered Directly to Your Inbox
Making Your Plugin Do Something
After Jeremy finished his presentation, I discussed how to create a custom post type, then David discussed how to create a shortcode, how to create a widget, and how to add styling. Mike closed out the workshop with an explanation of how to create a plugin settings page in your WordPress dashboard admin menu. I'll be back later in the week to discuss creating custom post types in detail, but if you would like to review the materials from the workshop in the meantime, you can do so on our GitHub account. This repository includes the full code of the testimonials plugin we created for the workshop and also each of our individual notes that we used while teaching.
Want to learn more about WordPress plugin development? Here are some recommended resources:
- Professional WordPress Plugin Development http://www.wrox.com/WileyCDA/WroxTitle/Professional-WordPress-Plugin-Development.productCd-0470916222.html