Boolean shorthand for add_filter
|Reported by:||ryanve||Owned by:|
Callbacks like __return_false or __return_true are often passed to add_filter to negate a filter or flip an option. This creates uneeded function calls. A potential performance-saver is to enable add_filter to support bools being passed as callbacks. add_filter doesn't validate the callback anyway, so no change would be needed there. A check could be done as apply_filters runs:
$value = is_bool($the_['function']) ? $the_['function'] : call_user_func_array( $the_['function'], array_slice($args, 1, (int) $the_['accepted_args']) );
3quals checks like false === $fn || true === $fn could be slightly faster. My hypothesis is that greater savings would be made from avoiding calls to array_slice, call_user_func_array, and the callback itself. A minor secondary benefit is that storing bools in the hash rather than strings like __return_false should reduce memory consumption.
It of course would also add syntactic sugar like: