_oembed_create_xml

Creates an XML string from a given array.

Description

(string|false) _oembed_create_xml( (array) $data, (null) $node = null ); 

Returns (string|false)

XML string on success, false on error.

Parameters (2)

0. $data (array)
The original oEmbed response data.
1. $node — Optional. (null) => null
XML node to append the result to recursively.

Usage

  1. if ( !function_exists( '_oembed_create_xml' ) ) { 
  2. require_once ABSPATH . WPINC . '/embed.php'; 
  3.  
  4. // The original oEmbed response data. 
  5. $data = array(); 
  6.  
  7. // Optional. XML node to append the result to recursively. 
  8. $node = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = _oembed_create_xml($data, $node); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/embed.php  
  1. function _oembed_create_xml( $data, $node = null ) { 
  2. if ( ! is_array( $data ) || empty( $data ) ) { 
  3. return false; 
  4.  
  5. if ( null === $node ) { 
  6. $node = new SimpleXMLElement( '<oembed></oembed>' ); 
  7.  
  8. foreach ( $data as $key => $value ) { 
  9. if ( is_numeric( $key ) ) { 
  10. $key = 'oembed'; 
  11.  
  12. if ( is_array( $value ) ) { 
  13. $item = $node->addChild( $key ); 
  14. _oembed_create_xml( $value, $item ); 
  15. } else { 
  16. $node->addChild( $key, esc_html( $value ) ); 
  17.  
  18. return $node->asXML();