wp_audio_shortcode

The timeline below displays how wordpress function wp_audio_shortcode has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.4

/**
 * Builds the Audio shortcode output.
 *
 * This implements the functionality of the Audio Shortcode for displaying
 * WordPress mp3s in a post.
 *
 * @since 3.6.0
 *
 * @param array  $attr {
 *     Attributes of the audio shortcode.
 *
 *     @type string $src      URL to the source of the audio file. Default empty.
 *     @type string $loop     The 'loop' attribute for the `<audio>` element. Default empty.
 *     @type string $autoplay The 'autoplay' attribute for the `<audio>` element. Default empty.
 *     @type string $preload  The 'preload' attribute for the `<audio>` element. Default 'none'.
 *     @type string $class    The 'class' attribute for the `<audio>` element. Default 'wp-audio-shortcode'.
 *     @type string $style    The 'style' attribute for the `<audio>` element. Default 'width: 100%;'.
 * }
 * @param string $content Shortcode content.
 * @return string|void HTML content to display audio.
 */
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' => '', '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');
    }
    /**
     * Filters the media library used for the audio shortcode.
     *
     * @since 3.6.0
     *
     * @param string $library Media library used for the audio shortcode.
     */
    $library = apply_filters('wp_audio_shortcode_library', 'mediaelement');
    if ('mediaelement' === $library && did_action('init')) {
        wp_enqueue_style('wp-mediaelement');
        wp_enqueue_script('wp-mediaelement');
    }
    /**
     * Filters the class attribute for the audio shortcode output container.
     *
     * @since 3.6.0
     * @since 4.9.0 The `$atts` parameter was added.
     *
     * @param string $class CSS class or list of space-separated classes.
     * @param array  $atts  Array of audio shortcode attributes.
     */
    $atts['class'] = apply_filters('wp_audio_shortcode_class', $atts['class'], $atts);
    $html_atts = array('class' => $atts['class'], 'id' => sprintf('audio-%d-%d', $post_id, $instance), 'loop' => wp_validate_boolean($atts['loop']), 'autoplay' => wp_validate_boolean($atts['autoplay']), 'preload' => $atts['preload'], 'style' => $atts['style']);
    // These ones should just be omitted altogether if they are blank.
    foreach (array('loop', 'autoplay', 'preload') as $a) {
        if (empty($html_atts[$a])) {
            unset($html_atts[$a]);
        }
    }
    $attr_strings = array();
    foreach ($html_atts as $k => $v) {
        $attr_strings[] = $k . '="' . esc_attr($v) . '"';
    }
    $html = '';
    if ('mediaelement' === $library && 1 === $instance) {
        $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
    }
    $html .= sprintf('<audio %s controls="controls">', implode(' ', $attr_strings));
    $fileurl = '';
    $source = '<source type="%s" src="%s" />';
    foreach ($default_types as $fallback) {
        if (!empty($atts[$fallback])) {
            if (empty($fileurl)) {
                $fileurl = $atts[$fallback];
            }
            $type = wp_check_filetype($atts[$fallback], wp_get_mime_types());
            $url = add_query_arg('_', $instance, $atts[$fallback]);
            $html .= sprintf($source, $type['type'], esc_url($url));
        }
    }
    if ('mediaelement' === $library) {
        $html .= wp_mediaelement_fallback($fileurl);
    }
    $html .= '</audio>';
    /**
     * Filters the audio shortcode output.
     *
     * @since 3.6.0
     *
     * @param string $html    Audio shortcode HTML output.
     * @param array  $atts    Array of audio shortcode attributes.
     * @param string $audio   Audio file.
     * @param int    $post_id Post ID.
     * @param string $library Media library used for the audio shortcode.
     */
    return apply_filters('wp_audio_shortcode', $html, $atts, $audio, $post_id, $library);
}

WordPress Version: 5.6

/**
 * Builds the Audio shortcode output.
 *
 * This implements the functionality of the Audio Shortcode for displaying
 * WordPress mp3s in a post.
 *
 * @since 3.6.0
 *
 * @param array  $attr {
 *     Attributes of the audio shortcode.
 *
 *     @type string $src      URL to the source of the audio file. Default empty.
 *     @type string $loop     The 'loop' attribute for the `<audio>` element. Default empty.
 *     @type string $autoplay The 'autoplay' attribute for the `<audio>` element. Default empty.
 *     @type string $preload  The 'preload' attribute for the `<audio>` element. Default 'none'.
 *     @type string $class    The 'class' attribute for the `<audio>` element. Default 'wp-audio-shortcode'.
 *     @type string $style    The 'style' attribute for the `<audio>` element. Default 'width: 100%;'.
 * }
 * @param string $content Shortcode content.
 * @return string|void HTML content to display audio.
 */
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 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' => '', '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');
    }
    /**
     * Filters the media library used for the audio shortcode.
     *
     * @since 3.6.0
     *
     * @param string $library Media library used for the audio shortcode.
     */
    $library = apply_filters('wp_audio_shortcode_library', 'mediaelement');
    if ('mediaelement' === $library && did_action('init')) {
        wp_enqueue_style('wp-mediaelement');
        wp_enqueue_script('wp-mediaelement');
    }
    /**
     * Filters the class attribute for the audio shortcode output container.
     *
     * @since 3.6.0
     * @since 4.9.0 The `$atts` parameter was added.
     *
     * @param string $class CSS class or list of space-separated classes.
     * @param array  $atts  Array of audio shortcode attributes.
     */
    $atts['class'] = apply_filters('wp_audio_shortcode_class', $atts['class'], $atts);
    $html_atts = array('class' => $atts['class'], 'id' => sprintf('audio-%d-%d', $post_id, $instance), 'loop' => wp_validate_boolean($atts['loop']), 'autoplay' => wp_validate_boolean($atts['autoplay']), 'preload' => $atts['preload'], 'style' => $atts['style']);
    // These ones should just be omitted altogether if they are blank.
    foreach (array('loop', 'autoplay', 'preload') as $a) {
        if (empty($html_atts[$a])) {
            unset($html_atts[$a]);
        }
    }
    $attr_strings = array();
    foreach ($html_atts as $k => $v) {
        $attr_strings[] = $k . '="' . esc_attr($v) . '"';
    }
    $html = '';
    if ('mediaelement' === $library && 1 === $instance) {
        $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
    }
    $html .= sprintf('<audio %s controls="controls">', implode(' ', $attr_strings));
    $fileurl = '';
    $source = '<source type="%s" src="%s" />';
    foreach ($default_types as $fallback) {
        if (!empty($atts[$fallback])) {
            if (empty($fileurl)) {
                $fileurl = $atts[$fallback];
            }
            $type = wp_check_filetype($atts[$fallback], wp_get_mime_types());
            $url = add_query_arg('_', $instance, $atts[$fallback]);
            $html .= sprintf($source, $type['type'], esc_url($url));
        }
    }
    if ('mediaelement' === $library) {
        $html .= wp_mediaelement_fallback($fileurl);
    }
    $html .= '</audio>';
    /**
     * Filters the audio shortcode output.
     *
     * @since 3.6.0
     *
     * @param string $html    Audio shortcode HTML output.
     * @param array  $atts    Array of audio shortcode attributes.
     * @param string $audio   Audio file.
     * @param int    $post_id Post ID.
     * @param string $library Media library used for the audio shortcode.
     */
    return apply_filters('wp_audio_shortcode', $html, $atts, $audio, $post_id, $library);
}

WordPress Version: 5.5

/**
 * Builds the Audio shortcode output.
 *
 * This implements the functionality of the Audio Shortcode for displaying
 * WordPress mp3s in a post.
 *
 * @since 3.6.0
 *
 * @param array  $attr {
 *     Attributes of the audio shortcode.
 *
 *     @type string $src      URL to the source of the audio file. Default empty.
 *     @type string $loop     The 'loop' attribute for the `<audio>` element. Default empty.
 *     @type string $autoplay The 'autoplay' attribute for the `<audio>` element. Default empty.
 *     @type string $preload  The 'preload' attribute for the `<audio>` element. Default 'none'.
 *     @type string $class    The 'class' attribute for the `<audio>` element. Default 'wp-audio-shortcode'.
 *     @type string $style    The 'style' attribute for the `<audio>` element. Default 'width: 100%;'.
 * }
 * @param string $content Shortcode content.
 * @return string|void HTML content to display audio.
 */
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 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' => '', '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');
    }
    /**
     * Filters the media library used for the audio shortcode.
     *
     * @since 3.6.0
     *
     * @param string $library Media library used for the audio shortcode.
     */
    $library = apply_filters('wp_audio_shortcode_library', 'mediaelement');
    if ('mediaelement' === $library && did_action('init')) {
        wp_enqueue_style('wp-mediaelement');
        wp_enqueue_script('wp-mediaelement');
    }
    /**
     * Filters the class attribute for the audio shortcode output container.
     *
     * @since 3.6.0
     * @since 4.9.0 The `$atts` parameter was added.
     *
     * @param string $class CSS class or list of space-separated classes.
     * @param array  $atts  Array of audio shortcode attributes.
     */
    $atts['class'] = apply_filters('wp_audio_shortcode_class', $atts['class'], $atts);
    $html_atts = array('class' => $atts['class'], 'id' => sprintf('audio-%d-%d', $post_id, $instance), 'loop' => wp_validate_boolean($atts['loop']), 'autoplay' => wp_validate_boolean($atts['autoplay']), 'preload' => $atts['preload'], 'style' => $atts['style']);
    // These ones should just be omitted altogether if they are blank.
    foreach (array('loop', 'autoplay', 'preload') as $a) {
        if (empty($html_atts[$a])) {
            unset($html_atts[$a]);
        }
    }
    $attr_strings = array();
    foreach ($html_atts as $k => $v) {
        $attr_strings[] = $k . '="' . esc_attr($v) . '"';
    }
    $html = '';
    if ('mediaelement' === $library && 1 === $instance) {
        $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
    }
    $html .= sprintf('<audio %s controls="controls">', join(' ', $attr_strings));
    $fileurl = '';
    $source = '<source type="%s" src="%s" />';
    foreach ($default_types as $fallback) {
        if (!empty($atts[$fallback])) {
            if (empty($fileurl)) {
                $fileurl = $atts[$fallback];
            }
            $type = wp_check_filetype($atts[$fallback], wp_get_mime_types());
            $url = add_query_arg('_', $instance, $atts[$fallback]);
            $html .= sprintf($source, $type['type'], esc_url($url));
        }
    }
    if ('mediaelement' === $library) {
        $html .= wp_mediaelement_fallback($fileurl);
    }
    $html .= '</audio>';
    /**
     * Filters the audio shortcode output.
     *
     * @since 3.6.0
     *
     * @param string $html    Audio shortcode HTML output.
     * @param array  $atts    Array of audio shortcode attributes.
     * @param string $audio   Audio file.
     * @param int    $post_id Post ID.
     * @param string $library Media library used for the audio shortcode.
     */
    return apply_filters('wp_audio_shortcode', $html, $atts, $audio, $post_id, $library);
}

WordPress Version: 5.4

/**
 * Builds the Audio shortcode output.
 *
 * This implements the functionality of the Audio Shortcode for displaying
 * WordPress mp3s in a post.
 *
 * @since 3.6.0
 *
 * @staticvar int $instance
 *
 * @param array  $attr {
 *     Attributes of the audio shortcode.
 *
 *     @type string $src      URL to the source of the audio file. Default empty.
 *     @type string $loop     The 'loop' attribute for the `<audio>` element. Default empty.
 *     @type string $autoplay The 'autoplay' attribute for the `<audio>` element. Default empty.
 *     @type string $preload  The 'preload' attribute for the `<audio>` element. Default 'none'.
 *     @type string $class    The 'class' attribute for the `<audio>` element. Default 'wp-audio-shortcode'.
 *     @type string $style    The 'style' attribute for the `<audio>` element. Default 'width: 100%;'.
 * }
 * @param string $content Shortcode content.
 * @return string|void HTML content to display audio.
 */
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 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' => '', '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');
    }
    /**
     * Filters the media library used for the audio shortcode.
     *
     * @since 3.6.0
     *
     * @param string $library Media library used for the audio shortcode.
     */
    $library = apply_filters('wp_audio_shortcode_library', 'mediaelement');
    if ('mediaelement' === $library && did_action('init')) {
        wp_enqueue_style('wp-mediaelement');
        wp_enqueue_script('wp-mediaelement');
    }
    /**
     * Filters the class attribute for the audio shortcode output container.
     *
     * @since 3.6.0
     * @since 4.9.0 The `$atts` parameter was added.
     *
     * @param string $class CSS class or list of space-separated classes.
     * @param array  $atts  Array of audio shortcode attributes.
     */
    $atts['class'] = apply_filters('wp_audio_shortcode_class', $atts['class'], $atts);
    $html_atts = array('class' => $atts['class'], 'id' => sprintf('audio-%d-%d', $post_id, $instance), 'loop' => wp_validate_boolean($atts['loop']), 'autoplay' => wp_validate_boolean($atts['autoplay']), 'preload' => $atts['preload'], 'style' => $atts['style']);
    // These ones should just be omitted altogether if they are blank.
    foreach (array('loop', 'autoplay', 'preload') as $a) {
        if (empty($html_atts[$a])) {
            unset($html_atts[$a]);
        }
    }
    $attr_strings = array();
    foreach ($html_atts as $k => $v) {
        $attr_strings[] = $k . '="' . esc_attr($v) . '"';
    }
    $html = '';
    if ('mediaelement' === $library && 1 === $instance) {
        $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
    }
    $html .= sprintf('<audio %s controls="controls">', join(' ', $attr_strings));
    $fileurl = '';
    $source = '<source type="%s" src="%s" />';
    foreach ($default_types as $fallback) {
        if (!empty($atts[$fallback])) {
            if (empty($fileurl)) {
                $fileurl = $atts[$fallback];
            }
            $type = wp_check_filetype($atts[$fallback], wp_get_mime_types());
            $url = add_query_arg('_', $instance, $atts[$fallback]);
            $html .= sprintf($source, $type['type'], esc_url($url));
        }
    }
    if ('mediaelement' === $library) {
        $html .= wp_mediaelement_fallback($fileurl);
    }
    $html .= '</audio>';
    /**
     * Filters the audio shortcode output.
     *
     * @since 3.6.0
     *
     * @param string $html    Audio shortcode HTML output.
     * @param array  $atts    Array of audio shortcode attributes.
     * @param string $audio   Audio file.
     * @param int    $post_id Post ID.
     * @param string $library Media library used for the audio shortcode.
     */
    return apply_filters('wp_audio_shortcode', $html, $atts, $audio, $post_id, $library);
}

WordPress Version: 5.3

/**
 * Builds the Audio shortcode output.
 *
 * This implements the functionality of the Audio Shortcode for displaying
 * WordPress mp3s in a post.
 *
 * @since 3.6.0
 *
 * @staticvar int $instance
 *
 * @param array  $attr {
 *     Attributes of the audio shortcode.
 *
 *     @type string $src      URL to the source of the audio file. Default empty.
 *     @type string $loop     The 'loop' attribute for the `<audio>` element. Default empty.
 *     @type string $autoplay The 'autoplay' attribute for the `<audio>` element. Default empty.
 *     @type string $preload  The 'preload' attribute for the `<audio>` element. Default 'none'.
 *     @type string $class    The 'class' attribute for the `<audio>` element. Default 'wp-audio-shortcode'.
 *     @type string $style    The 'style' attribute for the `<audio>` element. Default 'width: 100%;'.
 * }
 * @param string $content Shortcode content.
 * @return string|void HTML content to display audio.
 */
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 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' => '', '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');
    }
    /**
     * Filters the media library used for the audio shortcode.
     *
     * @since 3.6.0
     *
     * @param string $library Media library used for the audio shortcode.
     */
    $library = apply_filters('wp_audio_shortcode_library', 'mediaelement');
    if ('mediaelement' === $library && did_action('init')) {
        wp_enqueue_style('wp-mediaelement');
        wp_enqueue_script('wp-mediaelement');
    }
    /**
     * Filters the class attribute for the audio shortcode output container.
     *
     * @since 3.6.0
     * @since 4.9.0 The `$atts` parameter was added.
     *
     * @param string $class CSS class or list of space-separated classes.
     * @param array  $atts  Array of audio shortcode attributes.
     */
    $atts['class'] = apply_filters('wp_audio_shortcode_class', $atts['class'], $atts);
    $html_atts = array('class' => $atts['class'], 'id' => sprintf('audio-%d-%d', $post_id, $instance), 'loop' => wp_validate_boolean($atts['loop']), 'autoplay' => wp_validate_boolean($atts['autoplay']), 'preload' => $atts['preload'], 'style' => $atts['style']);
    // These ones should just be omitted altogether if they are blank
    foreach (array('loop', 'autoplay', 'preload') as $a) {
        if (empty($html_atts[$a])) {
            unset($html_atts[$a]);
        }
    }
    $attr_strings = array();
    foreach ($html_atts as $k => $v) {
        $attr_strings[] = $k . '="' . esc_attr($v) . '"';
    }
    $html = '';
    if ('mediaelement' === $library && 1 === $instance) {
        $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
    }
    $html .= sprintf('<audio %s controls="controls">', join(' ', $attr_strings));
    $fileurl = '';
    $source = '<source type="%s" src="%s" />';
    foreach ($default_types as $fallback) {
        if (!empty($atts[$fallback])) {
            if (empty($fileurl)) {
                $fileurl = $atts[$fallback];
            }
            $type = wp_check_filetype($atts[$fallback], wp_get_mime_types());
            $url = add_query_arg('_', $instance, $atts[$fallback]);
            $html .= sprintf($source, $type['type'], esc_url($url));
        }
    }
    if ('mediaelement' === $library) {
        $html .= wp_mediaelement_fallback($fileurl);
    }
    $html .= '</audio>';
    /**
     * Filters the audio shortcode output.
     *
     * @since 3.6.0
     *
     * @param string $html    Audio shortcode HTML output.
     * @param array  $atts    Array of audio shortcode attributes.
     * @param string $audio   Audio file.
     * @param int    $post_id Post ID.
     * @param string $library Media library used for the audio shortcode.
     */
    return apply_filters('wp_audio_shortcode', $html, $atts, $audio, $post_id, $library);
}

WordPress Version: 4.9

/**
 * Builds the Audio shortcode output.
 *
 * This implements the functionality of the Audio Shortcode for displaying
 * WordPress mp3s in a post.
 *
 * @since 3.6.0
 *
 * @staticvar int $instance
 *
 * @param array  $attr {
 *     Attributes of the audio shortcode.
 *
 *     @type string $src      URL to the source of the audio file. Default empty.
 *     @type string $loop     The 'loop' attribute for the `<audio>` element. Default empty.
 *     @type string $autoplay The 'autoplay' attribute for the `<audio>` element. Default empty.
 *     @type string $preload  The 'preload' attribute for the `<audio>` element. Default 'none'.
 *     @type string $class    The 'class' attribute for the `<audio>` element. Default 'wp-audio-shortcode'.
 *     @type string $style    The 'style' attribute for the `<audio>` element. Default 'width: 100%;'.
 * }
 * @param string $content Shortcode content.
 * @return string|void HTML content to display audio.
 */
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 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' => '', '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)) {
            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');
    }
    /**
     * Filters the media library used for the audio shortcode.
     *
     * @since 3.6.0
     *
     * @param string $library Media library used for the audio shortcode.
     */
    $library = apply_filters('wp_audio_shortcode_library', 'mediaelement');
    if ('mediaelement' === $library && did_action('init')) {
        wp_enqueue_style('wp-mediaelement');
        wp_enqueue_script('wp-mediaelement');
    }
    /**
     * Filters the class attribute for the audio shortcode output container.
     *
     * @since 3.6.0
     * @since 4.9.0 The `$atts` parameter was added.
     *
     * @param string $class CSS class or list of space-separated classes.
     * @param array  $atts  Array of audio shortcode attributes.
     */
    $atts['class'] = apply_filters('wp_audio_shortcode_class', $atts['class'], $atts);
    $html_atts = array('class' => $atts['class'], 'id' => sprintf('audio-%d-%d', $post_id, $instance), 'loop' => wp_validate_boolean($atts['loop']), 'autoplay' => wp_validate_boolean($atts['autoplay']), 'preload' => $atts['preload'], 'style' => $atts['style']);
    // These ones should just be omitted altogether if they are blank
    foreach (array('loop', 'autoplay', 'preload') as $a) {
        if (empty($html_atts[$a])) {
            unset($html_atts[$a]);
        }
    }
    $attr_strings = array();
    foreach ($html_atts as $k => $v) {
        $attr_strings[] = $k . '="' . esc_attr($v) . '"';
    }
    $html = '';
    if ('mediaelement' === $library && 1 === $instance) {
        $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
    }
    $html .= sprintf('<audio %s controls="controls">', join(' ', $attr_strings));
    $fileurl = '';
    $source = '<source type="%s" src="%s" />';
    foreach ($default_types as $fallback) {
        if (!empty($atts[$fallback])) {
            if (empty($fileurl)) {
                $fileurl = $atts[$fallback];
            }
            $type = wp_check_filetype($atts[$fallback], wp_get_mime_types());
            $url = add_query_arg('_', $instance, $atts[$fallback]);
            $html .= sprintf($source, $type['type'], esc_url($url));
        }
    }
    if ('mediaelement' === $library) {
        $html .= wp_mediaelement_fallback($fileurl);
    }
    $html .= '</audio>';
    /**
     * Filters the audio shortcode output.
     *
     * @since 3.6.0
     *
     * @param string $html    Audio shortcode HTML output.
     * @param array  $atts    Array of audio shortcode attributes.
     * @param string $audio   Audio file.
     * @param int    $post_id Post ID.
     * @param string $library Media library used for the audio shortcode.
     */
    return apply_filters('wp_audio_shortcode', $html, $atts, $audio, $post_id, $library);
}

WordPress Version: 4.6

/**
 * Builds the Audio shortcode output.
 *
 * This implements the functionality of the Audio Shortcode for displaying
 * WordPress mp3s in a post.
 *
 * @since 3.6.0
 *
 * @staticvar int $instance
 *
 * @param array  $attr {
 *     Attributes of the audio shortcode.
 *
 *     @type string $src      URL to the source of the audio file. Default empty.
 *     @type string $loop     The 'loop' attribute for the `<audio>` element. Default empty.
 *     @type string $autoplay The 'autoplay' attribute for the `<audio>` element. Default empty.
 *     @type string $preload  The 'preload' attribute for the `<audio>` element. Default 'none'.
 *     @type string $class    The 'class' attribute for the `<audio>` element. Default 'wp-audio-shortcode'.
 *     @type string $style    The 'style' attribute for the `<audio>` element. Default 'width: 100%;'.
 * }
 * @param string $content Shortcode content.
 * @return string|void HTML content to display audio.
 */
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 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' => '', '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)) {
            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');
    }
    /**
     * Filters the media library used for the audio shortcode.
     *
     * @since 3.6.0
     *
     * @param string $library Media library used for the audio shortcode.
     */
    $library = apply_filters('wp_audio_shortcode_library', 'mediaelement');
    if ('mediaelement' === $library && did_action('init')) {
        wp_enqueue_style('wp-mediaelement');
        wp_enqueue_script('wp-mediaelement');
    }
    /**
     * Filters the class attribute for the audio shortcode output container.
     *
     * @since 3.6.0
     *
     * @param string $class CSS class or list of space-separated classes.
     */
    $atts['class'] = apply_filters('wp_audio_shortcode_class', $atts['class']);
    $html_atts = array('class' => $atts['class'], 'id' => sprintf('audio-%d-%d', $post_id, $instance), 'loop' => wp_validate_boolean($atts['loop']), 'autoplay' => wp_validate_boolean($atts['autoplay']), 'preload' => $atts['preload'], 'style' => $atts['style']);
    // These ones should just be omitted altogether if they are blank
    foreach (array('loop', 'autoplay', 'preload') as $a) {
        if (empty($html_atts[$a])) {
            unset($html_atts[$a]);
        }
    }
    $attr_strings = array();
    foreach ($html_atts as $k => $v) {
        $attr_strings[] = $k . '="' . esc_attr($v) . '"';
    }
    $html = '';
    if ('mediaelement' === $library && 1 === $instance) {
        $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
    }
    $html .= sprintf('<audio %s controls="controls">', join(' ', $attr_strings));
    $fileurl = '';
    $source = '<source type="%s" src="%s" />';
    foreach ($default_types as $fallback) {
        if (!empty($atts[$fallback])) {
            if (empty($fileurl)) {
                $fileurl = $atts[$fallback];
            }
            $type = wp_check_filetype($atts[$fallback], wp_get_mime_types());
            $url = add_query_arg('_', $instance, $atts[$fallback]);
            $html .= sprintf($source, $type['type'], esc_url($url));
        }
    }
    if ('mediaelement' === $library) {
        $html .= wp_mediaelement_fallback($fileurl);
    }
    $html .= '</audio>';
    /**
     * Filters the audio shortcode output.
     *
     * @since 3.6.0
     *
     * @param string $html    Audio shortcode HTML output.
     * @param array  $atts    Array of audio shortcode attributes.
     * @param string $audio   Audio file.
     * @param int    $post_id Post ID.
     * @param string $library Media library used for the audio shortcode.
     */
    return apply_filters('wp_audio_shortcode', $html, $atts, $audio, $post_id, $library);
}

WordPress Version: 4.5

/**
 * Builds the Audio shortcode output.
 *
 * This implements the functionality of the Audio Shortcode for displaying
 * WordPress mp3s in a post.
 *
 * @since 3.6.0
 *
 * @staticvar int $instance
 *
 * @param array  $attr {
 *     Attributes of the audio shortcode.
 *
 *     @type string $src      URL to the source of the audio file. Default empty.
 *     @type string $loop     The 'loop' attribute for the `<audio>` element. Default empty.
 *     @type string $autoplay The 'autoplay' attribute for the `<audio>` element. Default empty.
 *     @type string $preload  The 'preload' attribute for the `<audio>` element. Default 'none'.
 *     @type string $class    The 'class' attribute for the `<audio>` element. Default 'wp-audio-shortcode'.
 *     @type string $style    The 'style' attribute for the `<audio>` element. Default 'width: 100%; visibility: hidden;'.
 * }
 * @param string $content Shortcode content.
 * @return string|void HTML content to display audio.
 */
function wp_audio_shortcode($attr, $content = '')
{
    $post_id = get_post() ? get_the_ID() : 0;
    static $instance = 0;
    $instance++;
    /**
     * Filter 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 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' => '', 'preload' => 'none', 'class' => 'wp-audio-shortcode', 'style' => 'width: 100%; visibility: hidden;');
    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)) {
            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');
    }
    /**
     * Filter the media library used for the audio shortcode.
     *
     * @since 3.6.0
     *
     * @param string $library Media library used for the audio shortcode.
     */
    $library = apply_filters('wp_audio_shortcode_library', 'mediaelement');
    if ('mediaelement' === $library && did_action('init')) {
        wp_enqueue_style('wp-mediaelement');
        wp_enqueue_script('wp-mediaelement');
    }
    /**
     * Filter the class attribute for the audio shortcode output container.
     *
     * @since 3.6.0
     *
     * @param string $class CSS class or list of space-separated classes.
     */
    $atts['class'] = apply_filters('wp_audio_shortcode_class', $atts['class']);
    $html_atts = array('class' => $atts['class'], 'id' => sprintf('audio-%d-%d', $post_id, $instance), 'loop' => wp_validate_boolean($atts['loop']), 'autoplay' => wp_validate_boolean($atts['autoplay']), 'preload' => $atts['preload'], 'style' => $atts['style']);
    // These ones should just be omitted altogether if they are blank
    foreach (array('loop', 'autoplay', 'preload') as $a) {
        if (empty($html_atts[$a])) {
            unset($html_atts[$a]);
        }
    }
    $attr_strings = array();
    foreach ($html_atts as $k => $v) {
        $attr_strings[] = $k . '="' . esc_attr($v) . '"';
    }
    $html = '';
    if ('mediaelement' === $library && 1 === $instance) {
        $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
    }
    $html .= sprintf('<audio %s controls="controls">', join(' ', $attr_strings));
    $fileurl = '';
    $source = '<source type="%s" src="%s" />';
    foreach ($default_types as $fallback) {
        if (!empty($atts[$fallback])) {
            if (empty($fileurl)) {
                $fileurl = $atts[$fallback];
            }
            $type = wp_check_filetype($atts[$fallback], wp_get_mime_types());
            $url = add_query_arg('_', $instance, $atts[$fallback]);
            $html .= sprintf($source, $type['type'], esc_url($url));
        }
    }
    if ('mediaelement' === $library) {
        $html .= wp_mediaelement_fallback($fileurl);
    }
    $html .= '</audio>';
    /**
     * Filter the audio shortcode output.
     *
     * @since 3.6.0
     *
     * @param string $html    Audio shortcode HTML output.
     * @param array  $atts    Array of audio shortcode attributes.
     * @param string $audio   Audio file.
     * @param int    $post_id Post ID.
     * @param string $library Media library used for the audio shortcode.
     */
    return apply_filters('wp_audio_shortcode', $html, $atts, $audio, $post_id, $library);
}

WordPress Version: 4.3

/**
 * Builds the Audio shortcode output.
 *
 * This implements the functionality of the Audio Shortcode for displaying
 * WordPress mp3s in a post.
 *
 * @since 3.6.0
 *
 * @staticvar int $instance
 *
 * @param array  $attr {
 *     Attributes of the audio shortcode.
 *
 *     @type string $src      URL to the source of the audio file. Default empty.
 *     @type string $loop     The 'loop' attribute for the `<audio>` element. Default empty.
 *     @type string $autoplay The 'autoplay' attribute for the `<audio>` element. Default empty.
 *     @type string $preload  The 'preload' attribute for the `<audio>` element. Default empty.
 *     @type string $class    The 'class' attribute for the `<audio>` element. Default 'wp-audio-shortcode'.
 *     @type string $style    The 'style' attribute for the `<audio>` element. Default 'width: 100%'.
 * }
 * @param string $content Shortcode content.
 * @return string|void HTML content to display audio.
 */
function wp_audio_shortcode($attr, $content = '')
{
    $post_id = get_post() ? get_the_ID() : 0;
    static $instance = 0;
    $instance++;
    /**
     * Filter 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 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' => '', 'preload' => 'none');
    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)) {
            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');
    }
    /**
     * Filter the media library used for the audio shortcode.
     *
     * @since 3.6.0
     *
     * @param string $library Media library used for the audio shortcode.
     */
    $library = apply_filters('wp_audio_shortcode_library', 'mediaelement');
    if ('mediaelement' === $library && did_action('init')) {
        wp_enqueue_style('wp-mediaelement');
        wp_enqueue_script('wp-mediaelement');
    }
    /**
     * Filter the class attribute for the audio shortcode output container.
     *
     * @since 3.6.0
     *
     * @param string $class CSS class or list of space-separated classes.
     */
    $html_atts = array('class' => apply_filters('wp_audio_shortcode_class', 'wp-audio-shortcode'), 'id' => sprintf('audio-%d-%d', $post_id, $instance), 'loop' => wp_validate_boolean($atts['loop']), 'autoplay' => wp_validate_boolean($atts['autoplay']), 'preload' => $atts['preload'], 'style' => 'width: 100%; visibility: hidden;');
    // These ones should just be omitted altogether if they are blank
    foreach (array('loop', 'autoplay', 'preload') as $a) {
        if (empty($html_atts[$a])) {
            unset($html_atts[$a]);
        }
    }
    $attr_strings = array();
    foreach ($html_atts as $k => $v) {
        $attr_strings[] = $k . '="' . esc_attr($v) . '"';
    }
    $html = '';
    if ('mediaelement' === $library && 1 === $instance) {
        $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
    }
    $html .= sprintf('<audio %s controls="controls">', join(' ', $attr_strings));
    $fileurl = '';
    $source = '<source type="%s" src="%s" />';
    foreach ($default_types as $fallback) {
        if (!empty($atts[$fallback])) {
            if (empty($fileurl)) {
                $fileurl = $atts[$fallback];
            }
            $type = wp_check_filetype($atts[$fallback], wp_get_mime_types());
            $url = add_query_arg('_', $instance, $atts[$fallback]);
            $html .= sprintf($source, $type['type'], esc_url($url));
        }
    }
    if ('mediaelement' === $library) {
        $html .= wp_mediaelement_fallback($fileurl);
    }
    $html .= '</audio>';
    /**
     * Filter the audio shortcode output.
     *
     * @since 3.6.0
     *
     * @param string $html    Audio shortcode HTML output.
     * @param array  $atts    Array of audio shortcode attributes.
     * @param string $audio   Audio file.
     * @param int    $post_id Post ID.
     * @param string $library Media library used for the audio shortcode.
     */
    return apply_filters('wp_audio_shortcode', $html, $atts, $audio, $post_id, $library);
}

WordPress Version: 4.2

/**
 * Builds the Audio shortcode output.
 *
 * This implements the functionality of the Audio Shortcode for displaying
 * WordPress mp3s in a post.
 *
 * @since 3.6.0
 *
 * @param array  $attr {
 *     Attributes of the audio shortcode.
 *
 *     @type string $src      URL to the source of the audio file. Default empty.
 *     @type string $loop     The 'loop' attribute for the `<audio>` element. Default empty.
 *     @type string $autoplay The 'autoplay' attribute for the `<audio>` element. Default empty.
 *     @type string $preload  The 'preload' attribute for the `<audio>` element. Default empty.
 *     @type string $class    The 'class' attribute for the `<audio>` element. Default 'wp-audio-shortcode'.
 *     @type string $id       The 'id' attribute for the `<audio>` element. Default 'audio-{$post_id}-{$instance}'.
 *     @type string $style    The 'style' attribute for the `<audio>` element. Default 'width: 100%'.
 * }
 * @param string $content Shortcode content.
 * @return string HTML content to display audio.
 */
function wp_audio_shortcode($attr, $content = '')
{
    $post_id = get_post() ? get_the_ID() : 0;
    static $instance = 0;
    $instance++;
    /**
     * Filter 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 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' => '', 'preload' => 'none');
    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)) {
            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');
    }
    /**
     * Filter the media library used for the audio shortcode.
     *
     * @since 3.6.0
     *
     * @param string $library Media library used for the audio shortcode.
     */
    $library = apply_filters('wp_audio_shortcode_library', 'mediaelement');
    if ('mediaelement' === $library && did_action('init')) {
        wp_enqueue_style('wp-mediaelement');
        wp_enqueue_script('wp-mediaelement');
    }
    /**
     * Filter the class attribute for the audio shortcode output container.
     *
     * @since 3.6.0
     *
     * @param string $class CSS class or list of space-separated classes.
     */
    $html_atts = array('class' => apply_filters('wp_audio_shortcode_class', 'wp-audio-shortcode'), 'id' => sprintf('audio-%d-%d', $post_id, $instance), 'loop' => wp_validate_boolean($atts['loop']), 'autoplay' => wp_validate_boolean($atts['autoplay']), 'preload' => $atts['preload'], 'style' => 'width: 100%; visibility: hidden;');
    // These ones should just be omitted altogether if they are blank
    foreach (array('loop', 'autoplay', 'preload') as $a) {
        if (empty($html_atts[$a])) {
            unset($html_atts[$a]);
        }
    }
    $attr_strings = array();
    foreach ($html_atts as $k => $v) {
        $attr_strings[] = $k . '="' . esc_attr($v) . '"';
    }
    $html = '';
    if ('mediaelement' === $library && 1 === $instance) {
        $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
    }
    $html .= sprintf('<audio %s controls="controls">', join(' ', $attr_strings));
    $fileurl = '';
    $source = '<source type="%s" src="%s" />';
    foreach ($default_types as $fallback) {
        if (!empty($atts[$fallback])) {
            if (empty($fileurl)) {
                $fileurl = $atts[$fallback];
            }
            $type = wp_check_filetype($atts[$fallback], wp_get_mime_types());
            $url = add_query_arg('_', $instance, $atts[$fallback]);
            $html .= sprintf($source, $type['type'], esc_url($url));
        }
    }
    if ('mediaelement' === $library) {
        $html .= wp_mediaelement_fallback($fileurl);
    }
    $html .= '</audio>';
    /**
     * Filter the audio shortcode output.
     *
     * @since 3.6.0
     *
     * @param string $html    Audio shortcode HTML output.
     * @param array  $atts    Array of audio shortcode attributes.
     * @param string $audio   Audio file.
     * @param int    $post_id Post ID.
     * @param string $library Media library used for the audio shortcode.
     */
    return apply_filters('wp_audio_shortcode', $html, $atts, $audio, $post_id, $library);
}

WordPress Version: 0.1

/**
 * The Audio shortcode.
 *
 * This implements the functionality of the Audio Shortcode for displaying
 * WordPress mp3s in a post.
 *
 * @since 3.6.0
 *
 * @param array $attr {
 *     Attributes of the audio shortcode.
 *
 *     @type string $src      URL to the source of the audio file. Default empty.
 *     @type string $loop     The 'loop' attribute for the `<audio>` element. Default empty.
 *     @type string $autoplay The 'autoplay' attribute for the `<audio>` element. Default empty.
 *     @type string $preload  The 'preload' attribute for the `<audio>` element. Default empty.
 *     @type string $class    The 'class' attribute for the `<audio>` element. Default 'wp-audio-shortcode'.
 *     @type string $id       The 'id' attribute for the `<audio>` element. Default 'audio-{$post_id}-{$instances}'.
 *     @type string $style    The 'style' attribute for the `<audio>` element. Default 'width: 100%'.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display audio.
 */
function wp_audio_shortcode($attr, $content = '')
{
    $post_id = get_post() ? get_the_ID() : 0;
    static $instances = 0;
    $instances++;
    /**
     * Filter 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 wp_audio_shortcode()
     * @param string $content   Shortcode content.
     * @param int    $instances Unique numeric ID of this audio shortcode instance.
     */
    $override = apply_filters('wp_audio_shortcode_override', '', $attr, $content, $instances);
    if ('' !== $override) {
        return $override;
    }
    $audio = null;
    $default_types = wp_get_audio_extensions();
    $defaults_atts = array('src' => '', 'loop' => '', 'autoplay' => '', 'preload' => 'none');
    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)) {
            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');
    }
    /**
     * Filter the media library used for the audio shortcode.
     *
     * @since 3.6.0
     *
     * @param string $library Media library used for the audio shortcode.
     */
    $library = apply_filters('wp_audio_shortcode_library', 'mediaelement');
    if ('mediaelement' === $library && did_action('init')) {
        wp_enqueue_style('wp-mediaelement');
        wp_enqueue_script('wp-mediaelement');
    }
    /**
     * Filter the class attribute for the audio shortcode output container.
     *
     * @since 3.6.0
     *
     * @param string $class CSS class or list of space-separated classes.
     */
    $html_atts = array('class' => apply_filters('wp_audio_shortcode_class', 'wp-audio-shortcode'), 'id' => sprintf('audio-%d-%d', $post_id, $instances), 'loop' => wp_validate_boolean($atts['loop']), 'autoplay' => wp_validate_boolean($atts['autoplay']), 'preload' => $atts['preload'], 'style' => 'width: 100%; visibility: hidden;');
    // These ones should just be omitted altogether if they are blank
    foreach (array('loop', 'autoplay', 'preload') as $a) {
        if (empty($html_atts[$a])) {
            unset($html_atts[$a]);
        }
    }
    $attr_strings = array();
    foreach ($html_atts as $k => $v) {
        $attr_strings[] = $k . '="' . esc_attr($v) . '"';
    }
    $html = '';
    if ('mediaelement' === $library && 1 === $instances) {
        $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
    }
    $html .= sprintf('<audio %s controls="controls">', join(' ', $attr_strings));
    $fileurl = '';
    $source = '<source type="%s" src="%s" />';
    foreach ($default_types as $fallback) {
        if (!empty($atts[$fallback])) {
            if (empty($fileurl)) {
                $fileurl = $atts[$fallback];
            }
            $type = wp_check_filetype($atts[$fallback], wp_get_mime_types());
            $url = add_query_arg('_', $instances, $atts[$fallback]);
            $html .= sprintf($source, $type['type'], esc_url($url));
        }
    }
    if ('mediaelement' === $library) {
        $html .= wp_mediaelement_fallback($fileurl);
    }
    $html .= '</audio>';
    /**
     * Filter the audio shortcode output.
     *
     * @since 3.6.0
     *
     * @param string $html    Audio shortcode HTML output.
     * @param array  $atts    Array of audio shortcode attributes.
     * @param string $audio   Audio file.
     * @param int    $post_id Post ID.
     * @param string $library Media library used for the audio shortcode.
     */
    return apply_filters('wp_audio_shortcode', $html, $atts, $audio, $post_id, $library);
}

WordPress Version: 4.0

/**
 * The Audio shortcode.
 *
 * This implements the functionality of the Audio Shortcode for displaying
 * WordPress mp3s in a post.
 *
 * @since 3.6.0
 *
 * @param array $attr {
 *     Attributes of the audio shortcode.
 *
 *     @type string $src      URL to the source of the audio file. Default empty.
 *     @type string $loop     The 'loop' attribute for the `<audio>` element. Default empty.
 *     @type string $autoplay The 'autoplay' attribute for the `<audio>` element. Default empty.
 *     @type string $preload  The 'preload' attribute for the `<audio>` element. Default empty.
 *     @type string $class    The 'class' attribute for the `<audio>` element. Default 'wp-audio-shortcode'.
 *     @type string $id       The 'id' attribute for the `<audio>` element. Default 'audio-{$post_id}-{$instances}'.
 *     @type string $style    The 'style' attribute for the `<audio>` element. Default 'width: 100%'.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display audio.
 */
function wp_audio_shortcode($attr, $content = '')
{
    $post_id = get_post() ? get_the_ID() : 0;
    static $instances = 0;
    $instances++;
    /**
     * Filter 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 wp_audio_shortcode()
     * @param string $content   Shortcode content.
     * @param int    $instances Unique numeric ID of this audio shortcode instance.
     */
    $override = apply_filters('wp_audio_shortcode_override', '', $attr, $content, $instances);
    if ('' !== $override) {
        return $override;
    }
    $audio = null;
    $default_types = wp_get_audio_extensions();
    $defaults_atts = array('src' => '', 'loop' => '', 'autoplay' => '', 'preload' => 'none');
    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)) {
            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');
    }
    /**
     * Filter the media library used for the audio shortcode.
     *
     * @since 3.6.0
     *
     * @param string $library Media library used for the audio shortcode.
     */
    $library = apply_filters('wp_audio_shortcode_library', 'mediaelement');
    if ('mediaelement' === $library && did_action('init')) {
        wp_enqueue_style('wp-mediaelement');
        wp_enqueue_script('wp-mediaelement');
    }
    /**
     * Filter the class attribute for the audio shortcode output container.
     *
     * @since 3.6.0
     *
     * @param string $class CSS class or list of space-separated classes.
     */
    $html_atts = array('class' => apply_filters('wp_audio_shortcode_class', 'wp-audio-shortcode'), 'id' => sprintf('audio-%d-%d', $post_id, $instances), 'loop' => $atts['loop'], 'autoplay' => $atts['autoplay'], 'preload' => $atts['preload'], 'style' => 'width: 100%; visibility: hidden;');
    // These ones should just be omitted altogether if they are blank
    foreach (array('loop', 'autoplay', 'preload') as $a) {
        if (empty($html_atts[$a])) {
            unset($html_atts[$a]);
        }
    }
    $attr_strings = array();
    foreach ($html_atts as $k => $v) {
        $attr_strings[] = $k . '="' . esc_attr($v) . '"';
    }
    $html = '';
    if ('mediaelement' === $library && 1 === $instances) {
        $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
    }
    $html .= sprintf('<audio %s controls="controls">', join(' ', $attr_strings));
    $fileurl = '';
    $source = '<source type="%s" src="%s" />';
    foreach ($default_types as $fallback) {
        if (!empty($atts[$fallback])) {
            if (empty($fileurl)) {
                $fileurl = $atts[$fallback];
            }
            $type = wp_check_filetype($atts[$fallback], wp_get_mime_types());
            $url = add_query_arg('_', $instances, $atts[$fallback]);
            $html .= sprintf($source, $type['type'], esc_url($url));
        }
    }
    if ('mediaelement' === $library) {
        $html .= wp_mediaelement_fallback($fileurl);
    }
    $html .= '</audio>';
    /**
     * Filter the audio shortcode output.
     *
     * @since 3.6.0
     *
     * @param string $html    Audio shortcode HTML output.
     * @param array  $atts    Array of audio shortcode attributes.
     * @param string $audio   Audio file.
     * @param int    $post_id Post ID.
     * @param string $library Media library used for the audio shortcode.
     */
    return apply_filters('wp_audio_shortcode', $html, $atts, $audio, $post_id, $library);
}

WordPress Version: 9.1

/**
 * The Audio shortcode.
 *
 * This implements the functionality of the Audio Shortcode for displaying
 * WordPress mp3s in a post.
 *
 * @since 3.6.0
 *
 * @param array $attr {
 *     Attributes of the audio shortcode.
 *
 *     @type string $src      URL to the source of the audio file. Default empty.
 *     @type string $loop     The 'loop' attribute for the `<audio>` element. Default empty.
 *     @type string $autoplay The 'autoplay' attribute for the `<audio>` element. Default empty.
 *     @type string $preload  The 'preload' attribute for the `<audio>` element. Default empty.
 *     @type string $class    The 'class' attribute for the `<audio>` element. Default 'wp-audio-shortcode'.
 *     @type string $id       The 'id' attribute for the `<audio>` element. Default 'audio-{$post_id}-{$instances}'.
 *     @type string $style    The 'style' attribute for the `<audio>` element. Default 'width: 100%'.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display audio.
 */
function wp_audio_shortcode($attr, $content = '')
{
    $post_id = get_post() ? get_the_ID() : 0;
    static $instances = 0;
    $instances++;
    /**
     * Filter 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 wp_audio_shortcode()
     * @param string $content   Shortcode content.
     * @param int    $instances Unique numeric ID of this audio shortcode instance.
     */
    $html = apply_filters('wp_audio_shortcode_override', '', $attr, $content, $instances);
    if ('' !== $html) {
        return $html;
    }
    $audio = null;
    $default_types = wp_get_audio_extensions();
    $defaults_atts = array('src' => '', 'loop' => '', 'autoplay' => '', 'preload' => 'none');
    foreach ($default_types as $type) {
        $defaults_atts[$type] = '';
    }
    $atts = shortcode_atts($defaults_atts, $attr, 'audio');
    extract($atts);
    $primary = false;
    if (!empty($src)) {
        $type = wp_check_filetype($src, wp_get_mime_types());
        if (!in_array(strtolower($type['ext']), $default_types)) {
            return sprintf('<a class="wp-embedded-audio" href="%s">%s</a>', esc_url($src), esc_html($src));
        }
        $primary = true;
        array_unshift($default_types, 'src');
    } else {
        foreach ($default_types as $ext) {
            if (!empty(${$ext})) {
                $type = wp_check_filetype(${$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);
        $src = wp_get_attachment_url($audio->ID);
        if (empty($src)) {
            return;
        }
        array_unshift($default_types, 'src');
    }
    /**
     * Filter the media library used for the audio shortcode.
     *
     * @since 3.6.0
     *
     * @param string $library Media library used for the audio shortcode.
     */
    $library = apply_filters('wp_audio_shortcode_library', 'mediaelement');
    if ('mediaelement' === $library && did_action('init')) {
        wp_enqueue_style('wp-mediaelement');
        wp_enqueue_script('wp-mediaelement');
    }
    /**
     * Filter the class attribute for the audio shortcode output container.
     *
     * @since 3.6.0
     *
     * @param string $class CSS class or list of space-separated classes.
     */
    $atts = array('class' => apply_filters('wp_audio_shortcode_class', 'wp-audio-shortcode'), 'id' => sprintf('audio-%d-%d', $post_id, $instances), 'loop' => $loop, 'autoplay' => $autoplay, 'preload' => $preload, 'style' => 'width: 100%; visibility: hidden;');
    // These ones should just be omitted altogether if they are blank
    foreach (array('loop', 'autoplay', 'preload') as $a) {
        if (empty($atts[$a])) {
            unset($atts[$a]);
        }
    }
    $attr_strings = array();
    foreach ($atts as $k => $v) {
        $attr_strings[] = $k . '="' . esc_attr($v) . '"';
    }
    $html = '';
    if ('mediaelement' === $library && 1 === $instances) {
        $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
    }
    $html .= sprintf('<audio %s controls="controls">', join(' ', $attr_strings));
    $fileurl = '';
    $source = '<source type="%s" src="%s" />';
    foreach ($default_types as $fallback) {
        if (!empty(${$fallback})) {
            if (empty($fileurl)) {
                $fileurl = ${$fallback};
            }
            $type = wp_check_filetype(${$fallback}, wp_get_mime_types());
            $url = add_query_arg('_', $instances, ${$fallback});
            $html .= sprintf($source, $type['type'], esc_url($url));
        }
    }
    if ('mediaelement' === $library) {
        $html .= wp_mediaelement_fallback($fileurl);
    }
    $html .= '</audio>';
    /**
     * Filter the audio shortcode output.
     *
     * @since 3.6.0
     *
     * @param string $html    Audio shortcode HTML output.
     * @param array  $atts    Array of audio shortcode attributes.
     * @param string $audio   Audio file.
     * @param int    $post_id Post ID.
     * @param string $library Media library used for the audio shortcode.
     */
    return apply_filters('wp_audio_shortcode', $html, $atts, $audio, $post_id, $library);
}

WordPress Version: 3.9

/**
 * The Audio shortcode.
 *
 * This implements the functionality of the Audio Shortcode for displaying
 * WordPress mp3s in a post.
 *
 * @since 3.6.0
 *
 * @param array $attr {
 *     Attributes of the audio shortcode.
 *
 *     @type string $src      URL to the source of the audio file. Default empty.
 *     @type string $loop     The 'loop' attribute for the `<audio>` element. Default empty.
 *     @type string $autoplay The 'autoplay' attribute for the `<audio>` element. Default empty.
 *     @type string $preload  The 'preload' attribute for the `<audio>` element. Default empty.
 *     @type string $class    The 'class' attribute for the `<audio>` element. Default 'wp-audio-shortcode'.
 *     @type string $id       The 'id' attribute for the `<audio>` element. Default 'audio-{$post_id}-{$instances}'.
 *     @type string $style    The 'style' attribute for the `<audio>` element. Default 'width: 100%'.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display audio.
 */
function wp_audio_shortcode($attr, $content = '')
{
    $post_id = get_post() ? get_the_ID() : 0;
    static $instances = 0;
    $instances++;
    /**
     * Filter 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 wp_audio_shortcode()
     * @param string $content   Shortcode content.
     * @param int    $instances Unique numeric ID of this audio shortcode instance.
     */
    $html = apply_filters('wp_audio_shortcode_override', '', $attr, $content, $instances);
    if ('' !== $html) {
        return $html;
    }
    $audio = null;
    $default_types = wp_get_audio_extensions();
    $defaults_atts = array('src' => '', 'loop' => '', 'autoplay' => '', 'preload' => 'none');
    foreach ($default_types as $type) {
        $defaults_atts[$type] = '';
    }
    $atts = shortcode_atts($defaults_atts, $attr, 'audio');
    extract($atts);
    $primary = false;
    if (!empty($src)) {
        $type = wp_check_filetype($src, wp_get_mime_types());
        if (!in_array(strtolower($type['ext']), $default_types)) {
            return sprintf('<a class="wp-embedded-audio" href="%s">%s</a>', esc_url($src), esc_html($src));
        }
        $primary = true;
        array_unshift($default_types, 'src');
    } else {
        foreach ($default_types as $ext) {
            if (!empty(${$ext})) {
                $type = wp_check_filetype(${$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);
        $src = wp_get_attachment_url($audio->ID);
        if (empty($src)) {
            return;
        }
        array_unshift($default_types, 'src');
    }
    /**
     * Filter the media library used for the audio shortcode.
     *
     * @since 3.6.0
     *
     * @param string $library Media library used for the audio shortcode.
     */
    $library = apply_filters('wp_audio_shortcode_library', 'mediaelement');
    if ('mediaelement' === $library && did_action('init')) {
        wp_enqueue_style('wp-mediaelement');
        wp_enqueue_script('wp-mediaelement');
    }
    /**
     * Filter the class attribute for the audio shortcode output container.
     *
     * @since 3.6.0
     *
     * @param string $class CSS class or list of space-separated classes.
     */
    $atts = array('class' => apply_filters('wp_audio_shortcode_class', 'wp-audio-shortcode'), 'id' => sprintf('audio-%d-%d', $post_id, $instances), 'loop' => $loop, 'autoplay' => $autoplay, 'preload' => $preload, 'style' => 'width: 100%');
    // These ones should just be omitted altogether if they are blank
    foreach (array('loop', 'autoplay', 'preload') as $a) {
        if (empty($atts[$a])) {
            unset($atts[$a]);
        }
    }
    $attr_strings = array();
    foreach ($atts as $k => $v) {
        $attr_strings[] = $k . '="' . esc_attr($v) . '"';
    }
    $html = '';
    if ('mediaelement' === $library && 1 === $instances) {
        $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
    }
    $html .= sprintf('<audio %s controls="controls">', join(' ', $attr_strings));
    $fileurl = '';
    $source = '<source type="%s" src="%s" />';
    foreach ($default_types as $fallback) {
        if (!empty(${$fallback})) {
            if (empty($fileurl)) {
                $fileurl = ${$fallback};
            }
            $type = wp_check_filetype(${$fallback}, wp_get_mime_types());
            $url = add_query_arg('_', $instances, ${$fallback});
            $html .= sprintf($source, $type['type'], esc_url($url));
        }
    }
    if ('mediaelement' === $library) {
        $html .= wp_mediaelement_fallback($fileurl);
    }
    $html .= '</audio>';
    /**
     * Filter the audio shortcode output.
     *
     * @since 3.6.0
     *
     * @param string $html    Audio shortcode HTML output.
     * @param array  $atts    Array of audio shortcode attributes.
     * @param string $audio   Audio file.
     * @param int    $post_id Post ID.
     * @param string $library Media library used for the audio shortcode.
     */
    return apply_filters('wp_audio_shortcode', $html, $atts, $audio, $post_id, $library);
}

WordPress Version: 3.7

/**
 * The Audio shortcode.
 *
 * This implements the functionality of the Audio Shortcode for displaying
 * WordPress mp3s in a post.
 *
 * @since 3.6.0
 *
 * @param array  $attr    Attributes of the shortcode.
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display audio.
 */
function wp_audio_shortcode($attr, $content = '')
{
    $post_id = get_post() ? get_the_ID() : 0;
    static $instances = 0;
    $instances++;
    /**
     * Override the default audio shortcode.
     *
     * @since 3.7.0
     *
     * @param null              Empty variable to be replaced with shortcode markup.
     * @param array  $attr      Attributes of the shortcode.
     * @param string $content   Shortcode content.
     * @param int    $instances Unique numeric ID of this audio shortcode instance.
     */
    $html = apply_filters('wp_audio_shortcode_override', '', $attr, $content, $instances);
    if ('' !== $html) {
        return $html;
    }
    $audio = null;
    $default_types = wp_get_audio_extensions();
    $defaults_atts = array('src' => '', 'loop' => '', 'autoplay' => '', 'preload' => 'none');
    foreach ($default_types as $type) {
        $defaults_atts[$type] = '';
    }
    $atts = shortcode_atts($defaults_atts, $attr, 'audio');
    extract($atts);
    $primary = false;
    if (!empty($src)) {
        $type = wp_check_filetype($src, wp_get_mime_types());
        if (!in_array(strtolower($type['ext']), $default_types)) {
            return sprintf('<a class="wp-embedded-audio" href="%s">%s</a>', esc_url($src), esc_html($src));
        }
        $primary = true;
        array_unshift($default_types, 'src');
    } else {
        foreach ($default_types as $ext) {
            if (!empty(${$ext})) {
                $type = wp_check_filetype(${$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);
        $src = wp_get_attachment_url($audio->ID);
        if (empty($src)) {
            return;
        }
        array_unshift($default_types, 'src');
    }
    $library = apply_filters('wp_audio_shortcode_library', 'mediaelement');
    if ('mediaelement' === $library && did_action('init')) {
        wp_enqueue_style('wp-mediaelement');
        wp_enqueue_script('wp-mediaelement');
    }
    $atts = array('class' => apply_filters('wp_audio_shortcode_class', 'wp-audio-shortcode'), 'id' => sprintf('audio-%d-%d', $post_id, $instances), 'loop' => $loop, 'autoplay' => $autoplay, 'preload' => $preload, 'style' => 'width: 100%');
    // These ones should just be omitted altogether if they are blank
    foreach (array('loop', 'autoplay', 'preload') as $a) {
        if (empty($atts[$a])) {
            unset($atts[$a]);
        }
    }
    $attr_strings = array();
    foreach ($atts as $k => $v) {
        $attr_strings[] = $k . '="' . esc_attr($v) . '"';
    }
    $html = '';
    if ('mediaelement' === $library && 1 === $instances) {
        $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
    }
    $html .= sprintf('<audio %s controls="controls">', join(' ', $attr_strings));
    $fileurl = '';
    $source = '<source type="%s" src="%s" />';
    foreach ($default_types as $fallback) {
        if (!empty(${$fallback})) {
            if (empty($fileurl)) {
                $fileurl = ${$fallback};
            }
            $type = wp_check_filetype(${$fallback}, wp_get_mime_types());
            $html .= sprintf($source, $type['type'], esc_url(${$fallback}));
        }
    }
    if ('mediaelement' === $library) {
        $html .= wp_mediaelement_fallback($fileurl);
    }
    $html .= '</audio>';
    return apply_filters('wp_audio_shortcode', $html, $atts, $audio, $post_id, $library);
}