插件Smartideo 无法生效解决方法

1.在大约87行:array($this, ‘smartideo_embed_handler_bilibili’) ); 下面加入以下代码:

wp_embed_register_handler( 'smartvideo_bilibili_bv',
    '#https?://www\.bilibili\.com/video/BV(?:(?<video_id1>[a-z0-9_=\-]+)/(?:index_|\#page=)(?<video_id2>[a-z0-9_=\-]+)|(?<video_id>[a-z0-9_=\-]+))#i',
    array($this, 'smartvideo_embed_handler_bilibili_bv') 
);

2.在大约195行:return apply_filters( ’embed_bilibili’, $embed, $matches, $attr, $url, $rawattr );下面加入以下代码:

public function smartvideo_embed_handler_bilibili_bv( $matches, $attr, $url, $rawattr ) {
    $matches['video_id'] = ($matches['video_id1'] == '') ? $matches['video_id'] : $matches['video_id1'];
    $page = ($matches['video_id2'] > 1) ? $matches['video_id2'] : 1;
    $cid = '';
    $embed = $this->get_iframe("//player.bilibili.com/player.html?bvid={$matches['video_id']}&cid={$cid}&page={$page}", $url);
    return apply_filters( 'embed_bilibili', $embed, $matches, $attr, $url, $rawattr );
}

如果你的AV开头的链接也不能用了,就把以下代码也替换了:

public function smartideo_embed_handler_bilibili( $matches, $attr, $url, $rawattr ) {
    $matches['video_id'] = ($matches['video_id1'] == '') ? $matches['video_id'] : $matches['video_id1'];
    $page = ($matches['video_id2'] > 1) ? $matches['video_id2'] : 1;
    $cid = '';
    /*
    try{
        $request = new WP_Http();
        $url = "https://api.bilibili.com/view?type=jsonp&appkey=8e9fc618fbd41e28&id=" . $matches['video_id'];
        $data = (array)$request->request($url, array('timeout' => 3));
        $json = json_decode($data['body'], true);
        $cid = $json['cid'];
 
    }catch(Exception $e){}
    */
    if(wp_is_mobile() || $this->bilibili_pc_player == 1){
        $embed = $this->get_iframe("//player.bilibili.com/player.html?aid={$matches['video_id']}&cid={$cid}&page={$page}", $url);
    }else{
        $embed = $this->get_link($url);
    }
    return apply_filters( 'embed_bilibili', $embed, $matches, $attr, $url, $rawattr );
}

用下面代码替换:

public function smartideo_embed_handler_bilibili( $matches, $attr, $url, $rawattr ) {
    $matches['video_id'] = ($matches['video_id1'] == '') ? $matches['video_id'] : $matches['video_id1'];
    $page = ($matches['video_id2'] > 1) ? $matches['video_id2'] : 1;
    $cid = '';
        $embed = $this->get_iframe("//player.bilibili.com/player.html?aid={$matches['video_id']}&cid={$cid}&page={$page}", $url);
    return apply_filters( 'embed_bilibili', $embed, $matches, $attr, $url, $rawattr );
}

原文地址: https://course.51qux.com/1384.html

© 版权声明
THE END
喜欢就支持一下吧
点赞15
分享
评论 抢沙发
天若有情的头像 | 比优小窝

昵称

取消
昵称表情