configure(array( 'privateKey' => $this->privateKey, 'captchaAction' => $this->captchaAction, 'spamAction' => $this->spamAction, 'scoreThreshold' => $this->scoreThreshold, )); $this->setValidation($validator); } /** * CSS that repositions or hides Google's floating badge, printed once per * page. The badge is injected into by api.js with inline styles, so * every rule needs !important; on the left it keeps the collapse/expand * behaviour by animating a transform instead of Google's own `right`. * * @param string $badge 'bottomleft' or 'hidden' ('bottomright' prints nothing). * @return string */ protected function badgeStyle($badge) { if (self::$badgeStylePrinted || ($badge !== 'bottomleft' && $badge !== 'hidden')) { return ''; } self::$badgeStylePrinted = true; if ($badge === 'hidden') { $css = '.grecaptcha-badge{visibility:hidden!important}'; } else { $css = '.grecaptcha-badge{left:4px!important;right:auto!important;' . 'transform:translateX(-186px)!important;transition:transform .3s ease!important}' . '.grecaptcha-badge:hover,.grecaptcha-badge:focus-within{transform:translateX(0)!important}'; } return "\n"; } /** * The reCAPTCHA notice Google requires when the badge is hidden. * * @return string */ protected function badgeNotice() { $notice = strtr( // translators: %PRIVACYLINK% and %TERMSLINK% are links to Google's Privacy Policy and Terms of Service __('This site is protected by reCAPTCHA and the Google %PRIVACYLINK% and %TERMSLINK% apply.', 'contact-forms'), array( '%PRIVACYLINK%' => '' . esc_html__('Privacy Policy', 'contact-forms') . '', '%TERMSLINK%' => '' . esc_html__('Terms of Service', 'contact-forms') . '', ) ); return '

' . $notice . '

' . "\n"; } public function render() { wp_enqueue_script( 'accua-forms-recaptcha3', ACCUA_FORMS_DIR_URL . 'assets/js/frontend/recaptcha3.js', array('jquery'), ACCUA_FORMS_JS_VERSION, true ); $js_registration = _accua_forms_json_encode(array( $this->attributes["id"], array('sitekey' => $this->publicKey, 'action' => $this->captchaAction), $this->form->getLanguage(), )); $field_id = htmlspecialchars($this->attributes["id"], ENT_QUOTES); // Site-wide setting, read at render time: element properties do not // survive Element::__sleep() on the encrypted-form round trip. $badge = function_exists('accua_forms_recaptcha3_badge') ? accua_forms_recaptcha3_badge() : 'bottomright'; $badge_style = $this->badgeStyle($badge); $badge_notice = ($badge === 'hidden') ? $this->badgeNotice() : ''; echo << {$badge_notice} EOT; } }