Enclosure::embed( $options = '', bool $native = false ): string
- Source
wp-includes/SimplePie/src/Enclosure.php:862
Description
$options is an array or comma-separated key:value string, with the following properties:
alt(string): Alternate content for when an end-user does not have the appropriate handler installed or when a file type is unsupported. Can be any text or HTML. Defaults to blank.altclass(string): If a file type is unsupported, the end-user will see the alt text (above) linked directly to the content. That link will have this value as its class name. Defaults to blank.audio(string): This is an image that should be used as a placeholder for audio files before they're loaded (QuickTime-only).
Can be any relative or absolute URL. Defaults to blank.bgcolor(string): The background color for the media, if not already transparent. Defaults to#ffffff.height(integer): The height of the embedded media. Accepts any numeric pixel value (such as360) orauto. Defaults toauto, and it is recommended that you use this default.loop(boolean): Do you want the media to loop when it's done? Defaults tofalse.mediaplayer(string): The location of the includedmediaplayer.swffile. This allows for the playback of Flash Video (.flv) files, and is the default handler for non-Odeo MP3's.
Defaults to blank.video(string): This is an image that should be used as a placeholder for video files before they're loaded (QuickTime-only).
Can be any relative or absolute URL. Defaults to blank.width(integer): The width of the embedded media. Accepts any numeric pixel value (such as480) orauto. Defaults toauto, and it is recommended that you use this default.widescreen(boolean): Is the enclosure widescreen or standard? This applies only to video enclosures, and will automatically resize the content appropriately. Defaults tofalse, implying 4:3 mode.
Note: Non-widescreen (4:3) mode with width and height set to auto will default to 480x360 video resolution. Widescreen (16:9) mode with width and height set to auto will default to 480x270 video resolution.
Compatibility
- WordPress
- core
- 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
$optionsoptional- Default:
'' $nativebooloptional- Use
<embed>Default:false
Return value
string- HTML string to output
Performance profile
How much work a call to Enclosure::embed() 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
- 68–115
- Plugin surface
- None
- 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 389.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What one call costs · 6 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost Enclosure::embed() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!is_array($options) | 68–99 | ->get_handler(), ->get_real_type(), explode(), explode(), ->get_link() |
!is_array($options) && $handler !== "flash" | 78–96 | ->get_handler(), ->get_real_type(), explode(), explode(), ->get_link(), ->get_extension(), rawurlencode() |
!is_array($options) && $mime === "video" | 81–109 | ->get_handler(), ->get_real_type(), explode(), explode(), round(), ->get_link() |
!is_array($options) && $mime === "video" && $handler !== "flash" | 91–106 | ->get_handler(), ->get_real_type(), explode(), explode(), round(), ->get_link(), ->get_extension(), rawurlencode() |
!is_array($options) && $mime === "video" && $mime !== "audio" | 94–115 | ->get_handler(), ->get_real_type(), explode(), explode(), round(), round(), ->get_link() |
!is_array($options) && $mime === "video" && $mime !== "audio" && $handler !== "flash" | 104–112 | ->get_handler(), ->get_real_type(), explode(), explode(), round(), round(), ->get_link(), ->get_extension(), rawurlencode() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 389 | 68–115 | 45 | |
| 8.5 | 389 | 68–115 | 45 | |
| 8.4 | 389 | 68–115 | 45 | 10 fewer instructions than PHP 8.3 |
| 8.3 | 399 | 68–117 | 45 | |
| 8.2 | 399 | 68–117 | 45 | 1 more instruction than PHP 8.1 |
| 8.1 | 398 | 68–117 | 45 | |
| 7.4 | 398 | 68–117 | 45 |
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.
Uses · 4
- \SimplePie\Enclosure::get_handler()
- \SimplePie\Enclosure::get_real_type()
- \SimplePie\Enclosure::get_link()
- \SimplePie\Enclosure::get_extension()
Source code
public function embed($options = '', bool $native = false) { // Set up defaults $audio = ''; $video = ''; $alt = ''; $altclass = ''; $loop = 'false'; $width = 'auto'; $height = 'auto'; $bgcolor = '#ffffff'; $mediaplayer = ''; $widescreen = false; $handler = $this->get_handler(); $type = $this->get_real_type(); $placeholder = ''; // Process options and reassign values as necessary if (is_array($options)) { extract($options); } else { $options = explode(',', $options); foreach ($options as $option) { $opt = explode(':', $option, 2); if (isset($opt[0], $opt[1])) { $opt[0] = trim($opt[0]); $opt[1] = trim($opt[1]); switch ($opt[0]) { case 'audio': $audio = $opt[1]; break; case 'video': $video = $opt[1]; break; case 'alt': $alt = $opt[1]; break; case 'altclass': $altclass = $opt[1]; break; case 'loop': $loop = $opt[1]; break; case 'width': $width = $opt[1]; break; case 'height': $height = $opt[1]; break; case 'bgcolor': $bgcolor = $opt[1]; break; case 'mediaplayer': $mediaplayer = $opt[1]; break; case 'widescreen': $widescreen = $opt[1]; break; } } } } $mime = explode('/', (string) $type, 2); $mime = $mime[0]; // Process values for 'auto' if ($width === 'auto') { if ($mime === 'video') { if ($height === 'auto') { $width = 480;Changelog
One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$options retyped from array|string to untyped.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/SimplePie/src/Enclosure.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.