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:
- 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 in WordPress is assigning HTML to a variable and then building up the HTML. But that’s problematic in that it’s hard to read, debug, and extend. Often times, it’s hard to find missing closing tags. Right?
A better approach is to pull all of that HTML out of the functions and business logic, putting them into a separate view file. Then you write it as native HTML. You will do that in this lab.
Your functions are bloated. Put them on a diet. Think "skinny" and "as few lines as possible."
Total Lab Runtime: 00:44:16