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.
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.
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.
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.
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 […]
Let’s talk about and plan what we are going to do in this lab. We want to build a central repository, some module, that will be responsible for generating and registering post types, taxonomies, and shortcodes. There are different strategies for building a central repository: You can build a central plugin, such as Fulcrum1. Build a package and then publish it on Packagist. Then you’d use Composer to include it into your plugin. Or you can build a module and place it into one of your plugins for the project. 1Fulcrum is currently being rebuilt with some new goodies in […]
Let’s talk about the “configuration” part of ModularConfig. How do you design your code to be configurable? What does it mean? Why would you want to? Our codebase is filled with hard-coded parameters that specify the implementation we want. For example, registering a custom post type requires: Labels Supported features Arguments Post type name Imagine that your project has more than one custom post type. For example, let’s say you’re building a business-centric website and the client wants: FAQ Portfolio Testimonials Team bios That means, your project has at least four new post types. Think about that. Imagine what your […]
Let’s talk about what the modular part of ModularConfig is. How do you design your code to be modular? What does it mean? The de facto in WordPress is to use snippets and boilerplates. This lab introduces you to the modular approach. Boilerplates give you a code structure or template. Then you edit the code to change the implementation. You may go to a website, fill out a form, and then that site automatically edits the code’s boilerplate to change it for you out of convenience. But the code is being changed to fit your project’s implementation. Snippets are tiny […]
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 […]