verify_url = 'https://hcaptcha.com/siteverify'; } /** * Set Captcha ID. * * @return void */ protected function set_id() { $this->id = self::$plugin_info['name'] . '-hcaptcha'; } /** * Set Captcha Key. * * @return void */ protected function set_key() { $this->key = 'hcaptcha'; } /** * Get Token Name. * * @return string */ public function get_token_name() { return 'h-captcha-response'; } /** * Get OnLoad Functino name. * * @return string */ private function on_load_func() { return str_replace( '-', '_', $this->id . '_on_load_' . $this->get_identifier() ); } /** * Hooks. * * @return void */ protected function hooks() { add_filter( self::$plugin_info['prefix'] . '-localize-data', array( $this, 'localize_data' ), 100, 1 ); } /** * Localize Data. * * @param array $localize_data * @return array */ public function localize_data( $localize_data ) { if ( ! $this->captcha_printed ) { return $localize_data; } $localize_data['captchas']['hcaptcha'] = array( 'token' => $this->get_token_name(), 'load_func' => $this->on_load_func(), 'html_id' => $this->get_html_id(), 'key' => $this->get_captcha_site_key(), ); return $localize_data; } /** * Get Assets. * * @return array */ public function get_assets() { if ( ! $this->captcha_printed ) { return array(); } return array( array( 'handle' => self::$plugin_info['name'] . '-' . $this->get_id(), 'type' => 'js', 'url' => 'https://js.hcaptcha.com/1/api.js?onload=' . $this->on_load_func() . '&render=explicit', 'in_footer' => true, ), ); } /** * Captcha HTML. * * @return void */ public function captcha_html( $html_id, $form_key ) { ?>