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