When editing wordpress code in Visual Studio Code,
if I have a function definition and than I use it as a callback for a call to add_action
or add_filter
than because its used as a string its not counted as a reference to the function and the intelisense says 0 references
above my function which is true to some degree but also false and misleading in the practical sense.
Can I do something to tell visual studio code to add a reference to that function?
I was hoping I maybe could do something like:
function myCallback() {
//do some stuff
}
add_action('init',myCallback.name)
or
add_action('init','myCallback' /* @references:myCallback */)
or something similar
2
Answers
If you are using PHP 8.1, you can use the first class callable syntax
You can use a callback to assign your function to:
This works for several versions: https://3v4l.org/1tH3K
If I read 3v4l.org right, it works for