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 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题