In the last episode, we parsed the URL and then used the host element to check if the URL is local to our website. Shouldn’t we use that same strategy for our version query string check? Think about it. Why search the entire URL for the version key pattern when we could just search the query itself? Plus, if the asset was enqueued with the version number set to null, then query may not even be in the parsed URL. Let’s improve our code. Then we’ll walk through all of the checks and make each one readable without an inline […]
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.
Reusable Rewrite Rules Handler
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 […]
Rewrite Rules
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’ );.
Flush Rewrite Rules
You learned in the Custom Post Type Basics lab that you need to flush the rewrite rules when registering a custom post type. You need to do it for a custom taxonomy too. Remember, never ever ever do it after you register. Listen to me. It’s too expensive and will slow down your website. The proper way is to do it when the plugin is activated. In this episode, let’s add our taxonomy registration function to the plugin’s activation handler. Then we’ll deactivate and test. Let me show what it does. Next, let’s add the handler for when a plugin […]
Flush Rewrite Rules – Taxonomy
Right if you were to view one of the new terms, you’d get a 404. Why? Think about it. Why does it give you a 404? Because you need to flush the rewrite rules. You can do this by going to Settings > Permalinks and clicking on “Save Changes” button. But for a real plugin, you won’t want to have your customer install, activate, and then have to go to Settings in order to get the taxonomy and custom post type to work. Right? Instead, you want to handle it within the plugin. In this video, you’ll add the taxonomy […]
Flush Rewrite Rules
In this episode, you will learn about why, when, what, and how of flushing the rewrite rules for your new custom post type. You’ll learn about permalinks, Rewrite API, and how the page request is mapped through the rewrite rules to figure out what record to pull from the Posts database table. The starter plugin you got at the start of this lab has the rewrite the right way. It’s attached to the plugin activation event. That is the right way to do it. Why? Rebuilding (flushing) rewrites is an expensive process. It takes a lot of time to do […]
Convert Web Request into a Web Page
In this episode, you will learn about how the web address is converted into a query for WordPress to know what data to pull from the database and what files to call. Let’s talk about how rewrite patterns are stored in the database. WordPress will compare the web address to these stored patterns in order to determine what request it is.