configure(array( 'privateKey' => $this->privateKey, 'captchaAction' => $this->captchaAction, 'spamAction' => $this->spamAction, 'scoreThreshold' => $this->scoreThreshold, )); $this->setValidation($validator); } /** * CSS that hides Google's floating badge, printed once per page. * * Only the 'hidden' choice needs CSS. 'bottomleft' is a badge parameter * Google itself understands (see recaptcha3.js), and api.js then mirrors * the strip so the logo sits against the left edge and the text slides * out of it. CSS cannot do that: the collapsed badge is the same 256px * strip with 186px of it pushed off screen, so moving the whole strip to * the left edge leaves the text half on screen instead of the logo. * * @param string $badge 'hidden' hides the badge, anything else prints nothing. * @return string */ protected function badgeStyle($badge) { if (self::$badgeStylePrinted || $badge !== 'hidden') { return ''; } self::$badgeStylePrinted = true; 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 ); // Site-wide setting, read at render time: element properties do not // survive Element::__sleep() on the encrypted-form round trip. The badge // travels to the JS loader too: placing it on the left is a parameter of // Google's own explicit render, not something CSS can do afterwards. $badge = function_exists('accua_forms_recaptcha3_badge') ? accua_forms_recaptcha3_badge() : 'bottomright'; $badge_style = $this->badgeStyle($badge); $badge_notice = ($badge === 'hidden') ? $this->badgeNotice() : ''; $js_registration = _accua_forms_json_encode(array( $this->attributes["id"], array('sitekey' => $this->publicKey, 'action' => $this->captchaAction, 'badge' => $badge), $this->form->getLanguage(), )); $field_id = htmlspecialchars($this->attributes["id"], ENT_QUOTES); echo <<