I'm trying to use the variable $args_array
inside an anonymous function that and a regular function.
The variable is declared at the top level, and yet I receive an error about this variable not being defined when I try to use it in these functions.
This is the warnings I get in my IDE:
And this is my code:
$args_array = array(
'endpoint' => 'my_endpoint',
'url' => 'my_url',
'api_key' => 'my_api_key',
'api_value' => 'my_api_value'
);
add_action( 'rest_api_init', function () {
register_rest_route( 'api', '/semir/', array(
'methods' => 'GET',
'callback' => 'semirs_function',
'args' => $args_array
));
});
function semirs_function() {
return $args_array;
}