'Display a responsive video by adding a link or embed code.', 'classname' => 'widget_alx_video') );;
}
/* Widget
/* ------------------------------------ */
public function widget($args, $instance) {
$before_widget = null;
$before_title = null;
$after_title = null;
$after_widget = null;
extract( $args );
$instance['title']?NULL:$instance['title']='';
$title = apply_filters('widget_title',$instance['title']);
$output = $before_widget."\n";
if($title)
$output .= $before_title.$title.$after_title;
ob_start();
// The widget
if ( !empty($instance['video_url']) ) {
// echo '
'; - We have a filter adding this to embed shortcode
global $wp_embed;
$video = $wp_embed->run_shortcode('[embed]'.$instance['video_url'].'[/embed]');
// echo '
';
}
elseif ( !empty($instance['video_embed_code']) ) {
echo '';
$video = wp_kses_post( $instance['video_embed_code'] );
echo '
';
} else {
$video = '';
}
echo $video;
$output .= ob_get_clean();
$output .= $after_widget."\n";
echo $output;
}
/* Widget update
/* ------------------------------------ */
public function update($new,$old) {
$instance = $old;
$instance['title'] = esc_attr($new['title']);
// Video
$instance['video_url'] = esc_url($new['video_url']);
$instance['video_embed_code'] = $new['video_embed_code'];
return $instance;
}
/* Widget form
/* ------------------------------------ */
public function form($instance) {
// Default widget settings
$defaults = array(
'title' => '',
// Video
'video_url' => '',
'video_embed_code' => '',
);
$instance = wp_parse_args( (array) $instance, $defaults );
?>