Mike wants to know: Why I type hint function parameters in PHP? What is it? What are the advantages? In this episode, Tonya talks about PHP type hinting and how it improves your code.
In this hands-on lab, you and I will walk through the entire process of adding a new feature to an existing WordPress plugin. You’ll start with the Collapsible Content plugin and then add a FAQ feature to it. This feature will require you to plan, think, and execute building a custom post type, custom taxonomy, advanced SQL queries, custom archive, and shortcode.
StudioPress includes a file called lib/theme-defaults.php. This file sets the default theme settings which are found in Genesis > Theme Settings. In this episode, you will refactor the redundancies and then add these into the setup of your new theme.
Next, you need to move the theme customizer files from the Genesis Sample Theme to your new developer’s theme. You’ll start by copying the files into your theme. Then you’ll start refactoring by applying the PHP namespace and removing the prefixing. You’ll give the functions purposeful names so that each tells you specifically what it does, i.e. what the expected behavior is when you call the function. You’ll be reorganizing the helper functions into a helper file. Also, there are some functions embedded within a function, which makes the code less readable. Let’s refactor those and make them their own […]
Your homework in the last episode was to refactor the image sizes on your own. In this episode, we’ll walk through how to move the image size name and arguments into a configuration variable. Just like the theme supports, calling the image sizes over and over again is WET and unnecessary. Let’s refactor to clean up the code and remove the redundancies.
Did you notice that the function add_theme_support() is being called over and over and over again in the setup? And did you notice that this function requires a key and then a value? I mentioned in the last episode that the final version of this starter theme will load all of the theme supports from a configuration file. Calling this function repeatedly is redundant and unnecessary. Let’s refactor it to convert the theme to clean, quality coding standard. In this episode, you will refactor the WordPress theme supports to move the parameters into a local configuration array. Then you’ll loop […]
In today’s quality code tip, you will learn about removing the HTML from your business logic and putting it into a view file. In programming, you want to separate out your code by its intent and purpose. Let’s discuss the what, how, and why of view files. (Side note: I’m showing you the actual code on this website which is powered by Genesis.
Code Smell Alert: A common code pattern that I see is where the if/else logic and the if conditional is backwards. I call this the “if/else backwards code pattern.” This code pattern makes the code less readable, which decreases its quality. There are two clues to let you know that you have stumbled into this pattern: The if conditional is set off of a false state. Typically you’ll see a not operator (!) as your clue. The if logic is setting a default state. But that is the job of the else. Smelly Version This is the smelling code pattern: […]
When doing a conditional expression, it’s a smelly code pattern to then return true or false. Why? The conditional expression already returns a true or false state. Therefore, you do not need to be so verbose and hardcode a boolean return. Here is the smelly code pattern: Refactor this code down to one line to make it more readable. It’s less code too (skinny). Strive to reduce your code and make it more simple. If you see this pattern in your code, then refactor it. Remember, you want your code to be as skinny (as few lines) as possible.
Let’s talk about naming of variables, functions, etc. in your code. In this video, you will learn some handy guidelines on naming by intent to let your code express what it’s doing, why it exists, how to use it, and what to expect from it. This tip is valid for all programming regardless of the language or technology.