wp_ajax_nopriv_{$action} WordPress Action Hook

The wp_ajax_nopriv_{$action} hook is triggered when an AJAX request is made by a user who is not logged in.

do_action( "wp_ajax_nopriv_{$action}" ) #

Fires non-authenticated Ajax actions for logged-out 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 is functionally the same as wp_ajax_{$action}, except the “nopriv” variant is used for handling AJAX requests from unauthenticated users, i.e. when is_user_logged_in() returns false.

Unlike wp_ajax_{$action} the ajaxurl javascript global property will not be automatically defined and must be included manually or by using wp_localize_script() with admin_url( ‘admin-ajax.php’ ) as the data.

See also wp_ajax_nopriv_{$_REQUEST[‘action’]}.

For more information, see Ajax Plugin Handbook on the new WordPress Developer Resource.


Top ↑

Source

File: wp-admin/admin-ajax.php

View on Trac


Top ↑

Changelog

Changelog
VersionDescription
2.8.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.