Let’s do a code review of the plugin as it stands now with 2 custom meta boxes. What do you see? Repeating code patterns. Right? Both the subtitle and portfolio details meta boxes have the same code patterns. Why is that problematic? Think about it. It takes your time to refactor the first implementation to make it’s function names unique. It takes your time to copy the first implementation to another and then change all of the specifics including the callback function names. That editing time is exponential by the number of implementations, i.e. your time x number of meta […]
In the last lab, you and I built a custom meta box for the Subtitle custom fields, adding the feature of subtitles for posts. What happens if you need to add more than one meta box to a project? Using the code from the last lab, you would have to copy and paste the meta box file, change what’s different and each of the function names, and then create a new view file. In doing so, your code is redundant with repeating code patterns. Plus, it takes you time to make the codes, meaning an error could occur. What if […]
Let’s test our plugin to make sure everything works as expected. Open up your browser and go to the Console tab. Look for errors. If you find an asset not found error, you’ll need to explore why. I found when testing that Yoast SEO has an admin stylesheet that has the version number as part of the filename. That causes a problem. Therefore, I added the enqueued handle to my configured list of assets to skip. If you want the final code for this project, click here to view it on GitHub .
It’s time for you and me to think about how to make the shortcodes reusable. Let’s put our three shortcodes up side-by-side and identify what each has in common. We are looking for patterns, those clues to identify reusable opportunities.
What if someone needs to specify some of the labels, but s/he wants the remaining ones to be generated? Hmmmm, that’s an interesting notion. It seems like a valid optional feature that someone would want from your plugin. Let’s build that feature.
Whew, now it’s time to refactor the label generator function. Our labels are split apart into the three categories. What do we need to do? First, we need to know if we are generating labels for a taxonomy or post type. Then we can merge those together with the shared labels.
Right now our Custom Module is embedded within the Collapsible Content plugin. When is that the right decision versus building a standalone central plugin? You will have projects that need more than one custom post type. And these new types may not be related. That means the architecture dedicates separate plugins. FAQ is part of the Collapsible Content. But a Portfolio feature does not relate to the Collapsible Content. Therefore, it would require its own plugin. A testimonial feature is another solid example of an additional custom plugin. Each of these plugins needs the Custom Module. In this use case, […]
Many projects require more than one custom post type or taxonomy. If you are building a typical business-centric website, then your client may need a FAQ, Portfolio, Testimonials, and more. Each of these requires a custom post type. Obviously, you would not want to add a Portfolio module to the Collapsible Content plugin. Displaying your client’s project portfolios to show off their work and services is not related to and does not have the same intent as what the Collapsible Content plugin. Therefore, you would build a separate Portfolio plugin. Let’s move our temporary portfolio code out of the FAQ […]
In this episode, you and I will move the rewrite rules handler out of the FAQ Module and put it into our new Custom Module. We’ll simplify the process during plugin activation by removing all the code and replacing it with delete_option( ‘rewrite_rules’ );.
It’s time to link the FAQ Module into our new Taxonomy Generator. This episode has a twist for you as you’ll discover the code is repeating between the post type and taxonomy configuration loading. You get to learn about how to use the same callback for two separate filter events and then using current_filter() to determine which one invoked the callback. It’s a slick approach I use often.