Loading functions.php +37 −5 Changes for functions.php: 37 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -56,12 +56,44 @@ function fscoli_embed_umap($regex_matches, $embed_attrs, $url, $raw_embed_attrs) wp_embed_register_handler('umap', '#^https://umap.openstreetmap.de/[a-z]{2}/map/[^/]*#', 'fscoli_embed_umap'); /* * Add privacy protection for embed elements: You have to click a button before the * content is loaded. * Add privacy protection for embed elements: You have to click a button of a consent prompt * before the content is loaded. */ function fscoli_protect_embed_privacy($embed_html) { return $embed_html; // TODO Wrap this in the code that displays the button before loading anything function fscoli_show_embed_privacy_consent_prompt($embed_html) { // Extract this from the embed_html string with regular expressions and heuristics $width = null; // TODO $height = null; // TODO $provider_url = null; // TODO $provider_domain = null; // TODO $privacy_policy_url = null; // TODO /* * We use the heredoc syntax (https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc) * to embed a multiline string in this document. Heredocs can be delimited by any string - we chose HTML, but EOT and END * are more commonly used options. Funny enough, when we use HTML to delimit the heredoc, at least Visual Studio Code * applies HTML syntax highlighting to the string... */ $privacy_consent_prompt = <<<HTML <div class="privacy-consent-prompt-area" style="width: ${esc_attr(width)}; height: ${esc_attr(height)};"> <div class="unloaded-content"> ${esc_html($embed_html)} </div> <section class="privacy-consent-prompt"> <button onclick="givePrivacyConsent(this.parentElement)">Inhalt anzeigen</button> <p>Dabei werden Daten an <a href="${esc_url(provider_url)}">${esc_html(provider_domain)}</a> (und ggfs. weitere Anbieter) übertragen. Es gilt die <a href="${esc_url(privacy_policy_url)}">dort verlinkte Datenschutzerklärung</a>.</p> </section> </div> <script> function givePrivacyConsent(consentPromptArea) { consentPromptArea.outerHTML = consentPromptArea.querySelector(".unloaded-content").textContent } </script> HTML; return $privacy_consent_prompt; } add_filter('embed_handler_html', 'fscoli_protect_embed_privacy'); add_filter('embed_handler_html', 'fscoli_show_embed_privacy_consent_prompt'); ?> Loading
functions.php +37 −5 Changes for functions.php: 37 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -56,12 +56,44 @@ function fscoli_embed_umap($regex_matches, $embed_attrs, $url, $raw_embed_attrs) wp_embed_register_handler('umap', '#^https://umap.openstreetmap.de/[a-z]{2}/map/[^/]*#', 'fscoli_embed_umap'); /* * Add privacy protection for embed elements: You have to click a button before the * content is loaded. * Add privacy protection for embed elements: You have to click a button of a consent prompt * before the content is loaded. */ function fscoli_protect_embed_privacy($embed_html) { return $embed_html; // TODO Wrap this in the code that displays the button before loading anything function fscoli_show_embed_privacy_consent_prompt($embed_html) { // Extract this from the embed_html string with regular expressions and heuristics $width = null; // TODO $height = null; // TODO $provider_url = null; // TODO $provider_domain = null; // TODO $privacy_policy_url = null; // TODO /* * We use the heredoc syntax (https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc) * to embed a multiline string in this document. Heredocs can be delimited by any string - we chose HTML, but EOT and END * are more commonly used options. Funny enough, when we use HTML to delimit the heredoc, at least Visual Studio Code * applies HTML syntax highlighting to the string... */ $privacy_consent_prompt = <<<HTML <div class="privacy-consent-prompt-area" style="width: ${esc_attr(width)}; height: ${esc_attr(height)};"> <div class="unloaded-content"> ${esc_html($embed_html)} </div> <section class="privacy-consent-prompt"> <button onclick="givePrivacyConsent(this.parentElement)">Inhalt anzeigen</button> <p>Dabei werden Daten an <a href="${esc_url(provider_url)}">${esc_html(provider_domain)}</a> (und ggfs. weitere Anbieter) übertragen. Es gilt die <a href="${esc_url(privacy_policy_url)}">dort verlinkte Datenschutzerklärung</a>.</p> </section> </div> <script> function givePrivacyConsent(consentPromptArea) { consentPromptArea.outerHTML = consentPromptArea.querySelector(".unloaded-content").textContent } </script> HTML; return $privacy_consent_prompt; } add_filter('embed_handler_html', 'fscoli_protect_embed_privacy'); add_filter('embed_handler_html', 'fscoli_show_embed_privacy_consent_prompt'); ?>