WP_Customize_Manager::doing_ajax() WordPress Method

The WP_Customize_Manager::doing_ajax() method is used to determine whether the current request is for an Ajax call. This can be useful for checking if you need to do any special handling for Ajax requests. For example, you might want to disable certain caching mechanisms for Ajax requests.

WP_Customize_Manager::doing_ajax( string|null $action = null ) #

Returns true if it’s an Ajax request.


Parameters

$action

(string|null)(Optional)Whether the supplied Ajax action is being run.

Default value: null


Top ↑

Return

(bool) True if it's an Ajax request, false otherwise.


Top ↑

Source

File: wp-includes/class-wp-customize-manager.php

	public function doing_ajax( $action = null ) {
		if ( ! wp_doing_ajax() ) {
			return false;
		}

		if ( ! $action ) {
			return true;
		} else {
			/*
			 * Note: we can't just use doing_action( "wp_ajax_{$action}" ) because we need
			 * to check before admin-ajax.php gets to that point.
			 */
			return isset( $_REQUEST['action'] ) && wp_unslash( $_REQUEST['action'] ) === $action;
		}
	}


Top ↑

Changelog

Changelog
VersionDescription
4.2.0Added $action param.
3.4.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.

Show More