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