This quick lesson will help you to understand your relationship as the programmer with the computer. It is one of the essential building blocks in your quest to build anything in software. Software development is a thinking profession. Computers cannot read your mind. They cannot infer or figure out what you want it to do. They are literal and exact. They only do exactly what you tell them to do. That’s it. Computers do not think. You do. When a computer is not doing what you want, stop and look at your code. Remember this tip. Then spend your time […]
Code Tip: Specify a default for get_option()
In this quick tip, you will see that you can specify a default return value for the WordPress function get_option(). When the option does not exist in the database, such as you are setting up a theme options page, then you can specify a return value as the default. Otherwise, you will get “false” back.
Code Tip – Alternate Ternary Operator syntax ?:
The ternary operator can be confusing, as it dehydrates the longer if/else code blocks into a single line of code. It eliminates the repeating pattern. But what about the ?: syntax? How does that work? When should you use it? Check out the other syntax here. This tip is valid for JavaScript and PHP.
Code Tip: Purposeful Naming
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.
Procedural, functional, or OOP?
Question: Which programming paradigm should I do? Answer: It doesn’t matter. Nope. You can program in any of these paradigms. What matters is you write clean, quality code and that you are proficient in one of these paradigms.
PHP Tip: What makes a conditional expression false (falsey state)?
In this video, you will learn the intent of this `if` conditional expression as well as what evaluates to false. This is known as checking the falsey state.
WordPress Tip: Do You Have to Specify all the Arguments for add_action and add_filter?
The question I often get is: If I only need a couple of the arguments that a filter or action makes available, do I have to specify all of them in the callback function for add_filter() and add_action(). For example, if a filter, such as shortcode_atts_{$shortcode} has 4 arguments, but I only need 3, do I have to wire it up for all 4? In this video, Tonya explains why you have control over what you want to receive by looking into WordPress core at apply_filters().
PHP Tip: Use array_merge and Not foreach to Merge Defaults
In this quick tip, Tonya shows you how to reduce your code when you want to merge default parameters (settings) together with the implement. She shows you a shortcode example from WordPress which uses a foreach() to accomplish what one line of code and do, i.e. using array_merge.
WordPress Tip – Put in the Shortcode Name for shortcode_atts
Help out your fellow developers and put the shortcode name as the third parameter in the function shortcode_atts(). Why? To allow other developers to modify the default attributes you specify with your shortcode. Tonya shows you how this works and the benefit to the site owner.
PhpStorm Tip – Multiple Selections (Multicursor)
Ever wonder how to quickly select multiple instances of a literal, variable, function, or comment? PhpStorm provides you with a keymapping for making multiple selections (multicusors). Check it out. Thank you to Jeffrey Way at Laracasts.com for the tip!