Index: src/wp-includes/functions.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/wp-includes/functions.php	(revision 44628)
+++ src/wp-includes/functions.php	(date 1547680593000)
@@ -2993,7 +2993,16 @@
 		 * @param callable $function Callback function name.
 		 */
 		$function = apply_filters( 'wp_die_xmlrpc_handler', '_xmlrpc_wp_die_handler' );
-	} else {
+	} elseif ( wp_is_xml_request() ) {
+		/**
+		 * Filters the callback for killing WordPress execution for XML requests.
+		 *
+		 * @since 5.1.0
+		 *
+		 * @param callable $function Callback function name.
+		 */
+		$function = apply_filters( 'wp_die_xml_handler', '_xml_wp_die_handler' );
+	}else {
 		/**
 		 * Filters the callback for killing WordPress execution for all non-Ajax, non-XML-RPC requests.
 		 *
@@ -3258,6 +3267,44 @@
 	die();
 }
 
+/**
+ * Kill WordPress execution and display XML message with error message.
+ *
+ * This is the handler for wp_die when processing XML requests.
+ *
+ * @since 5.1.0
+ * @access private
+ *
+ * @param string       $message Error message.
+ * @param string       $title   Optional. Error title. Default empty.
+ * @param string|array $args    Optional. Arguments to control behavior. Default empty array.
+ */
+function _xml_wp_die_handler( $message, $title = '', $args = array() ) {
+	$defaults = array( 'response' => 500 );
+
+	$r = wp_parse_args( $args, $defaults );
+
+	$data = array(
+		'error' => array(
+			'code'    => 'wp_die',
+			'message' => $message,
+			'status'  => $r['response'],
+		)
+	);
+
+	if ( ! headers_sent() ) {
+		header( 'Content-Type: text/xml; charset=utf-8' );
+		if ( null !== $r['response'] ) {
+			status_header( $r['response'] );
+		}
+		nocache_headers();
+	}
+	echo '<?xml version="1.0" encoding="UTF-8"?>';
+	array_walk( $data, '_wp_wrap_xml' );
+	die();
+}
+
+
 /**
  * Kill WordPress execution and display XML message with error message.
  *
@@ -3330,6 +3377,33 @@
 	die();
 }
 
+/**
+ * Helper function to walk through array and echo xml elements
+ *
+ * @since 5.1.0
+ * @access private
+ *
+ * @param $value
+ * @param $element
+ */
+function _wp_wrap_xml( $value, $element ) {
+
+	if ( ! is_string( $element ) ) {
+		$element = 'item';
+	}
+	if ( is_object( $value ) ) {
+		$value = (array) $value;
+	}
+
+	echo "<$element>";
+	if ( is_array( $value ) ) {
+		array_walk( $value, '_wp_wrap_xml' );
+	} elseif ( is_scalar( $value ) ) {
+		echo $value;
+	}
+	echo "</$element>";
+}
+
 /**
  * Encode a variable into JSON, with some sanity checks.
  *
Index: src/wp-includes/load.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/wp-includes/load.php	(revision 44628)
+++ src/wp-includes/load.php	(date 1547675670000)
@@ -1488,3 +1488,35 @@
 	return false;
 
 }
+
+/**
+ * Checks whether current request is a XML request, or is expecting a XML response.
+ *
+ * @since 5.1.0
+ *
+ * @return bool True if Accepts or Content-Type headers contain xml, false otherwise.
+ */
+function wp_is_xml_request() {
+
+	$accepted = array(
+		'application/rss+xml',
+		'application/rss+xml',
+		'text/xml',
+		'application/atom+xml',
+		'application/rdf+xml',
+	);
+
+	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;
+}
