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.
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? […]
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 […]
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.
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
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.
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.
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.
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.
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 […]