PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.8
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.8
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/controllers/FrmStylesController.php +84 -305 6.276.8 View file →
@@ -5,25 +5,22 @@
5 5
6 6 class FrmStylesController {
7 7
8 8 /**
9 - * @var string
9 + * @var string $post_type
10 10 */
11 11 public static $post_type = 'frm_styles';
12 12
13 13 /**
14 - * @var string
14 + * @var string $screen
15 15 */
16 16 public static $screen = 'formidable_page_formidable-styles';
17 17
18 18 /**
19 - * @var string|null
19 + * @var string|null $message
20 20 */
21 21 private static $message;
22 22
23 - /**
24 - * @return void
25 - */
26 23 public static function load_pro_hooks() {
27 24 if ( FrmAppHelper::pro_is_installed() ) {
28 25 FrmProStylesController::load_pro_hooks();
29 26 }
@@ -28,11 +25,8 @@
28 25 FrmProStylesController::load_pro_hooks();
29 26 }
30 27 }
31 28
32 - /**
33 - * @return void
34 - */
35 29 public static function register_post_types() {
36 30 register_post_type(
37 31 self::$post_type,
38 32 array(
@@ -73,10 +67,10 @@
73 67 *
74 68 * @return void
75 69 */
76 70 public static function menu() {
77 - add_submenu_page( 'formidable', 'Formidable | ' . __( 'Styles', 'formidable' ), __( 'Styles', 'formidable' ), 'frm_change_settings', 'formidable-styles', 'FrmStylesController::route' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
78 - add_submenu_page( 'themes.php', 'Formidable | ' . __( 'Styles', 'formidable' ), __( 'Forms', 'formidable' ), 'frm_change_settings', 'formidable-styles2', 'FrmStylesController::route' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
71 + add_submenu_page( 'formidable', 'Formidable | ' . __( 'Styles', 'formidable' ), __( 'Styles', 'formidable' ), 'frm_change_settings', 'formidable-styles', 'FrmStylesController::route' );
72 + add_submenu_page( 'themes.php', 'Formidable | ' . __( 'Styles', 'formidable' ), __( 'Forms', 'formidable' ), 'frm_change_settings', 'formidable-styles2', 'FrmStylesController::route' );
79 73 }
80 74
81 75 /**
82 76 * Remove filters for the visual styler preview.
@@ -101,9 +95,9 @@
101 95 *
102 96 * @return void
103 97 */
104 98 private static function disable_form_css() {
105 - add_filter( 'get_frm_stylesheet', '__return_empty_array' );
99 + add_filter( 'get_frm_stylesheet', '__return_false' );
106 100 }
107 101
108 102 /**
109 103 * Removing this action prevents front end JavaScript from loading.
@@ -125,12 +119,12 @@
125 119 if ( ! FrmAppHelper::is_style_editor_page() ) {
126 120 return;
127 121 }
128 122
129 - FrmStyleComponent::register_assets();
130 123 self::load_pro_hooks();
131 124
132 125 $version = FrmAppHelper::plugin_version();
126 + wp_enqueue_script( 'jquery-ui-datepicker' );
133 127
134 128 if ( FrmAppHelper::is_style_editor_page( 'edit' ) ) {
135 129 wp_enqueue_style( 'wp-color-picker' );
136 130 }
@@ -137,11 +131,10 @@
137 131
138 132 wp_enqueue_style( 'frm-custom-theme', admin_url( 'admin-ajax.php?action=frmpro_css' ), array(), $version );
139 133
140 134 $style = apply_filters( 'frm_style_head', false );
141 -
142 135 if ( $style ) {
143 - wp_enqueue_style( 'frm-single-custom-theme', admin_url( 'admin-ajax.php?action=frmpro_load_css&flat=1' ) . '&' . http_build_query( $style->post_content ), array(), $version ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
136 + wp_enqueue_style( 'frm-single-custom-theme', admin_url( 'admin-ajax.php?action=frmpro_load_css&flat=1' ) . '&' . http_build_query( $style->post_content ), array(), $version );
144 137 }
145 138 }
146 139
147 140 /**
@@ -159,9 +152,9 @@
159 152 'frm_update_settings',
160 153 /**
161 154 * Update the form data on the "Manage Styles" tab after global settings are saved.
162 155 */
163 - function () {
156 + function() {
164 157 self::manage_styles();
165 158 }
166 159 );
167 160 }
@@ -168,9 +161,8 @@
168 161
169 162 /**
170 163 * @param string $register Either 'enqueue' or 'register'.
171 164 * @param bool $force True to enqueue/register the style if a form has not been loaded.
172 - *
173 165 * @return void
174 166 */
175 167 public static function enqueue_css( $register = 'enqueue', $force = false ) {
176 168 global $frm_vars;
@@ -182,9 +174,8 @@
182 174 return;
183 175 }
184 176
185 177 $frm_settings = FrmAppHelper::get_settings();
186 -
187 178 if ( $frm_settings->load_style === 'none' ) {
188 179 return;
189 180 }
190 181
@@ -200,10 +191,9 @@
200 191 wp_register_style( $css_key, $file, array(), $this_version );
201 192 }
202 193
203 194 $load_on_all = ! FrmAppHelper::is_admin() && 'all' === $frm_settings->load_style;
204 -
205 - if ( $load_on_all || $register !== 'register' ) {
195 + if ( $load_on_all || $register != 'register' ) {
206 196 wp_enqueue_style( $css_key );
207 197 }
208 198 unset( $css_key, $file );
209 199 }
@@ -233,20 +223,17 @@
233 223 }
234 224
235 225 /**
236 226 * @param array $stylesheet_urls
237 - *
238 227 * @return void
239 228 */
240 229 private static function get_url_to_custom_style( &$stylesheet_urls ) {
241 230 $file_name = '/css/' . self::get_file_name();
242 -
243 231 if ( is_readable( FrmAppHelper::plugin_path() . $file_name ) ) {
244 232 $url = FrmAppHelper::plugin_url() . $file_name;
245 233 } else {
246 234 $url = admin_url( 'admin-ajax.php?action=frmpro_css' );
247 235 }
248 -
249 236 $stylesheet_urls['formidable'] = $url;
250 237 }
251 238
252 239 /**
@@ -252,30 +239,23 @@
252 239 /**
253 240 * Use a different stylesheet per site in a multisite install
254 241 *
255 242 * @since 3.0.03
256 - *
257 - * @return string
258 243 */
259 244 public static function get_file_name() {
260 245 if ( is_multisite() ) {
261 246 $blog_id = get_current_blog_id();
262 - return 'formidableforms' . absint( $blog_id ) . '.css';
247 + $name = 'formidableforms' . absint( $blog_id ) . '.css';
248 + } else {
249 + $name = 'formidableforms.css';
263 250 }
264 251
265 - return 'formidableforms.css';
252 + return $name;
266 253 }
267 254
268 - /**
269 - * @param string $css_key
270 - * @param string $version
271 - *
272 - * @return string
273 - */
274 255 private static function get_css_version( $css_key, $version ) {
275 - if ( 'formidable' === $css_key ) {
256 + if ( 'formidable' == $css_key ) {
276 257 $this_version = get_option( 'frm_last_style_update' );
277 -
278 258 if ( ! $this_version ) {
279 259 $this_version = $version;
280 260 }
281 261 } else {
@@ -284,17 +264,14 @@
284 264
285 265 return $this_version;
286 266 }
287 267
288 - /**
289 - * @param string $tag
290 - * @param string $handle
291 - *
292 - * @return string
293 - */
294 268 public static function add_tags_to_css( $tag, $handle ) {
295 - if ( ( 'formidable' === $handle || 'jquery-theme' === $handle ) && ! str_contains( $tag, ' property=' ) ) {
296 - $tag = str_replace( ' type="', ' property="stylesheet" type="', $tag );
269 + if ( ( 'formidable' == $handle || 'jquery-theme' == $handle ) && strpos( $tag, ' property=' ) === false ) {
270 + $frm_settings = FrmAppHelper::get_settings();
271 + if ( $frm_settings->use_html ) {
272 + $tag = str_replace( ' type="', ' property="stylesheet" type="', $tag );
273 + }
297 274 }
298 275
299 276 return $tag;
300 277 }
@@ -342,35 +319,20 @@
342 319
343 320 self::setup_styles_and_scripts_for_styler();
344 321
345 322 $style_id = self::get_style_id_for_styler();
346 -
347 323 if ( ! $style_id ) {
348 - $error_args = array(
349 - 'title' => __( 'No styles', 'formidable' ),
350 - 'body' => __( 'You must have a style to use the Visual Styler.', 'formidable' ),
351 - 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
352 - );
353 - FrmAppController::show_error_modal( $error_args );
354 - return;
324 + wp_die( esc_html__( 'Invalid route', 'formidable' ), esc_html__( 'Invalid route', 'formidable' ), 400 );
355 325 }
356 326
357 327 $form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 );
358 -
359 328 if ( ! $form_id ) {
360 329 $form_id = self::get_form_id_for_style( $style_id );
361 330 }
362 331
363 332 $form = FrmForm::getOne( $form_id );
364 -
365 333 if ( ! is_object( $form ) ) {
366 - $error_args = array(
367 - 'title' => __( 'No forms', 'formidable' ),
368 - 'body' => __( 'You must have a form to use the Visual Styler.', 'formidable' ),
369 - 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
370 - );
371 - FrmAppController::show_error_modal( $error_args );
372 - return;
334 + wp_die( esc_html__( 'Invalid route', 'formidable' ), esc_html__( 'Invalid route', 'formidable' ), 400 );
373 335 }
374 336
375 337 $frm_style = new FrmStyle( $style_id );
376 338 $active_style = $frm_style->get_one();
@@ -380,9 +342,11 @@
380 342
381 343 /**
382 344 * @since 6.0
383 345 *
384 - * @param array{form:\stdClass} $data
346 + * @param array {
347 + * @type stdClass $form
348 + * }
385 349 */
386 350 do_action( 'frm_before_render_style_page', compact( 'form' ) );
387 351
388 352 self::render_style_page( $active_style, $form, $default_style );
@@ -394,9 +358,8 @@
394 358 * @return int
395 359 */
396 360 private static function get_style_id_for_styler() {
397 361 $action = FrmAppHelper::simple_get( 'frm_action' );
398 -
399 362 if ( 'duplicate' === $action ) {
400 363 // The duplicate action uses style_id instead of id for better backward compatibility.
401 364 return FrmAppHelper::simple_get( 'style_id', 'absint', 0 );
402 365 }
@@ -401,9 +364,8 @@
401 364 return FrmAppHelper::simple_get( 'style_id', 'absint', 0 );
402 365 }
403 366
404 367 $style_id = FrmAppHelper::simple_get( 'id', 'absint', 0 );
405 -
406 368 if ( $style_id ) {
407 369 // Always use the style ID from the URL if one is specified.
408 370 return $style_id;
409 371 }
@@ -408,9 +370,8 @@
408 370 return $style_id;
409 371 }
410 372
411 373 $request_form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 );
412 -
413 374 if ( $request_form_id && is_callable( 'FrmProStylesController::get_active_style_for_form' ) ) {
414 375 return FrmProStylesController::get_active_style_for_form( $request_form_id )->ID;
415 376 }
416 377
@@ -422,9 +383,8 @@
422 383 *
423 384 * @since 6.0
424 385 *
425 386 * @param int $style_id
426 - *
427 387 * @return int
428 388 */
429 389 private static function get_form_id_for_style( $style_id ) {
430 390 $check = serialize( array( 'custom_style' => (string) $style_id ) );
@@ -437,10 +397,11 @@
437 397 )
438 398 );
439 399
440 400 if ( ! $form_id ) {
401 + // TODO: Show a message why a random form is being shown (because no form is assigned to the style).
441 402 // Fallback to any form.
442 - $where = array(
403 + $where = array(
443 404 'status' => 'published',
444 405 // Make sure it's not a repeater.
445 406 'parent_form_id' => array( null, 0 ),
446 407 );
@@ -457,9 +418,9 @@
457 418 */
458 419 private static function disable_admin_page_styling_on_submit_buttons() {
459 420 add_filter(
460 421 'frm_submit_button_class',
461 - function ( $classes ) {
422 + function( $classes ) {
462 423 $classes[] = 'frm_no_style_button';
463 424 return $classes;
464 425 }
465 426 );
@@ -470,10 +431,11 @@
470 431 *
471 432 * @return WP_Post
472 433 */
473 434 private static function get_default_style() {
474 - $frm_style = new FrmStyle( 'default' );
475 - return $frm_style->get_one();
435 + $frm_style = new FrmStyle( 'default' );
436 + $default_style = $frm_style->get_one();
437 + return $default_style;
476 438 }
477 439
478 440 /**
479 441 * Save style for form (from Styler list page) via a POST action.
@@ -483,15 +445,13 @@
483 445 * @return void
484 446 */
485 447 private static function save_form_style() {
486 448 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form_style', 'frm_save_form_style_nonce' );
487 -
488 449 if ( $permission_error !== false ) {
489 450 wp_die( 'Unable to save form', '', 403 );
490 451 }
491 452
492 453 $style_id = FrmAppHelper::get_post_param( 'style_id', 0, 'absint' );
493 -
494 454 if ( $style_id && ! self::confirm_style_exists_before_setting( $style_id ) ) {
495 455 wp_die( esc_html__( 'Invalid target style', 'formidable' ), esc_html__( 'Invalid target style', 'formidable' ), 400 );
496 456 return;
497 457 }
@@ -504,16 +464,15 @@
504 464 * @param int $style_id
505 465 */
506 466 $style_id = apply_filters( 'frm_saved_form_style_id', $style_id );
507 467
508 - if ( ! $style_id && '0' !== FrmAppHelper::get_post_param( 'style_id', '', 'sanitize_text_field' ) ) {
468 + if ( ! $style_id && '0' !== FrmAppHelper::get_post_param( 'style_id', 'sanitize_text_field', '' ) ) {
509 469 // "0" is a special value used for the enable/disable toggle.
510 470 wp_die( esc_html__( 'Invalid style value', 'formidable' ), esc_html__( 'Invalid style value', 'formidable' ), 400 );
511 471 return;
512 472 }
513 473
514 - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
515 -
474 + $form_id = FrmAppHelper::get_post_param( 'form_id', 'absint', 0 );
516 475 if ( ! $form_id ) {
517 476 wp_die( esc_html__( 'No form specified', 'formidable' ), esc_html__( 'No form specified', 'formidable' ), 400 );
518 477 return;
519 478 }
@@ -518,21 +477,17 @@
518 477 return;
519 478 }
520 479
521 480 $form = FrmForm::getOne( $form_id );
522 -
523 481 if ( ! $form ) {
524 482 wp_die( esc_html__( 'Form does not exist', 'formidable' ), esc_html__( 'Form does not exist', 'formidable' ), 400 );
525 483 return;
526 484 }
527 485
528 - $previous_style_id = $form->options['custom_style'];
529 -
530 486 // If the default style is selected, use the "Always use default" legacy option instead of the default style.
531 487 // There's also a check here for conversational forms.
532 488 // Without the check it isn't possible to select "Default" because "Always use default" will convert to "Lines" dynamically.
533 489 $default_style = self::get_default_style();
534 -
535 490 if ( $style_id === $default_style->ID && empty( $form->options['chat'] ) ) {
536 491 $style_id = 1;
537 492 }
538 493
@@ -538,27 +493,13 @@
538 493
539 494 // We want to save a string for consistency. FrmStylesHelper::get_form_count_for_style expects the custom style ID is a string.
540 495 $form->options['custom_style'] = (string) $style_id;
541 496
542 - if ( $previous_style_id === $form->options['custom_style'] ) {
543 - // Exit early before updating DB if nothing actually changed.
544 - self::$message = __( 'Successfully updated style.', 'formidable' );
545 - return;
546 - }
547 -
548 497 global $wpdb;
549 498 $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) );
550 499
551 500 FrmForm::clear_form_cache();
552 501
553 - /**
554 - * @since 6.25.1
555 - *
556 - * @param int $form_id
557 - * @param int $style_id
558 - */
559 - do_action( 'frm_after_changed_form_style', absint( $form_id ), absint( $style_id ) );
560 -
561 502 self::$message = __( 'Successfully updated style.', 'formidable' );
562 503 }
563 504
564 505 /**
@@ -564,9 +505,8 @@
564 505 /**
565 506 * Validate that we're assigning a form to a style that actually exists before assigning it to a form.
566 507 *
567 508 * @param int $style_id
568 - *
569 509 * @return bool True if the style actually exists.
570 510 */
571 511 private static function confirm_style_exists_before_setting( $style_id ) {
572 512 global $wpdb;
@@ -585,9 +525,9 @@
585 525 $plugin_url = FrmAppHelper::plugin_url();
586 526 $version = FrmAppHelper::plugin_version();
587 527 $js_dependencies = array( 'wp-i18n', 'wp-hooks', 'formidable_dom' );
588 528
589 - if ( FrmAppHelper::pro_is_installed() && is_callable( 'FrmProAppHelper::use_jquery_datepicker' ) && FrmProAppHelper::use_jquery_datepicker() ) {
529 + if ( FrmAppHelper::pro_is_installed() ) {
590 530 $js_dependencies[] = 'jquery-ui-datepicker';
591 531 }
592 532
593 533 wp_register_script( 'formidable_style', $plugin_url . '/js/admin/style.js', $js_dependencies, $version );
@@ -595,9 +535,8 @@
595 535 wp_print_styles( 'formidable_style' );
596 536
597 537 wp_print_styles( 'formidable' );
598 538 wp_enqueue_script( 'formidable_style' );
599 - wp_set_script_translations( 'formidable_style', 'formidable' );
600 539 }
601 540
602 541 /**
603 542 * Render the style page (with a more limited and typed scope than calling it from self::style directly).
@@ -606,9 +545,8 @@
606 545 *
607 546 * @param stdClass|WP_Post $active_style
608 547 * @param stdClass $form
609 548 * @param WP_Post $default_style
610 - *
611 549 * @return void
612 550 */
613 551 private static function render_style_page( $active_style, $form, $default_style ) {
614 552 $style_views_path = self::get_views_path();
@@ -682,23 +620,22 @@
682 620 * Filter form classes so the form uses the preview style, not the form's active style.
683 621 *
684 622 * @since 6.0
685 623 *
686 - * @param stdClass|WP_Post $style A new style is not a WP_Post object.
687 - *
624 + * @param WP_Post|stdClass $style A new style is not a WP_Post object.
688 625 * @return void
689 626 */
690 627 private static function force_form_style( $style ) {
691 628 add_filter(
692 629 'frm_add_form_style_class',
693 - function ( $class ) use ( $style ) {
694 - $split = array_filter(
630 + function( $class ) use ( $style ) {
631 + $split = array_filter(
695 632 explode( ' ', $class ),
696 633 /**
697 634 * @param string $class
698 635 */
699 - function ( $class ) {
700 - return $class && ! str_starts_with( $class, 'frm_style_' );
636 + function( $class ) {
637 + return $class && 0 !== strpos( $class, 'frm_style_' );
701 638 }
702 639 );
703 640 $split[] = 'frm_style_' . $style->post_name;
704 641 return implode( ' ', $split );
@@ -714,8 +651,9 @@
714 651 * @return void
715 652 */
716 653 public static function save_style() {
717 654 $frm_style = new FrmStyle();
655 + $message = '';
718 656 $post_id = FrmAppHelper::get_post_param( 'ID', false, 'sanitize_title' );
719 657 $style_nonce = FrmAppHelper::get_post_param( 'frm_style', '', 'sanitize_text_field' );
720 658
721 659 if ( $post_id === false || ! wp_verify_nonce( $style_nonce, 'frm_style_nonce' ) ) {
@@ -724,9 +662,8 @@
724 662 return;
725 663 }
726 664
727 665 $id = $frm_style->update( $post_id );
728 -
729 666 if ( ! $post_id && $id ) {
730 667 self::maybe_redirect_after_save( $id );
731 668 // Set the post id to the new style so it will be loaded for editing.
732 669 $post_id = reset( $id );
@@ -731,15 +668,8 @@
731 668 // Set the post id to the new style so it will be loaded for editing.
732 669 $post_id = reset( $id );
733 670 }
734 671
735 - /**
736 - * @since 6.25.1
737 - *
738 - * @param int $post_id
739 - */
740 - do_action( 'frm_after_saved_style', absint( $post_id ) );
741 -
742 672 self::$message = __( 'Your styling settings have been saved.', 'formidable' );
743 673 }
744 674
745 675 /**
@@ -758,20 +688,19 @@
758 688 *
759 689 * @since 6.0
760 690 *
761 691 * @param array $ids
762 - *
763 692 * @return void
764 693 */
765 694 private static function maybe_redirect_after_save( $ids ) {
766 - $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
767 - $parsed = parse_url( $referer );
768 - $query = $parsed['query'];
695 + $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
696 + $parsed = parse_url( $referer );
697 + $query = $parsed['query'];
698 +
769 699 $current_action = false;
770 700 $actions_to_redirect = array( 'duplicate', 'new_style' );
771 -
772 701 foreach ( $actions_to_redirect as $action ) {
773 - if ( str_contains( $query, 'frm_action=' . $action ) ) {
702 + if ( false !== strpos( $query, 'frm_action=' . $action ) ) {
774 703 $current_action = $action;
775 704 break;
776 705 }
777 706 }
@@ -781,9 +710,10 @@
781 710 return;
782 711 }
783 712
784 713 parse_str( $query, $parsed_query );
785 - $form_id = ! empty( $parsed_query['form'] ) ? absint( $parsed_query['form'] ) : 0;
714 + $form_id = ! empty( $parsed_query['form'] ) ? absint( $parsed_query['form'] ) : 0;
715 +
786 716 $style = new stdClass();
787 717 $style->ID = end( $ids );
788 718 wp_safe_redirect( esc_url_raw( FrmStylesHelper::get_edit_url( $style, $form_id ) ) );
789 719 die();
@@ -793,9 +723,8 @@
793 723 * @since 6.0
794 724 *
795 725 * @param string $message
796 726 * @param array|object $forms
797 - *
798 727 * @return void
799 728 */
800 729 public static function manage( $message = '', $forms = array() ) {
801 730 $frm_style = new FrmStyle();
@@ -800,9 +729,8 @@
800 729 public static function manage( $message = '', $forms = array() ) {
801 730 $frm_style = new FrmStyle();
802 731 $styles = $frm_style->get_all();
803 732 $default_style = $frm_style->get_default_style( $styles );
804 - $frm_settings = FrmAppHelper::get_settings();
805 733
806 734 if ( ! $forms ) {
807 735 $forms = FrmForm::get_published_forms();
808 736 }
@@ -819,16 +747,15 @@
819 747 private static function manage_styles() {
820 748 global $wpdb;
821 749
822 750 $forms = FrmForm::get_published_forms();
823 -
824 751 foreach ( $forms as $form ) {
825 - if ( ! isset( $_POST['style'] ) || ! isset( $_POST['style'][ $form->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
752 + $new_style = ( isset( $_POST['style'] ) && isset( $_POST['style'][ $form->id ] ) ) ? sanitize_text_field( wp_unslash( $_POST['style'][ $form->id ] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
753 + $previous_style = ( isset( $_POST['prev_style'] ) && isset( $_POST['prev_style'][ $form->id ] ) ) ? sanitize_text_field( wp_unslash( $_POST['prev_style'][ $form->id ] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
754 + if ( $new_style == $previous_style ) {
826 755 continue;
827 756 }
828 757
829 - $new_style = sanitize_text_field( wp_unslash( $_POST['style'][ $form->id ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
830 -
831 758 $form->options['custom_style'] = $new_style;
832 759 $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) );
833 760 unset( $form );
834 761 }
@@ -837,28 +764,15 @@
837 764 /**
838 765 * Echo content for the Custom CSS page.
839 766 *
840 767 * @param string $message
841 - * @param array $extra_args An array of extra arguments.
842 - *
843 768 * @return void
844 769 */
845 - public static function custom_css( $message = '', $extra_args = array() ) {
846 - $id = $extra_args['id'] ?? 'frm_codemirror_box';
847 - $settings = self::enqueue_codemirror( $id, $extra_args['placeholder'] ?? '' );
848 - $id = $settings ? $id : 'frm_custom_css_box';
849 - $show_errors = $extra_args['show_errors'] ?? true;
850 - $custom_css = $extra_args['custom_css'] ?? self::get_custom_css();
851 - $heading = $extra_args['heading'] ?? __( 'You can add custom css here or in your theme style.css. Any CSS added here will be used anywhere the Formidable CSS is loaded.', 'formidable' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
852 - $textarea_params = ! empty( $extra_args['textarea_params'] ) ? $extra_args['textarea_params'] : array(
853 - 'name' => 'frm_custom_css',
854 - 'id' => $id,
855 - );
770 + public static function custom_css( $message = '' ) {
771 + $settings = self::enqueue_codemirror();
772 + $id = $settings ? 'frm_codemirror_box' : 'frm_custom_css_box';
773 + $custom_css = self::get_custom_css();
856 774
857 - if ( $settings ) {
858 - $textarea_params['class'] = 'hide-if-js';
859 - }
860 -
861 775 include FrmAppHelper::plugin_path() . '/classes/views/styles/custom_css.php';
862 776 }
863 777
864 778 /**
@@ -865,33 +779,22 @@
865 779 * Get custom CSS code entered in the Custom CSS page.
866 780 *
867 781 * @since 6.0
868 782 *
869 - * @param array|null $single_style_settings The single style settings.
870 - *
871 783 * @return string
872 784 */
873 - public static function get_custom_css( $single_style_settings = null ) {
874 - if ( $single_style_settings ) {
875 - // If the single style settings are passed, return the custom CSS from the single style settings.
876 - if ( ! empty( $single_style_settings['single_style_custom_css'] ) && ! empty( $single_style_settings['enable_style_custom_css'] ) ) {
877 - return $single_style_settings['single_style_custom_css'];
878 - }
879 -
880 - return '';
881 - }
882 -
785 + public static function get_custom_css() {
883 786 $settings = FrmAppHelper::get_settings();
884 -
885 787 if ( is_string( $settings->custom_css ) ) {
886 788 return $settings->custom_css;
887 789 }
888 790
889 791 // If it does not exist, check the default style as a fallback.
890 - $frm_style = new FrmStyle();
891 - $style = $frm_style->get_default_style();
792 + $frm_style = new FrmStyle();
793 + $style = $frm_style->get_default_style();
794 + $custom_css = $style->post_content['custom_css'];
892 795
893 - return $style->post_content['custom_css'];
796 + return $custom_css;
894 797 }
895 798
896 799 /**
897 800 * Enqueue assets for codemirror, built into WordPress since 4.9.
@@ -898,14 +801,11 @@
898 801 * The Custom CSS page uses codemirror.
899 802 *
900 803 * @since 6.0 Previously this code was embedded in self::custom_css.
901 804 *
902 - * @param string $id The ID of the codemirror box.
903 - * @param string $placeholder The placeholder text for the codemirror box.
904 - *
905 805 * @return array|false
906 806 */
907 - private static function enqueue_codemirror( $id = 'frm_codemirror_box', $placeholder = '' ) {
807 + private static function enqueue_codemirror() {
908 808 if ( ! function_exists( 'wp_enqueue_code_editor' ) ) {
909 809 // The WordPress version is likely older than 4.9.
910 810 return false;
911 811 }
@@ -918,9 +818,8 @@
918 818 'tabSize' => 2,
919 819 // As the codemirror box only appears once you click into the Custom CSS tab, we need to auto-refresh.
920 820 // Otherwise the line numbers all end up with a 1px width causing overlap issues with the text in the content.
921 821 'autoRefresh' => true,
922 - 'placeholder' => $placeholder,
923 822 ),
924 823 )
925 824 );
926 825
@@ -927,11 +826,9 @@
927 826 if ( $settings ) {
928 827 wp_add_inline_script(
929 828 'code-editor',
930 829 sprintf(
931 - 'jQuery( function() { window.%s_wp_editor = wp.codeEditor.initialize( \'%s\', %s ); } );',
932 - $id,
933 - $id,
830 + 'jQuery( function() { wp.codeEditor.initialize( \'frm_codemirror_box\', %s ); } );',
934 831 wp_json_encode( $settings )
935 832 )
936 833 );
937 834 }
@@ -983,9 +880,8 @@
983 880 FrmAppHelper::permission_check( 'frm_change_settings' );
984 881 check_ajax_referer( 'frm_ajax', 'nonce' );
985 882
986 883 $style_id = FrmAppHelper::get_post_param( 'style_id', '', 'absint' );
987 -
988 884 if ( ! $style_id ) {
989 885 // A style ID is not sent when resetting on the edit page.
990 886 // Instead of resetting the style, send the defaults back so the inputs can be updated with JavaScript.
991 887 $frm_style = new FrmStyle();
@@ -993,26 +889,23 @@
993 889 echo json_encode( $defaults );
994 890 wp_die();
995 891 }
996 892
997 - $frm_style = new FrmStyle();
998 - $default_template_style = $frm_style->get_default_template_style( $style_id );
999 - $where = array(
893 + $frm_style = new FrmStyle();
894 + $defaults = $frm_style->get_defaults();
895 + $default_post_content = FrmAppHelper::prepare_and_encode( $defaults );
896 + $where = array(
1000 897 'ID' => $style_id,
1001 898 'post_type' => self::$post_type,
1002 899 );
1003 -
1004 - $style_object = $frm_style->get_new();
1005 - $style_object->post_content = json_decode( $default_template_style, true );
1006 -
1007 900 global $wpdb;
1008 - $wpdb->update( $wpdb->posts, array( 'post_content' => $default_template_style ), $where );
901 + $wpdb->update( $wpdb->posts, array( 'post_content' => $default_post_content ), $where );
1009 902
1010 903 // Save the settings after resetting to default or the old style will still appear.
1011 904 $frm_style->save_settings();
1012 905
1013 906 $data = array(
1014 - 'style' => FrmStylesCardHelper::get_style_param_for_card( $style_object ),
907 + 'style' => FrmStylesCardHelper::get_style_param_for_card( $frm_style->get_new() ),
1015 908 );
1016 909 wp_send_json_success( $data );
1017 910 wp_die();
1018 911 }
@@ -1027,10 +920,9 @@
1027 920 public static function change_styling() {
1028 921 FrmAppHelper::permission_check( 'frm_change_settings' );
1029 922 check_ajax_referer( 'frm_ajax', 'nonce' );
1030 923
1031 - $is_loaded_via_ajax = true;
1032 - $frm_style = new FrmStyle();
924 + $frm_style = new FrmStyle();
1033 925
1034 926 // Intentionally avoid defaults here so nothing gets removed from our style.
1035 927 $defaults = array();
1036 928 $style = '';
@@ -1076,9 +968,8 @@
1076 968
1077 969 /**
1078 970 * @param array $atts
1079 971 * @param array $sec
1080 - *
1081 972 * @return void
1082 973 */
1083 974 public static function include_style_section( $atts, $sec ) {
1084 975 extract( $atts ); // phpcs:ignore WordPress.PHP.DontExtract
@@ -1141,9 +1032,9 @@
1141 1032 }
1142 1033
1143 1034 /**
1144 1035 * Add an extra style rule to hide a broken style warning.
1145 - * To avoid cluttering the front end with any unnecessary styles this is only added when the referer URL matches the styler.
1036 + * To avoid cluttering the front end with any unecessary styles this is only added when the referer URL matches the styler.
1146 1037 *
1147 1038 * @since 6.2.3
1148 1039 *
1149 1040 * @return void
@@ -1149,10 +1040,9 @@
1149 1040 * @return void
1150 1041 */
1151 1042 public static function maybe_hide_sample_form_error_message() {
1152 1043 $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
1153 -
1154 - if ( str_contains( $referer, 'admin.php?page=formidable-styles' ) ) {
1044 + if ( false !== strpos( $referer, 'admin.php?page=formidable-styles' ) ) {
1155 1045 echo '#frm_broken_styles_warning { display: none; }';
1156 1046 }
1157 1047 }
1158 1048
@@ -1161,9 +1051,8 @@
1161 1051 *
1162 1052 * @since 4.11.03
1163 1053 *
1164 1054 * @param string $css CSS content.
1165 - *
1166 1055 * @return string
1167 1056 */
1168 1057 public static function replace_relative_url( $css ) {
1169 1058 $plugin_url = trailingslashit( FrmAppHelper::plugin_url() );
@@ -1186,22 +1075,19 @@
1186 1075 * Check if the Formidable styling should be loaded,
1187 1076 * then enqueue it for the footer
1188 1077 *
1189 1078 * @since 2.0
1190 - *
1191 - * @return void
1192 1079 */
1193 1080 public static function enqueue_style() {
1194 1081 global $frm_vars;
1195 1082
1196 - if ( ! empty( $frm_vars['css_loaded'] ) ) {
1083 + if ( isset( $frm_vars['css_loaded'] ) && $frm_vars['css_loaded'] ) {
1197 1084 // The CSS has already been loaded.
1198 1085 return;
1199 1086 }
1200 1087
1201 1088 $frm_settings = FrmAppHelper::get_settings();
1202 -
1203 - if ( $frm_settings->load_style !== 'none' ) {
1089 + if ( $frm_settings->load_style != 'none' ) {
1204 1090 wp_enqueue_style( 'formidable' );
1205 1091 $frm_vars['css_loaded'] = true;
1206 1092 }
1207 1093 }
@@ -1212,23 +1098,23 @@
1212 1098 * @return array<WP_Post>
1213 1099 */
1214 1100 public static function get_style_opts() {
1215 1101 $frm_style = new FrmStyle();
1216 - return $frm_style->get_all();
1102 + $styles = $frm_style->get_all();
1103 +
1104 + return $styles;
1217 1105 }
1218 1106
1219 1107 /**
1220 1108 * Get the style post object for a target form.
1221 1109 *
1222 - * @param bool|object|string $form
1223 - *
1110 + * @param object|string|boolean $form
1224 1111 * @return WP_Post|null
1225 1112 */
1226 1113 public static function get_form_style( $form = 'default' ) {
1227 1114 $style = FrmFormsHelper::get_form_style( $form );
1228 1115
1229 - // phpcs:ignore Universal.Operators.StrictComparisons
1230 - if ( ! $style || 1 == $style ) {
1116 + if ( empty( $style ) || 1 == $style ) {
1231 1117 $style = 'default';
1232 1118 }
1233 1119
1234 1120 $frm_style = new FrmStyle( $style );
@@ -1237,13 +1123,10 @@
1237 1123
1238 1124 /**
1239 1125 * @param string $class
1240 1126 * @param string $style
1241 - *
1242 - * @return string
1243 1127 */
1244 1128 public static function get_form_style_class( $class, $style ) {
1245 - // phpcs:ignore Universal.Operators.StrictComparisons
1246 1129 if ( 1 == $style ) {
1247 1130 $style = 'default';
1248 1131 }
1249 1132
@@ -1258,18 +1141,15 @@
1258 1141 return $class;
1259 1142 }
1260 1143
1261 1144 /**
1262 - * @since 3.0
1263 - *
1264 1145 * @param object $style
1265 1146 * @param string $class
1266 1147 *
1267 - * @return void
1148 + * @since 3.0
1268 1149 */
1269 1150 private static function maybe_add_rtl_class( $style, &$class ) {
1270 1151 $is_rtl = isset( $style->post_content['direction'] ) && 'rtl' === $style->post_content['direction'];
1271 -
1272 1152 if ( $is_rtl ) {
1273 1153 $class .= ' frm_rtl';
1274 1154 }
1275 1155 }
@@ -1274,28 +1154,17 @@
1274 1154 }
1275 1155 }
1276 1156
1277 1157 /**
1278 - * @param string $val Style setting key.
1279 - * @param int|string $form Form ID or 'default'.
1280 - *
1281 - * @return mixed
1158 + * @param string $val
1282 1159 */
1283 1160 public static function get_style_val( $val, $form = 'default' ) {
1284 1161 $style = self::get_form_style( $form );
1285 -
1286 1162 if ( $style && isset( $style->post_content[ $val ] ) ) {
1287 1163 return $style->post_content[ $val ];
1288 1164 }
1289 -
1290 - return null;
1291 1165 }
1292 1166
1293 - /**
1294 - * @param array $default_styles
1295 - *
1296 - * @return array
1297 - */
1298 1167 public static function show_entry_styles( $default_styles ) {
1299 1168 $frm_style = new FrmStyle( 'default' );
1300 1169 $style = $frm_style->get_one();
1301 1170
@@ -1304,15 +1173,13 @@
1304 1173 }
1305 1174
1306 1175 foreach ( $default_styles as $name => $val ) {
1307 1176 $setting = $name;
1308 -
1309 - if ( 'border_width' === $name ) {
1177 + if ( 'border_width' == $name ) {
1310 1178 $setting = 'field_border_width';
1311 - } elseif ( 'alt_bg_color' === $name ) {
1179 + } elseif ( 'alt_bg_color' == $name ) {
1312 1180 $setting = 'bg_color_active';
1313 1181 }
1314 -
1315 1182 $default_styles[ $name ] = $style->post_content[ $setting ];
1316 1183 unset( $name, $val );
1317 1184 }
1318 1185
@@ -1318,101 +1185,16 @@
1318 1185
1319 1186 return $default_styles;
1320 1187 }
1321 1188
1322 - /**
1323 - * @param string $important
1324 - * @param array $field
1325 - *
1326 - * @return string
1327 - */
1328 1189 public static function &important_style( $important, $field ) {
1329 1190 $important = self::get_style_val( 'important_style', $field['form_id'] );
1191 +
1330 1192 return $important;
1331 1193 }
1332 1194
1333 - /**
1334 - * Duplicate of WordPress do_accordion_section function, it adds an additional svg icon support.
1335 - *
1336 - * @since 6.8.3
1337 - *
1338 - * @param string|WP_Screen $screen Screen ID or screen object.
1339 - * @param string $context Meta box context.
1340 - * @param mixed $data_object Data object passed to callbacks.
1341 - *
1342 - * @return int
1343 - */
1344 - public static function do_accordion_sections( $screen, $context, $data_object ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
1345 - global $wp_meta_boxes;
1346 -
1347 - // the symbol id from icons.svg
1348 - $icon_ids = array(
1349 - 'ranking-fields-style' => 'frm_chart_bar_icon',
1350 - 'section-fields-style' => 'frm-form-title-style',
1351 - );
1352 -
1353 - wp_enqueue_script( 'accordion' );
1354 -
1355 - if ( ! $screen ) {
1356 - $screen = get_current_screen();
1357 - } elseif ( is_string( $screen ) ) {
1358 - $screen = convert_to_screen( $screen );
1359 - }
1360 -
1361 - $page = $screen->id;
1362 -
1363 - ?>
1364 - <div id="side-sortables" class="accordion-container">
1365 - <ul class="outer-border">
1366 - <?php
1367 - $i = 0;
1368 - $first_open = false;
1369 -
1370 - if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
1371 - foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
1372 - if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
1373 - foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
1374 - if ( false === $box || ! $box['title'] ) {
1375 - continue;
1376 - }
1377 -
1378 - ++$i;
1379 - $icon_id = array_key_exists( $box['id'], $icon_ids ) ? $icon_ids[ $box['id'] ] : 'frm-' . $box['id'];
1380 - $open_class = '';
1381 -
1382 - if ( ! $first_open ) {
1383 - $first_open = true;
1384 - $open_class = 'open';
1385 - }
1386 -
1387 - $accordion_content_id = 'frm_style_section_' . $box['id'];
1388 - ?>
1389 - <li class="control-section accordion-section <?php echo esc_attr( $open_class ); ?> <?php echo esc_attr( $box['id'] ); ?>" id="<?php echo esc_attr( $box['id'] ); ?>"><?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?>
1390 - <h3 class="accordion-section-title hndle">
1391 - <?php
1392 - FrmAppHelper::icon_by_class( 'frmfont ' . $icon_id . ' frm_svg24' );
1393 - echo esc_html( $box['title'] );
1394 - ?>
1395 - <button type="button" aria-expanded="<?php echo esc_attr( 'open' === $open_class ? 'true' : 'false' ); ?>" aria-controls="<?php echo esc_attr( $accordion_content_id ); ?>" aria-label="<?php echo esc_attr( $box['title'] ); ?>"><?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?>
1396 - <?php FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown8_icon' ); ?>
1397 - </button>
1398 - </h3>
1399 - <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>" id="<?php echo esc_attr( $accordion_content_id ); ?>">
1400 - <div class="inside">
1401 - <?php call_user_func( $box['callback'], $data_object, $box ); ?>
1402 - </div><!-- .inside -->
1403 - </div><!-- .accordion-section-content -->
1404 - </li><!-- .accordion-section -->
1405 - <?php
1406 - }//end foreach
1407 - }//end if
1408 - }//end foreach
1409 - }//end if
1410 - ?>
1411 - </ul><!-- .outer-border -->
1412 - </div><!-- .accordion-container -->
1413 - <?php
1414 - return $i;
1195 + public static function do_accordion_sections( $screen, $context, $object ) {
1196 + return do_accordion_sections( $screen, $context, $object );
1415 1197 }
1416 1198
1417 1199 /**
1418 1200 * Rename a style via an AJAX action.
@@ -1422,9 +1204,8 @@
1422 1204 * @return void
1423 1205 */
1424 1206 public static function rename_style() {
1425 1207 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'nonce', 'frm_ajax' );
1426 -
1427 1208 if ( $permission_error !== false ) {
1428 1209 $data = array(
1429 1210 'message' => __( 'Unable to rename style', 'formidable' ),
1430 1211 );
@@ -1443,9 +1224,8 @@
1443 1224 die();
1444 1225 }
1445 1226
1446 1227 $post = get_post( $style_id );
1447 -
1448 1228 if ( ! $post || $post->post_type !== self::$post_type ) {
1449 1229 $data = array(
1450 1230 'message' => __( 'The style you are renaming either does not exist or it is not a style', 'formidable' ),
1451 1231 );
@@ -1466,9 +1246,8 @@
1466 1246 *
1467 1247 * @since 6.0
1468 1248 *
1469 1249 * @param WP_Styles $styles
1470 - *
1471 1250 * @return void
1472 1251 */
1473 1252 public static function disable_conflicting_wp_admin_css( $styles ) {
1474 1253 if ( ! FrmAppHelper::is_style_editor_page() ) {