apply_filters's handling of extra arguments is broken
|Reported by:||michel v||Owned by:||ryan|
In bug 768, the code for extra parameters in apply_filters() was badly added to WP: morganiq's code had $args = array_slice(func_get_args(), 3) because the function called for three parameters.
With 3, the first and second extra arguments are discarded.
*Fix: 3 must be changed to 2.
However, later in the code, an array union is made: array($string) + $args. An array union keeps the first array's values while eventually adding the second array's values if the second array has more rows.
It's better explained there: http://fr.php.net/manual/en/language.operators.array.php
So the problem is array($string) + $args is always eating the first element of $args.
*Fix: change the 2 into 1, to have $args contain $string as first element.
However, this brings a third problem: WP indiscriminately passed all args to all functions. This means single args functions like strtoupper, trim (this one is called by the_title by default) give a warning for too many elements.
*Fix: I have no idea, but I've got a proposal.
*Proposal: filters that accept more than just $string should notify WP of how many extra arguments they accept. This way, WP can default to 0, stripping extra args for most filters currently in use, and then serve extra args for those filters that can handle them.
Change History (40)
comment:35 ryan — 9 years ago
- fixed_in_version set to 1.5.1
- Owner changed from anonymous to rboren
- Resolution changed from 10 to 20
- Status changed from new to closed
comment:36 angsuman — 8 years ago
- Priority changed from high to normal
- Resolution fixed deleted
- Severity changed from major to normal
- Status changed from closed to reopened