It seems that there's a dispatch
on shutdown
, so, it seems that wp_ajax_my_action
is executed at the very last of the request but I can't be sure since it doesn't show in the normal actions viewer.
What's the latest I can hook into it?
Not sure why this created confusion, but I meant that, obviously, if you do wp_ajax_%
when you are in the footer, it's not gonna work. If you do it close to init
, say in functions.php
, it works, the hooking happens so it seems that before WP does the AJAX call, which calls wp_die()
anyways, it sets up the hooks and there is a point after which you can no longer hook into these endpoints and there-in lies my question: when exactly is it too late to hook a function to a wp_ajax_
endpoint?
Example:
add_action( 'wp_ajax_my_endpoint', 'my_function' ) in functions.php
works.
add_action( 'wp_ajax_my_endpoint', 'my_function' ) in footer.php
does not work.
How so?
wp_die()
as soon as the AJAX hook is run. So it's the last thing to happen. But why would you be hooking it 'late'?