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.
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, Review, and Commit Changes
Let’s do a little clean up before you commit these changes. Then let’s commit the final changes to your GitHub repository. What’s the whole point to the ModularConfig architecture? The point is to help you to build your projects faster. ModularConfig puts code to work for you to generate code for you. It abstracts away redundant code so that you have less code to build, test, and maintain. It saves you a ton of time! What happens when you remove the common tasks and redundant code? What happens? It takes less code to build your projects. If a bug happens, […]
Test the Shortcodes
In this episode, you and I are going to test all three shortcodes. Here is the test content we’ll use:
Shortcode Configuration Store
Let’s build the shortcode configuration “store” and then the API wrapper functions to work with the store. The store does two separate functions: Stores configuration by the shortcode name as the key Get the shortcode configuration out of the store by its name (key) We use a static variable to retain the array of stored configurations, as a static retains even after the function completes.
Registering Shortcode with Custom Module
Next, let’s work on the registration handling within the Custom Module. This function needs to do the following: Loads the configuration file for the shortcode. Merge the configuration with the defaults. Add the shortcode and its callback. Store the configuration. In this episode, you and I will complete the registration code. Then we’ll register all three shortcodes from our Collapsible Content plugin.
Starting the Shortcode Boilerplate
Let’s start by building the beginning of our Shortcode boilerplate within the Custom Module. This boilerplate code will be responsible for: Registering the shortcode configuration from each of the modules, plugins, and/or theme within your project. Loading each configuration file into memory. Storing the configuration for the shortcode to access. Registering the shortcode and its callback with WordPress, i.e. add_shortcode and processing and rendering the shortcode’s HTML. Let’s walk through the thought process together step-by-step.
Finish by Topic Shortcode
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 […]
Continue Building the Shortcode
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 […]
Add a FAQ Feature to the Collapsible Content Plugin – Part 2
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.
Test, Fix, Commit, and Wrap
Now let’s walk through and test our module. In doing so, you’ll find that we need to change the taxonomy’s registration as we don’t want to show it on the front-end. Let’s make that change. Then we’ll commit the final changes to your GitHub repository. I have to say how proud I am of you! Seriously! You worked right along with me. I know it was a long lab. The whole point was to walk you through the entire process of building a new feature module, step-by-step. I hope you learned about WordPress, PHP, Plugins, HTML, and more. We covered […]