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