You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Today is the second day in a row I've had to fix a bug in production due to incorrect usage of filters. When writing or reviewing code that involves actions or filters please always be sure about the following:
Make sure the type of hook matches, never use add_action for filters or add_filter for actions. It may seem like it works on a simple test but it will lead to issues.
A filter should always return the first argument if nothing needs to be done. Don't return the value originally passed into the filter as other plugins may have changed it. Always return the first argument.
All WordPress core actions and filters are documented and can easily be found on https://developer.wordpress.org/reference/hooks/. It's your responsibility to search for them when you write code that adds a new filter or action and it's your responsibility to do the same when code reviewing new additions.
There is a sniff in the Automattic VIPCS which can check that functions which are hooked into filters always return something as long as the "hook-in" and the function being hooked are in the same file. The sniff is pretty buggy at this time, but I'm working on fixing that in the foreseeable future.
The text was updated successfully, but these errors were encountered:
From https://yoast.slack.com/archives/C5SUKMF2T/p1595412782373600
Related:
Notes:
There is a sniff in the Automattic VIPCS which can check that functions which are hooked into filters always return something as long as the "hook-in" and the function being hooked are in the same file. The sniff is pretty buggy at this time, but I'm working on fixing that in the foreseeable future.
The text was updated successfully, but these errors were encountered: