For the feature that fetches the FAQs by a specified topic, we need to build a custom query. WordPress provides the ability for us to configure what we want using WP_Query. Let’s walk through the configuration parameters and figure out what we need to build a query that is based upon a certain post type, taxonomy, and term slug. We’ll use the reference guide from Bill Erickson to explore the needed configuration parameters. We’ll also take a look in WordPress Core at the WP_Query class construct and talk a little bit about PHP OOP.
Sometimes you go down a path with your architecture and then discover that it doesn’t fit your needs. It’s good that the problem happened, as now you and I can walk through the process of fixing the architecture. Let’s talk through the thought process of fixing the architecture. It’s a good exercise of how to re-think your code and approach.
Let’s start building the shortcode processor for the single FAQ, i.e. when the shortcode user-defined attribute specifies a single post ID to display. You and I will look at what we receive as user-defined attributes when processing the shortcode. We’ll look at the configuration parameters. We’ll think about different scenarios of how to process when we don’t receive a post ID or topic as well as when we receive an invalid post ID. This episode is heavy PHP fundamentals. We’ll talk about: ternary operator variable scope variable scope when including a file type casting from string to integer data type […]
The feature from the product backlog says that we need to develop a shortcode that embeds a single FAQ or a group of FAQs by a single topic. Hum, how are we going to accomplish this with one shortcode? We can use the user-defined attributes to let the author tell us which one to process. We can do the following: [faq post_id=”43″] [faq topic=”billing-and-payments”] Therefore, we are building a faq shortcode with two different user-defined attributes: post_id and topic. How are we going to process these two different requests? For the single FAQ, we get the post ID. Therefore, we […]
Let’s talk about what you are going to do and build in this lab. We’ll talk about why. Why are we adding this FAQ feature? We’ll talk about what you’ll learn and the expertise you will gain after doing this lab with me. This lab is awesome. It has advanced plugin development concepts and processes. It will help you to move forward in your plugin development career. Don’t worry. I’m going to walk you through the entire process, sharing how I’m thinking about it, why we’re going in a particular direction, and alternative strategies. Ready? Let’s get to work.
Let’s activate our plugin and the UpDevTools plugin. Then you’ll add the shortcode into a post. Let’s test that it works. We’ll walk through the code and see the configuration and attributes. We’ll do some testing on different options and iterations. Before we finish, let’s commit our changes to your GitHub repository.
In your bootstrap file, let’s make sure that WordPress is calling our file and not something else. You’ll learn about this code pattern: Next, we need to autoload our shortcode processing file.
Let’s build the shortcode processor. This is the function that is called when the shortcode is found in the content. WordPress will call our function. In our plugin, we are going to use one function for both shortcodes. We’ll do a deep discussion on how to prepare and process the hidden content. First, we talk about why we are not sanitizing it at this point. We’ll talk about why, when, and how WordPress sanitizes. We’ll talk about processing other shortcodes that are embedded within our hidden content. Next, we need to define our file’s namespace and specify the real fully […]
To make our code reusable, we want to remove the hard-coded runtime configuration parameters. For our shortcodes, these parameters include the view filename and shortcode defaults. In this episode, you will learn the technique of abstracting the runtime configuration parameters to a separate function. You’ll build this function and setup the configuration for each shortcode. You’ll add the show and hide font icons from Dashicons (or Font Awesome if you are using that library). We’ll work through a thought process to reduce our code, refactor it, and improve its readability and reusability. Shared Quick Tips In this episode, I shared […]
First, we need to commit our code into our Git repository. Next, let’s talk about shortcodes. We’ll do an introduction to shortcodes including what it is and what is its intent. Deep Dive into Shortcodes A shortcode is a placeholder for additional content to be processed on the server when the content is being processed. You use a shortcode when you want to embed additional dynamic content, a set HTML structure, or redundant content. In this episode, we will dive deep into the process of how and why a shortcode works. The process starts when you register a custom shortcode […]