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