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