Migrating to 1.10.+ Custom Embed usage, regex issue with script tag
-
Hi, since after 1.9.2 there has been a lot of API- and other changes, I needed to migrate my template function to embedding google maps via script tag.
In my template I use my custom function as follows:$map_content = '<script src="https://maps.google.com/maps/api/js?v=3&callback=mapLibReadyHandler&key=APIKEY" async defer></script>';
echo custom_replace_content_with_overlay( $map_content );Following the Migration Guide at https://epiph.yt/en/embed-privacy/documentation/migration-to-version-1-10-0/ the function
custom_replace_content_with_overlay
looks like this now:function custom_replace_content_with_overlay($content) {
if (!class_exists('epiphyt\Embed_Privacy\data\Replacer')) {
return $content;
}
$wrapped_content = '<div class="embed-privacy google-maps">' . $content . '</div>';
$content = \epiphyt\Embed_Privacy\data\Replacer::replace_embeds($wrapped_content);
return $content;
}I did create a custom embed provider in wp-admin via embed privacy settings called Google Maps.
In the updated documentation it is explicitly discouraged to use just the url as a Regex pattern like before, so I tried to use/<script\s+src="https:\/\/maps.google.com\/maps\/api\/js\?[^"]+".*?><\/script>/
which positively matches my tag in the regexr web tool.But I was not able to get the overlay to show up this way. The script tag would always just be returned.
I did eventually get the overlay when I reverted back to the discouragedmaps.google.com\/maps\/api\/js
and added the script tag to the allowed tags via the filter:add_filter('embed_privacy_replacer_matcher_elements', function($allowed_tags, $provider) {
$allowed_tags[] = 'script';
return $allowed_tags;
}, 10, 2);I’m sure there are good reasons not to generally include the script tag, so I’d still like to use the more precise Regex.
Any idea what am I missing here?
- You must be logged in to reply to this topic.