wp_video_shortcode() – Builds the Video shortcode output.
You appear to be a bot. Output may be restricted
Description
Builds the Video shortcode output.
This implements the functionality of the Video Shortcode for displaying WordPress mp4s in a post.
Usage
$string|void = wp_video_shortcode( $attr, $content );
Parameters
- $attr
- ( array ) required – { Attributes of the shortcode.
- $src
- ( string ) required – URL to the source of the video file. Default empty.
- $height
- ( int ) required – Height of the video embed in pixels. Default 360.
- $width
- ( int ) required – Width of the video embed in pixels. Default $content_width or 640.
- $poster
- ( string ) required – The 'poster' attribute for the
<video>
element. Default empty. - $loop
- ( string ) required – The 'loop' attribute for the
<video>
element. Default empty. - $autoplay
- ( string ) required – The 'autoplay' attribute for the
<video>
element. Default empty. - $muted
- ( string ) required – The 'muted' attribute for the
<video>
element. Default false. - $preload
- ( string ) required – The 'preload' attribute for the
<video>
element. Default 'metadata'. - $class
- ( string ) required – The 'class' attribute for the
<video>
element. Default 'wp-video-shortcode'. } - $content
- ( string ) optional – Shortcode content.
Returns
string|void HTML content to display video.
Source
File name: wordpress/wp-includes/media.php
Lines:
1 to 100 of 241
function wp_video_shortcode( $attr, $content = '' ) { global $content_width; $post_id = get_post() ? get_the_ID() : 0; static $instance = 0; ++$instance; /** * Filters the default video shortcode output. * * If the filtered output isn't empty, it will be used instead of generating * the default video template. * * @since 3.6.0 * * @see wp_video_shortcode() * * @param string $html Empty variable to be replaced with shortcode markup. * @param array $attr Attributes of the shortcode. See {@see wp_video_shortcode()}. * @param string $content Video shortcode content. * @param int $instance Unique numeric ID of this video shortcode instance. */ $override = apply_filters( 'wp_video_shortcode_override', '', $attr, $content, $instance ); if ( '' !== $override ) { return $override; } $video = null; $default_types = wp_get_video_extensions(); $defaults_atts = array( 'src' => '', 'poster' => '', 'loop' => '', 'autoplay' => '', 'muted' => 'false', 'preload' => 'metadata', 'width' => 640, 'height' => 360, 'class' => 'wp-video-shortcode', ); foreach ( $default_types as $type ) { $defaults_atts[ $type ] = ''; } $atts = shortcode_atts( $defaults_atts, $attr, 'video' ); if ( is_admin() ) { // Shrink the video so it isn't huge in the admin. if ( $atts['width'] > $defaults_atts['width'] ) { $atts['height'] = round( ( $atts['height'] * $defaults_atts['width'] ) / $atts['width'] ); $atts['width'] = $defaults_atts['width']; } } else { // If the video is bigger than the theme. if ( ! empty( $content_width ) && $atts['width'] > $content_width ) { $atts['height'] = round( ( $atts['height'] * $content_width ) / $atts['width'] ); $atts['width'] = $content_width; } } $is_vimeo = false; $is_youtube = false; $yt_pattern = '#^https?://(?:www\.)?(?:youtube\.com/watch|youtu\.be/)#'; $vimeo_pattern = '#^https?://(.+\.)?vimeo\.com/.*#'; $primary = false; if ( ! empty( $atts['src'] ) ) { $is_vimeo = ( preg_match( $vimeo_pattern, $atts['src'] ) ); $is_youtube = ( preg_match( $yt_pattern, $atts['src'] ) ); if ( ! $is_youtube && ! $is_vimeo ) { $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-video" href="%s">%s</a>', esc_url( $atts['src'] ), esc_html( $atts['src'] ) ); } } if ( $is_vimeo ) { wp_enqueue_script( 'mediaelement-vimeo' ); } $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 ) { $videos = get_attached_media( 'video', $post_id );