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