WordPress has a lot of helper functions built into its core. Some of these functions are obvious and some are obscure … and almost every one of them can be easily put to use.

A chat group I was in the other day lead me to looking for a set of these helper functions in the code we were discussing … I didn’t find them. Well, I did find them in use but I did not find where they were defined. Next stop, the WordPress core … and there they were.

Now, as the title may suggest I am referring to the following WordPress core functions:

  • __return_true() – returns the Boolean state of true
  • __return_false() – returns the Boolean state of false
  • __return_zero() – returns a value of zero (0)
  • __return_empty_array() – returns an empty array, as in array()
  • __return_null() – returns null (or void)

All of these functions have a very similar structure and were implemented at WordPress version 3.0.0, with the exception of `__return_null` which will be introduced at WordPress version 3.4 per their definitions in ‘../wp-includes/functions.php‘. For example, here is the code for `__return_true`:

function __return_true() {
	return true;
}

Why are these great helper functions? Simple really … they provide easy to remember, and very useful, callback functions for filters. You should not need to write your own return functions now, just __return_* it instead.