Generally you do not want to access your PHP files directly within WordPress because you lose a lot of “juice”, meaning all WP functionality would have to be re-imported (and might break). WP is setup in a way that all requests to the CMS get routed to index.php and some mechanisms then decide what to do with the request.
From what you write, it sounds like a custom REST endpoint might serve you well.
Expanding your code to the following should already show some results:
add_action('rest_api_init', function () {
register_rest_route('my-plugin/v1', '/my-page', [
'methods' => [\Requests::POST],
'callback' => 'my_awesome_func',
]);
});
function my_awesome_func()
{
if (!isset($returnVal))
$returnVal = new stdClass();
$returnVal->status = "success";
$returnVal->info = "seems to work";
return $returnVal;
}
(using short array syntax and) changed
'methods' => 'GET',
to
'methods' => [\Requests::POST],
which references the Requests’ class const (my preferred style – you can also use 'POST'
directly).
Most likely you want to do something with the form data, so change your my_awesome_func()
to something like this
function my_awesome_func(\WP_REST_Request $request)
{
if ($request->get_param('main_license_number') !== 'something') {
return new WP_Error('Invalid license number!');
}
return [
'status' => 'success',
'info' => 'hello',
];
}
Now there is only one problem left: everybody can call this endpoint, they don’t have to come through the form. Your request contains a fusion-form-nonce-1808
and I assume this can be used to verify that it was indeed submitted from the form – but seems very Avada/FusionForm/some third party plugin specific – which I have no knowledge of and is out of scope for this site. But you should try contacting them and ask how to verify it, something along the lines of:
add_action('rest_api_init', function () {
register_rest_route('my-plugin/v1', '/my-page', [
'methods' => [\Requests::POST],
'callback' => 'my_awesome_func',
'permission_callback' => function () {
return magic_validate_my_nonce_please();
},
]);
});
or with the fancy arrow function added in PHP 7.4:
add_action('rest_api_init', function () {
register_rest_route('my-plugin/v1', '/my-page', [
'methods' => [\Requests::POST],
'callback' => 'my_awesome_func',
'permission_callback' => fn () => magic_validate_my_nonce_please(),
]);
});