WP Plugin BootCamp
This repo is used for the WordCamp San Diego Plugin BootCamp Presentation on 2015-03-28.
It will show you how to migrate functionality from a WordPress Theme into a WordPress Plugin.
- Clone this repo
- Checkout the step_0 branch:
git checkout step_0
- Create a local DB and import the MySQL dump in
- Update your DB name / username / password
- Update the SALT
- Optional, recommended for running local on OS X, add
- Set up your local server (XAMPP, DesktopServer, MAMP etc)
- Setup host name as bootcamp.dev
This is the starting point of the tutorial. We have a 2015 child theme with all of its logic in
functions.php and all of its styling in
- Custom Post Type:
- Custom Taxonomy:
- Custom Fields (with CMB2):
- Custom Shortcode:
This step takes the 2015 child theme functions and templates and breaks them out into a simple plugin using a similar structure to Bill Erickson's Core Functionality plugin.
Some basic principles of this approach include the following:
- WordPress plugin header
- prefixing your functions
- definitions and calling your plugin directory
- organizing your plugin files
- Conditionally including template files
Branch: step_2 This branch uses an Object Oriented Design approach to a plugin. It utilizes the WordPress Plugin Boilerplate 3, http://wppb.io/, by Tom McFarlin and company. The custom post type, taxonomy, shortcode and metabox have been moved into the plugin under the admin and public classes. The styles have been moved into the public stylesheet as well. The template files are still in the theme folder.
This branch migrates the template files
archive-books.php into the plugin and out of the theme
while allowing theme authors and users to override this markup to better suit their theme by copying the templates back into
their theme folder. It then replaces the built in
get_template_part() method with one that checks the plugin first
allowing us to migrate
content-archive-books.php into the plugin as well.
Branch: step_4 This branch adds an admin options page using a refactored CMB2 snippet and uses it to modify the CSS of the books page via a static helper method.
This branch reorganizes all the classes into single responsibility classes:
- Public Classes
- Admin Classes