wppaste
WordPress

get_media_embedded_in_content( string $content, string[] $types = null ): string[]

Since
3.6.0
Source
wp-includes/media.php:5166
Checks the HTML content for an audio, video, object, embed, or iframe tags.

Compatibility

WordPress
since 3.6.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$contentstring
A string of HTML which might contain media elements.
$typesstring[]optional
An array of media types: 'audio', 'video', 'object', 'embed', or 'iframe'.Default: null

Return value

string[]
Array of found HTML media elements.

Performance profile

How much work a call to get_media_embedded_in_content() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Light

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
20–33

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 36.

Plugin surface
1 hook

Third-party callbacks on 'media_embedded_in_content_allowed_types' run inside this call, and their cost is not bounded by anything here.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksapply_filters()called directly
  • regexregular expression over the whole inputpreg_match_all()called directly

What one call costs · 2 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost get_media_embedded_in_content() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
empty($types)20–24apply_filters(), preg_match_all()
!empty($types)27–33apply_filters(), array_intersect(), preg_match_all()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev3620–335
8.53620–335
8.43620–3354 fewer instructions than PHP 8.3
8.34024–375
8.24024–375
8.14024–375
7.44024–375

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while get_media_embedded_in_content() runs, in this order:

  1. apply_filters( media_embedded_in_content_allowed_types )filterline 5177 (+11 into the body)

    Filters the embedded media types that are allowed to be returned from the content blob.

Uses · 1

  • apply_filters()Calls the callback functions that have been added to a filter hook.

Source code

function get_media_embedded_in_content( $content, $types = null ) {	$html = array(); 	/**	 * Filters the embedded media types that are allowed to be returned from the content blob.	 *	 * @since 4.2.0	 *	 * @param string[] $allowed_media_types An array of allowed media types. Default media types are	 *                                      'audio', 'video', 'object', 'embed', and 'iframe'.	 */	$allowed_media_types = apply_filters( 'media_embedded_in_content_allowed_types', array( 'audio', 'video', 'object', 'embed', 'iframe' ) ); 	if ( ! empty( $types ) ) {		if ( ! is_array( $types ) ) {			$types = array( $types );		} 		$allowed_media_types = array_intersect( $allowed_media_types, $types );	} 	$tags = implode( '|', $allowed_media_types ); 	if ( preg_match_all( '#<(?P<tag>' . $tags . ')[^<]*?(?:>[\s\S]*?<\/(?P=tag)>|\s*\/>)#', $content, $matches ) ) {		foreach ( $matches[0] as $match ) {			$html[] = $match;		}	} 	return $html;}

Changelog

Introduced in 3.6.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/media.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.