do_action( "wp_ajax_{$action}" )
Fires authenticated Ajax actions for logged-in users.
Description
The dynamic portion of the hook name, $action
, refers to the name of the Ajax action callback being fired.
More Information
- This hook allows you to handle your custom AJAX endpoints. The
wp_ajax_
hooks follows the format “wp_ajax_$action
“, where$action
is the ‘action
‘ field submitted toadmin-ajax.php
. - This hook only fires for logged-in users. If your action only allows Ajax requests to come from users not logged-in, you need to instead use wp_ajax_nopriv_$action such as:
add_action( 'wp_ajax_nopriv_add_foobar', 'prefix_ajax_add_foobar' );
. To allow both, you must register both hooks! - See also wp_ajax__requestaction
- See also Ajax Plugin Handbook
Source
File: wp-admin/admin-ajax.php
Changelog
Version | Description |
---|---|
2.1.0 | Introduced. |
© 2003–2021 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/hooks/wp_ajax__requestaction