In this project we learn how to build a WordPress plugin. We will start with an overview of what plugins are and how they work. We will then move into best practices for coding in the WordPress environment and some basic functions and reference material you need to know. In the process you'll learn actions, filters and how to create widgets and shortcodes. You'll even learn how to integrate with 3rd party APIs and create your own WordPress plugins from scratch.
WordPress plugins add or change functionality to a WordPress site. Just about anything you can program outside of WordPress, you can likely come up with a way to integrate it into a WordPress site via a plugin or turn it into a plugin itself. Likewise when you feel functionality is missing from a part of WordPress, a plugin can add that functionality. It does this by tying into various programmatic hooks that allow developers to execute their own code at just about any point when WordPress does something. In this first stage we will cover what plugins are and how they work from a high level perspective.
Some plugins operate without any user customization. They may just add a widget to the site or some shortcodes that don’t require any settings. Or they may require a huge number of settings and have several settings pages in the admin area. For our plugin we will design a single settings page where the user can add their username and see information about their account that they can add in various ways to their site.
When your plugin pulls in content from another website or interacts with data stored outside of WordPress you will likely have to work with an API. API stands for application programming interface, which is what many web apps use to communicate with each other. For our project we will connect to the Treehouse profile API that comes in the form of a JSON file. Since many sites use JSON, this skill will be something you will likely be able to use in other projects.
When a plugin requires things to show up on the front-end of the site developers will often use a one or several widgets, shortcodes or template tags. Widgets are a special type of plugin that gets added to the widgets sections in the admin area and allows site owners to drag and drop your content or widget into widgetized areas on their site. Shortcodes are simplified macros that site editors can easily add into content fields when editing posts and pages. Template tags let developers add your plugin content directly into a theme template. In this stage we will look at how to build each of these.
If you only plan to use your plugin internally on a specific project you don’t have to worry about releasing and supporting your plugin. However, if you plan on adding your plugin to the WordPress plugin repository or selling it as a premium plugin you will have to put some serious thought into planning it’s launch, marketing, and support. In this final stage we will go over best practices for releasing and supporting WordPress plugins.