get_media_embedded_in_content

Check the content blob for an audio, video, object, embed, or iframe tags.

Description

(array) get_media_embedded_in_content( (string) $content, (null) $types = null ); 

Returns (array)

A list of found HTML media embeds.

Parameters (2)

0. $content (string)
A string which might contain media data.
1. $types — Optional. (null) => null
An array of media types: audio,, video., object, embed, or iframe.

Usage

  1. if ( !function_exists( 'get_media_embedded_in_content' ) ) { 
  2. require_once ABSPATH . WPINC . '/media.php'; 
  3.  
  4. // A string which might contain media data. 
  5. $content = ''; 
  6.  
  7. // An array of media types: 'audio', 'video', 'object', 'embed', or 'iframe'. 
  8. $types = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = get_media_embedded_in_content($content, $types); 
  12.  

Defined (1)

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

/wp-includes/media.php  
  1. function get_media_embedded_in_content( $content, $types = null ) { 
  2. $html = array(); 
  3.  
  4. /** 
  5. * Filters the embedded media types that are allowed to be returned from the content blob. 
  6. * @since 4.2.0 
  7. * @param array $allowed_media_types An array of allowed media types. Default media types are 
  8. * 'audio', 'video', 'object', 'embed', and 'iframe'. 
  9. */ 
  10. $allowed_media_types = apply_filters( 'media_embedded_in_content_allowed_types', array( 'audio', 'video', 'object', 'embed', 'iframe' ) ); 
  11.  
  12. if ( ! empty( $types ) ) { 
  13. if ( ! is_array( $types ) ) { 
  14. $types = array( $types ); 
  15.  
  16. $allowed_media_types = array_intersect( $allowed_media_types, $types ); 
  17.  
  18. $tags = implode( '|', $allowed_media_types ); 
  19.  
  20. if ( preg_match_all( '#<(?P<tag>' . $tags . ')[^<]*?(?:>[\s\S]*?<\/(?P=tag)>|\s*\/>)#', $content, $matches ) ) { 
  21. foreach ( $matches[0] as $match ) { 
  22. $html[] = $match; 
  23.  
  24. return $html;