=> sprintf( 'audio-%d-%d', $post_id, $instance ),
'loop' => wp_validate_boolean( $atts['loop'] ),
'autoplay' => wp_validate_boolean( $atts['autoplay'] ),
'muted' => wp_validate_boolean( $atts['muted'] ),
'preload' => $atts['preload'],
'style' => $atts['style'],
);
// These ones should just be omitted altogether if they are blank.
foreach ( array( 'loop', 'autoplay', 'preload', 'muted' ) as $a ) {
if ( empty( $html_atts[ $a ] ) ) {
unset( $html_atts[ $a ] );
}
}
$attr_strings = array();
foreach ( $html_atts as $attribute_name => $attribute_value ) {
if ( in_array( $attribute_name, array( 'loop', 'autoplay', 'muted' ), true ) && true === $attribute_value ) {
// Add boolean attributes without a value.
$attr_strings[] = esc_attr( $attribute_name );
} elseif ( 'preload' === $attribute_name && ! empty( $attribute_value ) ) {
// Handle the preload attribute with specific allowed values.
$allowed_preload_values = array( 'none', 'metadata', 'auto' );
if ( in_array( $attribute_value, $allowed_preload_values, true ) ) {
$attr_strings[] = sprintf( '%s="%s"', esc_attr( $attribute_name ), esc_attr( $attribute_value ) );
}
} else {
// For other attributes, include the value.
$attr_strings[] = sprintf( '%s="%s"', esc_attr( $attribute_name ), esc_attr( $attribute_value ) );
}
}
$html = '';
if ( 'mediaelement' === $library && 1 === $instance ) {
$html .= "\n";
}
$html .= sprintf( '';
/**
* 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 );
}
add_shortcode( 'audio', 'wp_audio_shortcode' );
/**
* Returns a filtered list of supported video formats.
*
* @since 3.6.0
*
* @return string[] List of supported video formats.
*/
function wp_get_video_extensions() {
/**
* Filters the list of supported video formats.
*
* @since 3.6.0
*
* @param string[] $extensions An array of supported video formats. Defaults are
* 'mp4', 'm4v', 'webm', 'ogv', 'flv'.
*/
return apply_filters( 'wp_video_extensions', array( 'mp4', 'm4v', 'webm', 'ogv', 'flv' ) );
}
/**
* Builds the Video shortcode output.
*
* This implements the functionality of the Video Shortcode for displaying
* WordPress mp4s in a post.
*
* @since 3.6.0
*
* @global int $content_width
*
* @param array $attr {
* Attributes of the shortcode.
*
* @type string $src URL to the source of the video file. Default empty.
* @type int $height Height of the video embed in pixels. Default 360.
* @type int $width Width of the video embed in pixels. Default $content_width or 640.
* @type string $poster The 'poster' attribute for the `