wp_is_xml_request() WordPress Function
The wp_is_xml_request() function checks whether the current request is an XMLHttpRequest (AJAX). This is useful for checking if an AJAX request is made, and then performing certain actions if it is. For example, you could use this function to return a different response if an AJAX request is made, or to run a different set of code.
wp_is_xml_request() #
Checks whether current request is an XML request, or is expecting an XML response.
Return
(bool) True if Accepts
or Content-Type
headers contain text/xml
or one of the related MIME types. False otherwise.
Source
File: wp-includes/load.php
function wp_is_xml_request() { $accepted = array( 'text/xml', 'application/rss+xml', 'application/atom+xml', 'application/rdf+xml', 'text/xml+oembed', 'application/xml+oembed', ); if ( isset( $_SERVER['HTTP_ACCEPT'] ) ) { foreach ( $accepted as $type ) { if ( false !== strpos( $_SERVER['HTTP_ACCEPT'], $type ) ) { return true; } } } if ( isset( $_SERVER['CONTENT_TYPE'] ) && in_array( $_SERVER['CONTENT_TYPE'], $accepted, true ) ) { return true; } return false; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.2.0 | Introduced. |