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 -258 6.286.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 );
@@ -720,9 +667,8 @@
720 667 return;
721 668 }
722 669
723 670 $id = $frm_style->update( $post_id );
724 -
725 671 if ( ! $post_id && $id ) {
726 672 self::maybe_redirect_after_save( $id );
727 673 // Set the post id to the new style so it will be loaded for editing.
728 674 $post_id = reset( $id );
@@ -727,15 +673,8 @@
727 673 // Set the post id to the new style so it will be loaded for editing.
728 674 $post_id = reset( $id );
729 675 }
730 676
731 - /**
732 - * @since 6.25.1
733 - *
734 - * @param int $post_id
735 - */
736 - do_action( 'frm_after_saved_style', absint( $post_id ) );
737 -
738 677 self::$message = __( 'Your styling settings have been saved.', 'formidable' );
739 678 }
740 679
741 680 /**
@@ -754,20 +693,19 @@
754 693 *
755 694 * @since 6.0
756 695 *
757 696 * @param array $ids
758 - *
759 697 * @return void
760 698 */
761 699 private static function maybe_redirect_after_save( $ids ) {
762 - $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
763 - $parsed = parse_url( $referer );
764 - $query = $parsed['query'];
700 + $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
701 + $parsed = parse_url( $referer );
702 + $query = $parsed['query'];
703 +
765 704 $current_action = false;
766 705 $actions_to_redirect = array( 'duplicate', 'new_style' );
767 -
768 706 foreach ( $actions_to_redirect as $action ) {
769 - if ( str_contains( $query, 'frm_action=' . $action ) ) {
707 + if ( false !== strpos( $query, 'frm_action=' . $action ) ) {
770 708 $current_action = $action;
771 709 break;
772 710 }
773 711 }
@@ -777,9 +715,10 @@
777 715 return;
778 716 }
779 717
780 718 parse_str( $query, $parsed_query );
781 - $form_id = ! empty( $parsed_query['form'] ) ? absint( $parsed_query['form'] ) : 0;
719 + $form_id = ! empty( $parsed_query['form'] ) ? absint( $parsed_query['form'] ) : 0;
720 +
782 721 $style = new stdClass();
783 722 $style->ID = end( $ids );
784 723 wp_safe_redirect( esc_url_raw( FrmStylesHelper::get_edit_url( $style, $form_id ) ) );
785 724 die();
@@ -789,9 +728,8 @@
789 728 * @since 6.0
790 729 *
791 730 * @param string $message
792 731 * @param array|object $forms
793 - *
794 732 * @return void
795 733 */
796 734 public static function manage( $message = '', $forms = array() ) {
797 735 $frm_style = new FrmStyle();
@@ -796,9 +734,8 @@
796 734 public static function manage( $message = '', $forms = array() ) {
797 735 $frm_style = new FrmStyle();
798 736 $styles = $frm_style->get_all();
799 737 $default_style = $frm_style->get_default_style( $styles );
800 - $frm_settings = FrmAppHelper::get_settings();
801 738
802 739 if ( ! $forms ) {
803 740 $forms = FrmForm::get_published_forms();
804 741 }
@@ -815,16 +752,15 @@
815 752 private static function manage_styles() {
816 753 global $wpdb;
817 754
818 755 $forms = FrmForm::get_published_forms();
819 -
820 756 foreach ( $forms as $form ) {
821 - 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 ) {
822 760 continue;
823 761 }
824 762
825 - $new_style = sanitize_text_field( wp_unslash( $_POST['style'][ $form->id ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
826 -
827 763 $form->options['custom_style'] = $new_style;
828 764 $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) );
829 765 unset( $form );
830 766 }
@@ -833,28 +769,15 @@
833 769 /**
834 770 * Echo content for the Custom CSS page.
835 771 *
836 772 * @param string $message
837 - * @param array $extra_args An array of extra arguments.
838 - *
839 773 * @return void
840 774 */
841 - public static function custom_css( $message = '', $extra_args = array() ) {
842 - $id = $extra_args['id'] ?? 'frm_codemirror_box';
843 - $settings = self::enqueue_codemirror( $id, $extra_args['placeholder'] ?? '' );
844 - $id = $settings ? $id : 'frm_custom_css_box';
845 - $show_errors = $extra_args['show_errors'] ?? true;
846 - $custom_css = $extra_args['custom_css'] ?? self::get_custom_css();
847 - $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
848 - $textarea_params = ! empty( $extra_args['textarea_params'] ) ? $extra_args['textarea_params'] : array(
849 - 'name' => 'frm_custom_css',
850 - 'id' => $id,
851 - );
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();
852 779
853 - if ( $settings ) {
854 - $textarea_params['class'] = 'hide-if-js';
855 - }
856 -
857 780 include FrmAppHelper::plugin_path() . '/classes/views/styles/custom_css.php';
858 781 }
859 782
860 783 /**
@@ -861,33 +784,22 @@
861 784 * Get custom CSS code entered in the Custom CSS page.
862 785 *
863 786 * @since 6.0
864 787 *
865 - * @param array|null $single_style_settings The single style settings.
866 - *
867 788 * @return string
868 789 */
869 - public static function get_custom_css( $single_style_settings = null ) {
870 - if ( $single_style_settings ) {
871 - // If the single style settings are passed, return the custom CSS from the single style settings.
872 - if ( ! empty( $single_style_settings['single_style_custom_css'] ) && ! empty( $single_style_settings['enable_style_custom_css'] ) ) {
873 - return $single_style_settings['single_style_custom_css'];
874 - }
875 -
876 - return '';
877 - }
878 -
790 + public static function get_custom_css() {
879 791 $settings = FrmAppHelper::get_settings();
880 -
881 792 if ( is_string( $settings->custom_css ) ) {
882 793 return $settings->custom_css;
883 794 }
884 795
885 796 // If it does not exist, check the default style as a fallback.
886 - $frm_style = new FrmStyle();
887 - $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'];
888 800
889 - return $style->post_content['custom_css'];
801 + return $custom_css;
890 802 }
891 803
892 804 /**
893 805 * Enqueue assets for codemirror, built into WordPress since 4.9.
@@ -894,14 +806,11 @@
894 806 * The Custom CSS page uses codemirror.
895 807 *
896 808 * @since 6.0 Previously this code was embedded in self::custom_css.
897 809 *
898 - * @param string $id The ID of the codemirror box.
899 - * @param string $placeholder The placeholder text for the codemirror box.
900 - *
901 810 * @return array|false
902 811 */
903 - private static function enqueue_codemirror( $id = 'frm_codemirror_box', $placeholder = '' ) {
812 + private static function enqueue_codemirror() {
904 813 if ( ! function_exists( 'wp_enqueue_code_editor' ) ) {
905 814 // The WordPress version is likely older than 4.9.
906 815 return false;
907 816 }
@@ -914,9 +823,8 @@
914 823 'tabSize' => 2,
915 824 // As the codemirror box only appears once you click into the Custom CSS tab, we need to auto-refresh.
916 825 // Otherwise the line numbers all end up with a 1px width causing overlap issues with the text in the content.
917 826 'autoRefresh' => true,
918 - 'placeholder' => $placeholder,
919 827 ),
920 828 )
921 829 );
922 830
@@ -923,11 +831,9 @@
923 831 if ( $settings ) {
924 832 wp_add_inline_script(
925 833 'code-editor',
926 834 sprintf(
927 - 'jQuery( function() { window.%s_wp_editor = wp.codeEditor.initialize( \'%s\', %s ); } );',
928 - $id,
929 - $id,
835 + 'jQuery( function() { wp.codeEditor.initialize( \'frm_codemirror_box\', %s ); } );',
930 836 wp_json_encode( $settings )
931 837 )
932 838 );
933 839 }
@@ -979,9 +885,8 @@
979 885 FrmAppHelper::permission_check( 'frm_change_settings' );
980 886 check_ajax_referer( 'frm_ajax', 'nonce' );
981 887
982 888 $style_id = FrmAppHelper::get_post_param( 'style_id', '', 'absint' );
983 -
984 889 if ( ! $style_id ) {
985 890 // A style ID is not sent when resetting on the edit page.
986 891 // Instead of resetting the style, send the defaults back so the inputs can be updated with JavaScript.
987 892 $frm_style = new FrmStyle();
@@ -989,26 +894,23 @@
989 894 echo json_encode( $defaults );
990 895 wp_die();
991 896 }
992 897
993 - $frm_style = new FrmStyle();
994 - $default_template_style = $frm_style->get_default_template_style( $style_id );
995 - $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(
996 902 'ID' => $style_id,
997 903 'post_type' => self::$post_type,
998 904 );
999 -
1000 - $style_object = $frm_style->get_new();
1001 - $style_object->post_content = json_decode( $default_template_style, true );
1002 -
1003 905 global $wpdb;
1004 - $wpdb->update( $wpdb->posts, array( 'post_content' => $default_template_style ), $where );
906 + $wpdb->update( $wpdb->posts, array( 'post_content' => $default_post_content ), $where );
1005 907
1006 908 // Save the settings after resetting to default or the old style will still appear.
1007 909 $frm_style->save_settings();
1008 910
1009 911 $data = array(
1010 - 'style' => FrmStylesCardHelper::get_style_param_for_card( $style_object ),
912 + 'style' => FrmStylesCardHelper::get_style_param_for_card( $frm_style->get_new() ),
1011 913 );
1012 914 wp_send_json_success( $data );
1013 915 wp_die();
1014 916 }
@@ -1023,10 +925,9 @@
1023 925 public static function change_styling() {
1024 926 FrmAppHelper::permission_check( 'frm_change_settings' );
1025 927 check_ajax_referer( 'frm_ajax', 'nonce' );
1026 928
1027 - $is_loaded_via_ajax = true;
1028 - $frm_style = new FrmStyle();
929 + $frm_style = new FrmStyle();
1029 930
1030 931 // Intentionally avoid defaults here so nothing gets removed from our style.
1031 932 $defaults = array();
1032 933 $style = '';
@@ -1040,9 +941,9 @@
1040 941 /**
1041 942 * @return void
1042 943 */
1043 944 public static function add_meta_boxes() {
1044 - // Setup meta boxes
945 + // setup meta boxes
1045 946 $meta_boxes = array(
1046 947 'general' => __( 'General', 'formidable' ),
1047 948 'form-title' => __( 'Form Title', 'formidable' ),
1048 949 'form-description' => __( 'Form Description', 'formidable' ),
@@ -1072,9 +973,8 @@
1072 973
1073 974 /**
1074 975 * @param array $atts
1075 976 * @param array $sec
1076 - *
1077 977 * @return void
1078 978 */
1079 979 public static function include_style_section( $atts, $sec ) {
1080 980 extract( $atts ); // phpcs:ignore WordPress.PHP.DontExtract
@@ -1137,9 +1037,9 @@
1137 1037 }
1138 1038
1139 1039 /**
1140 1040 * Add an extra style rule to hide a broken style warning.
1141 - * 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.
1142 1042 *
1143 1043 * @since 6.2.3
1144 1044 *
1145 1045 * @return void
@@ -1145,10 +1045,9 @@
1145 1045 * @return void
1146 1046 */
1147 1047 public static function maybe_hide_sample_form_error_message() {
1148 1048 $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
1149 -
1150 - if ( str_contains( $referer, 'admin.php?page=formidable-styles' ) ) {
1049 + if ( false !== strpos( $referer, 'admin.php?page=formidable-styles' ) ) {
1151 1050 echo '#frm_broken_styles_warning { display: none; }';
1152 1051 }
1153 1052 }
1154 1053
@@ -1157,9 +1056,8 @@
1157 1056 *
1158 1057 * @since 4.11.03
1159 1058 *
1160 1059 * @param string $css CSS content.
1161 - *
1162 1060 * @return string
1163 1061 */
1164 1062 public static function replace_relative_url( $css ) {
1165 1063 $plugin_url = trailingslashit( FrmAppHelper::plugin_url() );
@@ -1182,27 +1080,22 @@
1182 1080 * Check if the Formidable styling should be loaded,
1183 1081 * then enqueue it for the footer
1184 1082 *
1185 1083 * @since 2.0
1186 - *
1187 - * @return void
1188 1084 */
1189 1085 public static function enqueue_style() {
1190 1086 global $frm_vars;
1191 1087
1192 - if ( ! empty( $frm_vars['css_loaded'] ) ) {
1088 + if ( isset( $frm_vars['css_loaded'] ) && $frm_vars['css_loaded'] ) {
1193 1089 // The CSS has already been loaded.
1194 1090 return;
1195 1091 }
1196 1092
1197 1093 $frm_settings = FrmAppHelper::get_settings();
1198 -
1199 - if ( $frm_settings->load_style === 'none' ) {
1200 - return;
1094 + if ( $frm_settings->load_style !== 'none' ) {
1095 + wp_enqueue_style( 'formidable' );
1096 + $frm_vars['css_loaded'] = true;
1201 1097 }
1202 -
1203 - wp_enqueue_style( 'formidable' );
1204 - $frm_vars['css_loaded'] = true;
1205 1098 }
1206 1099
1207 1100 /**
1208 1101 * Get the stylesheets for the form settings page
@@ -1210,9 +1103,11 @@
1210 1103 * @return array<WP_Post>
1211 1104 */
1212 1105 public static function get_style_opts() {
1213 1106 $frm_style = new FrmStyle();
1214 - return $frm_style->get_all();
1107 + $styles = $frm_style->get_all();
1108 +
1109 + return $styles;
1215 1110 }
1216 1111
1217 1112 /**
1218 1113 * Get the style post object for a target form.
@@ -1217,16 +1112,14 @@
1217 1112 /**
1218 1113 * Get the style post object for a target form.
1219 1114 *
1220 1115 * @param bool|object|string $form
1221 - *
1222 1116 * @return WP_Post|null
1223 1117 */
1224 1118 public static function get_form_style( $form = 'default' ) {
1225 1119 $style = FrmFormsHelper::get_form_style( $form );
1226 1120
1227 - // phpcs:ignore Universal.Operators.StrictComparisons
1228 - if ( ! $style || 1 == $style ) {
1121 + if ( empty( $style ) || 1 == $style ) {
1229 1122 $style = 'default';
1230 1123 }
1231 1124
1232 1125 $frm_style = new FrmStyle( $style );
@@ -1235,13 +1128,10 @@
1235 1128
1236 1129 /**
1237 1130 * @param string $class
1238 1131 * @param string $style
1239 - *
1240 - * @return string
1241 1132 */
1242 1133 public static function get_form_style_class( $class, $style ) {
1243 - // phpcs:ignore Universal.Operators.StrictComparisons
1244 1134 if ( 1 == $style ) {
1245 1135 $style = 'default';
1246 1136 }
1247 1137
@@ -1257,17 +1147,13 @@
1257 1147 }
1258 1148
1259 1149 /**
1260 1150 * @since 3.0
1261 - *
1262 1151 * @param object $style
1263 1152 * @param string $class
1264 - *
1265 - * @return void
1266 1153 */
1267 1154 private static function maybe_add_rtl_class( $style, &$class ) {
1268 1155 $is_rtl = isset( $style->post_content['direction'] ) && 'rtl' === $style->post_content['direction'];
1269 -
1270 1156 if ( $is_rtl ) {
1271 1157 $class .= ' frm_rtl';
1272 1158 }
1273 1159 }
@@ -1272,28 +1158,17 @@
1272 1158 }
1273 1159 }
1274 1160
1275 1161 /**
1276 - * @param string $val Style setting key.
1277 - * @param int|string $form Form ID or 'default'.
1278 - *
1279 - * @return mixed
1162 + * @param string $val
1280 1163 */
1281 1164 public static function get_style_val( $val, $form = 'default' ) {
1282 1165 $style = self::get_form_style( $form );
1283 -
1284 1166 if ( $style && isset( $style->post_content[ $val ] ) ) {
1285 1167 return $style->post_content[ $val ];
1286 1168 }
1287 -
1288 - return null;
1289 1169 }
1290 1170
1291 - /**
1292 - * @param array $default_styles
1293 - *
1294 - * @return array
1295 - */
1296 1171 public static function show_entry_styles( $default_styles ) {
1297 1172 $frm_style = new FrmStyle( 'default' );
1298 1173 $style = $frm_style->get_one();
1299 1174
@@ -1302,15 +1177,13 @@
1302 1177 }
1303 1178
1304 1179 foreach ( $default_styles as $name => $val ) {
1305 1180 $setting = $name;
1306 -
1307 - if ( 'border_width' === $name ) {
1181 + if ( 'border_width' == $name ) {
1308 1182 $setting = 'field_border_width';
1309 - } elseif ( 'alt_bg_color' === $name ) {
1183 + } elseif ( 'alt_bg_color' == $name ) {
1310 1184 $setting = 'bg_color_active';
1311 1185 }
1312 -
1313 1186 $default_styles[ $name ] = $style->post_content[ $setting ];
1314 1187 unset( $name, $val );
1315 1188 }
1316 1189
@@ -1316,16 +1189,12 @@
1316 1189
1317 1190 return $default_styles;
1318 1191 }
1319 1192
1320 - /**
1321 - * @param string $important
1322 - * @param array $field
1323 - *
1324 - * @return string
1325 - */
1326 - public static function important_style( $important, $field ) {
1327 - 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;
1328 1197 }
1329 1198
1330 1199 /**
1331 1200 * Duplicate of WordPress do_accordion_section function, it adds an additional svg icon support.
@@ -1331,18 +1200,14 @@
1331 1200 * Duplicate of WordPress do_accordion_section function, it adds an additional svg icon support.
1332 1201 *
1333 1202 * @since 6.8.3
1334 1203 *
1335 - * @param string|WP_Screen $screen Screen ID or screen object.
1336 - * @param string $context Meta box context.
1337 - * @param mixed $data_object Data object passed to callbacks.
1338 - *
1339 1204 * @return int
1340 1205 */
1341 - 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 ) {
1342 1207 global $wp_meta_boxes;
1343 1208
1344 - // The symbol id from icons.svg
1209 + // the symbol id from icons.svg
1345 1210 $icon_ids = array(
1346 1211 'ranking-fields-style' => 'frm_chart_bar_icon',
1347 1212 'section-fields-style' => 'frm-form-title-style',
1348 1213 );
@@ -1348,9 +1213,9 @@
1348 1213 );
1349 1214
1350 1215 wp_enqueue_script( 'accordion' );
1351 1216
1352 - if ( ! $screen ) {
1217 + if ( empty( $screen ) ) {
1353 1218 $screen = get_current_screen();
1354 1219 } elseif ( is_string( $screen ) ) {
1355 1220 $screen = convert_to_screen( $screen );
1356 1221 }
@@ -1356,9 +1221,8 @@
1356 1221 }
1357 1222
1358 1223 $page = $screen->id;
1359 1224
1360 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1361 1225 ?>
1362 1226 <div id="side-sortables" class="accordion-container">
1363 1227 <ul class="outer-border">
1364 1228 <?php
@@ -1366,46 +1230,40 @@
1366 1230 $first_open = false;
1367 1231
1368 1232 if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
1369 1233 foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
1370 - if ( ! isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
1371 - continue;
1372 - }
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 + }
1373 1239
1374 - foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
1375 - if ( false === $box || ! $box['title'] ) {
1376 - continue;
1377 - }
1240 + ++$i;
1241 + $icon_id = array_key_exists( $box['id'], $icon_ids ) ? $icon_ids[ $box['id'] ] : 'frm-' . $box['id'];
1378 1242
1379 - ++$i;
1380 - $icon_id = array_key_exists( $box['id'], $icon_ids ) ? $icon_ids[ $box['id'] ] : 'frm-' . $box['id'];
1381 - $open_class = '';
1382 -
1383 - if ( ! $first_open ) {
1384 - $first_open = true;
1385 - $open_class = 'open';
1386 - }
1387 -
1388 - $accordion_content_id = 'frm_style_section_' . $box['id'];
1389 - ?>
1390 - <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 ?>
1391 - <h3 class="accordion-section-title hndle">
1392 - <?php
1393 - FrmAppHelper::icon_by_class( 'frmfont ' . $icon_id . ' frm_svg24' );
1394 - echo esc_html( $box['title'] );
1395 - ?>
1396 - <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 ?>
1397 - <?php FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown8_icon' ); ?>
1398 - </button>
1399 - </h3>
1400 - <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>" id="<?php echo esc_attr( $accordion_content_id ); ?>">
1401 - <div class="inside">
1402 - <?php call_user_func( $box['callback'], $data_object, $box ); ?>
1403 - </div><!-- .inside -->
1404 - </div><!-- .accordion-section-content -->
1405 - </li><!-- .accordion-section -->
1406 - <?php
1407 - }//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
1408 1266 }//end foreach
1409 1267 }//end if
1410 1268 ?>
1411 1269 </ul><!-- .outer-border -->
@@ -1410,9 +1268,8 @@
1410 1268 ?>
1411 1269 </ul><!-- .outer-border -->
1412 1270 </div><!-- .accordion-container -->
1413 1271 <?php
1414 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1415 1272 return $i;
1416 1273 }
1417 1274
1418 1275 /**
@@ -1423,9 +1280,8 @@
1423 1280 * @return void
1424 1281 */
1425 1282 public static function rename_style() {
1426 1283 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'nonce', 'frm_ajax' );
1427 -
1428 1284 if ( $permission_error !== false ) {
1429 1285 $data = array(
1430 1286 'message' => __( 'Unable to rename style', 'formidable' ),
1431 1287 );
@@ -1444,9 +1300,8 @@
1444 1300 die();
1445 1301 }
1446 1302
1447 1303 $post = get_post( $style_id );
1448 -
1449 1304 if ( ! $post || $post->post_type !== self::$post_type ) {
1450 1305 $data = array(
1451 1306 'message' => __( 'The style you are renaming either does not exist or it is not a style', 'formidable' ),
1452 1307 );
@@ -1467,9 +1322,8 @@
1467 1322 *
1468 1323 * @since 6.0
1469 1324 *
1470 1325 * @param WP_Styles $styles
1471 - *
1472 1326 * @return void
1473 1327 */
1474 1328 public static function disable_conflicting_wp_admin_css( $styles ) {
1475 1329 if ( ! FrmAppHelper::is_style_editor_page() ) {