Trying to trigger do_the_thing() from wp_remote_request()
I'm using the Webhooks addon from Gravity Forms (https://docs.gravityforms.com/category/add-ons-gravity-forms/webhooks-add-on/)
to submit a form to an internal handler so I can take action on the form data.
Internally, it uses wp_remote_request() to send a request to /wp-admin/admin-ajax.php?action=application_submitted, but the
callback function never fires.
When I visit https://mysite.local/wp-admin/admin-ajax.php?action=application_submitted in my browser,
or use curl to GET or POST to it via curl, the function works and replies 'done' to let me know.
When the webhooks plugin sends a request (either GET or POST) to the same URL, admin-ajax.php never gets run, even though I
can see with Xdebug that the correct callback has been registered to the correct hooks.
Also, when I trace out the call stack I can see that the request succeeds with 200, but never hits the breakpoint I've set on
the callback like it does with a regular page visit.
<?php
add_action( 'wp_ajax_nopriv_application_submitted', __NAMESPACE__ . '\\do_the_thing' );
add_action( 'wp_ajax_application_submitted', __NAMESPACE__ . '\\do_the_thing' );
function do_the_thing() {
// The thing to do, but never gets done.
wp_send_json( 'done' );
}
{
"0": {
"title": "Test GET",
"description": "",
"labelPlacement": "top_label",
"descriptionPlacement": "below",
"button": {
"type": "text",
"text": "Submit",
"imageUrl": ""
},
"fields": [{
"type": "checkbox",
"id": 1,
"label": "Does this work?",
"adminLabel": "",
"isRequired": false,
"size": "medium",
"errorMessage": "",
"visibility": "visible",
"choices": [{
"text": "It works!",
"value": "It works!",
"isSelected": false,
"price": ""
}],
"inputs": [{
"id": "1.1",
"label": "It works!",
"name": ""
}],
"formId": 2,
"description": "",
"allowsPrepopulate": false,
"inputMask": false,
"inputMaskValue": "",
"inputType": "",
"labelPlacement": "",
"descriptionPlacement": "",
"subLabelPlacement": "",
"placeholder": "",
"cssClass": "",
"inputName": "",
"noDuplicates": false,
"defaultValue": "",
"conditionalLogic": "",
"productField": "",
"enableSelectAll": "",
"enablePrice": "",
"displayOnly": "",
"multipleFiles": false,
"maxFiles": "",
"calculationFormula": "",
"calculationRounding": "",
"enableCalculation": "",
"disableQuantity": false,
"displayAllCategories": false,
"useRichTextEditor": false
}],
"version": "2.3.2",
"id": 2,
"useCurrentUserAsAuthor": true,
"postContentTemplateEnabled": false,
"postTitleTemplateEnabled": false,
"postTitleTemplate": "",
"postContentTemplate": "",
"lastPageButton": null,
"pagination": null,
"firstPageCssClass": null,
"subLabelPlacement": "below",
"cssClass": "braums-careers-application",
"enableHoneypot": false,
"enableAnimation": false,
"save": {
"enabled": false,
"button": {
"type": "link",
"text": "Save and Continue Later"
}
},
"limitEntries": false,
"limitEntriesCount": "",
"limitEntriesPeriod": "",
"limitEntriesMessage": "",
"scheduleForm": false,
"scheduleStart": "",
"scheduleStartHour": "",
"scheduleStartMinute": "",
"scheduleStartAmpm": "",
"scheduleEnd": "",
"scheduleEndHour": "",
"scheduleEndMinute": "",
"scheduleEndAmpm": "",
"schedulePendingMessage": "",
"scheduleMessage": "",
"requireLogin": false,
"requireLoginMessage": "",
"confirmations": [{
"id": "5b196c5c0011a",
"name": "Default Confirmation",
"isDefault": true,
"type": "message",
"message": "Thanks for contacting us! We will get in touch with you shortly.",
"url": "",
"pageId": "",
"queryString": ""
}],
"notifications": [{
"id": "5b196c5bf3f45",
"to": "{admin_email}",
"name": "Admin Notification",
"event": "form_submission",
"toType": "email",
"subject": "New submission from {form_title}",
"message": "{all_fields}",
"isActive": false
}]
},
"version": "2.3.2"
}