# contact-forms/trunk/classes/Element/Cap.php

Contact Forms by Cimatti, version trunk. 77 lines.

- Page: https://pluginprobe.com/plugins/contact-forms/trunk/code/classes/Element/Cap.php
- Raw: https://pluginprobe.com/plugins/contact-forms/trunk/raw/classes/Element/Cap.php
- Modified: 2026-08-05T09:37:24+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/trunk/code/classes/Element/Cap.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_Cap extends Element {
	protected $instanceUrl = "";
	protected $siteKey = "";
	protected $secretKey = "";

	public function __construct($label = "", $unused = null, ?array $properties = null) {
	  if ($properties === null && is_array($unused)) {
	    $properties = $unused;
	  }
		parent::__construct($label, "accua-forms-cap-response", $properties);
		$validator = new AccuaForm_Validation_Cap(__("Captcha verification failed. Please retry.", 'contact-forms'));
		$validator->configure(array('instanceUrl' => $this->instanceUrl, 'siteKey' => $this->siteKey, 'secretKey' => $this->secretKey));
		$this->setValidation($validator);
	}

	public function render() {
    wp_enqueue_script(
      'accua-forms-cap',
      ACCUA_FORMS_DIR_URL . 'assets/js/frontend/cap.js',
      array('jquery'),
      ACCUA_FORMS_JS_VERSION,
      true
    );

    $instance_url = trailingslashit($this->instanceUrl);

    /**
     * Filter the URL the Cap widget script is loaded from.
     *
     * Defaults to the assets server of the configured Cap Standalone instance
     * (requires ENABLE_ASSETS_SERVER=true on the instance).
     *
     * @param string $widget_url   URL of the cap-widget script.
     * @param string $instance_url The configured Cap instance URL.
     */
    $widget_url = apply_filters('accua_forms_cap_widget_url', $instance_url . 'assets/widget.js', $this->instanceUrl);

    /**
     * Filter the URL of the WASM solver loaded by the Cap widget.
     *
     * @param string $wasm_url     URL of the Cap WASM binary.
     * @param string $instance_url The configured Cap instance URL.
     */
    $wasm_url = apply_filters('accua_forms_cap_wasm_url', $instance_url . 'assets/cap_wasm_bg.wasm', $this->instanceUrl);

    $js_registration = _accua_forms_json_encode(array(
      $this->attributes["id"],
      array(
        'endpoint'  => $instance_url . rawurlencode($this->siteKey) . '/',
        'widgetUrl' => $widget_url,
        'wasmUrl'   => $wasm_url,
        'i18n'      => array(
          /* translators: Label shown on the Cap captcha widget before verification */
          'initial-state'   => __("I'm a human", 'contact-forms'),
          /* translators: Label shown on the Cap captcha widget while verifying */
          'verifying-label' => __('Verifying…', 'contact-forms'),
          /* translators: Label shown on the Cap captcha widget after verification */
          'solved-label'    => __('Verified', 'contact-forms'),
          /* translators: Label shown on the Cap captcha widget on error */
          'error-label'     => __('Verification failed. Try again.', 'contact-forms'),
        ),
      ),
      $this->form ? $this->form->getLanguage() : '',
    ));
    $field_id = htmlspecialchars($this->attributes["id"], ENT_QUOTES);
	  echo <<<EOT
<input type="hidden" name="accua-forms-cap-response" id="{$field_id}" class="accua_forms_cap_input" value="" />
<div id="{$field_id}-widget" class="accua_forms_cap_container"></div>
<script type="text/javascript">
(window.accuaformCapQueue = window.accuaformCapQueue || []).push( $js_registration );
</script>
EOT;
	}
}

```
