wp_ajax_{$action} WordPress Action Hook

The wp_ajax_{$action} hook allows you to perform an action when an AJAX request is made to WordPress.

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.


Top ↑

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 to admin-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

Top ↑

Source

File: wp-admin/admin-ajax.php

View on Trac


Top ↑

Changelog

Changelog
VersionDescription
2.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.