wp_maybe_load_embeds()
- Since
- 2.9.0
- Source
wp-includes/embed.php:191
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
- Scaling
- Constant
- Instructions
- 6–41
- Plugin surface
- 3 hooks
- Called by
- 0
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 42.
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.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_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.
| When | Instructions | Calls it makes |
|---|---|---|
!apply_filters() | 6 | apply_filters() |
apply_filters() | 41 | apply_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 42 | 6–41 | 1 | |
| 8.5 | 42 | 6–41 | 1 | |
| 8.4 | 42 | 6–41 | 1 | 6 fewer instructions than PHP 8.3 |
| 8.3 | 48 | 6–47 | 1 | |
| 8.2 | 48 | 6–47 | 1 | |
| 8.1 | 48 | 6–47 | 1 | |
| 7.4 | 48 | 6–47 | 1 |
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:
- apply_filters( load_default_embeds )filterline 201 (+10 into the body)
Filters whether to load the default embed handlers.
- apply_filters( wp_audio_embed_handler )filterline 214 (+23 into the body)
Filters the audio embed handler callback.
- apply_filters( wp_video_embed_handler )filterline 223 (+32 into the body)
Filters the video embed handler callback.
Uses · 4
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_embed_register_handler()Registers an embed handler.
- wp_get_audio_extensions()Returns a filtered list of supported audio formats.
- wp_get_video_extensions()Returns a filtered list of supported video formats.
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.
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/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.