PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.1
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/FrmSettings.php +68 -367 6.276.1 View file →
@@ -4,254 +4,59 @@
4 4 }
5 5
6 6 #[\AllowDynamicProperties]
7 7 class FrmSettings {
8 -
9 - /**
10 - * @var string
11 - */
12 8 public $option_name = 'frm_options';
13 -
14 - /**
15 - * @var int
16 - */
17 9 public $menu;
18 -
19 - /**
20 - * @var int
21 - */
22 10 public $mu_menu;
23 -
24 - /**
25 - * @var int
26 - */
11 + public $use_html;
12 + public $jquery_css;
13 + public $accordion_js;
27 14 public $fade_form;
28 -
29 - /**
30 - * @var bool
31 - */
15 + public $old_css;
32 16 public $admin_bar;
33 17
34 - /**
35 - * @var string
36 - */
37 18 public $success_msg;
38 -
39 - /**
40 - * @var string
41 - */
42 19 public $blank_msg;
43 -
44 - /**
45 - * @var string
46 - */
47 20 public $unique_msg;
48 -
49 - /**
50 - * @var string
51 - */
52 21 public $invalid_msg;
53 -
54 - /**
55 - * @var string
56 - */
57 22 public $failed_msg;
58 -
59 - /**
60 - * @var string
61 - */
62 23 public $submit_value;
63 -
64 - /**
65 - * @var string
66 - */
67 24 public $login_msg;
68 -
69 - /**
70 - * @var string
71 - */
72 25 public $admin_permission;
73 26
74 - /**
75 - * @var string
76 - */
77 27 public $email_to;
78 -
79 - /**
80 - * @var string|null
81 - */
82 28 public $load_style;
83 -
84 - /**
85 - * @var bool|int|null
86 - */
87 29 public $custom_style;
88 30
89 - /**
90 - * @var string|null
91 - */
92 31 public $active_captcha;
93 -
94 - /**
95 - * Settings for reCAPTCHA.
96 - */
97 -
98 - /**
99 - * @var string|null
100 - */
32 + public $hcaptcha_pubkey;
33 + public $hcaptcha_privkey;
101 34 public $pubkey;
102 -
103 - /**
104 - * @var string|null
105 - */
106 35 public $privkey;
107 -
108 - /**
109 - * @var string|null
110 - */
111 36 public $re_lang;
112 -
113 - /**
114 - * @var string|null
115 - */
116 37 public $re_type;
117 -
118 - /**
119 - * @var string
120 - */
121 38 public $re_msg;
122 -
123 - /**
124 - * @var bool
125 - */
126 39 public $re_multi;
127 40
128 - /**
129 - * @var float|string|null
130 - */
131 - public $re_threshold;
132 -
133 - /**
134 - * Settings for hCaptcha.
135 - */
136 -
137 - /**
138 - * @var string
139 - */
140 - public $hcaptcha_pubkey;
141 -
142 - /**
143 - * @var string|null
144 - */
145 - public $hcaptcha_privkey;
146 -
147 - /**
148 - * Settings for Turnstile.
149 - */
150 -
151 - /**
152 - * @var string
153 - */
154 - public $turnstile_pubkey;
155 -
156 - /**
157 - * @var string|null
158 - */
159 - public $turnstile_privkey;
160 -
161 - /**
162 - * @var bool
163 - */
164 41 public $no_ips;
165 -
166 - /**
167 - * @var string
168 - */
169 42 public $custom_header_ip;
170 -
171 - /**
172 - * @var int
173 - */
174 43 public $current_form = 0;
175 -
176 - /**
177 - * @var bool
178 - */
179 44 public $tracking;
180 45
181 46 /**
182 - * @var bool
183 - */
184 - public $summary_emails;
185 -
186 - /**
187 - * @var string
188 - */
189 - public $summary_emails_recipients;
190 -
191 - /**
192 - * @var string|null
193 - */
194 - public $default_email;
195 -
196 - /**
197 - * @var string
198 - */
199 - public $from_email;
200 -
201 - /**
202 - * @var string|null
203 - */
204 - public $currency;
205 -
206 - /**
207 47 * @since 6.0
208 48 *
209 - * @var false|string|null
49 + * @var string|false|null
210 50 */
211 51 public $custom_css;
212 52
213 - /**
214 - * @var string
215 - */
216 - public $honeypot;
217 -
218 - /**
219 - * @var bool
220 - */
221 - public $wp_spam_check;
222 -
223 - /**
224 - * @var bool
225 - */
226 - public $denylist_check;
227 -
228 - /**
229 - * @since 6.25.1
230 - *
231 - * @var int|null 1 if installed after welcome tour update, null otherwise.
232 - */
233 - public $installed_after_welcome_tour_update;
234 -
235 - /**
236 - * @var string
237 - */
238 - public $disallowed_words;
239 -
240 - /**
241 - * @var string
242 - */
243 - public $allowed_words;
244 -
245 - /**
246 - * @param array $args
247 - */
248 53 public function __construct( $args = array() ) {
249 54 if ( ! defined( 'ABSPATH' ) ) {
250 55 die( 'You are not allowed to call this page directly.' );
251 56 }
252 57
253 - $settings = get_option( $this->option_name );
58 + $settings = get_transient( $this->option_name );
254 59
255 60 if ( ! is_object( $settings ) ) {
256 61 $settings = $this->translate_settings( $settings );
257 62 }
@@ -265,24 +70,30 @@
265 70
266 71 $this->maybe_filter_for_form( $args );
267 72 }
268 73
269 - /**
270 - * @param false|object $settings
271 - *
272 - * @return object
273 - */
274 74 private function translate_settings( $settings ) {
275 - if ( $settings ) {
276 - // Workaround for W3 total cache conflict.
75 + if ( $settings ) { //workaround for W3 total cache conflict
277 76 return unserialize( serialize( $settings ) );
278 77 }
279 78
280 - // If unserializing didn't work.
281 - $settings = $this;
79 + $settings = get_option( $this->option_name );
80 + if ( is_object( $settings ) ) {
81 + set_transient( $this->option_name, $settings );
282 82
283 - update_option( $this->option_name, $settings, 'yes' );
83 + return $settings;
84 + }
284 85
86 + // If unserializing didn't work
87 + if ( $settings ) { //workaround for W3 total cache conflict
88 + $settings = unserialize( serialize( $settings ) );
89 + } else {
90 + $settings = $this;
91 + }
92 +
93 + update_option( $this->option_name, $settings );
94 + set_transient( $this->option_name, $settings );
95 +
285 96 return $settings;
286 97 }
287 98
288 99 /**
@@ -289,52 +100,39 @@
289 100 * @return array
290 101 */
291 102 public function default_options() {
292 103 return array(
293 - 'menu' => apply_filters( 'frm_default_menu', 'Formidable' ),
294 - 'mu_menu' => 0,
295 - 'fade_form' => false,
296 - 'admin_bar' => false,
104 + 'menu' => apply_filters( 'frm_default_menu', 'Formidable' ),
105 + 'mu_menu' => 0,
106 + 'use_html' => true,
107 + 'jquery_css' => false,
108 + 'accordion_js' => false,
109 + 'fade_form' => false,
110 + 'old_css' => false,
111 + 'admin_bar' => false,
297 112
298 - 're_multi' => 1,
113 + 're_multi' => 1,
299 114
300 - 'success_msg' => __( 'Your responses were successfully submitted. Thank you!', 'formidable' ),
301 - // translators: %s: [field_name] shortcode.
302 - 'blank_msg' => sprintf( __( '%s cannot be blank.', 'formidable' ), '[field_name]' ),
303 - // translators: %s: [field_name] shortcode.
304 - 'unique_msg' => sprintf( __( '%s must be unique.', 'formidable' ), '[field_name]' ),
305 - 'invalid_msg' => __( 'There was a problem with your submission. Errors are marked below.', 'formidable' ),
306 - 'failed_msg' => __( 'We\'re sorry. It looks like you\'ve already submitted that.', 'formidable' ),
307 - 'submit_value' => __( 'Submit', 'formidable' ),
308 - 'login_msg' => __( 'You do not have permission to view this form.', 'formidable' ),
309 - 'admin_permission' => __( 'You do not have permission to do that', 'formidable' ),
310 - 'new_tab_msg' => __( 'The page has been opened in a new tab.', 'formidable' ),
115 + 'success_msg' => __( 'Your responses were successfully submitted. Thank you!', 'formidable' ),
116 + 'blank_msg' => __( 'This field cannot be blank.', 'formidable' ),
117 + 'unique_msg' => __( 'This value must be unique.', 'formidable' ),
118 + 'invalid_msg' => __( 'There was a problem with your submission. Errors are marked below.', 'formidable' ),
119 + 'failed_msg' => __( 'We\'re sorry. It looks like you\'ve already submitted that.', 'formidable' ),
120 + 'submit_value' => __( 'Submit', 'formidable' ),
121 + 'login_msg' => __( 'You do not have permission to view this form.', 'formidable' ),
122 + 'admin_permission' => __( 'You do not have permission to do that', 'formidable' ),
311 123
312 - 'email_to' => '[admin_email]',
313 - 'enable_gdpr' => 0,
314 - 'no_gdpr_cookies' => 0,
315 - 'no_ips' => 0,
316 - 'custom_header_ip' => 0,
317 - 'tracking' => FrmAppHelper::pro_is_installed(),
318 - // Only enable this by default for the main site.
319 - 'summary_emails' => get_current_blog_id() === get_main_site_id(),
320 - 'summary_emails_recipients' => '[admin_email]',
124 + 'email_to' => '[admin_email]',
125 + 'no_ips' => 0,
126 + 'custom_header_ip' => false, // Use false by default. We show a warning when this is unset. Once global settings have been saved, this gets saved
127 + 'tracking' => FrmAppHelper::pro_is_installed(),
321 128
322 129 // Normally custom CSS is a string. A false value is used when nothing has been set.
323 130 // When it is false, we try to use the old custom_key value from the default style's post_content array.
324 - 'custom_css' => false,
325 - 'honeypot' => 1,
326 - 'wp_spam_check' => 0,
327 - 'denylist_check' => 0,
328 - 'disallowed_words' => '',
329 - 'allowed_words' => '',
330 - 'email_style' => 'classic',
131 + 'custom_css' => false,
331 132 );
332 133 }
333 134
334 - /**
335 - * @return void
336 - */
337 135 private function set_default_options() {
338 136 $this->fill_captcha_settings();
339 137
340 138 if ( ! isset( $this->load_style ) ) {
@@ -348,10 +146,9 @@
348 146 $this->fill_with_defaults();
349 147
350 148 if ( is_multisite() && is_admin() ) {
351 149 $mu_menu = get_site_option( 'frm_admin_menu_name' );
352 -
353 - if ( $mu_menu && $mu_menu ) {
150 + if ( $mu_menu && ! empty( $mu_menu ) ) {
354 151 $this->menu = $mu_menu;
355 152 $this->mu_menu = 1;
356 153 }
357 154 }
@@ -356,27 +153,17 @@
356 153 }
357 154 }
358 155
359 156 $frm_roles = FrmAppHelper::frm_capabilities( 'pro' );
360 -
361 157 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
362 158 if ( ! isset( $this->$frm_role ) ) {
363 159 $this->$frm_role = 'administrator';
364 160 }
365 161 }
366 -
367 - if ( ! isset( $this->default_email ) ) {
368 - $this->default_email = get_option( 'admin_email' );
369 - }
370 -
371 - if ( ! isset( $this->currency ) ) {
372 - $this->currency = 'USD';
373 - }
374 162 }
375 163
376 164 /**
377 165 * @param array $params
378 - *
379 166 * @return void
380 167 */
381 168 public function fill_with_defaults( $params = array() ) {
382 169 $settings = $this->default_options();
@@ -383,9 +170,8 @@
383 170 $filter_html = ! FrmAppHelper::allow_unfiltered_html();
384 171
385 172 if ( $filter_html ) {
386 173 $filter_keys = array( 'failed_msg', 'blank_msg', 'invalid_msg', 'admin_permission', 'unique_msg', 'success_msg', 'submit_value', 'login_msg', 'menu' );
387 -
388 174 if ( ! empty( $params['additional_filter_keys'] ) ) {
389 175 $filter_keys = array_merge( $filter_keys, $params['additional_filter_keys'] );
390 176 }
391 177 } else {
@@ -415,9 +201,8 @@
415 201 *
416 202 * @param mixed $value The unsanitized global setting value.
417 203 * @param string $key The key of the global setting being saved.
418 204 * @param array $filter_keys These keys that are filtered with kses.
419 - *
420 205 * @return mixed
421 206 */
422 207 private function maybe_sanitize_global_setting( $value, $key, $filter_keys ) {
423 208 if ( 'custom_css' === $key ) {
@@ -424,9 +209,8 @@
424 209 if ( false === $value ) {
425 210 // Avoid changing the false default value to an empty string.
426 211 return $value;
427 212 }
428 -
429 213 return sanitize_textarea_field( $value );
430 214 }
431 215
432 216 if ( in_array( $key, $filter_keys, true ) ) {
@@ -435,36 +219,29 @@
435 219
436 220 return $value;
437 221 }
438 222
439 - /**
440 - * @return void
441 - */
442 223 private function fill_captcha_settings() {
443 224 if ( ! isset( $this->active_captcha ) ) {
444 225 $this->active_captcha = 'recaptcha';
445 226 }
446 227
447 - $privkey = '';
448 - $re_lang = '';
228 + $privkey = '';
229 + $re_lang = '';
449 230
450 231 if ( ! isset( $this->hcaptcha_privkey ) ) {
451 232 $this->hcaptcha_privkey = '';
452 233 }
453 234
454 - if ( ! isset( $this->turnstile_privkey ) ) {
455 - $this->turnstile_privkey = '';
456 - }
457 -
458 235 if ( ! isset( $this->pubkey ) ) {
459 - // Get the options from the database.
236 + // get the options from the database
460 237 $recaptcha_opt = is_multisite() ? get_site_option( 'recaptcha' ) : get_option( 'recaptcha' );
461 - $this->pubkey = $recaptcha_opt['pubkey'] ?? '';
462 - $privkey = $recaptcha_opt['privkey'] ?? $privkey;
463 - $re_lang = $recaptcha_opt['re_lang'] ?? $re_lang;
238 + $this->pubkey = isset( $recaptcha_opt['pubkey'] ) ? $recaptcha_opt['pubkey'] : '';
239 + $privkey = isset( $recaptcha_opt['privkey'] ) ? $recaptcha_opt['privkey'] : $privkey;
240 + $re_lang = isset( $recaptcha_opt['re_lang'] ) ? $recaptcha_opt['re_lang'] : $re_lang;
464 241 }
465 242
466 - if ( empty( $this->re_msg ) ) {
243 + if ( ! isset( $this->re_msg ) || empty( $this->re_msg ) ) {
467 244 $this->re_msg = __( 'The CAPTCHA was not entered correctly', 'formidable' );
468 245 }
469 246
470 247 if ( ! isset( $this->privkey ) ) {
@@ -487,10 +264,8 @@
487 264 /**
488 265 * Get values that may be shown on the front-end without an override in the form settings.
489 266 *
490 267 * @since 3.06.01
491 - *
492 - * @return string[]
493 268 */
494 269 public function translatable_strings() {
495 270 return array(
496 271 'invalid_msg',
@@ -503,17 +278,12 @@
503 278 /**
504 279 * Allow strings to be filtered when a specific form may be displaying them.
505 280 *
506 281 * @since 3.06.01
507 - *
508 - * @param array $args
509 - *
510 - * @return void
511 282 */
512 283 public function maybe_filter_for_form( $args ) {
513 284 if ( isset( $args['current_form'] ) && is_numeric( $args['current_form'] ) ) {
514 285 $this->current_form = $args['current_form'];
515 -
516 286 foreach ( $this->translatable_strings() as $string ) {
517 287 $this->{$string} = apply_filters( 'frm_global_setting', $this->{$string}, $string, $this );
518 288 $this->{$string} = apply_filters( 'frm_global_' . $string, $this->{$string}, $this );
519 289 }
@@ -519,23 +289,12 @@
519 289 }
520 290 }
521 291 }
522 292
523 - /**
524 - * @param array $params
525 - * @param array $errors
526 - *
527 - * @return array
528 - */
529 293 public function validate( $params, $errors ) {
530 294 return apply_filters( 'frm_validate_settings', $errors, $params );
531 295 }
532 296
533 - /**
534 - * @param array $params
535 - *
536 - * @return void
537 - */
538 297 public function update( $params ) {
539 298 $this->fill_with_defaults( $params );
540 299 $this->update_settings( $params );
541 300
@@ -555,72 +314,41 @@
555 314 $frm_style->update( 'default' );
556 315 }
557 316 }
558 317
559 - /**
560 - * @param array $params
561 - *
562 - * @return void
563 - */
564 318 private function update_settings( $params ) {
565 - $this->active_captcha = $params['frm_active_captcha'];
566 - $this->pubkey = trim( $params['frm_pubkey'] );
567 - $this->privkey = trim( $params['frm_privkey'] );
568 - $this->re_type = $params['frm_re_type'];
569 - $this->re_lang = $params['frm_re_lang'];
570 - $this->re_threshold = floatval( $params['frm_re_threshold'] );
571 - $this->hcaptcha_pubkey = trim( $params['frm_hcaptcha_pubkey'] );
572 - $this->hcaptcha_privkey = trim( $params['frm_hcaptcha_privkey'] );
573 - $this->turnstile_pubkey = trim( $params['frm_turnstile_pubkey'] );
574 - $this->turnstile_privkey = trim( $params['frm_turnstile_privkey'] );
575 - $this->load_style = $params['frm_load_style'];
576 - $this->custom_css = $params['frm_custom_css'];
577 - $this->default_email = $params['frm_default_email'];
578 - $this->from_email = $params['frm_from_email'];
579 - $this->currency = $params['frm_currency'];
319 + $this->active_captcha = $params['frm_active_captcha'];
320 + $this->hcaptcha_pubkey = trim( $params['frm_hcaptcha_pubkey'] );
321 + $this->hcaptcha_privkey = $params['frm_hcaptcha_privkey'];
322 + $this->pubkey = trim( $params['frm_pubkey'] );
323 + $this->privkey = $params['frm_privkey'];
324 + $this->re_type = $params['frm_re_type'];
325 + $this->re_lang = $params['frm_re_lang'];
326 + $this->re_threshold = floatval( $params['frm_re_threshold'] );
327 + $this->load_style = $params['frm_load_style'];
328 + $this->custom_css = $params['frm_custom_css'];
580 329
581 - $checkboxes = array(
582 - 'mu_menu',
583 - 're_multi',
584 - 'fade_form',
585 - 'no_ips',
586 - 'no_gdpr_cookies',
587 - 'enable_gdpr',
588 - 'custom_header_ip',
589 - 'tracking',
590 - 'admin_bar',
591 - 'summary_emails',
592 - 'honeypot',
593 - 'wp_spam_check',
594 - 'denylist_check',
595 - );
596 -
330 + $checkboxes = array( 'mu_menu', 're_multi', 'use_html', 'jquery_css', 'accordion_js', 'fade_form', 'no_ips', 'custom_header_ip', 'tracking', 'admin_bar' );
597 331 foreach ( $checkboxes as $set ) {
598 332 $this->$set = isset( $params[ 'frm_' . $set ] ) ? absint( $params[ 'frm_' . $set ] ) : 0;
599 333 }
600 334 }
601 335
602 - /**
603 - * @param array $params
604 - *
605 - * @return void
606 - */
607 336 private function update_roles( $params ) {
608 337 global $wp_roles;
609 338
610 339 $frm_roles = FrmAppHelper::frm_capabilities();
611 340 $roles = get_editable_roles();
612 -
613 341 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
614 - $this->$frm_role = (array) ( $params[ $frm_role ] ?? 'administrator' );
342 + $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' );
615 343
616 344 // Make sure administrators always have permissions
617 - if ( ! in_array( 'administrator', $this->$frm_role, true ) ) {
345 + if ( ! in_array( 'administrator', $this->$frm_role ) ) {
618 346 array_push( $this->$frm_role, 'administrator' );
619 347 }
620 348
621 349 foreach ( $roles as $role => $details ) {
622 - if ( in_array( $role, $this->$frm_role, true ) ) {
350 + if ( in_array( $role, $this->$frm_role ) ) {
623 351 $wp_roles->add_cap( $role, $frm_role );
624 352 } else {
625 353 $wp_roles->remove_cap( $role, $frm_role );
626 354 }
@@ -627,35 +355,8 @@
627 355 }
628 356 }
629 357 }
630 358
631 - /**
632 - * Updates a single setting with specified sanitization.
633 - *
634 - * @since 6.9
635 - *
636 - * @param string $key The setting key to update.
637 - * @param mixed $value The new value for the setting.
638 - * @param string $sanitize The name of the sanitization function to apply to the new value.
639 - *
640 - * @return bool True on success, false on failure.
641 - */
642 - public function update_setting( $key, $value, $sanitize ) {
643 - if ( ! property_exists( $this, $key ) || ! is_callable( $sanitize ) ) {
644 - // Setting does not exist or sanitization function name is not callable.
645 - return false;
646 - }
647 -
648 - // Update the property value.
649 - FrmAppHelper::sanitize_value( $sanitize, $value );
650 - $this->{$key} = $value;
651 -
652 - return true;
653 - }
654 -
655 - /**
656 - * @return void
657 - */
658 359 public function store() {
659 360 // Save the posted value in the database
660 361
661 362 update_option( 'frm_options', $this );