We’re done with our plugin, but we do have an opportunity for optimization as well as housekeeping. It’s a good practice to walk through your code when you’re done to: re-evaluate look for optimization opportunities do some housekeeping like commenting, formatting, and cleanup and ensuring everything in a file supports the intent of that file. Let’s walk through our Metadata Module together.
Labs
Labs are hands-on coding projects that you build along with Tonya as she explains the code, concepts, and thought processes behind it. You can use the labs to further your code knowledge or to use right in your projects. Each lab ties into the Docx to ensure you have the information you need.
Each lab is designed to further your understanding and mastery of code. You learn more about how to think about its construction, quality, maintainability, programmatic and logical thought, and problem-solving. While you may be building a specific thing, Tonya presents the why of it to make it adaptable far beyond that specific implementation, thereby giving you the means to make it your own, in any context.
Wrap it Up
WooHoo! You did it! I’m so proud of you. Whew that was a long, long lab. But it was more than just building a reusable meta box module. My intent was to help you learn about: the Reusable Mindset – developing how you think about software, quality, and costs Architecture – developing how you layout your code Advanced programming concepts for filtering, merging, recursively merging and replacing, and remapping of arrays, as well as assigning a callable to a variable and then invoking it. Tell me what you think Now I want to hear from you. What do you think? […]
Get Only the Meta Box Keys From ConfigStore
We have a problem with our architecture. Do you know what it is? We have no way to differentiate and fetch only the keys for a specific component or module. In your work, you’ll likely have multiple modules using the ConfigStore. For example, you may have shortcodes, widgets, meta boxes, and custom post types all loading configurations into the store. How can you get only the configurations for the meta boxes? Right now, you can’t. In this episode, we’ll walk through a refactoring process to provide the means of fetching keys for just that component or module level. You’ll add […]
Fix the Config Model
We have a structural error in our configuration models. Oh bummer. Did you notice it? In this episode, let’s fix all 3 files before we move onto the Configuration Store.
The Implementation Configurations
We’ve completed our meta box configuration model. Now, let’s take that model and load up our 2 custom implementations. You’ll want to store each configuration file into the config folder. If the plugin was doing more than a meta box, then you’d put the configs into config/meta-box folder. Resources intval sanitize_text_field
Configuration Model – Render Parameters
In the last episode, I challenged you to complete the render parameters yourself. In this episode, we’ll walk through how I solved it. We’ll fill out the custom fields in our Configuration Model. Plus, we’ll refactor our render function for our new generic, configuration business logic.
Laying Out the Architecture
Let’s layout the basic architecture of the configs, config store, and metadata. Work along with me in the video to get your plugin architecture setup and ready for the remaining parts of this lab.
Improving the Render
Let’s improve the render function, as we have too much going on in that function. We’ll abstract away the task of fetching the metadata from the database for our custom fields’ values. Why? Our render function’s job is to render the view. It needs the values, but does not need to know how to do it. Rather, just gimme the values for the custom fields. We’ll also add a WordPress filter event to extend our meta data, allowing an external process to filter the values, do some processing, or just run before we render out to the browser.
Rethink the Save Functionality
Our current save function is not reusable. As we’ve done with the register and render functions, we need to remove the implementation and allow the saving process to accept a configuration and then process it. Let’s rethink our save function, split up the different parts, and prepare for how to refactor it.
Merging Configuration with the Defaults
If we run our code as it is right now, the meta boxes did not appear. Why? Because we only configured what was different in the Portfolio and Subtitle configuration models. We need to merge each of those with the default configuration parameters. Let’s do that in this episode. You’ll be using the PHP function array_replace_recursive to merge all levels within our multidimensional arrays. When you get done with this episode, both custom meta boxes will now render for a post. WooHoo!! Pat yourself on the back, as you did a lot of work to get to this point. Keep […]