Throughout this lab, you were introduced ever so gently to PHP programming and how WordPress uses it. You looked at the basic concepts and constructs in the language. Then you wrote some code to see it work for yourself. Then you went into WordPress Core, Genesis framework, and two different themes to see it in action. Whew, that’s a lot to take in. Where do you go from here then? That depends upon your professional goals. What do you want to do? If you want to learn more about PHP, go to the PHP Mastery Library. If you want to […]
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.
Naming Stuff
Throughout this lab, you learned about how to name variables and functions. It’s part of the syntax. But let’s go a little deeper. Names must be unique. Why? If you have two functions that are named exactly the same, how would PHP know which one to run? Think about it. It wouldn’t know which one you want. Aha! Therefore, you give unique names to functions, classes, etc. In WordPress, the defacto approach is to use prefixing. Why? In a nutshell, it gives a unique suffix to a function to avoid naming collisions. What do I mean by naming collisions? That’s […]
What’s the deal with scope?
What is the deal with scope? If you are working on a theme or some code, you’ll hear about scope. Or maybe you’ve tried to access a variable that’s in another function and you don’t understand why you can’t access it. Why? How about the global variables? Let’s talk about scope. Scope defines what parts of your code can access other code. In this episode, we’ll talk specifically about variables and their scope. Variables have scope. They belong to some access level. Variables within a function belong to that function. The function can use them, but code outside of that […]
Repeating code using Loops
There are many times when you need to repeat code over and over again. The WordPress main loop is a big one that we can all relate to. The premise of it is this: The while controls the code block, meaning the code does not run unless the conditional expression is true. have_posts() checks to see if there any more posts to process The code runs when there are more posts to run, meaning have_posts() returned true. Then it loops back around to the while again. Repeat. Therefore, when using the while, the loop will continue looping (repeating the code […]
Sequencing – Yup, code runs in order
Like all programming languages, PHP executes code in order. It starts at line 1 of the first file and goes down the page. As each file is loaded, its code is loaded into memory. Any code that can run does. When it’s done, control runs back to the point in the code that loaded it. Let’s talk about how code sequences.
To Run or Not to Run – Making Decisions
We need to make decisions about the state as well as information in order to determine whether to run a block of code or not. There are multiple constructs available for us to use. In this episode, we’ll focus on the if/else if/else construct. We’ll look at different code examples in the Genesis framework and twentyseventeen themes. We’ll also talk about conditional expressions. The code that is controlled by the decision is enclosed within the curly braces (there is alternative syntax that uses a colon for the opening curly brace and endif; for the closing one). For that code block […]
What’s the deal with Variables?
What is a variable? What does it do? How do you use? Why does it exist? Let’s talk about variables and, more specifically, variables in PHP. Just like in mathematical equations and formulas, variables are used to “represent” a value. In programming, we use variables to represent some piece of information. We give that information a name and context, i.e. some human-readable meaning by the way we name the variable. Then we use the variable within our code to make decisions, do processing, configure a task to run, etc. Variables are defined and named by the author of the code. […]
Subroutines – Behold the function
In this episode, let’s focus on functions within PHP. PHP lets you define a user-defined function, which is a subroutine. You define it using the keyword function. Then you give it a unique name. You can specify any parameters which are variables. These parameters allow your function to receive information to do work on when it’s called. Then you use the curly braces to block off the code that belongs to the function. That code does not run until the function is called. Let’s look at the WordPress Core function called get_theme_mod(). We’ll look at the twentyseventeen theme and how […]
Break Up Code into Logical Parts
We break up our code into logical parts in order to organize our code. In PHP we do this by files, folders, and functions. It lets us organize and structure our code. Why? Imagine all of the code in WordPress in one huge file. It would have tens of thousands of lines of code. Imagine trying to work on that one huge file. It would be very difficult and prone to errors. It’s also hard to build code in teams. We break up code to improve: readability reusability maintainability Imagine that 3 months from now your customer calls you with […]
Syntax Basics
Before you do this episode, go watch the Fundamentals of Syntax. Seriously, do it now. This episode will help you to understand what it is and why we need syntax. Your natural language needs a set of rules in order for you and me to understand one another. We put sentences together based upon those rules. For example, if I said: “Tonya woman engineer” would you know what I was talking about or the context of what I meant? Not necessarily. Why? Because it’s not a complete sentence. It’s just words. We need to understand the basic rules of language […]