wppaste
WordPress

wp_maybe_load_embeds()

Since
2.9.0
Source
wp-includes/embed.php:191
Determines if default embed handlers should be loaded.

Description

Checks to make sure that the embeds library hasn't already been loaded. If it hasn't, then it will load the embeds library.

Compatibility

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

Performance profile

How much work a call to wp_maybe_load_embeds() 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
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
6–41

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

Plugin surface
3 hooks

Third-party callbacks on 'load_default_embeds', 'wp_audio_embed_handler', 'wp_video_embed_handler' 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

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 wp_maybe_load_embeds() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!apply_filters()6apply_filters()
apply_filters()41apply_filters(), wp_embed_register_handler(), wp_get_audio_extensions(), apply_filters(), wp_embed_register_handler(), wp_get_video_extensions(), apply_filters(), wp_embed_register_handler()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev426–411
8.5426–411
8.4426–4116 fewer instructions than PHP 8.3
8.3486–471
8.2486–471
8.1486–471
7.4486–471

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 · 3

3 hooks fire while wp_maybe_load_embeds() runs, in this order:

  1. apply_filters( load_default_embeds )filterline 201 (+10 into the body)

    Filters whether to load the default embed handlers.

  2. apply_filters( wp_audio_embed_handler )filterline 214 (+23 into the body)

    Filters the audio embed handler callback.

  3. apply_filters( wp_video_embed_handler )filterline 223 (+32 into the body)

    Filters the video embed handler callback.

Uses · 4

Source code

function wp_maybe_load_embeds() {	/**	 * Filters whether to load the default embed handlers.	 *	 * Returning a falsey value will prevent loading the default embed handlers.	 *	 * @since 2.9.0	 *	 * @param bool $maybe_load_embeds Whether to load the embeds library. Default true.	 */	if ( ! apply_filters( 'load_default_embeds', true ) ) {		return;	} 	wp_embed_register_handler( 'youtube_embed_url', '#https?://(www\.)?youtube\.com/(?:v|embed)/([^/]+)#i', 'wp_embed_handler_youtube' ); 	/**	 * Filters the audio embed handler callback.	 *	 * @since 3.6.0	 *	 * @param callable $handler Audio embed handler callback function.	 */	wp_embed_register_handler( 'audio', '#^https?://.+?\.(' . implode( '|', wp_get_audio_extensions() ) . ')$#i', apply_filters( 'wp_audio_embed_handler', 'wp_embed_handler_audio' ), 9999 ); 	/**	 * Filters the video embed handler callback.	 *	 * @since 3.6.0	 *	 * @param callable $handler Video embed handler callback function.	 */	wp_embed_register_handler( 'video', '#^https?://.+?\.(' . implode( '|', wp_get_video_extensions() ) . ')$#i', apply_filters( 'wp_video_embed_handler', 'wp_embed_handler_video' ), 9999 );}

Changelog

Introduced in 2.9.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 7.0.4 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.