I’m working on a list_cats plug-in. (Cool plug-in architecture, btw.) It appears that apply_filters is supposed to pass a string to the plug-in followed by additional arguments. In the case of list_cats, it would be nice to have the $category object with the cat_ID.
However, apply_filters has two bugs that prevent this mechanism from working. First, it’s not grabbing the right args. the line:
$args = array_slice(func_get_args(), 3);
needs to be
$args = array_slice(func_get_args(), 2);
And secondly, the plus/union array operator is not working correctly since both arrays are indexed from zero. This line:
$string = call_user_func_array($function, array($string) + $args);
needs to be:
$string = call_user_func_array($function, array_merge(array($string), $args));
After those changes, I’m now getting the $category object in my plug-in and it’s working very nicely. However, now I’m getting a “Warning: Wrong parameter count for trim()” error from the call_user_func_array. Since WP supports adding arbitrary functions to the filter/action list, those extra args might cause problems.
- The topic ‘Bug in apply_filters’ is closed to new replies.