PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.19
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.19
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 +58 -182 6.276.19 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,30 +240,23 @@
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 ) {
257 + if ( 'formidable' == $css_key ) {
276 258 $this_version = get_option( 'frm_last_style_update' );
277 -
278 259 if ( ! $this_version ) {
279 260 $this_version = $version;
280 261 }
281 262 } else {
@@ -287,14 +268,14 @@
287 268
288 269 /**
289 270 * @param string $tag
290 271 * @param string $handle
291 - *
292 272 * @return string
293 273 */
294 274 public static function add_tags_to_css( $tag, $handle ) {
295 - if ( ( 'formidable' === $handle || 'jquery-theme' === $handle ) && ! str_contains( $tag, ' property=' ) ) {
296 - $tag = 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 );
297 278 }
298 279
299 280 return $tag;
300 281 }
@@ -342,11 +323,10 @@
342 323
343 324 self::setup_styles_and_scripts_for_styler();
344 325
345 326 $style_id = self::get_style_id_for_styler();
346 -
347 327 if ( ! $style_id ) {
348 - $error_args = array(
328 + $error_args = array(
349 329 'title' => __( 'No styles', 'formidable' ),
350 330 'body' => __( 'You must have a style to use the Visual Styler.', 'formidable' ),
351 331 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
352 332 );
@@ -354,9 +334,8 @@
354 334 return;
355 335 }
356 336
357 337 $form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 );
358 -
359 338 if ( ! $form_id ) {
360 339 $form_id = self::get_form_id_for_style( $style_id );
361 340 }
362 341
@@ -362,9 +341,9 @@
362 341
363 342 $form = FrmForm::getOne( $form_id );
364 343
365 344 if ( ! is_object( $form ) ) {
366 - $error_args = array(
345 + $error_args = array(
367 346 'title' => __( 'No forms', 'formidable' ),
368 347 'body' => __( 'You must have a form to use the Visual Styler.', 'formidable' ),
369 348 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
370 349 );
@@ -394,9 +373,8 @@
394 373 * @return int
395 374 */
396 375 private static function get_style_id_for_styler() {
397 376 $action = FrmAppHelper::simple_get( 'frm_action' );
398 -
399 377 if ( 'duplicate' === $action ) {
400 378 // The duplicate action uses style_id instead of id for better backward compatibility.
401 379 return FrmAppHelper::simple_get( 'style_id', 'absint', 0 );
402 380 }
@@ -401,9 +379,8 @@
401 379 return FrmAppHelper::simple_get( 'style_id', 'absint', 0 );
402 380 }
403 381
404 382 $style_id = FrmAppHelper::simple_get( 'id', 'absint', 0 );
405 -
406 383 if ( $style_id ) {
407 384 // Always use the style ID from the URL if one is specified.
408 385 return $style_id;
409 386 }
@@ -408,9 +385,8 @@
408 385 return $style_id;
409 386 }
410 387
411 388 $request_form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 );
412 -
413 389 if ( $request_form_id && is_callable( 'FrmProStylesController::get_active_style_for_form' ) ) {
414 390 return FrmProStylesController::get_active_style_for_form( $request_form_id )->ID;
415 391 }
416 392
@@ -422,9 +398,8 @@
422 398 *
423 399 * @since 6.0
424 400 *
425 401 * @param int $style_id
426 - *
427 402 * @return int
428 403 */
429 404 private static function get_form_id_for_style( $style_id ) {
430 405 $check = serialize( array( 'custom_style' => (string) $style_id ) );
@@ -437,8 +412,9 @@
437 412 )
438 413 );
439 414
440 415 if ( ! $form_id ) {
416 + // TODO: Show a message why a random form is being shown (because no form is assigned to the style).
441 417 // Fallback to any form.
442 418 $where = array(
443 419 'status' => 'published',
444 420 // Make sure it's not a repeater.
@@ -470,10 +446,11 @@
470 446 *
471 447 * @return WP_Post
472 448 */
473 449 private static function get_default_style() {
474 - $frm_style = new FrmStyle( 'default' );
475 - return $frm_style->get_one();
450 + $frm_style = new FrmStyle( 'default' );
451 + $default_style = $frm_style->get_one();
452 + return $default_style;
476 453 }
477 454
478 455 /**
479 456 * Save style for form (from Styler list page) via a POST action.
@@ -483,15 +460,13 @@
483 460 * @return void
484 461 */
485 462 private static function save_form_style() {
486 463 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form_style', 'frm_save_form_style_nonce' );
487 -
488 464 if ( $permission_error !== false ) {
489 465 wp_die( 'Unable to save form', '', 403 );
490 466 }
491 467
492 468 $style_id = FrmAppHelper::get_post_param( 'style_id', 0, 'absint' );
493 -
494 469 if ( $style_id && ! self::confirm_style_exists_before_setting( $style_id ) ) {
495 470 wp_die( esc_html__( 'Invalid target style', 'formidable' ), esc_html__( 'Invalid target style', 'formidable' ), 400 );
496 471 return;
497 472 }
@@ -511,9 +486,8 @@
511 486 return;
512 487 }
513 488
514 489 $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
515 -
516 490 if ( ! $form_id ) {
517 491 wp_die( esc_html__( 'No form specified', 'formidable' ), esc_html__( 'No form specified', 'formidable' ), 400 );
518 492 return;
519 493 }
@@ -518,21 +492,17 @@
518 492 return;
519 493 }
520 494
521 495 $form = FrmForm::getOne( $form_id );
522 -
523 496 if ( ! $form ) {
524 497 wp_die( esc_html__( 'Form does not exist', 'formidable' ), esc_html__( 'Form does not exist', 'formidable' ), 400 );
525 498 return;
526 499 }
527 500
528 - $previous_style_id = $form->options['custom_style'];
529 -
530 501 // If the default style is selected, use the "Always use default" legacy option instead of the default style.
531 502 // There's also a check here for conversational forms.
532 503 // Without the check it isn't possible to select "Default" because "Always use default" will convert to "Lines" dynamically.
533 504 $default_style = self::get_default_style();
534 -
535 505 if ( $style_id === $default_style->ID && empty( $form->options['chat'] ) ) {
536 506 $style_id = 1;
537 507 }
538 508
@@ -538,27 +508,13 @@
538 508
539 509 // We want to save a string for consistency. FrmStylesHelper::get_form_count_for_style expects the custom style ID is a string.
540 510 $form->options['custom_style'] = (string) $style_id;
541 511
542 - if ( $previous_style_id === $form->options['custom_style'] ) {
543 - // Exit early before updating DB if nothing actually changed.
544 - self::$message = __( 'Successfully updated style.', 'formidable' );
545 - return;
546 - }
547 -
548 512 global $wpdb;
549 513 $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) );
550 514
551 515 FrmForm::clear_form_cache();
552 516
553 - /**
554 - * @since 6.25.1
555 - *
556 - * @param int $form_id
557 - * @param int $style_id
558 - */
559 - do_action( 'frm_after_changed_form_style', absint( $form_id ), absint( $style_id ) );
560 -
561 517 self::$message = __( 'Successfully updated style.', 'formidable' );
562 518 }
563 519
564 520 /**
@@ -564,9 +520,8 @@
564 520 /**
565 521 * Validate that we're assigning a form to a style that actually exists before assigning it to a form.
566 522 *
567 523 * @param int $style_id
568 - *
569 524 * @return bool True if the style actually exists.
570 525 */
571 526 private static function confirm_style_exists_before_setting( $style_id ) {
572 527 global $wpdb;
@@ -585,9 +540,9 @@
585 540 $plugin_url = FrmAppHelper::plugin_url();
586 541 $version = FrmAppHelper::plugin_version();
587 542 $js_dependencies = array( 'wp-i18n', 'wp-hooks', 'formidable_dom' );
588 543
589 - if ( FrmAppHelper::pro_is_installed() && is_callable( 'FrmProAppHelper::use_jquery_datepicker' ) && FrmProAppHelper::use_jquery_datepicker() ) {
544 + if ( FrmAppHelper::pro_is_installed() ) {
590 545 $js_dependencies[] = 'jquery-ui-datepicker';
591 546 }
592 547
593 548 wp_register_script( 'formidable_style', $plugin_url . '/js/admin/style.js', $js_dependencies, $version );
@@ -606,9 +561,8 @@
606 561 *
607 562 * @param stdClass|WP_Post $active_style
608 563 * @param stdClass $form
609 564 * @param WP_Post $default_style
610 - *
611 565 * @return void
612 566 */
613 567 private static function render_style_page( $active_style, $form, $default_style ) {
614 568 $style_views_path = self::get_views_path();
@@ -683,9 +637,8 @@
683 637 *
684 638 * @since 6.0
685 639 *
686 640 * @param stdClass|WP_Post $style A new style is not a WP_Post object.
687 - *
688 641 * @return void
689 642 */
690 643 private static function force_form_style( $style ) {
691 644 add_filter(
@@ -696,9 +649,9 @@
696 649 /**
697 650 * @param string $class
698 651 */
699 652 function ( $class ) {
700 - return $class && ! str_starts_with( $class, 'frm_style_' );
653 + return $class && 0 !== strpos( $class, 'frm_style_' );
701 654 }
702 655 );
703 656 $split[] = 'frm_style_' . $style->post_name;
704 657 return implode( ' ', $split );
@@ -724,9 +677,8 @@
724 677 return;
725 678 }
726 679
727 680 $id = $frm_style->update( $post_id );
728 -
729 681 if ( ! $post_id && $id ) {
730 682 self::maybe_redirect_after_save( $id );
731 683 // Set the post id to the new style so it will be loaded for editing.
732 684 $post_id = reset( $id );
@@ -731,15 +683,8 @@
731 683 // Set the post id to the new style so it will be loaded for editing.
732 684 $post_id = reset( $id );
733 685 }
734 686
735 - /**
736 - * @since 6.25.1
737 - *
738 - * @param int $post_id
739 - */
740 - do_action( 'frm_after_saved_style', absint( $post_id ) );
741 -
742 687 self::$message = __( 'Your styling settings have been saved.', 'formidable' );
743 688 }
744 689
745 690 /**
@@ -758,20 +703,19 @@
758 703 *
759 704 * @since 6.0
760 705 *
761 706 * @param array $ids
762 - *
763 707 * @return void
764 708 */
765 709 private static function maybe_redirect_after_save( $ids ) {
766 - $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
767 - $parsed = parse_url( $referer );
768 - $query = $parsed['query'];
710 + $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
711 + $parsed = parse_url( $referer );
712 + $query = $parsed['query'];
713 +
769 714 $current_action = false;
770 715 $actions_to_redirect = array( 'duplicate', 'new_style' );
771 -
772 716 foreach ( $actions_to_redirect as $action ) {
773 - if ( str_contains( $query, 'frm_action=' . $action ) ) {
717 + if ( false !== strpos( $query, 'frm_action=' . $action ) ) {
774 718 $current_action = $action;
775 719 break;
776 720 }
777 721 }
@@ -781,9 +725,10 @@
781 725 return;
782 726 }
783 727
784 728 parse_str( $query, $parsed_query );
785 - $form_id = ! empty( $parsed_query['form'] ) ? absint( $parsed_query['form'] ) : 0;
729 + $form_id = ! empty( $parsed_query['form'] ) ? absint( $parsed_query['form'] ) : 0;
730 +
786 731 $style = new stdClass();
787 732 $style->ID = end( $ids );
788 733 wp_safe_redirect( esc_url_raw( FrmStylesHelper::get_edit_url( $style, $form_id ) ) );
789 734 die();
@@ -793,9 +738,8 @@
793 738 * @since 6.0
794 739 *
795 740 * @param string $message
796 741 * @param array|object $forms
797 - *
798 742 * @return void
799 743 */
800 744 public static function manage( $message = '', $forms = array() ) {
801 745 $frm_style = new FrmStyle();
@@ -819,9 +763,8 @@
819 763 private static function manage_styles() {
820 764 global $wpdb;
821 765
822 766 $forms = FrmForm::get_published_forms();
823 -
824 767 foreach ( $forms as $form ) {
825 768 if ( ! isset( $_POST['style'] ) || ! isset( $_POST['style'][ $form->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
826 769 continue;
827 770 }
@@ -837,28 +780,15 @@
837 780 /**
838 781 * Echo content for the Custom CSS page.
839 782 *
840 783 * @param string $message
841 - * @param array $extra_args An array of extra arguments.
842 - *
843 784 * @return void
844 785 */
845 - public static function custom_css( $message = '', $extra_args = array() ) {
846 - $id = $extra_args['id'] ?? 'frm_codemirror_box';
847 - $settings = self::enqueue_codemirror( $id, $extra_args['placeholder'] ?? '' );
848 - $id = $settings ? $id : 'frm_custom_css_box';
849 - $show_errors = $extra_args['show_errors'] ?? true;
850 - $custom_css = $extra_args['custom_css'] ?? self::get_custom_css();
851 - $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
852 - $textarea_params = ! empty( $extra_args['textarea_params'] ) ? $extra_args['textarea_params'] : array(
853 - 'name' => 'frm_custom_css',
854 - 'id' => $id,
855 - );
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();
856 790
857 - if ( $settings ) {
858 - $textarea_params['class'] = 'hide-if-js';
859 - }
860 -
861 791 include FrmAppHelper::plugin_path() . '/classes/views/styles/custom_css.php';
862 792 }
863 793
864 794 /**
@@ -865,33 +795,22 @@
865 795 * Get custom CSS code entered in the Custom CSS page.
866 796 *
867 797 * @since 6.0
868 798 *
869 - * @param array|null $single_style_settings The single style settings.
870 - *
871 799 * @return string
872 800 */
873 - public static function get_custom_css( $single_style_settings = null ) {
874 - if ( $single_style_settings ) {
875 - // If the single style settings are passed, return the custom CSS from the single style settings.
876 - if ( ! empty( $single_style_settings['single_style_custom_css'] ) && ! empty( $single_style_settings['enable_style_custom_css'] ) ) {
877 - return $single_style_settings['single_style_custom_css'];
878 - }
879 -
880 - return '';
881 - }
882 -
801 + public static function get_custom_css() {
883 802 $settings = FrmAppHelper::get_settings();
884 -
885 803 if ( is_string( $settings->custom_css ) ) {
886 804 return $settings->custom_css;
887 805 }
888 806
889 807 // If it does not exist, check the default style as a fallback.
890 - $frm_style = new FrmStyle();
891 - $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'];
892 811
893 - return $style->post_content['custom_css'];
812 + return $custom_css;
894 813 }
895 814
896 815 /**
897 816 * Enqueue assets for codemirror, built into WordPress since 4.9.
@@ -898,14 +817,11 @@
898 817 * The Custom CSS page uses codemirror.
899 818 *
900 819 * @since 6.0 Previously this code was embedded in self::custom_css.
901 820 *
902 - * @param string $id The ID of the codemirror box.
903 - * @param string $placeholder The placeholder text for the codemirror box.
904 - *
905 821 * @return array|false
906 822 */
907 - private static function enqueue_codemirror( $id = 'frm_codemirror_box', $placeholder = '' ) {
823 + private static function enqueue_codemirror() {
908 824 if ( ! function_exists( 'wp_enqueue_code_editor' ) ) {
909 825 // The WordPress version is likely older than 4.9.
910 826 return false;
911 827 }
@@ -918,9 +834,8 @@
918 834 'tabSize' => 2,
919 835 // As the codemirror box only appears once you click into the Custom CSS tab, we need to auto-refresh.
920 836 // Otherwise the line numbers all end up with a 1px width causing overlap issues with the text in the content.
921 837 'autoRefresh' => true,
922 - 'placeholder' => $placeholder,
923 838 ),
924 839 )
925 840 );
926 841
@@ -927,11 +842,9 @@
927 842 if ( $settings ) {
928 843 wp_add_inline_script(
929 844 'code-editor',
930 845 sprintf(
931 - 'jQuery( function() { window.%s_wp_editor = wp.codeEditor.initialize( \'%s\', %s ); } );',
932 - $id,
933 - $id,
846 + 'jQuery( function() { wp.codeEditor.initialize( \'frm_codemirror_box\', %s ); } );',
934 847 wp_json_encode( $settings )
935 848 )
936 849 );
937 850 }
@@ -983,9 +896,8 @@
983 896 FrmAppHelper::permission_check( 'frm_change_settings' );
984 897 check_ajax_referer( 'frm_ajax', 'nonce' );
985 898
986 899 $style_id = FrmAppHelper::get_post_param( 'style_id', '', 'absint' );
987 -
988 900 if ( ! $style_id ) {
989 901 // A style ID is not sent when resetting on the edit page.
990 902 // Instead of resetting the style, send the defaults back so the inputs can be updated with JavaScript.
991 903 $frm_style = new FrmStyle();
@@ -1076,9 +988,8 @@
1076 988
1077 989 /**
1078 990 * @param array $atts
1079 991 * @param array $sec
1080 - *
1081 992 * @return void
1082 993 */
1083 994 public static function include_style_section( $atts, $sec ) {
1084 995 extract( $atts ); // phpcs:ignore WordPress.PHP.DontExtract
@@ -1149,10 +1060,9 @@
1149 1060 * @return void
1150 1061 */
1151 1062 public static function maybe_hide_sample_form_error_message() {
1152 1063 $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
1153 -
1154 - if ( str_contains( $referer, 'admin.php?page=formidable-styles' ) ) {
1064 + if ( false !== strpos( $referer, 'admin.php?page=formidable-styles' ) ) {
1155 1065 echo '#frm_broken_styles_warning { display: none; }';
1156 1066 }
1157 1067 }
1158 1068
@@ -1161,9 +1071,8 @@
1161 1071 *
1162 1072 * @since 4.11.03
1163 1073 *
1164 1074 * @param string $css CSS content.
1165 - *
1166 1075 * @return string
1167 1076 */
1168 1077 public static function replace_relative_url( $css ) {
1169 1078 $plugin_url = trailingslashit( FrmAppHelper::plugin_url() );
@@ -1186,21 +1095,18 @@
1186 1095 * Check if the Formidable styling should be loaded,
1187 1096 * then enqueue it for the footer
1188 1097 *
1189 1098 * @since 2.0
1190 - *
1191 - * @return void
1192 1099 */
1193 1100 public static function enqueue_style() {
1194 1101 global $frm_vars;
1195 1102
1196 - if ( ! empty( $frm_vars['css_loaded'] ) ) {
1103 + if ( isset( $frm_vars['css_loaded'] ) && $frm_vars['css_loaded'] ) {
1197 1104 // The CSS has already been loaded.
1198 1105 return;
1199 1106 }
1200 1107
1201 1108 $frm_settings = FrmAppHelper::get_settings();
1202 -
1203 1109 if ( $frm_settings->load_style !== 'none' ) {
1204 1110 wp_enqueue_style( 'formidable' );
1205 1111 $frm_vars['css_loaded'] = true;
1206 1112 }
@@ -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,11 @@
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 1208 public static function &important_style( $important, $field ) {
1329 1209 $important = self::get_style_val( 'important_style', $field['form_id'] );
1210 +
1330 1211 return $important;
1331 1212 }
1332 1213
1333 1214 /**
@@ -1334,15 +1215,11 @@
1334 1215 * Duplicate of WordPress do_accordion_section function, it adds an additional svg icon support.
1335 1216 *
1336 1217 * @since 6.8.3
1337 1218 *
1338 - * @param string|WP_Screen $screen Screen ID or screen object.
1339 - * @param string $context Meta box context.
1340 - * @param mixed $data_object Data object passed to callbacks.
1341 - *
1342 1219 * @return int
1343 1220 */
1344 - 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 ) {
1345 1222 global $wp_meta_boxes;
1346 1223
1347 1224 // the symbol id from icons.svg
1348 1225 $icon_ids = array(
@@ -1351,9 +1228,9 @@
1351 1228 );
1352 1229
1353 1230 wp_enqueue_script( 'accordion' );
1354 1231
1355 - if ( ! $screen ) {
1232 + if ( empty( $screen ) ) {
1356 1233 $screen = get_current_screen();
1357 1234 } elseif ( is_string( $screen ) ) {
1358 1235 $screen = convert_to_screen( $screen );
1359 1236 }
@@ -1375,11 +1252,11 @@
1375 1252 continue;
1376 1253 }
1377 1254
1378 1255 ++$i;
1379 - $icon_id = array_key_exists( $box['id'], $icon_ids ) ? $icon_ids[ $box['id'] ] : 'frm-' . $box['id'];
1256 + $icon_id = array_key_exists( $box['id'], $icon_ids ) ? $icon_ids[ $box['id'] ] : 'frm-' . $box['id'];
1257 +
1380 1258 $open_class = '';
1381 -
1382 1259 if ( ! $first_open ) {
1383 1260 $first_open = true;
1384 1261 $open_class = 'open';
1385 1262 }
@@ -1385,16 +1262,18 @@
1385 1262 }
1386 1263
1387 1264 $accordion_content_id = 'frm_style_section_' . $box['id'];
1388 1265 ?>
1389 - <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 ?>
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'] ); ?>">
1390 1267 <h3 class="accordion-section-title hndle">
1391 1268 <?php
1392 - FrmAppHelper::icon_by_class( 'frmfont ' . $icon_id . ' frm_svg24' );
1269 + FrmAppHelper::icon_by_class( 'frmfont ' . $icon_id );
1393 1270 echo esc_html( $box['title'] );
1394 1271 ?>
1395 - <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 ?>
1396 - <?php FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown8_icon' ); ?>
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 + ?>
1397 1276 </button>
1398 1277 </h3>
1399 1278 <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>" id="<?php echo esc_attr( $accordion_content_id ); ?>">
1400 1279 <div class="inside">
@@ -1422,9 +1301,8 @@
1422 1301 * @return void
1423 1302 */
1424 1303 public static function rename_style() {
1425 1304 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'nonce', 'frm_ajax' );
1426 -
1427 1305 if ( $permission_error !== false ) {
1428 1306 $data = array(
1429 1307 'message' => __( 'Unable to rename style', 'formidable' ),
1430 1308 );
@@ -1443,9 +1321,8 @@
1443 1321 die();
1444 1322 }
1445 1323
1446 1324 $post = get_post( $style_id );
1447 -
1448 1325 if ( ! $post || $post->post_type !== self::$post_type ) {
1449 1326 $data = array(
1450 1327 'message' => __( 'The style you are renaming either does not exist or it is not a style', 'formidable' ),
1451 1328 );
@@ -1466,9 +1343,8 @@
1466 1343 *
1467 1344 * @since 6.0
1468 1345 *
1469 1346 * @param WP_Styles $styles
1470 - *
1471 1347 * @return void
1472 1348 */
1473 1349 public static function disable_conflicting_wp_admin_css( $styles ) {
1474 1350 if ( ! FrmAppHelper::is_style_editor_page() ) {