【发布时间】:2017-03-21 08:10:58
【问题描述】:
我找到了一个名为oEmbed Featured Image 的插件,它可以完成我想要的一切,除了输出最大尺寸。
插件的默认 YouTube 输出大小为 480x360。我需要能够使用至少 YouTube/Vimeo 的完整分辨率大小。
我想我可以从插件的第 68 行开始编辑函数。
这是我想出的:
public function oembed_dataparse( $return, $data, $url )
{
if ($yt = $data->provider_name == 'YouTube')
{
if(preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $data->thumbnail_url, $youtube_id))
$ytvideo_id = $youtube_id;
$max = get_headers($data->thumbnail_url);
if (substr($max[0], 9, 3) !== '404')
{
$data->thumbnail_url = 'http://img.youtube.com/vi/$ytvideo_id/maxresdefault.jpg';
}
}
if ($vm = $data->provider_name == 'Vimeo')
{
if (preg_match("/https?:\/\/(?:www\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|)(\d+)(?:$|\/|\?)/", $data->thumbnail_url, $vimeo_id))
$vmvideo_id = $vimeo_id[3];
$hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$vmvideo_id.php"));
$data->thumbnail_url = $hash[0]['thumbnail_large'];
}
if ( ! empty( $data->thumbnail_url ) && ! $this->_thumb_id ) {
//if ( in_array( @ $data->type, array( 'video' ) ) ) // Only set for video embeds
$this->set_thumb_by_url( $data->thumbnail_url, @ $data->title );
}
}
【问题讨论】:
标签: php wordpress youtube oembed