__('Privacy settings', 'adghost-lite')], $atts, 'adghost_privacy_settings'); return self::link((string) $atts['text']); } public static function link($text) { if (self::is_amp()) { return ''; } self::$link_used = true; return '' . esc_html($text) . ''; } public static function footer() { if (is_admin() || self::is_amp()) { return; } if (get_option('adghost_privacy_link', false)) { echo '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- link() escapes its text. } if (self::$link_used) { wp_print_inline_script_tag(self::link_script()); } if (self::checking()) { wp_print_inline_script_tag(self::check_script()); } } public static function link_script() { return "(function(w,d){w.googlefc=w.googlefc||{};var q=w.googlefc.callbackQueue=w.googlefc.callbackQueue||[];" . "q.push({CONSENT_API_READY:function(){[].forEach.call(d.querySelectorAll('.adghost-privacy-settings'),function(a){a.hidden=false;});}});" . "d.addEventListener('click',function(e){var a=e.target.closest&&e.target.closest('.adghost-privacy-settings');if(!a)return;e.preventDefault();" . "w.googlefc.callbackQueue.push({CONSENT_DATA_READY:function(){w.googlefc.showRevocationMessage();}});});})(window,document);"; } public static function checking() { return isset($_GET['adghost_consent_check']) && current_user_can('manage_options'); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read only, shown only to an administrator. } public static function check_script() { $why = class_exists('AdGhost_Targeting') ? AdGhost_Targeting::page_exclusion_reason() : null; $text = [ 'google' => __('Google\'s consent message (Privacy & messaging) is on this page.', 'adghost-lite'), 'tcf' => __('A consent platform answers on this page (IAB TCF), not Google\'s own message.', 'adghost-lite'), 'none' => __('No consent platform answered on this page. Google shows its message only in the regions you chose for it: if you are outside them, check from a visitor\'s region or with a VPN.', 'adghost-lite'), 'off' => $why === null ? '' : sprintf( /* translators: %s: why ads are off on this page. */ __('Ads are off on this page for you (%s), so Google\'s message cannot load here. Open the site in a private window to check.', 'adghost-lite'), $why ), 'title' => __('AdGhost consent check', 'adghost-lite'), 'waiting' => __('Waiting for a consent platform…', 'adghost-lite'), ]; return '(function(w,d,t){var b=d.createElement("div");b.setAttribute("role","status");' . 'b.style.cssText="position:fixed;z-index:2147483647;left:16px;bottom:16px;max-width:360px;padding:12px 14px;background:#fff;color:#1d2327;border:1px solid #c3c4c7;border-left:4px solid #2271b1;box-shadow:0 2px 8px rgba(0,0,0,.15);font:14px/1.5 sans-serif";' . 'function say(k,c){b.innerHTML="";var s=d.createElement("strong");s.textContent=t.title;var p=d.createElement("p");p.style.margin="4px 0 0";p.textContent=t[k];b.appendChild(s);b.appendChild(p);if(c)b.style.borderLeftColor=c;}' . 'd.body.appendChild(b);if(t.off){say("off","#dba617");return;}say("waiting");var done=false;' . 'w.googlefc=w.googlefc||{};w.googlefc.callbackQueue=w.googlefc.callbackQueue||[];' . 'w.googlefc.callbackQueue.push({CONSENT_API_READY:function(){if(!done){done=true;say("google","#00a32a");}}});' . 'setTimeout(function(){if(done)return;done=true;say(typeof w.__tcfapi==="function"?"tcf":"none",typeof w.__tcfapi==="function"?"#2271b1":"#d63638");},10000);' . '})(window,document,' . wp_json_encode($text) . ');'; } private static function is_amp() { return class_exists('AdGhost_AMP') && AdGhost_AMP::is_amp(); } }