ACF_Field_User::ajax_query_initpublicACF 5.8.8

Runs during the AJAX query initialization.

Method of the class: ACF_Field_User{}

No Hooks.

Returns

void. Nothing (null).

Usage

$ACF_Field_User = new ACF_Field_User();
$ACF_Field_User->ajax_query_init( $request, $query );
$request(array) (required)
The query request.
$query(ACF_Ajax_Query) (required)
The query object.

Changelog

Since 5.8.8 Introduced.

ACF_Field_User::ajax_query_init() code ACF 6.8.8

function ajax_query_init( $request, $query ) {
	// Require field and make sure it's a user field.
	if ( ! $query->field || $query->field['type'] !== $this->name ) {
		$query->send( new WP_Error( 'acf_missing_field', __( 'Error loading field.', 'acf' ), array( 'status' => 404 ) ) );
	}

	// Verify that this is a legitimate request using a separate nonce from the main AJAX nonce.
	$nonce = acf_request_arg( 'nonce', '' );
	$key   = acf_request_arg( 'field_key', '' );

	if ( ! acf_verify_ajax( $nonce, $key, true, 'user' ) ) {
		$query->send( new WP_Error( 'acf_invalid_request', __( 'Invalid request.', 'acf' ), array( 'status' => 404 ) ) );
	}
}