'Video',
'description'=>'Button description',
'icon_class'=>'fa fa-youtube-play',
'container'=>false,
'has_content'=>false,
'defaults'=>array(),
);
parent::__construct($id_base,$name,$options);
}
function init(){
$this->support('CssEditor');
}
function element($instance,$content=''){
$title=$link=$class=$remove_title=$remove_controls=$auto_play='';
extract( shortcode_atts( array(
'title' => '',
'link' => 'https://www.youtube.com/watch?v=pCQUMAD-Jao',
'size' => ( isset( $content_width ) ) ? $content_width : 500,
'class' => '',
'css' => '',
'auto_play' => '',
'remove_title' => '',
'remove_control' => ''
), $instance ) );
$this->addClass($class);
$video_w = ( isset( $content_width ) ) ? $content_width : 500;
$video_h = $video_w / 1.61; //1.61 golden ratio
global $wp_embed;
/**
* @var WP_Embed $wp_embed
*/
if (stripos($link, "youtube.com") !== "false" || stripos($link, "youtu.be") !== false)
{
$embed = $this->cookLink($link, $instance, $video_w, $video_h);
} else
{
$embed = $wp_embed->run_shortcode( '[embed width="' . $video_w . '"' . $video_h . ']' . $link . '[/embed]' );
}
//echo $embed;die;
$this->element_title($title);
$embed=sprintf('
%s
',$embed);
$this->element_content($embed);
}
function cookLink($link, $instance, $video_w, $video_h)
{
$remove_title = isset($instance['remove_title']) ? $instance['remove_title'] : "";
$remove_controls = isset($instance['remove_control']) ? $instance['remove_control'] : "";
$autoplay = isset($instance['auto_play']) ? $instance['auto_play'] : "";
$link = "https://www.youtube.com/embed/" . $this->getYTID($link);
$link .= "?rel=0&modestbranding=1";
if ($remove_title == "on")
{
$link .= "&showinfo=0";
} else
{
$link = str_replace("&showinfo=0", "", $link);
}
if ($remove_controls =="on")
{
$link.= "&controls=0";
} else
{
$link = str_replace("&controls=0", "", $link);
}
if ($autoplay == "on")
{
$link .= "&autoplay=1";
} else
{
$link = str_replace("&autoplay=1", "", $link);
}
return '';
}
function getYTID($link)
{
if (stripos("youtu.be", $link) !== false) {
$id = explode("/", $link);
if (count($id) > 0) {
return $id[0];
}
}
preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $link, $result);
// preg_match('/=[a-zA-Z0-9\\-\\_]*/', $link, $result);
return str_replace("=", "", $result[1]);
}
function form($instance,$content=''){
$instance=wp_parse_args($instance,array('title'=>'','link'=>'','class'=>'', 'remove_title'=>'', 'remove_control' => '', 'auto_play' => ''));
$title=esc_attr($instance['title']);
$video_link=esc_attr($instance['link']);
$class=esc_attr($instance['class']);
$remove_title = esc_attr($instance['remove_title']);
$remove_controls = esc_attr($instance['remove_control']);
$auto_play = esc_attr($instance['auto_play']);
?>
/>
/>
/>