PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.10
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.10
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 +112 -260 6.296.10 View file →
@@ -19,11 +19,8 @@
19 19 * @var string|null
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 /**
@@ -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,9 +191,8 @@
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 195 if ( $load_on_all || $register !== 'register' ) {
206 196 wp_enqueue_style( $css_key );
207 197 }
208 198 unset( $css_key, $file );
@@ -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,45 +239,44 @@
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 ) {
276 - return $version;
256 + if ( 'formidable' == $css_key ) {
257 + $this_version = get_option( 'frm_last_style_update' );
258 + if ( ! $this_version ) {
259 + $this_version = $version;
260 + }
261 + } else {
262 + $this_version = $version;
277 263 }
278 264
279 - $this_version = get_option( 'frm_last_style_update' );
280 -
281 - return $this_version ? $this_version : $version;
265 + return $this_version;
282 266 }
283 267
284 268 /**
285 269 * @param string $tag
286 270 * @param string $handle
287 - *
288 271 * @return string
289 272 */
290 273 public static function add_tags_to_css( $tag, $handle ) {
291 - if ( ( 'formidable' === $handle || 'jquery-theme' === $handle ) && ! str_contains( $tag, ' property=' ) ) {
292 - return str_replace( ' type="', ' property="stylesheet" type="', $tag );
274 + if ( ( 'formidable' === $handle || 'jquery-theme' === $handle ) && strpos( $tag, ' property=' ) === false ) {
275 + $frm_settings = FrmAppHelper::get_settings();
276 + if ( $frm_settings->use_html ) {
277 + $tag = str_replace( ' type="', ' property="stylesheet" type="', $tag );
278 + }
293 279 }
294 280
295 281 return $tag;
296 282 }
@@ -338,35 +324,20 @@
338 324
339 325 self::setup_styles_and_scripts_for_styler();
340 326
341 327 $style_id = self::get_style_id_for_styler();
342 -
343 328 if ( ! $style_id ) {
344 - $error_args = array(
345 - 'title' => __( 'No styles', 'formidable' ),
346 - 'body' => __( 'You must have a style to use the Visual Styler.', 'formidable' ),
347 - 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
348 - );
349 - FrmAppController::show_error_modal( $error_args );
350 - return;
329 + wp_die( esc_html__( 'Invalid route', 'formidable' ), esc_html__( 'Invalid route', 'formidable' ), 400 );
351 330 }
352 331
353 332 $form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 );
354 -
355 333 if ( ! $form_id ) {
356 334 $form_id = self::get_form_id_for_style( $style_id );
357 335 }
358 336
359 337 $form = FrmForm::getOne( $form_id );
360 -
361 338 if ( ! is_object( $form ) ) {
362 - $error_args = array(
363 - 'title' => __( 'No forms', 'formidable' ),
364 - 'body' => __( 'You must have a form to use the Visual Styler.', 'formidable' ),
365 - 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
366 - );
367 - FrmAppController::show_error_modal( $error_args );
368 - return;
339 + wp_die( esc_html__( 'Invalid route', 'formidable' ), esc_html__( 'Invalid route', 'formidable' ), 400 );
369 340 }
370 341
371 342 $frm_style = new FrmStyle( $style_id );
372 343 $active_style = $frm_style->get_one();
@@ -376,9 +347,11 @@
376 347
377 348 /**
378 349 * @since 6.0
379 350 *
380 - * @param array{form:\stdClass} $data
351 + * @param array {
352 + * @type stdClass $form
353 + * }
381 354 */
382 355 do_action( 'frm_before_render_style_page', compact( 'form' ) );
383 356
384 357 self::render_style_page( $active_style, $form, $default_style );
@@ -390,9 +363,8 @@
390 363 * @return int
391 364 */
392 365 private static function get_style_id_for_styler() {
393 366 $action = FrmAppHelper::simple_get( 'frm_action' );
394 -
395 367 if ( 'duplicate' === $action ) {
396 368 // The duplicate action uses style_id instead of id for better backward compatibility.
397 369 return FrmAppHelper::simple_get( 'style_id', 'absint', 0 );
398 370 }
@@ -397,9 +369,8 @@
397 369 return FrmAppHelper::simple_get( 'style_id', 'absint', 0 );
398 370 }
399 371
400 372 $style_id = FrmAppHelper::simple_get( 'id', 'absint', 0 );
401 -
402 373 if ( $style_id ) {
403 374 // Always use the style ID from the URL if one is specified.
404 375 return $style_id;
405 376 }
@@ -404,9 +375,8 @@
404 375 return $style_id;
405 376 }
406 377
407 378 $request_form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 );
408 -
409 379 if ( $request_form_id && is_callable( 'FrmProStylesController::get_active_style_for_form' ) ) {
410 380 return FrmProStylesController::get_active_style_for_form( $request_form_id )->ID;
411 381 }
412 382
@@ -418,9 +388,8 @@
418 388 *
419 389 * @since 6.0
420 390 *
421 391 * @param int $style_id
422 - *
423 392 * @return int
424 393 */
425 394 private static function get_form_id_for_style( $style_id ) {
426 395 $check = serialize( array( 'custom_style' => (string) $style_id ) );
@@ -433,8 +402,9 @@
433 402 )
434 403 );
435 404
436 405 if ( ! $form_id ) {
406 + // TODO: Show a message why a random form is being shown (because no form is assigned to the style).
437 407 // Fallback to any form.
438 408 $where = array(
439 409 'status' => 'published',
440 410 // Make sure it's not a repeater.
@@ -466,10 +436,11 @@
466 436 *
467 437 * @return WP_Post
468 438 */
469 439 private static function get_default_style() {
470 - $frm_style = new FrmStyle( 'default' );
471 - return $frm_style->get_one();
440 + $frm_style = new FrmStyle( 'default' );
441 + $default_style = $frm_style->get_one();
442 + return $default_style;
472 443 }
473 444
474 445 /**
475 446 * Save style for form (from Styler list page) via a POST action.
@@ -479,15 +450,13 @@
479 450 * @return void
480 451 */
481 452 private static function save_form_style() {
482 453 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form_style', 'frm_save_form_style_nonce' );
483 -
484 454 if ( $permission_error !== false ) {
485 455 wp_die( 'Unable to save form', '', 403 );
486 456 }
487 457
488 458 $style_id = FrmAppHelper::get_post_param( 'style_id', 0, 'absint' );
489 -
490 459 if ( $style_id && ! self::confirm_style_exists_before_setting( $style_id ) ) {
491 460 wp_die( esc_html__( 'Invalid target style', 'formidable' ), esc_html__( 'Invalid target style', 'formidable' ), 400 );
492 461 return;
493 462 }
@@ -507,9 +476,8 @@
507 476 return;
508 477 }
509 478
510 479 $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
511 -
512 480 if ( ! $form_id ) {
513 481 wp_die( esc_html__( 'No form specified', 'formidable' ), esc_html__( 'No form specified', 'formidable' ), 400 );
514 482 return;
515 483 }
@@ -514,21 +482,17 @@
514 482 return;
515 483 }
516 484
517 485 $form = FrmForm::getOne( $form_id );
518 -
519 486 if ( ! $form ) {
520 487 wp_die( esc_html__( 'Form does not exist', 'formidable' ), esc_html__( 'Form does not exist', 'formidable' ), 400 );
521 488 return;
522 489 }
523 490
524 - $previous_style_id = $form->options['custom_style'];
525 -
526 491 // If the default style is selected, use the "Always use default" legacy option instead of the default style.
527 492 // There's also a check here for conversational forms.
528 493 // Without the check it isn't possible to select "Default" because "Always use default" will convert to "Lines" dynamically.
529 494 $default_style = self::get_default_style();
530 -
531 495 if ( $style_id === $default_style->ID && empty( $form->options['chat'] ) ) {
532 496 $style_id = 1;
533 497 }
534 498
@@ -534,27 +498,13 @@
534 498
535 499 // We want to save a string for consistency. FrmStylesHelper::get_form_count_for_style expects the custom style ID is a string.
536 500 $form->options['custom_style'] = (string) $style_id;
537 501
538 - if ( $previous_style_id === $form->options['custom_style'] ) {
539 - // Exit early before updating DB if nothing actually changed.
540 - self::$message = __( 'Successfully updated style.', 'formidable' );
541 - return;
542 - }
543 -
544 502 global $wpdb;
545 503 $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) );
546 504
547 505 FrmForm::clear_form_cache();
548 506
549 - /**
550 - * @since 6.25.1
551 - *
552 - * @param int $form_id
553 - * @param int $style_id
554 - */
555 - do_action( 'frm_after_changed_form_style', absint( $form_id ), absint( $style_id ) );
556 -
557 507 self::$message = __( 'Successfully updated style.', 'formidable' );
558 508 }
559 509
560 510 /**
@@ -560,9 +510,8 @@
560 510 /**
561 511 * Validate that we're assigning a form to a style that actually exists before assigning it to a form.
562 512 *
563 513 * @param int $style_id
564 - *
565 514 * @return bool True if the style actually exists.
566 515 */
567 516 private static function confirm_style_exists_before_setting( $style_id ) {
568 517 global $wpdb;
@@ -581,9 +530,9 @@
581 530 $plugin_url = FrmAppHelper::plugin_url();
582 531 $version = FrmAppHelper::plugin_version();
583 532 $js_dependencies = array( 'wp-i18n', 'wp-hooks', 'formidable_dom' );
584 533
585 - if ( FrmAppHelper::pro_is_installed() && is_callable( 'FrmProAppHelper::use_jquery_datepicker' ) && FrmProAppHelper::use_jquery_datepicker() ) {
534 + if ( FrmAppHelper::pro_is_installed() ) {
586 535 $js_dependencies[] = 'jquery-ui-datepicker';
587 536 }
588 537
589 538 wp_register_script( 'formidable_style', $plugin_url . '/js/admin/style.js', $js_dependencies, $version );
@@ -602,9 +551,8 @@
602 551 *
603 552 * @param stdClass|WP_Post $active_style
604 553 * @param stdClass $form
605 554 * @param WP_Post $default_style
606 - *
607 555 * @return void
608 556 */
609 557 private static function render_style_page( $active_style, $form, $default_style ) {
610 558 $style_views_path = self::get_views_path();
@@ -679,9 +627,8 @@
679 627 *
680 628 * @since 6.0
681 629 *
682 630 * @param stdClass|WP_Post $style A new style is not a WP_Post object.
683 - *
684 631 * @return void
685 632 */
686 633 private static function force_form_style( $style ) {
687 634 add_filter(
@@ -692,9 +639,9 @@
692 639 /**
693 640 * @param string $class
694 641 */
695 642 function ( $class ) {
696 - return $class && ! str_starts_with( $class, 'frm_style_' );
643 + return $class && 0 !== strpos( $class, 'frm_style_' );
697 644 }
698 645 );
699 646 $split[] = 'frm_style_' . $style->post_name;
700 647 return implode( ' ', $split );
@@ -709,10 +656,8 @@
709 656 *
710 657 * @return void
711 658 */
712 659 public static function save_style() {
713 - FrmAppHelper::permission_check( 'frm_change_settings' );
714 -
715 660 $frm_style = new FrmStyle();
716 661 $post_id = FrmAppHelper::get_post_param( 'ID', false, 'sanitize_title' );
717 662 $style_nonce = FrmAppHelper::get_post_param( 'frm_style', '', 'sanitize_text_field' );
718 663
@@ -722,9 +667,8 @@
722 667 return;
723 668 }
724 669
725 670 $id = $frm_style->update( $post_id );
726 -
727 671 if ( ! $post_id && $id ) {
728 672 self::maybe_redirect_after_save( $id );
729 673 // Set the post id to the new style so it will be loaded for editing.
730 674 $post_id = reset( $id );
@@ -729,15 +673,8 @@
729 673 // Set the post id to the new style so it will be loaded for editing.
730 674 $post_id = reset( $id );
731 675 }
732 676
733 - /**
734 - * @since 6.25.1
735 - *
736 - * @param int $post_id
737 - */
738 - do_action( 'frm_after_saved_style', absint( $post_id ) );
739 -
740 677 self::$message = __( 'Your styling settings have been saved.', 'formidable' );
741 678 }
742 679
743 680 /**
@@ -756,20 +693,19 @@
756 693 *
757 694 * @since 6.0
758 695 *
759 696 * @param array $ids
760 - *
761 697 * @return void
762 698 */
763 699 private static function maybe_redirect_after_save( $ids ) {
764 - $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
765 - $parsed = parse_url( $referer );
766 - $query = $parsed['query'];
700 + $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
701 + $parsed = parse_url( $referer );
702 + $query = $parsed['query'];
703 +
767 704 $current_action = false;
768 705 $actions_to_redirect = array( 'duplicate', 'new_style' );
769 -
770 706 foreach ( $actions_to_redirect as $action ) {
771 - if ( str_contains( $query, 'frm_action=' . $action ) ) {
707 + if ( false !== strpos( $query, 'frm_action=' . $action ) ) {
772 708 $current_action = $action;
773 709 break;
774 710 }
775 711 }
@@ -779,9 +715,10 @@
779 715 return;
780 716 }
781 717
782 718 parse_str( $query, $parsed_query );
783 - $form_id = ! empty( $parsed_query['form'] ) ? absint( $parsed_query['form'] ) : 0;
719 + $form_id = ! empty( $parsed_query['form'] ) ? absint( $parsed_query['form'] ) : 0;
720 +
784 721 $style = new stdClass();
785 722 $style->ID = end( $ids );
786 723 wp_safe_redirect( esc_url_raw( FrmStylesHelper::get_edit_url( $style, $form_id ) ) );
787 724 die();
@@ -791,9 +728,8 @@
791 728 * @since 6.0
792 729 *
793 730 * @param string $message
794 731 * @param array|object $forms
795 - *
796 732 * @return void
797 733 */
798 734 public static function manage( $message = '', $forms = array() ) {
799 735 $frm_style = new FrmStyle();
@@ -798,9 +734,8 @@
798 734 public static function manage( $message = '', $forms = array() ) {
799 735 $frm_style = new FrmStyle();
800 736 $styles = $frm_style->get_all();
801 737 $default_style = $frm_style->get_default_style( $styles );
802 - $frm_settings = FrmAppHelper::get_settings();
803 738
804 739 if ( ! $forms ) {
805 740 $forms = FrmForm::get_published_forms();
806 741 }
@@ -817,16 +752,15 @@
817 752 private static function manage_styles() {
818 753 global $wpdb;
819 754
820 755 $forms = FrmForm::get_published_forms();
821 -
822 756 foreach ( $forms as $form ) {
823 - if ( ! isset( $_POST['style'] ) || ! isset( $_POST['style'][ $form->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
757 + $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
758 + $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
759 + if ( $new_style == $previous_style ) {
824 760 continue;
825 761 }
826 762
827 - $new_style = sanitize_text_field( wp_unslash( $_POST['style'][ $form->id ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
828 -
829 763 $form->options['custom_style'] = $new_style;
830 764 $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) );
831 765 unset( $form );
832 766 }
@@ -835,28 +769,15 @@
835 769 /**
836 770 * Echo content for the Custom CSS page.
837 771 *
838 772 * @param string $message
839 - * @param array $extra_args An array of extra arguments.
840 - *
841 773 * @return void
842 774 */
843 - public static function custom_css( $message = '', $extra_args = array() ) {
844 - $id = $extra_args['id'] ?? 'frm_codemirror_box';
845 - $settings = self::enqueue_codemirror( $id, $extra_args['placeholder'] ?? '' );
846 - $id = $settings ? $id : 'frm_custom_css_box';
847 - $show_errors = $extra_args['show_errors'] ?? true;
848 - $custom_css = $extra_args['custom_css'] ?? self::get_custom_css();
849 - $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
850 - $textarea_params = ! empty( $extra_args['textarea_params'] ) ? $extra_args['textarea_params'] : array(
851 - 'name' => 'frm_custom_css',
852 - 'id' => $id,
853 - );
775 + public static function custom_css( $message = '' ) {
776 + $settings = self::enqueue_codemirror();
777 + $id = $settings ? 'frm_codemirror_box' : 'frm_custom_css_box';
778 + $custom_css = self::get_custom_css();
854 779
855 - if ( $settings ) {
856 - $textarea_params['class'] = 'hide-if-js';
857 - }
858 -
859 780 include FrmAppHelper::plugin_path() . '/classes/views/styles/custom_css.php';
860 781 }
861 782
862 783 /**
@@ -863,33 +784,22 @@
863 784 * Get custom CSS code entered in the Custom CSS page.
864 785 *
865 786 * @since 6.0
866 787 *
867 - * @param array|null $single_style_settings The single style settings.
868 - *
869 788 * @return string
870 789 */
871 - public static function get_custom_css( $single_style_settings = null ) {
872 - if ( $single_style_settings ) {
873 - // If the single style settings are passed, return the custom CSS from the single style settings.
874 - if ( ! empty( $single_style_settings['single_style_custom_css'] ) && ! empty( $single_style_settings['enable_style_custom_css'] ) ) {
875 - return $single_style_settings['single_style_custom_css'];
876 - }
877 -
878 - return '';
879 - }
880 -
790 + public static function get_custom_css() {
881 791 $settings = FrmAppHelper::get_settings();
882 -
883 792 if ( is_string( $settings->custom_css ) ) {
884 793 return $settings->custom_css;
885 794 }
886 795
887 796 // If it does not exist, check the default style as a fallback.
888 - $frm_style = new FrmStyle();
889 - $style = $frm_style->get_default_style();
797 + $frm_style = new FrmStyle();
798 + $style = $frm_style->get_default_style();
799 + $custom_css = $style->post_content['custom_css'];
890 800
891 - return $style->post_content['custom_css'];
801 + return $custom_css;
892 802 }
893 803
894 804 /**
895 805 * Enqueue assets for codemirror, built into WordPress since 4.9.
@@ -896,14 +806,11 @@
896 806 * The Custom CSS page uses codemirror.
897 807 *
898 808 * @since 6.0 Previously this code was embedded in self::custom_css.
899 809 *
900 - * @param string $id The ID of the codemirror box.
901 - * @param string $placeholder The placeholder text for the codemirror box.
902 - *
903 810 * @return array|false
904 811 */
905 - private static function enqueue_codemirror( $id = 'frm_codemirror_box', $placeholder = '' ) {
812 + private static function enqueue_codemirror() {
906 813 if ( ! function_exists( 'wp_enqueue_code_editor' ) ) {
907 814 // The WordPress version is likely older than 4.9.
908 815 return false;
909 816 }
@@ -916,9 +823,8 @@
916 823 'tabSize' => 2,
917 824 // As the codemirror box only appears once you click into the Custom CSS tab, we need to auto-refresh.
918 825 // Otherwise the line numbers all end up with a 1px width causing overlap issues with the text in the content.
919 826 'autoRefresh' => true,
920 - 'placeholder' => $placeholder,
921 827 ),
922 828 )
923 829 );
924 830
@@ -925,11 +831,9 @@
925 831 if ( $settings ) {
926 832 wp_add_inline_script(
927 833 'code-editor',
928 834 sprintf(
929 - 'jQuery( function() { window.%s_wp_editor = wp.codeEditor.initialize( \'%s\', %s ); } );',
930 - $id,
931 - $id,
835 + 'jQuery( function() { wp.codeEditor.initialize( \'frm_codemirror_box\', %s ); } );',
932 836 wp_json_encode( $settings )
933 837 )
934 838 );
935 839 }
@@ -981,9 +885,8 @@
981 885 FrmAppHelper::permission_check( 'frm_change_settings' );
982 886 check_ajax_referer( 'frm_ajax', 'nonce' );
983 887
984 888 $style_id = FrmAppHelper::get_post_param( 'style_id', '', 'absint' );
985 -
986 889 if ( ! $style_id ) {
987 890 // A style ID is not sent when resetting on the edit page.
988 891 // Instead of resetting the style, send the defaults back so the inputs can be updated with JavaScript.
989 892 $frm_style = new FrmStyle();
@@ -991,26 +894,23 @@
991 894 echo json_encode( $defaults );
992 895 wp_die();
993 896 }
994 897
995 - $frm_style = new FrmStyle();
996 - $default_template_style = $frm_style->get_default_template_style( $style_id );
997 - $where = array(
898 + $frm_style = new FrmStyle();
899 + $defaults = $frm_style->get_defaults();
900 + $default_post_content = FrmAppHelper::prepare_and_encode( $defaults );
901 + $where = array(
998 902 'ID' => $style_id,
999 903 'post_type' => self::$post_type,
1000 904 );
1001 -
1002 - $style_object = $frm_style->get_new();
1003 - $style_object->post_content = json_decode( $default_template_style, true );
1004 -
1005 905 global $wpdb;
1006 - $wpdb->update( $wpdb->posts, array( 'post_content' => $default_template_style ), $where );
906 + $wpdb->update( $wpdb->posts, array( 'post_content' => $default_post_content ), $where );
1007 907
1008 908 // Save the settings after resetting to default or the old style will still appear.
1009 909 $frm_style->save_settings();
1010 910
1011 911 $data = array(
1012 - 'style' => FrmStylesCardHelper::get_style_param_for_card( $style_object ),
912 + 'style' => FrmStylesCardHelper::get_style_param_for_card( $frm_style->get_new() ),
1013 913 );
1014 914 wp_send_json_success( $data );
1015 915 wp_die();
1016 916 }
@@ -1025,10 +925,9 @@
1025 925 public static function change_styling() {
1026 926 FrmAppHelper::permission_check( 'frm_change_settings' );
1027 927 check_ajax_referer( 'frm_ajax', 'nonce' );
1028 928
1029 - $is_loaded_via_ajax = true;
1030 - $frm_style = new FrmStyle();
929 + $frm_style = new FrmStyle();
1031 930
1032 931 // Intentionally avoid defaults here so nothing gets removed from our style.
1033 932 $defaults = array();
1034 933 $style = '';
@@ -1042,9 +941,9 @@
1042 941 /**
1043 942 * @return void
1044 943 */
1045 944 public static function add_meta_boxes() {
1046 - // Setup meta boxes
945 + // setup meta boxes
1047 946 $meta_boxes = array(
1048 947 'general' => __( 'General', 'formidable' ),
1049 948 'form-title' => __( 'Form Title', 'formidable' ),
1050 949 'form-description' => __( 'Form Description', 'formidable' ),
@@ -1074,9 +973,8 @@
1074 973
1075 974 /**
1076 975 * @param array $atts
1077 976 * @param array $sec
1078 - *
1079 977 * @return void
1080 978 */
1081 979 public static function include_style_section( $atts, $sec ) {
1082 980 extract( $atts ); // phpcs:ignore WordPress.PHP.DontExtract
@@ -1139,9 +1037,9 @@
1139 1037 }
1140 1038
1141 1039 /**
1142 1040 * Add an extra style rule to hide a broken style warning.
1143 - * To avoid cluttering the front end with any unnecessary styles this is only added when the referer URL matches the styler.
1041 + * To avoid cluttering the front end with any unecessary styles this is only added when the referer URL matches the styler.
1144 1042 *
1145 1043 * @since 6.2.3
1146 1044 *
1147 1045 * @return void
@@ -1147,10 +1045,9 @@
1147 1045 * @return void
1148 1046 */
1149 1047 public static function maybe_hide_sample_form_error_message() {
1150 1048 $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
1151 -
1152 - if ( str_contains( $referer, 'admin.php?page=formidable-styles' ) ) {
1049 + if ( false !== strpos( $referer, 'admin.php?page=formidable-styles' ) ) {
1153 1050 echo '#frm_broken_styles_warning { display: none; }';
1154 1051 }
1155 1052 }
1156 1053
@@ -1159,9 +1056,8 @@
1159 1056 *
1160 1057 * @since 4.11.03
1161 1058 *
1162 1059 * @param string $css CSS content.
1163 - *
1164 1060 * @return string
1165 1061 */
1166 1062 public static function replace_relative_url( $css ) {
1167 1063 $plugin_url = trailingslashit( FrmAppHelper::plugin_url() );
@@ -1184,27 +1080,22 @@
1184 1080 * Check if the Formidable styling should be loaded,
1185 1081 * then enqueue it for the footer
1186 1082 *
1187 1083 * @since 2.0
1188 - *
1189 - * @return void
1190 1084 */
1191 1085 public static function enqueue_style() {
1192 1086 global $frm_vars;
1193 1087
1194 - if ( ! empty( $frm_vars['css_loaded'] ) ) {
1088 + if ( isset( $frm_vars['css_loaded'] ) && $frm_vars['css_loaded'] ) {
1195 1089 // The CSS has already been loaded.
1196 1090 return;
1197 1091 }
1198 1092
1199 1093 $frm_settings = FrmAppHelper::get_settings();
1200 -
1201 - if ( $frm_settings->load_style === 'none' ) {
1202 - return;
1094 + if ( $frm_settings->load_style !== 'none' ) {
1095 + wp_enqueue_style( 'formidable' );
1096 + $frm_vars['css_loaded'] = true;
1203 1097 }
1204 -
1205 - wp_enqueue_style( 'formidable' );
1206 - $frm_vars['css_loaded'] = true;
1207 1098 }
1208 1099
1209 1100 /**
1210 1101 * Get the stylesheets for the form settings page
@@ -1212,9 +1103,11 @@
1212 1103 * @return array<WP_Post>
1213 1104 */
1214 1105 public static function get_style_opts() {
1215 1106 $frm_style = new FrmStyle();
1216 - return $frm_style->get_all();
1107 + $styles = $frm_style->get_all();
1108 +
1109 + return $styles;
1217 1110 }
1218 1111
1219 1112 /**
1220 1113 * Get the style post object for a target form.
@@ -1219,16 +1112,14 @@
1219 1112 /**
1220 1113 * Get the style post object for a target form.
1221 1114 *
1222 1115 * @param bool|object|string $form
1223 - *
1224 1116 * @return WP_Post|null
1225 1117 */
1226 1118 public static function get_form_style( $form = 'default' ) {
1227 1119 $style = FrmFormsHelper::get_form_style( $form );
1228 1120
1229 - // phpcs:ignore Universal.Operators.StrictComparisons
1230 - if ( ! $style || 1 == $style ) {
1121 + if ( empty( $style ) || 1 == $style ) {
1231 1122 $style = 'default';
1232 1123 }
1233 1124
1234 1125 $frm_style = new FrmStyle( $style );
@@ -1237,13 +1128,10 @@
1237 1128
1238 1129 /**
1239 1130 * @param string $class
1240 1131 * @param string $style
1241 - *
1242 - * @return string
1243 1132 */
1244 1133 public static function get_form_style_class( $class, $style ) {
1245 - // phpcs:ignore Universal.Operators.StrictComparisons
1246 1134 if ( 1 == $style ) {
1247 1135 $style = 'default';
1248 1136 }
1249 1137
@@ -1259,17 +1147,13 @@
1259 1147 }
1260 1148
1261 1149 /**
1262 1150 * @since 3.0
1263 - *
1264 1151 * @param object $style
1265 1152 * @param string $class
1266 - *
1267 - * @return void
1268 1153 */
1269 1154 private static function maybe_add_rtl_class( $style, &$class ) {
1270 1155 $is_rtl = isset( $style->post_content['direction'] ) && 'rtl' === $style->post_content['direction'];
1271 -
1272 1156 if ( $is_rtl ) {
1273 1157 $class .= ' frm_rtl';
1274 1158 }
1275 1159 }
@@ -1274,28 +1158,17 @@
1274 1158 }
1275 1159 }
1276 1160
1277 1161 /**
1278 - * @param string $val Style setting key.
1279 - * @param int|string $form Form ID or 'default'.
1280 - *
1281 - * @return mixed
1162 + * @param string $val
1282 1163 */
1283 1164 public static function get_style_val( $val, $form = 'default' ) {
1284 1165 $style = self::get_form_style( $form );
1285 -
1286 1166 if ( $style && isset( $style->post_content[ $val ] ) ) {
1287 1167 return $style->post_content[ $val ];
1288 1168 }
1289 -
1290 - return null;
1291 1169 }
1292 1170
1293 - /**
1294 - * @param array $default_styles
1295 - *
1296 - * @return array
1297 - */
1298 1171 public static function show_entry_styles( $default_styles ) {
1299 1172 $frm_style = new FrmStyle( 'default' );
1300 1173 $style = $frm_style->get_one();
1301 1174
@@ -1304,15 +1177,13 @@
1304 1177 }
1305 1178
1306 1179 foreach ( $default_styles as $name => $val ) {
1307 1180 $setting = $name;
1308 -
1309 - if ( 'border_width' === $name ) {
1181 + if ( 'border_width' == $name ) {
1310 1182 $setting = 'field_border_width';
1311 - } elseif ( 'alt_bg_color' === $name ) {
1183 + } elseif ( 'alt_bg_color' == $name ) {
1312 1184 $setting = 'bg_color_active';
1313 1185 }
1314 -
1315 1186 $default_styles[ $name ] = $style->post_content[ $setting ];
1316 1187 unset( $name, $val );
1317 1188 }
1318 1189
@@ -1318,16 +1189,12 @@
1318 1189
1319 1190 return $default_styles;
1320 1191 }
1321 1192
1322 - /**
1323 - * @param string $important
1324 - * @param array $field
1325 - *
1326 - * @return string
1327 - */
1328 - public static function important_style( $important, $field ) {
1329 - return self::get_style_val( 'important_style', $field['form_id'] );
1193 + public static function &important_style( $important, $field ) {
1194 + $important = self::get_style_val( 'important_style', $field['form_id'] );
1195 +
1196 + return $important;
1330 1197 }
1331 1198
1332 1199 /**
1333 1200 * Duplicate of WordPress do_accordion_section function, it adds an additional svg icon support.
@@ -1333,18 +1200,14 @@
1333 1200 * Duplicate of WordPress do_accordion_section function, it adds an additional svg icon support.
1334 1201 *
1335 1202 * @since 6.8.3
1336 1203 *
1337 - * @param string|WP_Screen $screen Screen ID or screen object.
1338 - * @param string $context Meta box context.
1339 - * @param mixed $data_object Data object passed to callbacks.
1340 - *
1341 1204 * @return int
1342 1205 */
1343 - public static function do_accordion_sections( $screen, $context, $data_object ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
1206 + public static function do_accordion_sections( $screen, $context, $data_object ) {
1344 1207 global $wp_meta_boxes;
1345 1208
1346 - // The symbol id from icons.svg
1209 + // the symbol id from icons.svg
1347 1210 $icon_ids = array(
1348 1211 'ranking-fields-style' => 'frm_chart_bar_icon',
1349 1212 'section-fields-style' => 'frm-form-title-style',
1350 1213 );
@@ -1350,9 +1213,9 @@
1350 1213 );
1351 1214
1352 1215 wp_enqueue_script( 'accordion' );
1353 1216
1354 - if ( ! $screen ) {
1217 + if ( empty( $screen ) ) {
1355 1218 $screen = get_current_screen();
1356 1219 } elseif ( is_string( $screen ) ) {
1357 1220 $screen = convert_to_screen( $screen );
1358 1221 }
@@ -1358,9 +1221,8 @@
1358 1221 }
1359 1222
1360 1223 $page = $screen->id;
1361 1224
1362 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1363 1225 ?>
1364 1226 <div id="side-sortables" class="accordion-container">
1365 1227 <ul class="outer-border">
1366 1228 <?php
@@ -1368,46 +1230,40 @@
1368 1230 $first_open = false;
1369 1231
1370 1232 if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
1371 1233 foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
1372 - if ( ! isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
1373 - continue;
1374 - }
1234 + if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
1235 + foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
1236 + if ( false === $box || ! $box['title'] ) {
1237 + continue;
1238 + }
1375 1239
1376 - foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
1377 - if ( false === $box || ! $box['title'] ) {
1378 - continue;
1379 - }
1240 + ++$i;
1241 + $icon_id = array_key_exists( $box['id'], $icon_ids ) ? $icon_ids[ $box['id'] ] : 'frm-' . $box['id'];
1380 1242
1381 - ++$i;
1382 - $icon_id = array_key_exists( $box['id'], $icon_ids ) ? $icon_ids[ $box['id'] ] : 'frm-' . $box['id'];
1383 - $open_class = '';
1384 -
1385 - if ( ! $first_open ) {
1386 - $first_open = true;
1387 - $open_class = 'open';
1388 - }
1389 -
1390 - $accordion_content_id = 'frm_style_section_' . $box['id'];
1391 - ?>
1392 - <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 ?>
1393 - <h3 class="accordion-section-title hndle">
1394 - <?php
1395 - FrmAppHelper::icon_by_class( 'frmfont ' . $icon_id . ' frm_svg24' );
1396 - echo esc_html( $box['title'] );
1397 - ?>
1398 - <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 ?>
1399 - <?php FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown8_icon' ); ?>
1400 - </button>
1401 - </h3>
1402 - <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>" id="<?php echo esc_attr( $accordion_content_id ); ?>">
1403 - <div class="inside">
1404 - <?php call_user_func( $box['callback'], $data_object, $box ); ?>
1405 - </div><!-- .inside -->
1406 - </div><!-- .accordion-section-content -->
1407 - </li><!-- .accordion-section -->
1408 - <?php
1409 - }//end foreach
1243 + $open_class = '';
1244 + if ( ! $first_open ) {
1245 + $first_open = true;
1246 + $open_class = 'open';
1247 + }
1248 + ?>
1249 + <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'] ); ?>">
1250 + <h3 class="accordion-section-title hndle" tabindex="0">
1251 + <?php
1252 + FrmAppHelper::icon_by_class( 'frmfont ' . $icon_id );
1253 + echo esc_html( $box['title'] );
1254 + FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown8_icon' );
1255 + ?>
1256 + </h3>
1257 + <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>">
1258 + <div class="inside">
1259 + <?php call_user_func( $box['callback'], $data_object, $box ); ?>
1260 + </div><!-- .inside -->
1261 + </div><!-- .accordion-section-content -->
1262 + </li><!-- .accordion-section -->
1263 + <?php
1264 + }//end foreach
1265 + }//end if
1410 1266 }//end foreach
1411 1267 }//end if
1412 1268 ?>
1413 1269 </ul><!-- .outer-border -->
@@ -1412,9 +1268,8 @@
1412 1268 ?>
1413 1269 </ul><!-- .outer-border -->
1414 1270 </div><!-- .accordion-container -->
1415 1271 <?php
1416 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1417 1272 return $i;
1418 1273 }
1419 1274
1420 1275 /**
@@ -1425,9 +1280,8 @@
1425 1280 * @return void
1426 1281 */
1427 1282 public static function rename_style() {
1428 1283 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'nonce', 'frm_ajax' );
1429 -
1430 1284 if ( $permission_error !== false ) {
1431 1285 $data = array(
1432 1286 'message' => __( 'Unable to rename style', 'formidable' ),
1433 1287 );
@@ -1446,9 +1300,8 @@
1446 1300 die();
1447 1301 }
1448 1302
1449 1303 $post = get_post( $style_id );
1450 -
1451 1304 if ( ! $post || $post->post_type !== self::$post_type ) {
1452 1305 $data = array(
1453 1306 'message' => __( 'The style you are renaming either does not exist or it is not a style', 'formidable' ),
1454 1307 );
@@ -1469,9 +1322,8 @@
1469 1322 *
1470 1323 * @since 6.0
1471 1324 *
1472 1325 * @param WP_Styles $styles
1473 - *
1474 1326 * @return void
1475 1327 */
1476 1328 public static function disable_conflicting_wp_admin_css( $styles ) {
1477 1329 if ( ! FrmAppHelper::is_style_editor_page() ) {