I am trying to setup a filter which supports more than one parameter:
function FILTER_CALLBACK($block_id, array $items)
{
// How can I pass both parameters to the next hook?
return $items;
}
add_filter('HOOK_NAME', 'FILTER_CALLBACK', 10, 2);
Then in my plugin I do this:
apply_filters('HOOK_NAME', 'BLOCK_ID', $items);
If I then in for instance the theme using something like this:
add_filter('HOOK_NAME', function ($block_id, array $items) {
if ($block_id == 'MY_BLOCK') {
return array(
'A' => 1,
);
}
}, 10, 2);
Then I have a problem where the $block_id
is actually the array since I cannot return both parameters from the callback.
Of course I could solve this by using a single parameter like this:
$args = array(
'block_id' => 'MY_BLOCK',
'items' => $items,
);
And then modify the callback:
function FILTER_CALLBACK(array $options)
{
// Here options both contains block_id and items.
return $options;
}
But not sure if this is the correct way of doing it or if I really should use filters in this case? Perhaps an action or similar would be better? I can also say that I would like to filter the original values of the array depending on the $block_id
argument.