When you’re developing, the solution to your problem might already exist. Many problems in code aren’t new, whether in debugging or creating new features. Ryan Kienstra, WordPress Engineer, shares his insights of borrowing from existing solutions and making your job easier.
Local Development Environment Setup for Mac
Your local web development environment is critical to your ability to efficiently produce high quality and well-tested software projects. This environment should be incredibly easy to use. It should support the way you work, making you better and faster while demanding very little of your time. In this hands-on lab, you will setup your local web development environment. It will include version control with Git, helper apps, package managers (Composer, Node, and npm), task runner with Gulp, local webserver, and a professional editor.
Append “…” After the Text
What if you want to remove the icon and replace it with a “…”? How would you do that? Think about it. Think about the code from the last episode. You have the default text coming into your callback. That means you can concatenate that string and append the dots after the incoming text.
PHP Output Control and Buffer Basics
There are times when you need to control the PHP output buffer. Shortcodes are a good example of when you want to capture the buffer and return it to WordPress instead of sending it out to the browser. In this hands-on lab, you will dive into the functionality available to you for the PHP output control.
Setting Up the Lab
Let’s walk through how to setup your sandbox to work with me through the lab episode. You will need: PHP Output Buffer Companion plugin Kint For Kint, you can use either my Kint PHP Debugger plugin, which is in the WordPress repository, or UpDevTools.
Wrap it Up
Let’s finish up with a quick review. Plus, I’ll show you how I do it in my code here on Know the Code. And I’m giving you a challenge too.
Shortcode View File
Using the same strategy, let’s apply it to a shortcode. In this episode, you’ll do the following: Move the HTML out of the shortcode function and put it into a View file Start the output buffer Load the view file Then get the HTML out of the buffer, clean the buffer, and return it back to WordPress You are leveraging the PHP output buffer to separate out the HTML into a view file. Why? We’ve covered that many times. However, for you, it’s so much easier to deal with native HTML instead of placing it into strings and storing it […]
Add HTML to Content and Return it Back
There are a lot of use cases where we want to add HTML, continue processing, and then render it out to the browser. WordPress has multiple filter events that let us tap into the process just before it goes out. It gives us the ability to change it. One example is when you call the function the_content(). There is a filter with the same name. In this episode, you’ll use the companion plugin you installed in the last episode. Then you’ll add more HTML to the content. Next, I’ll show you the way I see so often which is like […]
Lab Introduction
Let me introduce you to what you will be doing in this lab and why it matters. PHP gives you the ability to capture what you are sending out to the browser. Instead of sending it immediately out, you capture it in a buffer. Why would you want to do that? In order to continue processing the HTML. Some good examples are: Shortcodes Post title filter Content filter For each of the above, you need to return the HTML back to WordPress, the theme, or the plugin that needs to continue processing it. A design pattern that I often see […]
What is the difference between a HTML “tag” and “element”?
A member wants to know: What is the difference between a HTML “tag” and “element.” In this episode, Tonya shows you what they are, demonstrates it in the browser, and discusses why it’s important to know the proper terms.