Let’s talk about code reusability and the reusable mindset. The first step is to identify repeating code patterns where you can separate the implementation from the code. The next step is abstract the code, building it in such a way that it can accept an input(s) to pass in or configure the implementation. Then this black box code that you’ve abstracted handles everything for you based upon the input you provide and delivering an expected behavior every single time.
For our code, imagine moving the meta box add/register, render, and save functionality into a module that generates your custom meta boxes. Imagine passing in a configuration for each specific meta box you want to create, identifying things like the metadata, view file, meta box title and id, default values, and sanitizing function.
This technique reduces your time, costs, testing, and maintenance. It speeds you up while removing the complexity away. Build it once. Make it a module. Then for each meta box, build a configuration and view file. That’s it. Bam, done.
The entire point of this lab is to teach you the reusable mindset to empower your efficiency, productivity, and effectiveness.
What’s the Difference Between Boilerplate/Snippet and a Module?
A boilerplate is a snippet or scaffolding to give you a starting point. Then you edit the code for your specific implementation. You edit each implementation.
A module is reusable. You build it once. Then you reuse it. You don’t touch the code in it. Rather, you pass it what it needs to do the work.
Who needs copy/paste? Right. Writing code from scratch is fun!
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