It’s time to write the code to turn on the editor in the back-end for the Posts Page. You’ll walk through the steps, step-by-step, and discuss how to write the code.
Let’s convert the basic plugin you built in Let’s Build a Basic WordPress Plugin lab into a new custom plugin called Blog Intro.
Let’s talk about the architecture and intent. While you could build a home.php or page_blog.php template, this plugin is portable and modular. It allows you to move it from project-to-project without having to change the theme. It uses the built-in WordPress editor, which your client is used to using. We are not using a widget because widgets are cumbersome for clients. A widget does not have the editor interface. It’s not as intuitive for the site owner to figure out where to put content when you use widgets instead of the page itself.
Out-of-the-box WordPress does not provide a way to introduce the Posts Page (Blog), as the editor is turned off and there is no automatic rendering of the content before the posts. In this lab, you will build a Blog Intro real-world, custom plugin which provides an introduction or welcome feature for your clients. As you build this plugin, you are learning about fetching content from the database, sanitizing, the Genesis framework, views, and more.
Congratulations! You just built a custom real-world WordPress plugin. You did from scratch. While you can use this plugin for all of your projects and even extend it, this lab gave you so much more. You learned some of these valuable coding knowledge: Custom plugin – writing it from scratch Unregister callbacks Investigate a theme Genesis Sanitizing Views Database Clean code Software principles All of these, especially the last two, are essential to you as a software developer. This lab gave you knowledge and skills that you will use in everything you do. It is adaptable then to all of […]
Let’s talk about how I knew to use after_setup_theme. You will look at in WordPress Core.
In this episode, you will unregister the Genesis page title. Remember, you need to unregister it after it has been registered. Huh, what does that mean? It means after the theme is called. In this episode, you will learn about how to unregister callbacks and the WordPress event after_setup_theme. WordPress Events (Hooks) Psst, events, unregistering, and registering is fuzzy for you, make sure you take the Introduction & Registering Events hands-on lab. [/infoxbox]
Let’s talk about why you want to not intermingle your business logic with the HTML. Why do you use a view? It’s based upon the proven software principles such as Separation of Concerns and Single Responsibility. APIs, frameworks, tools, and apps come and go. But these principles remain. More importantly you will learn about intent. Intent is important in all of the code that you will ever build.
It’s time to build out the HTML structure and put it into the view. What is a view? Why do you want to use it? Let’s talk about the qualities of clean, quality code. You will also learn about how to load the view as well as the variable scope. To learn more about variable scope and including files, go to the PHP Variables Bootcamp.
Let’s finish preparing the content for rendering out to the browser. How about if there are shortcodes in the code? How do we process those? How about using auto-formatting the paragraph HTML elements? In this episode, you will add in the do_shortcode and then wpautop.