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!
PhpStorm Tip – One Keystroke to Automatically Format to WordPress Coding Standard
Ever wonder how to automatically reformat your code to a particular coding standard in PhpStorm? In this video, you’ll learn how to configure PhpStorm to apply the WordPress PHP Coding Standard and then the key strokes to auto format your code.
WordPress Tip – Match Arguments and Parameters When Calling Functions
You have to match the number of arguments to the number of required parameters for a PHP function. A common error is when you forget to specify the number of arguments to send when wiring up an event callback for add_action() or add_filter(). In this video, Tonya shows you why you have to specify this number.
Code Tip: Understanding the Ternary Operator
Let’s talk about the ternary operator. It can be confusing for many. In this video, Tonya puts the if/else side-by-side with its equivalent ternary to help you know and understand it. The alternate syntax tip is found here. This tip is valid for JavaScript and PHP.
WordPress Tip – Linking Taxonomy to Custom Post Type
Do you need to include the optional parameter taxonomies when registering the custom post type register_post_type()? How do you link the taxonomy and post type? In this quick tip, Tonya shows the how and why of the `taxonomies` optional parameter.