wpseek.com
WordPress开发者和主题制作者的搜索引擎



_oembed_create_xml › WordPress Function

Since4.4.0
已弃用n/a
_oembed_create_xml ( $data, $node = null )
访问:
  • private
参数: (2)
  • (array) $data The original oEmbed response data.
    Required: Yes
  • (SimpleXMLElement) $node Optional. XML node to append the result to recursively.
    Required: No
    默认: null
返回:
  • (string|false) XML string on success, false on error.
定义在:
文档:

Creates an XML string from a given array.



源码

function _oembed_create_xml( $data, $node = null ) {
	if ( ! is_array( $data ) || empty( $data ) ) {
		return false;
	}

	if ( null === $node ) {
		$node = new SimpleXMLElement( '<oembed></oembed>' );
	}

	foreach ( $data as $key => $value ) {
		if ( is_numeric( $key ) ) {
			$key = 'oembed';
		}

		if ( is_array( $value ) ) {
			$item = $node->addChild( $key );
			_oembed_create_xml( $value, $item );
		} else {
			$node->addChild( $key, esc_html( $value ) );
		}
	}

	return $node->asXML();
}