dpzbh1779 2018-09-12 21:25
浏览 59
已采纳

从前端表单限制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.

  • 写回答

1条回答 默认 最新

  • duanmu2941 2018-09-14 17:51
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题