| @@ -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,35 +24,90 @@ | ||
| 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 | |
| 94 | + public $honeypot; | |
| 95 | + | |
| 96 | + public $wp_spam_check; | |
| 97 | + | |
| 98 | + public $denylist_check; | |
| 99 | + | |
| 100 | + public $disallowed_words; | |
| 101 | + | |
| 102 | + public $allowed_words; | |
| 103 | + | |
| 53 | 104 | public function __construct( $args = array() ) { |
| 54 | 105 | if ( ! defined( 'ABSPATH' ) ) { |
| 55 | 106 | die( 'You are not allowed to call this page directly.' ); |
| 56 | 107 | } |
| 57 | 108 | |
| 58 | - $settings = get_transient( $this->option_name ); | |
| 109 | + $settings = get_option( $this->option_name ); | |
| 59 | 110 | |
| 60 | 111 | if ( ! is_object( $settings ) ) { |
| 61 | 112 | $settings = $this->translate_settings( $settings ); |
| 62 | 113 | } |
| @@ -71,29 +122,18 @@ | ||
| 71 | 122 | $this->maybe_filter_for_form( $args ); |
| 72 | 123 | } |
| 73 | 124 | |
| 74 | 125 | private function translate_settings( $settings ) { |
| 75 | - if ( $settings ) { //workaround for W3 total cache conflict | |
| 126 | + if ( $settings ) { | |
| 127 | + // Workaround for W3 total cache conflict. | |
| 76 | 128 | return unserialize( serialize( $settings ) ); |
| 77 | 129 | } |
| 78 | 130 | |
| 79 | - $settings = get_option( $this->option_name ); | |
| 80 | - if ( is_object( $settings ) ) { | |
| 81 | - set_transient( $this->option_name, $settings ); | |
| 131 | + // If unserializing didn't work. | |
| 132 | + $settings = $this; | |
| 82 | 133 | |
| 83 | - return $settings; | |
| 84 | - } | |
| 134 | + update_option( $this->option_name, $settings, 'yes' ); | |
| 85 | 135 | |
| 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 | 136 | return $settings; |
| 97 | 137 | } |
| 98 | 138 | |
| 99 | 139 | /** |
| @@ -100,36 +140,45 @@ | ||
| 100 | 140 | * @return array |
| 101 | 141 | */ |
| 102 | 142 | public function default_options() { |
| 103 | 143 | 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, | |
| 144 | + 'menu' => apply_filters( 'frm_default_menu', 'Formidable' ), | |
| 145 | + 'mu_menu' => 0, | |
| 146 | + 'fade_form' => false, | |
| 147 | + 'admin_bar' => false, | |
| 112 | 148 | |
| 113 | - 're_multi' => 1, | |
| 149 | + 're_multi' => 1, | |
| 114 | 150 | |
| 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' ), | |
| 151 | + 'success_msg' => __( 'Your responses were successfully submitted. Thank you!', 'formidable' ), | |
| 152 | + // translators: %s: [field_name] shortcode. | |
| 153 | + 'blank_msg' => sprintf( __( '%s cannot be blank.', 'formidable' ), '[field_name]' ), | |
| 154 | + // translators: %s: [field_name] shortcode. | |
| 155 | + 'unique_msg' => sprintf( __( '%s must be unique.', 'formidable' ), '[field_name]' ), | |
| 156 | + 'invalid_msg' => __( 'There was a problem with your submission. Errors are marked below.', 'formidable' ), | |
| 157 | + 'failed_msg' => __( 'We\'re sorry. It looks like you\'ve already submitted that.', 'formidable' ), | |
| 158 | + 'submit_value' => __( 'Submit', 'formidable' ), | |
| 159 | + 'login_msg' => __( 'You do not have permission to view this form.', 'formidable' ), | |
| 160 | + 'admin_permission' => __( 'You do not have permission to do that', 'formidable' ), | |
| 161 | + 'new_tab_msg' => __( 'The page has been opened in a new tab.', 'formidable' ), | |
| 123 | 162 | |
| 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(), | |
| 163 | + 'email_to' => '[admin_email]', | |
| 164 | + 'enable_gdpr' => 0, | |
| 165 | + 'no_gdpr_cookies' => 0, | |
| 166 | + 'no_ips' => 0, | |
| 167 | + 'custom_header_ip' => 0, | |
| 168 | + 'tracking' => FrmAppHelper::pro_is_installed(), | |
| 169 | + // Only enable this by default for the main site. | |
| 170 | + 'summary_emails' => get_current_blog_id() === get_main_site_id(), | |
| 171 | + 'summary_emails_recipients' => '[admin_email]', | |
| 128 | 172 | |
| 129 | 173 | // Normally custom CSS is a string. A false value is used when nothing has been set. |
| 130 | 174 | // 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, | |
| 175 | + 'custom_css' => false, | |
| 176 | + 'honeypot' => 1, | |
| 177 | + 'wp_spam_check' => 0, | |
| 178 | + 'denylist_check' => 0, | |
| 179 | + 'disallowed_words' => '', | |
| 180 | + 'allowed_words' => '', | |
| 132 | 181 | ); |
| 133 | 182 | } |
| 134 | 183 | |
| 135 | 184 | /** |
| @@ -161,8 +210,16 @@ | ||
| 161 | 210 | if ( ! isset( $this->$frm_role ) ) { |
| 162 | 211 | $this->$frm_role = 'administrator'; |
| 163 | 212 | } |
| 164 | 213 | } |
| 214 | + | |
| 215 | + if ( ! isset( $this->default_email ) ) { | |
| 216 | + $this->default_email = get_option( 'admin_email' ); | |
| 217 | + } | |
| 218 | + | |
| 219 | + if ( ! isset( $this->currency ) ) { | |
| 220 | + $this->currency = 'USD'; | |
| 221 | + } | |
| 165 | 222 | } |
| 166 | 223 | |
| 167 | 224 | /** |
| 168 | 225 | * @param array $params |
| @@ -230,17 +287,21 @@ | ||
| 230 | 287 | if ( ! isset( $this->active_captcha ) ) { |
| 231 | 288 | $this->active_captcha = 'recaptcha'; |
| 232 | 289 | } |
| 233 | 290 | |
| 234 | - $privkey = ''; | |
| 235 | - $re_lang = ''; | |
| 291 | + $privkey = ''; | |
| 292 | + $re_lang = ''; | |
| 236 | 293 | |
| 237 | 294 | if ( ! isset( $this->hcaptcha_privkey ) ) { |
| 238 | 295 | $this->hcaptcha_privkey = ''; |
| 239 | 296 | } |
| 240 | 297 | |
| 298 | + if ( ! isset( $this->turnstile_privkey ) ) { | |
| 299 | + $this->turnstile_privkey = ''; | |
| 300 | + } | |
| 301 | + | |
| 241 | 302 | if ( ! isset( $this->pubkey ) ) { |
| 242 | - // get the options from the database | |
| 303 | + // Get the options from the database. | |
| 243 | 304 | $recaptcha_opt = is_multisite() ? get_site_option( 'recaptcha' ) : get_option( 'recaptcha' ); |
| 244 | 305 | $this->pubkey = isset( $recaptcha_opt['pubkey'] ) ? $recaptcha_opt['pubkey'] : ''; |
| 245 | 306 | $privkey = isset( $recaptcha_opt['privkey'] ) ? $recaptcha_opt['privkey'] : $privkey; |
| 246 | 307 | $re_lang = isset( $recaptcha_opt['re_lang'] ) ? $recaptcha_opt['re_lang'] : $re_lang; |
| @@ -245,9 +306,9 @@ | ||
| 245 | 306 | $privkey = isset( $recaptcha_opt['privkey'] ) ? $recaptcha_opt['privkey'] : $privkey; |
| 246 | 307 | $re_lang = isset( $recaptcha_opt['re_lang'] ) ? $recaptcha_opt['re_lang'] : $re_lang; |
| 247 | 308 | } |
| 248 | 309 | |
| 249 | - if ( ! isset( $this->re_msg ) || empty( $this->re_msg ) ) { | |
| 310 | + if ( empty( $this->re_msg ) ) { | |
| 250 | 311 | $this->re_msg = __( 'The CAPTCHA was not entered correctly', 'formidable' ); |
| 251 | 312 | } |
| 252 | 313 | |
| 253 | 314 | if ( ! isset( $this->privkey ) ) { |
| @@ -334,23 +395,43 @@ | ||
| 334 | 395 | } |
| 335 | 396 | } |
| 336 | 397 | |
| 337 | 398 | /** |
| 399 | + * @param array $params | |
| 338 | 400 | * @return void |
| 339 | 401 | */ |
| 340 | 402 | 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']; | |
| 403 | + $this->active_captcha = $params['frm_active_captcha']; | |
| 404 | + $this->pubkey = trim( $params['frm_pubkey'] ); | |
| 405 | + $this->privkey = trim( $params['frm_privkey'] ); | |
| 406 | + $this->re_type = $params['frm_re_type']; | |
| 407 | + $this->re_lang = $params['frm_re_lang']; | |
| 408 | + $this->re_threshold = floatval( $params['frm_re_threshold'] ); | |
| 409 | + $this->hcaptcha_pubkey = trim( $params['frm_hcaptcha_pubkey'] ); | |
| 410 | + $this->hcaptcha_privkey = trim( $params['frm_hcaptcha_privkey'] ); | |
| 411 | + $this->turnstile_pubkey = trim( $params['frm_turnstile_pubkey'] ); | |
| 412 | + $this->turnstile_privkey = trim( $params['frm_turnstile_privkey'] ); | |
| 413 | + $this->load_style = $params['frm_load_style']; | |
| 414 | + $this->custom_css = $params['frm_custom_css']; | |
| 415 | + $this->default_email = $params['frm_default_email']; | |
| 416 | + $this->from_email = $params['frm_from_email']; | |
| 417 | + $this->currency = $params['frm_currency']; | |
| 351 | 418 | |
| 352 | - $checkboxes = array( 'mu_menu', 're_multi', 'use_html', 'jquery_css', 'accordion_js', 'fade_form', 'no_ips', 'custom_header_ip', 'tracking', 'admin_bar' ); | |
| 419 | + $checkboxes = array( | |
| 420 | + 'mu_menu', | |
| 421 | + 're_multi', | |
| 422 | + 'fade_form', | |
| 423 | + 'no_ips', | |
| 424 | + 'no_gdpr_cookies', | |
| 425 | + 'enable_gdpr', | |
| 426 | + 'custom_header_ip', | |
| 427 | + 'tracking', | |
| 428 | + 'admin_bar', | |
| 429 | + 'summary_emails', | |
| 430 | + 'honeypot', | |
| 431 | + 'wp_spam_check', | |
| 432 | + 'denylist_check', | |
| 433 | + ); | |
| 353 | 434 | foreach ( $checkboxes as $set ) { |
| 354 | 435 | $this->$set = isset( $params[ 'frm_' . $set ] ) ? absint( $params[ 'frm_' . $set ] ) : 0; |
| 355 | 436 | } |
| 356 | 437 | } |
| @@ -366,9 +447,9 @@ | ||
| 366 | 447 | foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
| 367 | 448 | $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' ); |
| 368 | 449 | |
| 369 | 450 | // Make sure administrators always have permissions |
| 370 | - if ( ! in_array( 'administrator', $this->$frm_role ) ) { | |
| 451 | + if ( ! in_array( 'administrator', $this->$frm_role, true ) ) { | |
| 371 | 452 | array_push( $this->$frm_role, 'administrator' ); |
| 372 | 453 | } |
| 373 | 454 | |
| 374 | 455 | foreach ( $roles as $role => $details ) { |
| @@ -378,8 +459,31 @@ | ||
| 378 | 459 | $wp_roles->remove_cap( $role, $frm_role ); |
| 379 | 460 | } |
| 380 | 461 | } |
| 381 | 462 | } |
| 463 | + } | |
| 464 | + | |
| 465 | + /** | |
| 466 | + * Updates a single setting with specified sanitization. | |
| 467 | + * | |
| 468 | + * @since 6.9 | |
| 469 | + * | |
| 470 | + * @param string $key The setting key to update. | |
| 471 | + * @param mixed $value The new value for the setting. | |
| 472 | + * @param string $sanitize The name of the sanitization function to apply to the new value. | |
| 473 | + * @return bool True on success, false on failure. | |
| 474 | + */ | |
| 475 | + public function update_setting( $key, $value, $sanitize ) { | |
| 476 | + if ( ! property_exists( $this, $key ) || ! is_callable( $sanitize ) ) { | |
| 477 | + // Setting does not exist or sanitization function name is not callable. | |
| 478 | + return false; | |
| 479 | + } | |
| 480 | + | |
| 481 | + // Update the property value. | |
| 482 | + FrmAppHelper::sanitize_value( $sanitize, $value ); | |
| 483 | + $this->{$key} = $value; | |
| 484 | + | |
| 485 | + return true; | |
| 382 | 486 | } |
| 383 | 487 | |
| 384 | 488 | /** |
| 385 | 489 | * @return void |