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