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.
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, […]
Let’s test out all of our new code and make sure everything works as intended. There will be a few typos and boo boos. You’ll see me think through when I’ve made a mistake and find the root cause.
What does reusable mean to you? Why would you want to use it? In software, the concept of being “reusable” means that you design your code such that you can reuse it project-after-project with minimal to no rework of the code. Think about that. Imagine the time you’ll save when you have a library of pre-built, well-tested, and proven code modules. You can then load the modules and quickly build your projects. But the key is: minimal to no rework of the code. That is what makes it reusable. Why? Think about it. If you pull in a snippet of […]
In this lab, you will learn about how to make your code reusable. You’ll learn about what it is, why you want to change your mindset to build code in a reusable way, and then how to do it. You are a professional web developer. It’s your career and/or business. You need to make money. Designing your code to be reusable is a strategy to reduce your time and thus costs over the entire lifecycle of the code itself. In other words, it makes you more profitable. To get started, make sure that you have completed Part 1 and 2 […]
In this episode, you and I are going to refactor the FAQ module. We’ll have both shortcode versions and the archive template using the same container and FAQ view files. You’ll hear and see me walking through the thought and build process, thinking about different approaches, and then testing it out. It’s a good exercise of reducing the codebase and thinking about the build process. Come do this with me.
In this episode, you’ll finish building the loop code to render out each FAQ. We’ll use the same FAQ view file. Therefore, we need to keep the variables named the same. Since we are in the loop and we setup the post within WordPress Core, i.e. when we did $query->the_post(), we can use the API wrapper functions, such as get_the_title() and get_the_content(). Then we need to order the FAQs by the menu order. We’ll set both the order and orderby parameters. To finish up, let’s document our code now by adding the DocBlocks. We’ll also type hint the function parameters […]
In this episode, we’ll continue building the shortcode for the topic. We’ll look move the while loop to a new function to process the individual FAQs. As we are building, notice that we have a decision to make: Do we display a message when no FAQs are found? Let’s do that. But instead of echoing at each message, let’s make it configurable and give access through the shortcode’s user-defined attributes. Then the author (or you) can turn it off and on as well as change the messages. This is a refactoring exercise for you. We start off by making sure […]
In this hands-on lab, you and I will walk through the entire process of adding a new feature to an existing WordPress plugin. You’ll start with the Collapsible Content plugin and then add a FAQ feature to it. This feature will require you to plan, think, and execute building a custom post type, custom taxonomy, advanced SQL queries, custom archive, and shortcode.