dssqq64884 2018-12-11 21:57
浏览 135

admin-ajax.php找不到已经定义的ajax动作

I had come to the point where I have to ask for your help here.

There is a section on the admin-ajax.php code that checks for you registed ajax action. But for some reason my action is not found when the Ajax request is trigger. But if I check the action within my code is there. This the code section that checks for the valid action.

if ( ! has_action( 'wp_ajax_' . $_REQUEST['action'] ) )

And this is a code section from the file admin-ajax.php of WordPress:

if ( is_user_logged_in() ) {
    // If no action is registered, return a Bad Request response.
    if ( ! has_action( 'wp_ajax_' . $_REQUEST['action'] ) ) {
        wp_die( '0', 400 );
    }

    /**
     * Fires authenticated Ajax actions for logged-in users.
     *
     * The dynamic portion of the hook name, `$_REQUEST['action']`,
     * refers to the name of the Ajax action callback being fired.
     *
     * @since 2.1.0
     */
    do_action( 'wp_ajax_' . $_REQUEST['action'] );
} else {
    // If no action is registered, return a Bad Request response.
    if ( ! has_action( 'wp_ajax_nopriv_' . $_REQUEST['action'] ) ) {
        wp_die( '0', 400 );
    }

    /**
     * Fires non-authenticated Ajax actions for logged-out users.
     *
     * The dynamic portion of the hook name, `$_REQUEST['action']`,
     * refers to the name of the Ajax action callback being fired.
     *
     * @since 2.8.0
     */
    do_action( 'wp_ajax_nopriv_' . $_REQUEST['action'] );
}

You can take at the full code here:

https://github.com/WordPress/WordPress/blob/master/wp-admin/admin-ajax.php#L155

Thanks in advance with your help to lightning things out.

  • 写回答

1条回答 默认 最新

  • drgdn82648 2019-01-22 21:53
    关注

    For anyone else stopping by. I found my answer after a lot of debugging and testing. The action was registered in an inherited class and therefore by the time the code need it it was not present. So after calling the method that was registering the action in the Parent Constructor all started to work.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog