The bulk of the heavy lifting for working with meta boxes can be generated using a reusable module. In this hands-on coding lab, you will convert the meta box plugin you built in the Basics lab, making it configurable and reusable. Build it once. Then reuse it. For each custom meta box, build a configuration and view file. That’s it.
In the last lab, you built a subtitle meta box. You learned about the 4 components of a custom meta box: add/register, render, view file, and save. What if you needed multiple custom fields and they are not necessarily related to one another? Maybe you need a meta box for posts and then a different set of custom fields for a custom post type. Using our code from the last lab, you would have redundancy as you duplicate the
meta-box.php for each meta box.
Hmm, there has to be a better way. There is when we transform our meta box code into a configurable and modular generator. Imagine passing a configuration to a module and then it handles everything for you. All you need then is:
- A view file for each meta box.
- A configuration file.
In this hands-on lab, you’ll learn about the concepts of making code reusable. You’ll use my ModularConfiguration design pattern and learn how to adapt it for yourself. Less code is less time and costs for you.
Our Goal – Make it Reusable
In this hands-on coding lab, you and I are going to work together, step-by-step. I’ll teach you what reusability is and how to make it more reusable. I’ll introduce you to my ModularConfiguration design pattern. Then together, you and I will refactor our meta box plugin.
Our goal is to make the meta box code reusable. But in the bigger picture, my goal is to propel your web development skills forward by teaching you techniques that will reduce your code building and support efforts.
What You Will Learn
In this hands-on lab, you are going to learn:
Want to look ahead and see the code you will be building with me?
Go check it out on GitHub. Psst, it’s on the “reusable” branch.
If you prefer to just use it and not build it with me, that’s fine too. Just follow the instructions and have fun.
FYI: If you are curious, this methodology is also covered in the Custom WordPress Plugin Development A-Z Part 3 lab.
In order to do this hands-on, you will need to complete the first two parts of this series:
Don’t repeat yourself. Don’t repeat yourself. Don’t repeat yourself.
Total Lab Runtime: 04:38:42
- 1 Lab Introductionfree 13:01
- 2 Add Another Meta Box - Portfoliopro 11:05
- 3 Code Review - Repeating Patternspro 07:17
- 4 The Reusable Mindsetfree 07:52
- 5 Separating Implementation from Business Logicfree 06:31
- 6 Plan It Outpro 06:35
- 7 Laying Out the Architecturepro 08:16
- 8 Configuration Model - Add Parameterspro 11:58
- 9 Configuration Model - Render Parameterspro 10:36
- 10 Configuration Model - Save Parameterspro 07:23
- 11 The Implementation Configurationspro 08:33
- 12 Fix the Config Modelpro 01:53
- 13 Architect the ConfigStore - Part 1pro 07:33
- 14 Architect the ConfigStore - Part 2pro 13:34
- 15 Loading the Configuration into the Storepro 16:04
- 16 Get Configuration or Parameter from the Storepro 12:43
- 17 Wire Meta Box to the ConfigStorepro 13:03
- 18 Merging Configuration with the Defaultspro 10:50
- 19 Get Only the Meta Box Keys From ConfigStorepro 22:29
- 20 Rethink the Save Functionalitypro 07:58
- 21 Is it Okay to Save?pro 05:41
- 22 Remap Custom Fields Config for Savepro 11:54
- 23 Fix the Default Mergepro 18:03
- 24 Walk Through & Test Our Save Functionpro 08:53
- 25 Improving the Renderpro 09:30
- 26 Optimization, Review, & Housekeepingpro 10:13
- 27 Wrap it Upfree 09:14
What to Do Next?
WordPress Meta Box Repeater
Check out the WordPress Fundamentals Library for more hands-on labs, insights, Docx, and more.
Check out the series page for more labs: WordPress Metadata, Metaboxes, and Custom Fields Series