Я создал шорткод для получения видео с идентификатора канала, но он не работает без отключения проверки SSL. Я читал, что отключать проверку - не лучшая идея, поэтому есть ли лучший способ заставить ее работать, не отключая ее?
Вот мой код:
function latest_video_shortcode($atts = [], $content = null) {
$matches = [];
$output = '';
$res = '';
$atts = shortcode_atts(
array(
'id' => '',
'items' => '',
), $atts
);
if ($atts['id'] == "") {
$output = '';
} else {
if ($atts['items'] == "") {
$number = '3';
} else {
$number = $atts['items'];
}
$id = $atts['id'];
stream_context_set_default( [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
]);
$uploads = 'https://www.googleapis.com/youtube/v3/channels?part=contentDetails&key=KEY&id='. $id;
$data1 = json_decode(file_get_contents($uploads), true);
$uploads_object = $data1['items'][0]['contentDetails']['relatedPlaylists']['uploads'];
$url = 'https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId='.$uploads_object.'&key=KEY&maxResults='.$number;
$data2 = file_get_contents($url);
$characters = json_decode($data2, true);
for ($i = 0 ; $i < $number ; ++$i) {
$link = $characters['items'][$i]['snippet']['resourceId']['videoId'];
$img = $characters['items'][$i]['snippet']['thumbnails']['medium']['url'];
$title = $characters['items'][$i]['snippet']['title'];
$contenido = '<div class = "video">
<a target = "_blank" href = "https://thewikihow.com/video_'.$link.'">
<div class = "image">
<img src = "'.$img.'">
<div class = "vid"><i aria-hidden = "true" class = "fa fa-youtube-play"></i></div>
</div>
</a></div>';
$res .= $contenido;
}
$output = '<div id = "vid-feed">'.$res.'</div>';
}
return html_entity_decode($output);
}
add_shortcode('ytb_video', 'latest_video_shortcode');
А шорткод работает так:
[ytb_video id = "channelID" items = "4"]






Если вы отключите одноранговую проверку, вы станете уязвимыми для атак MITM. Взгляните на следующий пост и обсуждение. Обратите внимание на ссылку на пакет curl и способ ссылки на него: stackoverflow.com/a/28701786/9653083