'adapter-responsive-video', 'description' => __( 'Video from YouTube, Vimeo, and more.' , 'adapter-responsive-video' ), 'customize_selective_refresh' => true, ); parent::__construct( 'adapter_responsive_video' , __( 'Adapter Video' , 'adapter-responsive-video' ) , $options ); } /** * Output the widget form. * * @param array $instance Widget data. * @return void. */ public function form( $instance ) { $video_url = isset( $instance['video_url'] ) ? $instance['video_url'] : ''; ?>
get_raw_iframe_code( $video_url ); $instance['video_source'] = $this->get_iframe_attribute( $raw_iframe_code , 'src' ); $instance['aspect_ratio_class'] = $this->get_class_for_aspect_ratio( $raw_iframe_code ); $instance['video_url'] = esc_url( $video_url ); } return $instance; } /** * Echo the markup of the widget. * * @param array $args Widget display data. * @param array $instance Data for widget. * @return void. */ public function widget( $args, $instance ) { $video_source = isset( $instance['video_source'] ) ? $instance['video_source'] : ''; $aspect_ratio_class = isset( $instance['aspect_ratio_class'] ) ? $instance['aspect_ratio_class'] : ''; if ( $video_source ) { $bootstrap_responsive_video = $this->get_markup( $video_source , $aspect_ratio_class ); echo wp_kses_post( $args['before_widget'] ) . $bootstrap_responsive_video . wp_kses_post( $args['after_widget'] ); } } /** * Get the iframe code, in order to later output it on the widget. * * @param string $url To use in order to get the iframe markup. * @return false|string */ public function get_raw_iframe_code( $url ) { $raw_code = wp_oembed_get( esc_url( $url ) ); return $raw_code; } /** * * Get the full markup of a Bootstrap responsive video container * * @param string $src Value to output in src attribute. * @param string $class Value to output in class attribute. * @return string $video_container Full markup of a responsive video container. */ public function get_markup( $src, $class ) { $max_width = apply_filters( 'arv_video_max_width' , '580' ); return '