wppaste
WordPress

wp_filter_oembed_iframe_title_attribute( string|false $result, object $data, string $url ): string|false

Since
5.2.0
Source
wp-includes/embed.php:867
Filters the given oEmbed HTML to make sure iframes have a title attribute.

Compatibility

WordPress
since 5.2.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

$resultstring|false
The oEmbed HTML result.
$dataobject
A data object result from an oEmbed provider.
$urlstring
The URL of the content to be embedded.

Return value

string|false
The filtered oEmbed result.

Performance profile

How much work a call to wp_filter_oembed_iframe_title_attribute() 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
6–74

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

Plugin surface
1 hook

Third-party callbacks on 'oembed_iframe_title_attribute' 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

Further down the call graph this can also reach option, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 7 distinct outcomes

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

WhenInstructionsCalls it makes
always6–9none
$result !== false && !preg_match() && $title === ""32–36preg_match(), apply_filters()
$result !== false && preg_match() && $title === ""43–48preg_match(), wp_allowed_protocols(), wp_kses_hair(), apply_filters()
$result !== false && !preg_match() && $title !== "" && !isset($attrs)45–49preg_match(), apply_filters(), esc_attr(), str_ireplace()
$result !== false && preg_match() && $title !== "" && !isset($attrs)56–61preg_match(), wp_allowed_protocols(), wp_kses_hair(), apply_filters(), esc_attr(), str_ireplace()
$result !== false && !preg_match() && $title !== "" && isset($attrs)58–62preg_match(), apply_filters(), wp_list_pluck(), esc_attr(), str_ireplace()
$result !== false && preg_match() && $title !== "" && isset($attrs)69–74preg_match(), wp_allowed_protocols(), wp_kses_hair(), apply_filters(), wp_list_pluck(), esc_attr(), str_ireplace()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev906–7411
8.5906–7411
8.4906–741110 fewer instructions than PHP 8.3
8.31006–8411
8.21006–8411
8.11006–84111 fewer instruction than PHP 7.4
7.41016–8511

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 wp_filter_oembed_iframe_title_attribute() runs, in this order:

  1. apply_filters( oembed_iframe_title_attribute )filterline 904 (+37 into the body)

    Filters the title attribute of the given oEmbed HTML iframe.

Uses · 5

Source code

function wp_filter_oembed_iframe_title_attribute( $result, $data, $url ) {	if ( false === $result || ! in_array( $data->type, array( 'rich', 'video' ), true ) ) {		return $result;	} 	$title = ! empty( $data->title ) ? $data->title : ''; 	$pattern = '`<iframe([^>]*)>`i';	if ( preg_match( $pattern, $result, $matches ) ) {		$attrs = wp_kses_hair( $matches[1], wp_allowed_protocols() ); 		foreach ( $attrs as $attr => $item ) {			$lower_attr = strtolower( $attr );			if ( $lower_attr === $attr ) {				continue;			}			if ( ! isset( $attrs[ $lower_attr ] ) ) {				$attrs[ $lower_attr ] = $item;				unset( $attrs[ $attr ] );			}		}	} 	if ( ! empty( $attrs['title']['value'] ) ) {		$title = $attrs['title']['value'];	} 	/**	 * Filters the title attribute of the given oEmbed HTML iframe.	 *	 * @since 5.2.0	 *	 * @param string $title  The title attribute.	 * @param string $result The oEmbed HTML result.	 * @param object $data   A data object result from an oEmbed provider.	 * @param string $url    The URL of the content to be embedded.	 */	$title = apply_filters( 'oembed_iframe_title_attribute', $title, $result, $data, $url ); 	if ( '' === $title ) {		return $result;	} 	if ( isset( $attrs['title'] ) ) {		unset( $attrs['title'] );		$attr_string = implode( ' ', wp_list_pluck( $attrs, 'whole' ) );		$result      = str_replace( $matches[0], '<iframe ' . trim( $attr_string ) . '>', $result );	}	return str_ireplace( '<iframe ', sprintf( '<iframe title="%s" ', esc_attr( $title ) ), $result );}

Changelog

Introduced in 5.2.0. 2 changes between 6.7.7 and 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.

6.9.7
Parameter $result retyped from string to string|false.verified against source
6.9.7
Return type changed from string to string|false.verified against source
5.2.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/embed.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.