wp_audio_shortcode( array $attr, string $content = '' ): string|void
- Since
- 3.6.0, 6.8.0
- Source
wp-includes/media.php:3396
Description
This implements the functionality of the Audio Shortcode for displaying WordPress mp3s in a post.
Compatibility
- WordPress
- since 6.8.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
$attrarray- Attributes of the audio shortcode.
$srcstringdefault: emptyURL to the source of the audio file.$loopstringdefault: emptyThe 'loop' attribute for the<audio>element.$autoplaystringdefault: emptyThe 'autoplay' attribute for the<audio>element.$mutedstringdefault: 'false'The 'muted' attribute for the<audio>element.$preloadstringdefault: 'none'The 'preload' attribute for the<audio>element.$classstringdefault: 'wp-audio-shortcode'The 'class' attribute for the<audio>element.$stylestringdefault: 'width: 100%;'The 'style' attribute for the<audio>element.
$contentstringoptional- Shortcode content.Default:
''
Return value
string|void- HTML content to display audio.
Performance profile
How much work a call to wp_audio_shortcode() 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
- Heavy
- Scaling
- Scales with input
- Instructions
- 20–175
- Plugin surface
- 4 hooks
- Called by
- 3
Reaches the database via get_post().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 301.
Third-party callbacks on 'wp_audio_shortcode_override', 'wp_audio_shortcode_library', 'wp_audio_shortcode_class' run inside this call, and their cost is not bounded by anything here.
3 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_post()called directly - hookthird-party callbacks
apply_filters()called directly
Further down the call graph this can also reach option, cache, serialize 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 · 60 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_audio_shortcode() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!get_post() && $override !== "" | 20 | get_post(), apply_filters() |
get_post() && $override !== "" | 23 | get_post(), get_the_ID(), apply_filters() |
!get_post() && $override === "" && empty($atts) && empty($audios) | 46–48 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), get_attached_media() |
get_post() && $override === "" && empty($atts) && empty($audios) | 49–51 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), get_attached_media() |
!get_post() && $override === "" && empty($atts) && !empty($audios) | 59–61 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), get_attached_media(), reset(), wp_get_attachment_url() |
get_post() && $override === "" && empty($atts) && !empty($audios) | 62–64 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), get_attached_media(), reset(), wp_get_attachment_url() |
!get_post() && $override === "" && !empty($atts) && $default_types && empty($audios) | 66–67 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), get_attached_media() |
!get_post() && $override === "" && !empty($atts) && !$default_types | 67–68 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), esc_url(), esc_html() |
get_post() && $override === "" && !empty($atts) && $default_types && empty($audios) | 69–70 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), get_attached_media() |
get_post() && $override === "" && !empty($atts) && !$default_types | 70–71 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), esc_url(), esc_html() |
!get_post() && $override === "" && $default_types && !empty($audios) | 79–80 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), get_attached_media(), reset(), wp_get_attachment_url() |
get_post() && $override === "" && $default_types && !empty($audios) | 82–83 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), get_attached_media(), reset(), wp_get_attachment_url() |
48 further outcomes, up to 175 instructions
!get_post() && $override === "" && empty($atts) && $library !== "mediaelement" | 110–115 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), apply_filters(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), apply_filters() |
get_post() && $override === "" && empty($atts) && $library !== "mediaelement" | 113–118 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), apply_filters(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), apply_filters() |
!get_post() && $override === "" && empty($atts) | 114–119 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), apply_filters(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), wp_mediaelement_fallback(), apply_filters() |
!get_post() && $override === "" && empty($atts) && !did_action() | 114–119 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), apply_filters(), did_action(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), apply_filters() |
get_post() && $override === "" && empty($atts) | 117–122 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), apply_filters(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), wp_mediaelement_fallback(), apply_filters() |
get_post() && $override === "" && empty($atts) && !did_action() | 117–122 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), apply_filters(), did_action(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), apply_filters() |
!get_post() && $override === "" && empty($atts) && $library === "mediaelement" && !did_action() | 118–123 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), apply_filters(), did_action(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), wp_mediaelement_fallback(), apply_filters() |
!get_post() && $override === "" && empty($atts) && did_action() | 120–125 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), apply_filters(), did_action(), wp_enqueue_style(), wp_enqueue_script(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), apply_filters() |
get_post() && $override === "" && empty($atts) && $library === "mediaelement" && !did_action() | 121–126 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), apply_filters(), did_action(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), wp_mediaelement_fallback(), apply_filters() |
get_post() && $override === "" && empty($atts) && did_action() | 123–128 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), apply_filters(), did_action(), wp_enqueue_style(), wp_enqueue_script(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), apply_filters() |
!get_post() && $override === "" && empty($atts) && $library === "mediaelement" && did_action() | 124–129 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), apply_filters(), did_action(), wp_enqueue_style(), wp_enqueue_script(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), wp_mediaelement_fallback(), apply_filters() |
get_post() && $override === "" && empty($atts) && $library === "mediaelement" && did_action() | 127–132 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), apply_filters(), did_action(), wp_enqueue_style(), wp_enqueue_script(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), wp_mediaelement_fallback(), apply_filters() |
!get_post() && $override === "" && !empty($atts) && $default_types && $library !== "mediaelement" | 130–134 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), apply_filters(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), apply_filters() |
get_post() && $override === "" && !empty($atts) && $default_types && $library !== "mediaelement" | 133–137 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), apply_filters(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), apply_filters() |
!get_post() && $override === "" && !empty($audios) && $library !== "mediaelement" | 134–139 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), get_attached_media(), reset(), wp_get_attachment_url(), array_unshift(), apply_filters(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), apply_filters() |
!get_post() && $override === "" && !empty($atts) && $default_types | 134–138 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), apply_filters(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), wp_mediaelement_fallback(), apply_filters() |
!get_post() && $override === "" && !empty($atts) && $default_types && !did_action() | 134–138 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), apply_filters(), did_action(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), apply_filters() |
get_post() && $override === "" && !empty($audios) && $library !== "mediaelement" | 137–142 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), get_attached_media(), reset(), wp_get_attachment_url(), array_unshift(), apply_filters(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), apply_filters() |
get_post() && $override === "" && !empty($atts) && $default_types | 137–141 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), apply_filters(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), wp_mediaelement_fallback(), apply_filters() |
get_post() && $override === "" && !empty($atts) && $default_types && !did_action() | 137–141 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), apply_filters(), did_action(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), apply_filters() |
!get_post() && $override === "" && !empty($audios) | 138–143 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), get_attached_media(), reset(), wp_get_attachment_url(), array_unshift(), apply_filters(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), wp_mediaelement_fallback(), apply_filters() |
!get_post() && $override === "" && !empty($audios) && !did_action() | 138–143 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), get_attached_media(), reset(), wp_get_attachment_url(), array_unshift(), apply_filters(), did_action(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), apply_filters() |
!get_post() && $override === "" && !empty($atts) && $default_types && $library === "mediaelement" && !did_action() | 138–142 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), apply_filters(), did_action(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), wp_mediaelement_fallback(), apply_filters() |
!get_post() && $override === "" && !empty($atts) && $default_types && did_action() | 140–144 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), apply_filters(), did_action(), wp_enqueue_style(), wp_enqueue_script(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), apply_filters() |
get_post() && $override === "" && !empty($audios) | 141–146 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), get_attached_media(), reset(), wp_get_attachment_url(), array_unshift(), apply_filters(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), wp_mediaelement_fallback(), apply_filters() |
get_post() && $override === "" && !empty($audios) && !did_action() | 141–146 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), get_attached_media(), reset(), wp_get_attachment_url(), array_unshift(), apply_filters(), did_action(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), apply_filters() |
get_post() && $override === "" && !empty($atts) && $default_types && $library === "mediaelement" && !did_action() | 141–145 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), apply_filters(), did_action(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), wp_mediaelement_fallback(), apply_filters() |
!get_post() && $override === "" && !empty($audios) && $library === "mediaelement" && !did_action() | 142–147 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), get_attached_media(), reset(), wp_get_attachment_url(), array_unshift(), apply_filters(), did_action(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), wp_mediaelement_fallback(), apply_filters() |
get_post() && $override === "" && !empty($atts) && $default_types && did_action() | 143–147 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), apply_filters(), did_action(), wp_enqueue_style(), wp_enqueue_script(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), apply_filters() |
!get_post() && $override === "" && !empty($audios) && did_action() | 144–149 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), get_attached_media(), reset(), wp_get_attachment_url(), array_unshift(), apply_filters(), did_action(), wp_enqueue_style(), wp_enqueue_script(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), apply_filters() |
!get_post() && $override === "" && !empty($atts) && $default_types && $library === "mediaelement" && did_action() | 144–148 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), apply_filters(), did_action(), wp_enqueue_style(), wp_enqueue_script(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), wp_mediaelement_fallback(), apply_filters() |
get_post() && $override === "" && !empty($audios) && $library === "mediaelement" && !did_action() | 145–150 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), get_attached_media(), reset(), wp_get_attachment_url(), array_unshift(), apply_filters(), did_action(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), wp_mediaelement_fallback(), apply_filters() |
get_post() && $override === "" && !empty($audios) && did_action() | 147–152 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), get_attached_media(), reset(), wp_get_attachment_url(), array_unshift(), apply_filters(), did_action(), wp_enqueue_style(), wp_enqueue_script(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), apply_filters() |
get_post() && $override === "" && !empty($atts) && $default_types && $library === "mediaelement" && did_action() | 147–151 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), apply_filters(), did_action(), wp_enqueue_style(), wp_enqueue_script(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), wp_mediaelement_fallback(), apply_filters() |
!get_post() && $override === "" && !empty($audios) && $library === "mediaelement" && did_action() | 148–153 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), get_attached_media(), reset(), wp_get_attachment_url(), array_unshift(), apply_filters(), did_action(), wp_enqueue_style(), wp_enqueue_script(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), wp_mediaelement_fallback(), apply_filters() |
get_post() && $override === "" && !empty($audios) && $library === "mediaelement" && did_action() | 151–156 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), get_attached_media(), reset(), wp_get_attachment_url(), array_unshift(), apply_filters(), did_action(), wp_enqueue_style(), wp_enqueue_script(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), wp_mediaelement_fallback(), apply_filters() |
!get_post() && $override === "" && !empty($atts) && $default_types && !empty($audios) && $library !== "mediaelement" | 154–158 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), get_attached_media(), reset(), wp_get_attachment_url(), array_unshift(), apply_filters(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), apply_filters() |
get_post() && $override === "" && !empty($atts) && $default_types && !empty($audios) && $library !== "mediaelement" | 157–161 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), get_attached_media(), reset(), wp_get_attachment_url(), array_unshift(), apply_filters(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), apply_filters() |
!get_post() && $override === "" && !empty($atts) && $default_types && !empty($audios) | 158–162 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), get_attached_media(), reset(), wp_get_attachment_url(), array_unshift(), apply_filters(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), wp_mediaelement_fallback(), apply_filters() |
!get_post() && $override === "" && !empty($atts) && $default_types && !empty($audios) && !did_action() | 158–162 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), get_attached_media(), reset(), wp_get_attachment_url(), array_unshift(), apply_filters(), did_action(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), apply_filters() |
get_post() && $override === "" && !empty($atts) && $default_types && !empty($audios) | 161–165 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), get_attached_media(), reset(), wp_get_attachment_url(), array_unshift(), apply_filters(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), wp_mediaelement_fallback(), apply_filters() |
get_post() && $override === "" && !empty($atts) && $default_types && !empty($audios) && !did_action() | 161–165 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), get_attached_media(), reset(), wp_get_attachment_url(), array_unshift(), apply_filters(), did_action(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), apply_filters() |
!get_post() && $override === "" && !empty($atts) && $default_types && !empty($audios) && $library === "mediaelement" && !did_action() | 162–166 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), get_attached_media(), reset(), wp_get_attachment_url(), array_unshift(), apply_filters(), did_action(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), wp_mediaelement_fallback(), apply_filters() |
!get_post() && $override === "" && !empty($atts) && $default_types && !empty($audios) && did_action() | 164–168 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), get_attached_media(), reset(), wp_get_attachment_url(), array_unshift(), apply_filters(), did_action(), wp_enqueue_style(), wp_enqueue_script(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), apply_filters() |
get_post() && $override === "" && !empty($atts) && $default_types && !empty($audios) && $library === "mediaelement" && !did_action() | 165–169 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), get_attached_media(), reset(), wp_get_attachment_url(), array_unshift(), apply_filters(), did_action(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), wp_mediaelement_fallback(), apply_filters() |
get_post() && $override === "" && !empty($atts) && $default_types && !empty($audios) && did_action() | 167–171 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), get_attached_media(), reset(), wp_get_attachment_url(), array_unshift(), apply_filters(), did_action(), wp_enqueue_style(), wp_enqueue_script(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), apply_filters() |
!get_post() && $override === "" && !empty($atts) && $default_types && !empty($audios) && $library === "mediaelement" && did_action() | 168–172 | get_post(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), get_attached_media(), reset(), wp_get_attachment_url(), array_unshift(), apply_filters(), did_action(), wp_enqueue_style(), wp_enqueue_script(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), wp_mediaelement_fallback(), apply_filters() |
get_post() && $override === "" && !empty($atts) && $default_types && !empty($audios) && $library === "mediaelement" && did_action() | 171–175 | get_post(), get_the_ID(), apply_filters(), wp_get_audio_extensions(), shortcode_atts(), wp_get_mime_types(), wp_check_filetype(), strtolower(), array_unshift(), get_attached_media(), reset(), wp_get_attachment_url(), array_unshift(), apply_filters(), did_action(), wp_enqueue_style(), wp_enqueue_script(), apply_filters(), wp_validate_boolean(), wp_validate_boolean(), wp_validate_boolean(), wp_mediaelement_fallback(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 300 | 20–174 | 30 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 301 | 20–175 | 30 | |
| 8.4 | 301 | 20–175 | 30 | 9 fewer instructions than PHP 8.3 |
| 8.3 | 310 | 20–182 | 30 | |
| 8.2 | 310 | 20–182 | 30 | |
| 8.1 | 310 | 20–182 | 30 | |
| 7.4 | 310 | 20–182 | 30 |
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 · 4
4 hooks fire while wp_audio_shortcode() runs, in this order:
- apply_filters( wp_audio_shortcode_override )filterline 3414 (+18 into the body)
Filters the default audio shortcode output.
- apply_filters( wp_audio_shortcode_library )filterline 3484 (+88 into the body)
Filters the media library used for the audio shortcode.
- apply_filters( wp_audio_shortcode_class )filterline 3500 (+104 into the body)
Filters the class attribute for the audio shortcode output container.
- apply_filters( wp_audio_shortcode )filterline 3570 (+174 into the body)
Filters the audio shortcode output.
Uses · 18
- get_post()Retrieves post data given a post ID or post object.
- get_the_ID()Retrieves the ID of the current item in the WordPress Loop.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_get_audio_extensions()Returns a filtered list of supported audio formats.
- shortcode_atts()Combines user attributes with known attributes and fill in defaults when needed.
- wp_check_filetype()Retrieves the file type from the file name.
- wp_get_mime_types()Retrieves the list of mime types and file extensions.
- esc_url()Checks and cleans a URL.
- esc_html()Escaping for HTML blocks.
- get_attached_media()Retrieves media attached to the passed post.
- wp_get_attachment_url()Retrieves the URL for an attachment.
- did_action()Retrieves the number of times an action has been fired during the current request.
Show all 18
- wp_enqueue_style()Enqueues a CSS stylesheet.
- wp_enqueue_script()Enqueues a script.
- wp_validate_boolean()Filters/validates a variable as a boolean.
- esc_attr()Escaping for HTML attributes.
- add_query_arg()Retrieves a modified URL query string.
- wp_mediaelement_fallback()Provides a No-JS Flash fallback as a last resort for audio / video.
Used by · 3
- WP_Widget_Media_Audio::render_media()Render the media on the frontend.
- edit_form_image_editor()Displays the image and editor in the post editor
- prepend_attachment()Wraps attachment in paragraph tag before content.
Source code
function wp_audio_shortcode( $attr, $content = '' ) { $post_id = get_post() ? get_the_ID() : 0; static $instance = 0; ++$instance; /** * Filters the default audio shortcode output. * * If the filtered output isn't empty, it will be used instead of generating the default audio template. * * @since 3.6.0 * * @param string $html Empty variable to be replaced with shortcode markup. * @param array $attr Attributes of the shortcode. See {@see wp_audio_shortcode()}. * @param string $content Shortcode content. * @param int $instance Unique numeric ID of this audio shortcode instance. */ $override = apply_filters( 'wp_audio_shortcode_override', '', $attr, $content, $instance ); if ( '' !== $override ) { return $override; } $audio = null; $default_types = wp_get_audio_extensions(); $defaults_atts = array( 'src' => '', 'loop' => '', 'autoplay' => '', 'muted' => 'false', 'preload' => 'none', 'class' => 'wp-audio-shortcode', 'style' => 'width: 100%;', ); foreach ( $default_types as $type ) { $defaults_atts[ $type ] = ''; } $atts = shortcode_atts( $defaults_atts, $attr, 'audio' ); $primary = false; if ( ! empty( $atts['src'] ) ) { $type = wp_check_filetype( $atts['src'], wp_get_mime_types() ); if ( ! in_array( strtolower( $type['ext'] ), $default_types, true ) ) { return sprintf( '<a class="wp-embedded-audio" href="%s">%s</a>', esc_url( $atts['src'] ), esc_html( $atts['src'] ) ); } $primary = true; array_unshift( $default_types, 'src' ); } else { foreach ( $default_types as $ext ) { if ( ! empty( $atts[ $ext ] ) ) { $type = wp_check_filetype( $atts[ $ext ], wp_get_mime_types() ); if ( strtolower( $type['ext'] ) === $ext ) { $primary = true; } } } } if ( ! $primary ) { $audios = get_attached_media( 'audio', $post_id ); if ( empty( $audios ) ) { return; } $audio = reset( $audios ); $atts['src'] = wp_get_attachment_url( $audio->ID ); if ( empty( $atts['src'] ) ) { return; } array_unshift( $default_types, 'src' ); }Changelog
Introduced in 3.6.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
string|void to string|null.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 6.9.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.