You need to load files. Right? In PHP you use one of these constructs to load a file into memory (which then makes it run): include( ‘path/to/file’ ) include_once( ‘path/to/file’ ) require( ‘path/to/file’ ) require_once( ‘path/to/file’ ) Let’s look at how these work as well as talk about when you want to use one over the other. You’ll try to load a file that doesn’t exist and see that include gives you a warning while require causes the site to stop with a fatal error.
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.
Why and how does WordPress use PHP?
Let’s talk about why and how does WordPress use PHP. Why does it use it? Because it’s a solid programming language for web development. It’s very popular and prevalent and powers the majority of websites. WordPress uses PHP to do all of its processing including figuring out what the URL’s web request is, what to go grab from the database, what files to load and when, validating user permissions, checking options, fetching post metadata, calling plugins, and calling the theme. It uses it to process form fields, image and document uploads, and so much more. It uses it to build […]
What is PHP? Why use it?
In this episode, you will learn why we use PHP as well as what it does. We’ll talk about what a programming language is. We’ll talk about its role in general terms. You’ll see that WordPress is built on PHP. That’s why each file has a .php file extension on it. PHP is a programming language that runs on a web server. We use it because it’s a popular language for web development. We use it because WordPress is built with it. PHP does the following for the web pages on our websites: Processes Builds Sends out to the browser […]
Lab Introduction
Let’s talk about the goals of this lab and what we are going to do. This is a gentle introduction to PHP for WordPress theme customizers, theme developers, plugin developers, and anyone who wants to get a basic understanding of the PHP programming language. In this episode, you’ll walk through setting up the test website that you’ll use in this lab. We’ll call this site: php-sandbox.dev. I’ll walk you through using DesktopServer, which is the local web server. You can download the free version to use in this lab. It literally takes about 60 seconds to spin up the new […]
Strategy 4: Reusable Function
The fourth strategy is to encapsulate the functionality and abstract it away to a reusable function within your child theme. Let’s do this together. While you could add this function to your child theme’s functions.php file, it’s better to build your theme’s in a modular format. Best Practice – Modular Approach Using a modular approach, you will create a folder in the theme’s lib folder and call it structure. Then in the {child theme}/lib/structure folder, create a new file called footer.php. Here is the code that removes the site footer for each of the pages that you specify: You’ll need […]
Lab Introduction
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.
Passing PHP Values to JavaScript
There are many times when you need to pass values from PHP to your scripts. WordPress gives you the mechanism to do this with wp_localize_script. With this construct, you are passing an array of values to a JavaScript variable that you define. You target the script using its key or handle when it was enqueued. But did you know that JavaScript converts it to an object? Why? Because JavaScript does not have an associative array data type. Rather, the keys become properties on the object. Let’s see this in action and talk about it. Then we’ll look at how you […]
Build the jQuery Basic Structure
In this episode, you will create the jQuery script file and build the basic structure. You’ll code the IIFE, initialization function, and each of the basic functions. Then you’ll cache the elements into variables. You’ll learn about mapping a click event to a function and passing additional data to it. Let’s get started working and learning about jQuery and JavaScript. I’ll also share my process on defining functions and laying out scripts. If you need a refresher on function definitions, go back and watch this episode: Functions – Introduction to jQuery (and JavaScript).
Plugin Architecture
Let’s discuss the plugin architecture and build the folders and main files. We’ll think about the intent of the structure and each component. We’ll talk about why you want to build your code in modular format that complies to Single Responsibility Principle. Let’s build our file structure.
Planning Out the Plugin
Before you write a single line of code, first you want to sit down, think through your project, and plan out what you are going to build. Listen to me. Don’t just start writing your code. It will take you less time to plan it out first and then build it. What are we building? What are the building blocks of the plugin? Let’s break down the project into key components and figure out what we are building. It’s our big picture roadmap.