Skip to content

Instantly share code, notes, and snippets.

@aimahdi
Created November 28, 2024 07:02
Show Gist options
  • Save aimahdi/3c79b85777de946f78eaefa26f3cbac0 to your computer and use it in GitHub Desktop.
Save aimahdi/3c79b85777de946f78eaefa26f3cbac0 to your computer and use it in GitHub Desktop.
Get Fluent Forms approved entries via REST-API
add_action('rest_api_init', function () {
register_rest_route('fluentform/v1', '/approved-entries/(?P<form_id>\d+)', array(
'methods' => 'GET',
'callback' => 'get_fluent_form_approved_entries',
'permission_callback' => '__return_true'
));
});
function get_fluent_form_approved_entries($request) {
$form_id = $request['form_id'];
if (!function_exists('fluentFormApi')) {
return new WP_Error('fluent_forms_not_active', 'Fluent Forms is not active', array('status' => 404));
}
$formApi = fluentFormApi('forms')->entryInstance($form_id);
$atts = [
'per_page' => 10,
'page' => 1,
'entry_type' => 'all',
];
$entries_array = json_decode($formApi->entries($atts, true)['data'], true);
$approvedEntries = array_filter($entries_array, function ($entry) {
return $entry['status'] === "approved";
});
return new WP_REST_Response($approvedEntries, 200);
}
/***
Usage
* Make a request from Postman using https://testwp.test/wp-json/fluentform/v1/approved-entries/185
* Replace testwp.test with your domain name
* Replace 185 with form id
* The returned data will be approved entries form form id 185
***/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment