PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.19
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.19
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 +137 -63 6.46.19 View file →
@@ -7,13 +7,9 @@
7 7 class FrmSettings {
8 8 public $option_name = 'frm_options';
9 9 public $menu;
10 10 public $mu_menu;
11 - public $use_html;
12 - public $jquery_css;
13 - public $accordion_js;
14 11 public $fade_form;
15 - public $old_css;
16 12 public $admin_bar;
17 13
18 14 public $success_msg;
19 15 public $blank_msg;
@@ -28,26 +24,71 @@
28 24 public $load_style;
29 25 public $custom_style;
30 26
31 27 public $active_captcha;
32 - public $hcaptcha_pubkey;
33 - public $hcaptcha_privkey;
28 +
29 + /**
30 + * Settings for reCAPTCHA.
31 + */
32 +
33 + /**
34 + * @var string|null
35 + */
34 36 public $pubkey;
37 +
38 + /**
39 + * @var string|null
40 + */
35 41 public $privkey;
36 42 public $re_lang;
37 43 public $re_type;
38 44 public $re_msg;
39 45 public $re_multi;
46 + public $re_threshold;
40 47
48 + /**
49 + * Settings for hCaptcha.
50 + */
51 +
52 + /**
53 + * @var string
54 + */
55 + public $hcaptcha_pubkey;
56 +
57 + /**
58 + * @var string|null
59 + */
60 + public $hcaptcha_privkey;
61 +
62 + /**
63 + * Settings for Turnstile.
64 + */
65 +
66 + /**
67 + * @var string
68 + */
69 + public $turnstile_pubkey;
70 +
71 + /**
72 + * @var string|null
73 + */
74 + public $turnstile_privkey;
75 +
41 76 public $no_ips;
42 77 public $custom_header_ip;
43 78 public $current_form = 0;
44 79 public $tracking;
80 + public $summary_emails;
81 + public $summary_emails_recipients;
45 82
83 + public $default_email;
84 + public $from_email;
85 + public $currency;
86 +
46 87 /**
47 88 * @since 6.0
48 89 *
49 - * @var string|false|null
90 + * @var false|string|null
50 91 */
51 92 public $custom_css;
52 93
53 94 public function __construct( $args = array() ) {
@@ -54,9 +95,9 @@
54 95 if ( ! defined( 'ABSPATH' ) ) {
55 96 die( 'You are not allowed to call this page directly.' );
56 97 }
57 98
58 - $settings = get_transient( $this->option_name );
99 + $settings = get_option( $this->option_name );
59 100
60 101 if ( ! is_object( $settings ) ) {
61 102 $settings = $this->translate_settings( $settings );
62 103 }
@@ -71,29 +112,18 @@
71 112 $this->maybe_filter_for_form( $args );
72 113 }
73 114
74 115 private function translate_settings( $settings ) {
75 - if ( $settings ) { //workaround for W3 total cache conflict
116 + if ( $settings ) {
117 + // Workaround for W3 total cache conflict.
76 118 return unserialize( serialize( $settings ) );
77 119 }
78 120
79 - $settings = get_option( $this->option_name );
80 - if ( is_object( $settings ) ) {
81 - set_transient( $this->option_name, $settings );
121 + // If unserializing didn't work.
122 + $settings = $this;
82 123
83 - return $settings;
84 - }
124 + update_option( $this->option_name, $settings, 'yes' );
85 125
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 -
96 126 return $settings;
97 127 }
98 128
99 129 /**
@@ -100,37 +130,40 @@
100 130 * @return array
101 131 */
102 132 public function default_options() {
103 133 return array(
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,
134 + 'menu' => apply_filters( 'frm_default_menu', 'Formidable' ),
135 + 'mu_menu' => 0,
136 + 'fade_form' => false,
137 + 'admin_bar' => false,
112 138
113 - 're_multi' => 1,
139 + 're_multi' => 1,
114 140
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' ),
123 - 'new_tab_msg' => __( 'The page has been opened in a new tab.', 'formidable' ),
141 + 'success_msg' => __( 'Your responses were successfully submitted. Thank you!', 'formidable' ),
142 + // translators: %s: [field_name] shortcode.
143 + 'blank_msg' => sprintf( __( '%s cannot be blank.', 'formidable' ), '[field_name]' ),
144 + // translators: %s: [field_name] shortcode.
145 + 'unique_msg' => sprintf( __( '%s must be unique.', 'formidable' ), '[field_name]' ),
146 + 'invalid_msg' => __( 'There was a problem with your submission. Errors are marked below.', 'formidable' ),
147 + 'failed_msg' => __( 'We\'re sorry. It looks like you\'ve already submitted that.', 'formidable' ),
148 + 'submit_value' => __( 'Submit', 'formidable' ),
149 + 'login_msg' => __( 'You do not have permission to view this form.', 'formidable' ),
150 + 'admin_permission' => __( 'You do not have permission to do that', 'formidable' ),
151 + 'new_tab_msg' => __( 'The page has been opened in a new tab.', 'formidable' ),
124 152
125 - 'email_to' => '[admin_email]',
126 - 'no_ips' => 0,
127 - '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
128 - 'tracking' => FrmAppHelper::pro_is_installed(),
153 + 'email_to' => '[admin_email]',
154 + 'enable_gdpr' => 0,
155 + 'no_gdpr_cookies' => 0,
156 + 'no_ips' => 0,
157 + 'custom_header_ip' => 0,
158 + 'tracking' => FrmAppHelper::pro_is_installed(),
159 + // Only enable this by default for the main site.
160 + 'summary_emails' => get_current_blog_id() === get_main_site_id(),
161 + 'summary_emails_recipients' => '[admin_email]',
129 162
130 163 // Normally custom CSS is a string. A false value is used when nothing has been set.
131 164 // When it is false, we try to use the old custom_key value from the default style's post_content array.
132 - 'custom_css' => false,
165 + 'custom_css' => false,
133 166 );
134 167 }
135 168
136 169 /**
@@ -162,8 +195,16 @@
162 195 if ( ! isset( $this->$frm_role ) ) {
163 196 $this->$frm_role = 'administrator';
164 197 }
165 198 }
199 +
200 + if ( ! isset( $this->default_email ) ) {
201 + $this->default_email = get_option( 'admin_email' );
202 + }
203 +
204 + if ( ! isset( $this->currency ) ) {
205 + $this->currency = 'USD';
206 + }
166 207 }
167 208
168 209 /**
169 210 * @param array $params
@@ -231,17 +272,21 @@
231 272 if ( ! isset( $this->active_captcha ) ) {
232 273 $this->active_captcha = 'recaptcha';
233 274 }
234 275
235 - $privkey = '';
236 - $re_lang = '';
276 + $privkey = '';
277 + $re_lang = '';
237 278
238 279 if ( ! isset( $this->hcaptcha_privkey ) ) {
239 280 $this->hcaptcha_privkey = '';
240 281 }
241 282
283 + if ( ! isset( $this->turnstile_privkey ) ) {
284 + $this->turnstile_privkey = '';
285 + }
286 +
242 287 if ( ! isset( $this->pubkey ) ) {
243 - // get the options from the database
288 + // Get the options from the database.
244 289 $recaptcha_opt = is_multisite() ? get_site_option( 'recaptcha' ) : get_option( 'recaptcha' );
245 290 $this->pubkey = isset( $recaptcha_opt['pubkey'] ) ? $recaptcha_opt['pubkey'] : '';
246 291 $privkey = isset( $recaptcha_opt['privkey'] ) ? $recaptcha_opt['privkey'] : $privkey;
247 292 $re_lang = isset( $recaptcha_opt['re_lang'] ) ? $recaptcha_opt['re_lang'] : $re_lang;
@@ -246,9 +291,9 @@
246 291 $privkey = isset( $recaptcha_opt['privkey'] ) ? $recaptcha_opt['privkey'] : $privkey;
247 292 $re_lang = isset( $recaptcha_opt['re_lang'] ) ? $recaptcha_opt['re_lang'] : $re_lang;
248 293 }
249 294
250 - if ( ! isset( $this->re_msg ) || empty( $this->re_msg ) ) {
295 + if ( empty( $this->re_msg ) ) {
251 296 $this->re_msg = __( 'The CAPTCHA was not entered correctly', 'formidable' );
252 297 }
253 298
254 299 if ( ! isset( $this->privkey ) ) {
@@ -335,23 +380,29 @@
335 380 }
336 381 }
337 382
338 383 /**
384 + * @param array $params
339 385 * @return void
340 386 */
341 387 private function update_settings( $params ) {
342 - $this->active_captcha = $params['frm_active_captcha'];
343 - $this->hcaptcha_pubkey = trim( $params['frm_hcaptcha_pubkey'] );
344 - $this->hcaptcha_privkey = trim( $params['frm_hcaptcha_privkey'] );
345 - $this->pubkey = trim( $params['frm_pubkey'] );
346 - $this->privkey = trim( $params['frm_privkey'] );
347 - $this->re_type = $params['frm_re_type'];
348 - $this->re_lang = $params['frm_re_lang'];
349 - $this->re_threshold = floatval( $params['frm_re_threshold'] );
350 - $this->load_style = $params['frm_load_style'];
351 - $this->custom_css = $params['frm_custom_css'];
388 + $this->active_captcha = $params['frm_active_captcha'];
389 + $this->pubkey = trim( $params['frm_pubkey'] );
390 + $this->privkey = trim( $params['frm_privkey'] );
391 + $this->re_type = $params['frm_re_type'];
392 + $this->re_lang = $params['frm_re_lang'];
393 + $this->re_threshold = floatval( $params['frm_re_threshold'] );
394 + $this->hcaptcha_pubkey = trim( $params['frm_hcaptcha_pubkey'] );
395 + $this->hcaptcha_privkey = trim( $params['frm_hcaptcha_privkey'] );
396 + $this->turnstile_pubkey = trim( $params['frm_turnstile_pubkey'] );
397 + $this->turnstile_privkey = trim( $params['frm_turnstile_privkey'] );
398 + $this->load_style = $params['frm_load_style'];
399 + $this->custom_css = $params['frm_custom_css'];
400 + $this->default_email = $params['frm_default_email'];
401 + $this->from_email = $params['frm_from_email'];
402 + $this->currency = $params['frm_currency'];
352 403
353 - $checkboxes = array( 'mu_menu', 're_multi', 'use_html', 'jquery_css', 'accordion_js', 'fade_form', 'no_ips', 'custom_header_ip', 'tracking', 'admin_bar' );
404 + $checkboxes = array( 'mu_menu', 're_multi', 'fade_form', 'no_ips', 'no_gdpr_cookies', 'enable_gdpr', 'custom_header_ip', 'tracking', 'admin_bar', 'summary_emails' );
354 405 foreach ( $checkboxes as $set ) {
355 406 $this->$set = isset( $params[ 'frm_' . $set ] ) ? absint( $params[ 'frm_' . $set ] ) : 0;
356 407 }
357 408 }
@@ -367,9 +418,9 @@
367 418 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
368 419 $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' );
369 420
370 421 // Make sure administrators always have permissions
371 - if ( ! in_array( 'administrator', $this->$frm_role ) ) {
422 + if ( ! in_array( 'administrator', $this->$frm_role, true ) ) {
372 423 array_push( $this->$frm_role, 'administrator' );
373 424 }
374 425
375 426 foreach ( $roles as $role => $details ) {
@@ -379,8 +430,31 @@
379 430 $wp_roles->remove_cap( $role, $frm_role );
380 431 }
381 432 }
382 433 }
434 + }
435 +
436 + /**
437 + * Updates a single setting with specified sanitization.
438 + *
439 + * @since 6.9
440 + *
441 + * @param string $key The setting key to update.
442 + * @param mixed $value The new value for the setting.
443 + * @param string $sanitize The name of the sanitization function to apply to the new value.
444 + * @return bool True on success, false on failure.
445 + */
446 + public function update_setting( $key, $value, $sanitize ) {
447 + if ( ! property_exists( $this, $key ) || ! is_callable( $sanitize ) ) {
448 + // Setting does not exist or sanitization function name is not callable.
449 + return false;
450 + }
451 +
452 + // Update the property value.
453 + FrmAppHelper::sanitize_value( $sanitize, $value );
454 + $this->{$key} = $value;
455 +
456 + return true;
383 457 }
384 458
385 459 /**
386 460 * @return void