我找到了一個名爲oEmbed Featured Image的插件,它除了輸出最大尺寸外,完全可以做到我想要的任何東西。oEmbed精選圖片(大縮略圖)
插件的默認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);
}
}
我認爲你不能使用插件。並嘗試使用緩存WordPress的默認設置。此代碼不適用於插件。 –