Skip to content

Commit 14a394f

Browse files
committed
move handling of Iframely options URL value from the cloud to WordPress itself
1 parent 9d33349 commit 14a394f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

app/Embed/Gutenberg.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ public static function run(): void
1515

1616
public static function init(): void
1717
{
18+
# Always extract &iframely={serialized options} that we append to URLs
19+
# and add these options into the oEmbed endpoint's query-string parameters
20+
add_filter('oembed_fetch_url', [self::class, 'maybe_add_iframely_url_options'], 20, 3);
21+
1822
if (!current_user_can('edit_posts')) {
1923
return;
2024
}
@@ -58,6 +62,29 @@ public static function maybe_add_gutenberg_1($provider, $url, $args)
5862
return $provider;
5963
}
6064

65+
public static function maybe_add_iframely_url_options($provider, $url, $args)
66+
{
67+
# Options are added to URL the URL in utils.js this way:
68+
# 'iframely=' + encodeURIComponent(window.btoa(JSON.stringify(query)));
69+
if (Utils::stringContains($provider, 'iframe.ly') && Utils::stringContains($url, 'iframely=')) {
70+
$parsed_url = parse_url($url);
71+
if (isset($parsed_url['query'])) {
72+
$params = array();
73+
parse_str($parsed_url['query'], $params);
74+
75+
if (isset($params['iframely'])) {
76+
$options_str = base64_decode(urldecode($params['iframely']));
77+
$options_query = json_decode($options_str);
78+
79+
foreach($options_query as $key => $value) {
80+
$provider = add_query_arg($key, $value, $provider);
81+
}
82+
}
83+
}
84+
}
85+
return $provider;
86+
}
87+
6188
public static function inject_events_proxy_to_gutenberg($html, $url, $args)
6289
{
6390
$html = str_replace('"//cdn.iframe.ly', '"https://cdn.iframe.ly', $html);

0 commit comments

Comments
 (0)