从前端表单限制ACF的“acf / validate_save_post”操作

I am using ACF's acf/validate_save_post action hook to validate a serial number from a front-end form with a 3rd party API before the form submits and saves to a post type.

If the call to the 3rd party API returns an error I am using this action hook to display validation errors using the acf_add_validation_error() function.

Due to the acf/validation_save_post action hook being called when a post is published (and before, when doing the JS validation), the serial number ends up being validated 3 times. This ends up locking the user out due to limits set on the API side.

Is there a way to lock the action hook out from running when a post is published and only have it run when it is doing the JS validation?

I have tried using wp_doing_ajax() in an if statement but I think all the work is done via AJAX anyway, unless I am wrong on that. It still appears to run more than once while using wp_doing_ajax() anyway so maybe there is another solution out there.

In case anyone finds this in the future, the solution to the issue is to check if this is an AJAX request via wp_doing_ajax(). This will stop validation while publishing the post via the admin or the acf/save_post action hook.