W3cubDocs

/WordPress

WP_oEmbed::_parse_xml_body( string $response_body ): stdClass|false

Serves as a helper function for parsing an XML response body.

Parameters

$response_bodystringrequired

Return

stdClass|false

Source

private function _parse_xml_body( $response_body ) {
	if ( ! function_exists( 'simplexml_import_dom' ) || ! class_exists( 'DOMDocument', false ) ) {
		return false;
	}

	$dom     = new DOMDocument();
	$success = $dom->loadXML( $response_body );
	if ( ! $success ) {
		return false;
	}

	if ( isset( $dom->doctype ) ) {
		return false;
	}

	foreach ( $dom->childNodes as $child ) {
		if ( XML_DOCUMENT_TYPE_NODE === $child->nodeType ) {
			return false;
		}
	}

	$xml = simplexml_import_dom( $dom );
	if ( ! $xml ) {
		return false;
	}

	$return = new stdClass();
	foreach ( $xml as $key => $value ) {
		$return->$key = (string) $value;
	}

	return $return;
}

Changelog

Version Description
3.6.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_oembed/_parse_xml_body