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.
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.
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.
Build the Shortcodes Configurations
We have three shortcodes: QA, teaser, and FAQ. Let’s move their configurations out of the codebase and into their own configuration files. We’ll walk through creating the files and adding in the new parameters we specified in the last episode.
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.
Test the Taxonomy
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.
Auditing the Custom Labels
We want to use one label generator for both the custom post type and taxonomy. Why? Because both custom types share a number of the labels, i.e. we don’t want to be redundant. Therefore, before we can refactor the label generator, first we need to audit all of the labels.
Generate Post Type Labels
Custom post types and taxonomies both need custom labels to improve the user’s experience with the back-end interfaces. They both share some of the same label structures. Therefore, it makes sense to build one custom label generator that serves both the taxonomies and post types. In this episode, you will move the label generator out of the FAQ module and into the Custom module. You’ll be refactoring the code to accept the runtime configuration parameters.
Generate Post Type Supported Features
We need to improve our plugin’s post type supported features generator. Why? We need to include a mechanism to add new features when configured. Let’s walk through the refactoring process together, step-by-step. In this episode, you will improve the code and remove the specific implementation to make it reusable.
Reusable Taxonomy Generator
Next, we need to move the taxonomy registration out of the FAQ Module and build our generator. Let’s use the same strategy as the post type, where on init we fetch all of the configurations and then loop through them, passing one-by-one to the registration handler. This episode should be very simple for you.
Building Custom Post Type Generator
Let’s start building our central custom post type generator. This is the module that handles: Receiving all of the custom post type configurations in your project Loop through each of them to do the following: Generate the features supported by the custom post type Generate the labels Build the arguments and then register the custom post type with WordPress We’ll start by copying and pasting the code from our FAQ module into the new Custom module. Then we’ll start working on refactoring it. Our goal is to remove all of the specific implementation code, i.e. to make it generic and […]