WP_Widget_Media_Video::render_media( array $instance )

Render the media on the frontend.


Description Description


Parameters Parameters

$instance

(array) (Required) Widget instance props.


Top ↑

Return Return

(void)


Top ↑

Source Source

File: wp-includes/widgets/class-wp-widget-media-video.php

	public function render_media( $instance ) {
		$instance = array_merge( wp_list_pluck( $this->get_instance_schema(), 'default' ), $instance );
		$attachment = null;

		if ( $this->is_attachment_with_mime_type( $instance['attachment_id'], $this->widget_options['mime_type'] ) ) {
			$attachment = get_post( $instance['attachment_id'] );
		}

		if ( $attachment ) {
			$src = wp_get_attachment_url( $attachment->ID );
		} else {

			// Manually add the loop query argument.
			$loop = $instance['loop'] ? '1' : '0';
			$src = empty( $instance['url'] ) ? $instance['url'] : add_query_arg( 'loop', $loop, $instance['url'] );
		}

		if ( empty( $src ) ) {
			return;
		}

		add_filter( 'wp_video_shortcode', array( $this, 'inject_video_max_width_style' ) );

		echo wp_video_shortcode(
			array_merge(
				$instance,
				compact( 'src' )
			),
			$instance['content']
		);

		remove_filter( 'wp_video_shortcode', array( $this, 'inject_video_max_width_style' ) );
	}

Top ↑

Changelog Changelog

Changelog
Version Description
4.8.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.