PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.0
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmFieldCaptchaSettings.php +9 -252 6.316.0 View file →
@@ -7,265 +7,22 @@
7 7 * @since 6.0
8 8 */
9 9 class FrmFieldCaptchaSettings {
10 10
11 - /**
12 - * The global settings object.
13 - *
14 - * @var FrmSettings
15 - */
16 - public $frm_settings;
17 -
18 - /**
19 - * The private key used for validating the token.
20 - *
21 - * @since 6.0
22 - *
23 - * @var string
24 - */
25 11 public $secret;
26 12
27 - /**
28 - * The key value to check in $_POST data with the token for validation.
29 - *
30 - * @since 6.0
31 - *
32 - * @var string
33 - */
34 13 public $token_field;
35 14
36 - /**
37 - * The URL that is called when validating the token.
38 - *
39 - * @since 6.0
40 - *
41 - * @var string
42 - */
43 - public $endpoint;
15 + public $end_point;
44 16
45 - /**
46 - * @param FrmSettings $frm_settings
47 - */
48 17 public function __construct( $frm_settings ) {
49 - $this->frm_settings = $frm_settings;
50 - $this->set_secret();
51 - $this->set_token_field();
52 - $this->set_endpoint();
53 - }
54 -
55 - /**
56 - * Set the private key to $this->secret.
57 - *
58 - * @return void
59 - */
60 - protected function set_secret() {
61 - $key = $this->get_key_for_privkey();
62 - $this->secret = ! empty( $this->frm_settings->$key ) ? $this->frm_settings->$key : '';
63 - }
64 -
65 - /**
66 - * Set the string to use for $this->token_field.
67 - * This is consistent between the different CAPTCHA services.
68 - * The element class name is always the same as the key before "-response" in the $_POST value key.
69 - * For example (h-captcha-response, or cf-turnstile-response).
70 - *
71 - * @since 6.8.4
72 - *
73 - * @return void
74 - */
75 - protected function set_token_field() {
76 - $this->token_field = $this->get_element_class_name() . '-response';
77 - }
78 -
79 - /**
80 - * @since 6.8.4
81 - *
82 - * @return void
83 - */
84 - protected function set_endpoint() {
85 - $this->endpoint = '';
86 - }
87 -
88 - /**
89 - * Get the name of the CAPTCHA service.
90 - *
91 - * @since 6.8.4
92 - *
93 - * @return string
94 - */
95 - public function get_name() {
96 - return '';
97 - }
98 -
99 - /**
100 - * Get the class name used for the CAPTCHA element on the front end.
101 - *
102 - * @since 6.8.4
103 - *
104 - * @return string
105 - */
106 - public function get_element_class_name() {
107 - return '';
108 - }
109 -
110 - /**
111 - * Get the URL of the page to link to in global settings. This page should have
112 - * instructions on how to get site and secret keys.
113 - *
114 - * @since 6.8.4
115 - *
116 - * @return string
117 - */
118 - public function get_documentation_url() {
119 - return '';
120 - }
121 -
122 - /**
123 - * Get the prefix for the global setting.
124 - * reCAPTCHA fields just use pubkey/privkey.
125 - * But other captcha integrations use a prefix like hcaptcha_public/turnstile_privkey.
126 - *
127 - * @since 6.8.4
128 - *
129 - * @return string
130 - */
131 - public function get_settings_prefix() {
132 - return '';
133 - }
134 -
135 - /**
136 - * Get the string to use for the tooltip on the Global settings page when hovering over the Site Key label.
137 - *
138 - * @since 6.8.4
139 - *
140 - * @return string
141 - */
142 - public function get_site_key_tooltip() {
143 - return '';
144 - }
145 -
146 - /**
147 - * Get the key used in FrmSettings for the site secret used for validating a Captcha.
148 - *
149 - * @since 6.8.4
150 - *
151 - * @return string
152 - */
153 - protected function get_key_for_privkey() {
154 - return $this->get_settings_prefix() . 'privkey';
155 - }
156 -
157 - /**
158 - * Get the key used in FrmSettings for the site key used to initialize a Captcha on the front end.
159 - *
160 - * @since 6.8.4
161 - *
162 - * @return string
163 - */
164 - protected function get_key_for_pubkey() {
165 - return $this->get_settings_prefix() . 'pubkey';
166 - }
167 -
168 - /**
169 - * Get the site key to use for a Captcha on the front end.
170 - *
171 - * @since 6.8.4
172 - *
173 - * @return string
174 - */
175 - public function get_pubkey() {
176 - $key = $this->get_key_for_pubkey();
177 - return $this->frm_settings->$key ?? '';
178 - }
179 -
180 - /**
181 - * Check if the public key is not empty.
182 - *
183 - * @since 6.8.4
184 - *
185 - * @return bool
186 - */
187 - public function has_pubkey() {
188 - return ! empty( $this->get_pubkey() );
189 - }
190 -
191 - /**
192 - * This can be used to add additional attributes to a front end Captcha element.
193 - *
194 - * @since 6.8.4
195 - *
196 - * @param array $attributes
197 - * @param array $field
198 - *
199 - * @return array
200 - */
201 - public function add_front_end_element_attributes( $attributes, $field ) {
202 - $attributes['data-size'] = $this->get_captcha_size( $field );
203 -
204 - if ( ! empty( $field['captcha_theme'] ) ) {
205 - $attributes['data-theme'] = $field['captcha_theme'];
18 + if ( $frm_settings->active_captcha === 'recaptcha' ) {
19 + $this->secret = $frm_settings->privkey;
20 + $this->token_field = 'g-recaptcha-response';
21 + $this->endpoint = 'https://www.google.com/recaptcha/api/siteverify';
22 + } else {
23 + $this->secret = $frm_settings->hcaptcha_privkey;
24 + $this->token_field = 'h-captcha-response';
25 + $this->endpoint = 'https://hcaptcha.com/siteverify';
206 26 }
207 -
208 - return $attributes;
209 - }
210 -
211 - /**
212 - * @since 6.8.4
213 - *
214 - * @param array $field
215 - *
216 - * @return string Either 'normal' or 'compact'.
217 - */
218 - protected function get_captcha_size( $field ) {
219 - return $field['captcha_size'] === 'default' ? 'normal' : $field['captcha_size'];
220 - }
221 -
222 - /**
223 - * Determine if the Captcha Size setting should be shown in field settings.
224 - * This has options for "Normal" and "Compact".
225 - * This is supported by all CAPTCHA types except for invisible reCAPTCHAs.
226 - *
227 - * @since 6.8.4
228 - *
229 - * @return bool
230 - */
231 - public function should_show_captcha_size() {
232 - return true;
233 - }
234 -
235 - /**
236 - * Determine if we should show a theme dropdown for our Captcha field.
237 - * This is applicable for all Captcha types except for invisible reCAPTCHA.
238 - *
239 - * @since 6.8.4
240 - *
241 - * @return bool
242 - */
243 - public function should_show_captcha_theme() {
244 - return true;
245 - }
246 -
247 - /**
248 - * Determine if the "auto" option should be shown for a specific captcha type.
249 - * This is only applicable for Turnstile.
250 - *
251 - * @since 6.8.4
252 - *
253 - * @return bool
254 - */
255 - public function should_show_captcha_theme_auto_option() {
256 - return false;
257 - }
258 -
259 - /**
260 - * Default to no prefix. This is overwritten by child classes.
261 - *
262 - * @since 6.25.1
263 - *
264 - * @param bool $allow_multiple
265 - *
266 - * @return string
267 - */
268 - public function get_class_prefix( $allow_multiple ) {
269 - return '';
270 27 }
271 28 }