Fort Collins WordPress Meetup: How To Build A Plugin

If you missed the latest Meetup, find the highlights here!

Amber teaching at the Fort Collins WordPress meetup
Amber teaching at the Fort Collins WordPress meetup

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:

  1. How plugins operate in the WordPress ecosystem
  2. How to create your own custom plugins for clients or personal use
  3. Plugin development best practices
  4. When you should build a plugin instead of adding code to your theme’s functions.php file
  5. How to use actions and filters to create your own extensions for plugins like Gravity Forms, WooCommerce, and Yoast SEO
  6. How to create a custom post type, taxonomy and custom meta fields
  7. How to create a shortcode
  8. How to create a widget
  9. How to add styles to a plugin, and when to do so
  10. How to create an admin settings page

How To Build A Plugin for WordPress Basics

Jeremy started out the workshop with an overview of plugins.  If you have not heard of plugins before, they are modules you can activate on your site to provide a additional features or functionality that extends the core WordPress CMS.  Typically plugins are built with a combination of PHP and HTML.  Some also include CSS and JavaScript.  I previously presented on plugins at a WordPress meetup last year.  Jeremy shared three examples of simple WordPress plugins:

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.

and

Filters: accepts a variable or series of variables, modifies them, and returns them back.

Basic Plugin Requirements:

  1. Create a folder to store your plugin files. This will be your plugin’s slug. It should be unique through the WP repo.
  1. Create a file that has the same slug as your folder
  1. Add plugin comments to the beginning of the file
  1. Display plugin in Plugins screen

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.

Additional Resources

Want to learn more about WordPress plugin development? Here are some recommended resources:

Thoughts or Questions?

Our blog does not accept comments, but we want to know what you think!  Tag us on Twitter to get the conversation started or contact us.