print_render_attribute_string( 'video-wrapper' ); ?>>
has_image_overlay() ) {
$this->add_render_attribute( 'image-overlay', 'class', 'elementor-custom-embed-image-overlay' );
if ( $settings['lightbox'] ) {
if ( 'hosted' === $settings['video_type'] ) {
$lightbox_url = $video_url;
} else {
$lightbox_url = Embed::get_embed_url( $video_url, $embed_params, $embed_options );
}
$lightbox_options = [
'type' => 'video',
'videoType' => $settings['video_type'],
'url' => $lightbox_url,
'modalOptions' => [
'id' => 'elementor-lightbox-' . $this->get_id(),
'entranceAnimation' => $settings['lightbox_content_animation'],
'entranceAnimation_tablet' => $settings['lightbox_content_animation_tablet'],
'entranceAnimation_mobile' => $settings['lightbox_content_animation_mobile'],
'videoAspectRatio' => $settings['aspect_ratio'],
],
];
if ( 'hosted' === $settings['video_type'] ) {
$lightbox_options['videoParams'] = $this->get_hosted_params();
}
$this->add_render_attribute( 'image-overlay', [
'data-elementor-open-lightbox' => 'yes',
'data-elementor-lightbox' => wp_json_encode( $lightbox_options ),
'data-e-action-hash' => Plugin::instance()->frontend->create_action_hash( 'lightbox', $lightbox_options ),
] );
if ( Plugin::$instance->editor->is_edit_mode() ) {
$this->add_render_attribute( 'image-overlay', [
'class' => 'elementor-clickable',
] );
}
} else {
// When there is an image URL but no ID, it means the overlay image is the placeholder. In this case, get the placeholder URL.
if ( empty( $settings['image_overlay']['id'] && ! empty( $settings['image_overlay']['url'] ) ) ) {
$image_url = $settings['image_overlay']['url'];
} else {
$image_url = Group_Control_Image_Size::get_attachment_image_src( $settings['image_overlay']['id'], 'image_overlay', $settings );
}
$this->add_render_attribute( 'image-overlay', 'style', 'background-image: url(' . $image_url . ');' );
}
?>
print_render_attribute_string( 'image-overlay' ); ?>>
'eicons',
'value' => 'eicon-play',
];
}
Icons_Manager::render_icon( $settings['play_icon'], [ 'aria-hidden' => 'true' ] );
?>
print_a11y_text( $settings['image_overlay'] ); ?>
get_settings_for_display();
if ( 'hosted' !== $settings['video_type'] ) {
$url = $settings[ $settings['video_type'] . '_url' ];
} else {
$url = $this->get_hosted_video_url();
}
echo esc_url( $url );
}
/**
* Get embed params.
*
* Retrieve video widget embed parameters.
*
* @since 1.5.0
* @access public
*
* @return array Video embed parameters.
*/
public function get_embed_params() {
$settings = $this->get_settings_for_display();
$params = [];
if ( $settings['autoplay'] && ! $this->has_image_overlay() ) {
$params['autoplay'] = '1';
if ( $settings['play_on_mobile'] ) {
$params['playsinline'] = '1';
}
}
$params_dictionary = [];
if ( 'youtube' === $settings['video_type'] ) {
$params_dictionary = [
'loop',
'controls',
'mute',
'rel',
'modestbranding',
];
if ( $settings['loop'] ) {
$video_properties = Embed::get_video_properties( $settings['youtube_url'] );
$params['playlist'] = $video_properties['video_id'];
}
$params['start'] = $settings['start'];
$params['end'] = $settings['end'];
$params['wmode'] = 'opaque';
} elseif ( 'vimeo' === $settings['video_type'] ) {
$params_dictionary = [
'loop',
'mute' => 'muted',
'vimeo_title' => 'title',
'vimeo_portrait' => 'portrait',
'vimeo_byline' => 'byline',
];
$params['color'] = str_replace( '#', '', $settings['color'] );
$params['autopause'] = '0';
if ( ! empty( $settings['yt_privacy'] ) ) {
$params['dnt'] = 'true';
}
} elseif ( 'dailymotion' === $settings['video_type'] ) {
$params_dictionary = [
'controls',
'mute',
'showinfo' => 'ui-start-screen-info',
'logo' => 'ui-logo',
];
$params['ui-highlight'] = str_replace( '#', '', $settings['color'] );
$params['start'] = $settings['start'];
$params['endscreen-enable'] = '0';
}
foreach ( $params_dictionary as $key => $param_name ) {
$setting_name = $param_name;
if ( is_string( $key ) ) {
$setting_name = $key;
}
$setting_value = $settings[ $setting_name ] ? '1' : '0';
$params[ $param_name ] = $setting_value;
}
return $params;
}
/**
* Whether the video widget has an overlay image or not.
*
* Used to determine whether an overlay image was set for the video.
*
* @since 1.0.0
* @access protected
*
* @return bool Whether an image overlay was set for the video.
*/
protected function has_image_overlay() {
$settings = $this->get_settings_for_display();
return ! empty( $settings['image_overlay']['url'] ) && 'yes' === $settings['show_image_overlay'];
}
/**
* @since 2.1.0
* @access private
*/
private function get_embed_options() {
$settings = $this->get_settings_for_display();
$embed_options = [];
if ( 'youtube' === $settings['video_type'] ) {
$embed_options['privacy'] = $settings['yt_privacy'];
} elseif ( 'vimeo' === $settings['video_type'] ) {
$embed_options['start'] = $settings['start'];
}
$embed_options['lazy_load'] = ! empty( $settings['lazy_load'] );
return $embed_options;
}
/**
* @since 2.1.0
* @access private
*/
private function get_hosted_params() {
$settings = $this->get_settings_for_display();
$video_params = [];
foreach ( [ 'autoplay', 'loop', 'controls' ] as $option_name ) {
if ( $settings[ $option_name ] ) {
$video_params[ $option_name ] = '';
}
}
if ( $settings['preload'] ) {
$video_params['preload'] = $settings['preload'];
}
if ( $settings['mute'] ) {
$video_params['muted'] = 'muted';
}
if ( $settings['play_on_mobile'] ) {
$video_params['playsinline'] = '';
}
if ( ! $settings['download_button'] ) {
$video_params['controlsList'] = 'nodownload';
}
if ( $settings['poster']['url'] ) {
$video_params['poster'] = $settings['poster']['url'];
}
return $video_params;
}
/**
* @param bool $from_media
*
* @return string
* @since 2.1.0
* @access private
*/
private function get_hosted_video_url() {
$settings = $this->get_settings_for_display();
if ( ! empty( $settings['insert_url'] ) ) {
$video_url = $settings['external_url']['url'];
} else {
$video_url = $settings['hosted_url']['url'];
}
if ( empty( $video_url ) ) {
return '';
}
if ( $settings['start'] || $settings['end'] ) {
$video_url .= '#t=';
}
if ( $settings['start'] ) {
$video_url .= $settings['start'];
}
if ( $settings['end'] ) {
$video_url .= ',' . $settings['end'];
}
return $video_url;
}
/**
*
* @since 2.1.0
* @access private
*/
private function render_hosted_video() {
$video_url = $this->get_hosted_video_url();
if ( empty( $video_url ) ) {
return;
}
$video_params = $this->get_hosted_params();
/* Sometimes the video url is base64, therefore we use `esc_attr` in `src`. */
?>