# contact-forms/2.3.6/classes/Element/Captcha3.php

Contact Forms by Cimatti, version 2.3.6. 100 lines.

- Page: https://pluginprobe.com/plugins/contact-forms/2.3.6/code/classes/Element/Captcha3.php
- Raw: https://pluginprobe.com/plugins/contact-forms/2.3.6/raw/classes/Element/Captcha3.php
- Modified: 2026-08-21T08:39:40+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/contact-forms/2.3.6/code/classes/Element/Captcha3.php#L10-L20`.

```php
<?php
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped, WordPress.Security.EscapeOutput.HeredocOutputNotEscaped, PluginCheck.CodeAnalysis.Heredoc -- PFBC framework extension, HTML output is controlled
class AccuaForm_Element_Captcha3 extends Element {
	protected $privateKey = "";
	protected $publicKey = "";
	protected $captchaAction = "";
	protected $spamAction = "";
	protected $scoreThreshold = 0.5;

	/** Whether the badge stylesheet was already printed on this page. */
	protected static $badgeStylePrinted = false;

	public function __construct($label = "", $unused = null, ?array $properties = null) {
	  if ($properties === null && is_array($unused)) {
	    $properties = $unused;
	  }
		parent::__construct($label, "accua-forms-recaptcha3-response", $properties);
		$validator = new AccuaForm_Validation_Captcha3(__("Spam check failed. Please reload the page and retry.", 'contact-forms'));
		$validator->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 "<style>.grecaptcha-badge{visibility:hidden!important}</style>\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%' => '<a href="https://policies.google.com/privacy" target="_blank" rel="noopener noreferrer">'
					. esc_html__('Privacy Policy', 'contact-forms') . '</a>',
				'%TERMSLINK%' => '<a href="https://policies.google.com/terms" target="_blank" rel="noopener noreferrer">'
					. esc_html__('Terms of Service', 'contact-forms') . '</a>',
			)
		);
		return '<p class="accua-forms-recaptcha3-notice">' . $notice . '</p>' . "\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 <<<EOT
{$badge_style}<input type="hidden" name="accua-forms-recaptcha3-response" id="{$field_id}" class="accua_forms_recaptcha3_input" value="" />
{$badge_notice}<script type="text/javascript">
(window.accuaformRecaptcha3Queue = window.accuaformRecaptcha3Queue || []).push( $js_registration );
</script>
EOT;
	}
}

```
