When developing a WordPress Plugin that uses custom
apply_filters it’s always better to use a callback function.
They don’t explicitly say that you aren’t allowed to use anonymous functions but whenever you can, and when it’s appropriate, use a callback.
From the plugin development docs about actions
Create a callback function
First, create a callback function. This function will be run when the action it is hooked to is run.
The callback function is just like a normal function: it should be prefixed, and it should be in functions.php or somewhere callable. The parameters it should accept will be defined by the action you are hooking to; most hooks are well-defined, so review the hooks docs to see what parameters the action you have selected will pass to your function.
That being said, if you have some internal logic that relies on
apply_filters that you don’t want the user to mess with, then use an anonymous function.
It’s your plugin, and it’s up to you how much control and extensibility you want to provide your developer users.
Same goes for when you’re using add_action/add_filter.
If you’re using it on your own actions and filters and you don’t want users to mess with them, use anonymous function.
But if you use it with built in actions/filters you might consider using a callback so users can decide if they want it or maybe modify it.