Last active
March 17, 2022 03:34
-
-
Save gbrits/ffb34519c5b6cfca5ae97394bc9caae1 to your computer and use it in GitHub Desktop.
Replace Entry Keys w/ Admin Labels (GravityForms Webhook Add-on)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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