CiviCRM internal AJAX path ( q=civicrm/ajax/* ) should set wp_doing_ajax - Gravity Forms 2.5.3+ breaks Mailings
CiviCRM version: 5.37.2
Today ran into an issue on a few client sites where a Gravity Forms update to version 2.5.3+ would cause Mailings to not be loaded.
The cause for this was that a new filter in Gravity Forms would inject a <script>
tag immediately after the <head>
tag that appears in the body_html
JSON field from Mailing.getSingle
API calls, with no escaping - which then breaks the JSON parser.
Note that this uses the internal civicrm/ajax
path and thus doesn't go through the WP Rest interface.
Gravity Forms checks the DOING_AJAX
constant before performing this injection, so the workaround was to add a hook_civicrm_config implementation that would define('DOING_AJAX', true)
if the q
parameter starts with civicrm/ajax
Would be preferable if this was done something during the initialisation of the CiviCRM WordPress plugin itself, for both admin and front-end paths.
There is a filter wp_doing_ajax
, which defaults to DOING_AJAX
, however it's worth noting that Gravity Forms does not use the interface to this filter, but the DOING_AJAX
constant itself, so in this case it would be better to define DOING_AJAX
as well.