[wp-trac] [WordPress Trac] #40280: Short-circuit filters can't return common values
WordPress Trac
noreply at wordpress.org
Wed Aug 9 15:49:15 UTC 2017
#40280: Short-circuit filters can't return common values
-------------------------+------------------------------
Reporter: andy | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 4.8
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
-------------------------+------------------------------
Comment (by johnjamesjacoby):
I'm not convinced it will be possible to change existing filters with the
hooks API as it is today.
Strict type comparisons really solidified the fact that the `null` or
`false` values are permanently a part of those `pre_` style short-
circuits.
I spent the past hour trying to abstract the several existing usages, and
boiled it down to this terribleness:
{{{
/**
* Pre apply filters to a specific tag, allowing it to be short-circuited.
*
* @since 4.9.0
*
* @return mixed
*/
function pre_apply_filters() {
$args = func_get_args();
$tag = "pre_{$args[0]}";
// Don't pass the tag name
array_shift( $args );
// Apply filters & return
return apply_filters_ref_array( $tag, $args );
}
}}}
It basically does nothing, but there is also nothing else left to abstract
if:
* the initial variable could be anything
* the number of arguments could be 0 to infinity
----
If we agree to leave existing filters as-is and invent something new,
then... how about a constant to solidify the value of the default variable
in all of our minds, like `WP_PRE_FILTER_VAL` or something?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/40280#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list