I am wondering how can I add an endpoint where I would return the ninja form plugin data. I have made a function where I am getting the data from the ninja form:
add_action('init', function() {
function getNinjaFormData(WP_REST_Request $request) {
$id = $request->get_param('id');
$settings = ['label', 'type', 'required'];
$formFields = Ninja_Forms()->form(1)->get_fields();
$data = [];
foreach ($formFields as $formField) {
$key = $formField->get_setting('key');
foreach ($settings as $setting) {
$data[$key][] = $formField->get_setting($setting);
}
}
return $data;
}
});
add_action( 'rest_api_init', function () {
register_rest_route( 'ninja-forms/', '/id/(?P<id>\d+)', array(
'methods' => 'GET',
'callback' => 'getNinjaFormData',
));
});
But, this is not working, what am I doing wrong?