您需要返回WP\\u REST\\u响应对象。按以下方式编辑代码:
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 new WP_REST_Response( $data, 200 );
}
});
add_action( \'rest_api_init\', function () {
register_rest_route( \'ninja-forms/\', \'/id/(?P<id>\\d+)\', array(
\'methods\' => \'GET\',
\'callback\' => \'getNinjaFormData\',
));
});