Make WordPress Core


Ignore:
Timestamp:
03/26/2019 11:10:21 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Bootstrap/Load: Add support for XML requests to wp_die().

In addition to AJAX, XML-RPC, JSON, and JSONP requests, wp_die() now handles XML requests correctly, returning information in the expected content type.

Props spacedmonkey, birgire.
Fixes #46026. See #44458.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/load.php

    r45015 r45016  
    15301530
    15311531}
     1532
     1533/**
     1534 *
     1535 * Checks whether current request is a XML request, or is expecting a XML response.
     1536 *
     1537 * @since 5.2.0
     1538 *
     1539 * @return bool True if Accepts or Content-Type headers contain xml, false otherwise.
     1540 */
     1541function wp_is_xml_request() {
     1542    $accepted = array(
     1543        'text/xml',
     1544        'application/rss+xml',
     1545        'application/atom+xml',
     1546        'application/rdf+xml',
     1547        'text/xml+oembed',
     1548        'application/xml+oembed',
     1549    );
     1550
     1551    if ( isset( $_SERVER['HTTP_ACCEPT'] ) ) {
     1552        foreach ( $accepted as $type ) {
     1553            if ( false !== strpos( $_SERVER['HTTP_ACCEPT'], $type ) ) {
     1554                return true;
     1555            }
     1556        }
     1557    }
     1558
     1559    if ( isset( $_SERVER['CONTENT_TYPE'] ) && in_array( $_SERVER['CONTENT_TYPE'], $accepted, true ) ) {
     1560        return true;
     1561    }
     1562
     1563    return false;
     1564}
Note: See TracChangeset for help on using the changeset viewer.