'widget-oceanwp-video video-widget', 'description' => esc_html__( 'Easily to display any type of video.', 'ocean-extra' ), 'customize_selective_refresh' => true, ) ); } /** * Front-end display of widget. * * @see WP_Widget::widget() * @since 1.0.0 * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget( $args, $instance ) { $title = isset( $instance['title'] ) ? apply_filters( 'widget_title', $instance['title'] ) : ''; $video_url = isset( $instance['video_url'] ) ? $instance['video_url'] : ''; $description = isset( $instance['video_description'] ) ? $instance['video_description'] : ''; // Before widget WP hook echo $args['before_widget']; // Show widget title if ( $title ) { echo $args['before_title'] . esc_html( $title ) . $args['after_title']; } // Show video if ( $video_url ) { echo '

'; echo wp_oembed_get( $video_url, array( 'width' => 270 ) ); echo '

'; } else { esc_html_e( 'You forgot to enter a video URL.', 'ocean-extra' ); } // Show video description if field isn't empty if ( $description ) { echo '
'. do_shortcode( $description ) .'
'; } // After widget WP hook echo $args['after_widget']; } /** * Sanitize widget form values as they are saved. * * @see WP_Widget::update() * @since 1.0.0 * * @param array $new_instance Values just sent to be saved. * @param array $old_instance Previously saved values from database. * * @return array Updated safe values to be saved. */ public function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = ! empty( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : ''; $instance['video_url'] = ! empty( $new_instance['video_url'] ) ? esc_url( $new_instance['video_url'] ) : ''; $instance['video_description'] = ! empty( $new_instance['video_description'] ) ? strip_tags( $new_instance['video_description'] ) : ''; return $instance; } /** * Back-end widget form. * * @see WP_Widget::form() * @since 1.0.0 * * @param array $instance Previously saved values from database. */ public function form( $instance ) { // Parse arguments $instance = wp_parse_args((array) $instance, array( 'title' => esc_attr__( 'Video', 'ocean-extra' ), 'video_url' => '', 'video_description' => '', ) ); ?>