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