Skip to content

Instantly share code, notes, and snippets.

@gbrits
Last active March 17, 2022 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbrits/ffb34519c5b6cfca5ae97394bc9caae1 to your computer and use it in GitHub Desktop.
Save gbrits/ffb34519c5b6cfca5ae97394bc9caae1 to your computer and use it in GitHub Desktop.
Replace Entry Keys w/ Admin Labels (GravityForms Webhook Add-on)
<?php
add_filter('gform_webhooks_request_data', function ($request_data, $feed, $entry, $form) {
if (rgars($feed, 'meta/requestBodyType') === 'all_fields') {
foreach ($form['fields'] as $item) {
if ($item->adminLabel != '') {
if (isset($item->inputs) && is_array($item->inputs)) {
if ($item['type'] == 'time') {
foreach ($item->inputs as $key => $input) {
if (isset($entry[floor($input['id'])])) {
if (!is_null($entry[floor($input['id'])])) {
$time_elements = explode("-", str_replace(array(":", " "), "-", $entry[floor($input['id'])]));
if (count($time_elements) === 3) {
$request_data[$item->adminLabel . '-' . $input['label']] = $time_elements[$key];
}
}
}
}
} else {
$request_data[$item->adminLabel . '-' . $input['label']] = rgar($entry, $input['id']);
}
unset($request_data[$input['id']]);
} else {
$request_data[$item->adminLabel] = rgar($entry, $item->id);
unset($request_data[$item->id]);
}
} elseif ($item->type == 'hidden') {
$request_data[$item->label] = rgar($entry, $item->id);
unset($request_data[$item->id]);
}
}
}
return $request_data;
}, 10, 4);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment