Skip to content

Commit a3a6921

Browse files
authored
Merge pull request #96 from murdercode/twitter-fix
Twitter fix
2 parents b7f9791 + a2c8bb5 commit a3a6921

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/Shortcodes/TwitterShortcode.php

+10-5
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,18 @@ public function register($shortcode): string
2727

2828
private static function getOembed(string $url): ?string
2929
{
30-
curl_setopt_array($curl = curl_init(), [
31-
CURLOPT_URL => "https://publish.twitter.com/oembed?url=$url&omit_script=1",
32-
CURLOPT_RETURNTRANSFER => true,
33-
]);
30+
$curl = curl_init();
31+
curl_setopt($curl, CURLOPT_URL, 'https://publish.twitter.com/oembed?url='.urlencode($url).'&omit_script=1');
32+
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
3433
$response = curl_exec($curl);
3534
curl_close($curl);
3635

37-
return json_decode($response)->html ?? null;
36+
if ($response === false) {
37+
return null;
38+
}
39+
40+
$data = json_decode($response, true);
41+
42+
return $data['html'] ?? null;
3843
}
3944
}

0 commit comments

Comments
 (0)