It’s time to put your objects to work. It starts by thinking about the work (behavior) that a user would do. How is your code going to use and work with the object? Let’s talk through the different behaviors, such as checking if the user is logged in, changing password, etc. Then let’s make an object work by calling one of the methods. Remember, that in OOP, the keyword function is referred to as a “method” (confusing I know). Then let’s stop for a moment and see if you are grasping the concept of objects. Notice that you created two […]
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.
Creating an Object
The class is the blueprint. Then how do we make an object from it? You use the new keyword. Think about that. If you wanted to build a house, the architect gives the blueprints to the craftsmen. They will build you a new house. The house is the object, built off the blueprint. Got it?! Do you see how new makes sense? In this episode, you will create your first object from the blueprint you built in the last episode. You are creating a new user. New terms that you will learn are: Instance – meaning the object, i.e. it’s […]
Defining Characteristics
Objects have characteristics, which in PHP are called properties on the class blueprint. Let’s think about what a user would have, such as first name, last name, user id, etc. Then you’ll add these to your blueprint. Next, you’ll create two different users and set each one’s properties. As you are doing this episode, think about how each user is separate. Each one is an instance of the blueprint. But they are separate users, i.e. separate objects. Each has a name. Each has an ID. They are separate. You’ll be introduced to visibility keyword public and the object arrow accessor […]
Meet the Class Blueprint
The first step is to define our blueprint. In PHP, the keyword class alerts PHP that this is a blueprint. The syntax is: An object is a noun, i.e. a thing. Therefore, its name should be a singular noun. How you code the name varies depending upon if you are following PSR or the WordPress coding standard. Per PSR, class names should be in StudlyCaps, where the words are smooshed together and the first letter is capitalized. Per the WordPress Coding Standard, the words are separated by an underscore and the first letter of each word is capitalized. The curly […]
What is an object?
An object has both characteristics and behavior. It is built from a blueprint. To help you grasp the concept, let’s relate software objects to physical, real world objects. We are going to talk about homes in a new subdivision. You’ll see how the concept of homes (objects) and be translated into software objects and OOP.
What is Object-Oriented Programming (OOP)?
The acronym OOP stands for object-oriented programming. OOP is a programming paradigm, meaning it’s another approach for how you architect and build code. OOP is programming that is oriented to (focused on) objects. It seeks to emulate the real world. What does that mean? Let’s relate this concept to the objects you know. Look around your office. Grab an ink pen. Now, look at it. An ink pen is mass-produced from a blueprint. Millions of ink pens were made just like yours. Each pen has characteristics, such as the color of the ink, cap or click, body color, and size. […]
Lab Introduction
Welcome to the Introduction to PHP OOP for WordPress lab. This is a gentle introduction to object-oriented programming. This lab starts where the typical WordPress developer is at, meaning I’ll start with procedural and help you to make the leap over into OOP. In this lab, you’ll learn what OOP is and what it is not. You’ll be writing some code to help you see how it works. OOP is a different mindset. It can be difficult to wrap your mind around. Therefore, you need to work with me. You’ll also need to focus on the intent and concepts. Therefore, […]
Building Strings with Dots and Variables
PHP gives you the means to build dynamic strings. You can run a function and then append a string literal to the end of it. You can embed a variable into a string. You can append the value of the variable to another string. You see it in the themes and plugins, as well as WordPress Core. Let’s talk about it. With the PHP concatenation operator, i.e. . (dot), you are able to smoosh two string values together to make a new string. For example, look at this code: What is the above code doing? It’s loading a file using […]
Putting it All Together
As I told you before, the key is to read code. The more code that you read, the more you’ll learn and grow. The skills you gained in this lab empowered you to be able read the basic structure of themes and plugins. No, you might not be able to understand all of the code. But you can see the patterns. You’ll see the functions and know the basics of how they are defined and called. You’ll know that some can accept information to work on while others don’t need anything. You’ll see default parameters defined and know how that […]
PHP 101: Gentle Introduction to WordPress Programming
Welcome to WordPress programming. In this hands-on code building lab, you are going to get a gentle introduction into PHP programming. This lab assumes that you do not know anything about programming or PHP. You’ll start at the beginning and incrementally learn the major concepts and instructions you’ll encounter. It’s PHP 101.