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 +157 -53 6.36.19 View file →
@@ -5,19 +5,19 @@
5 5
6 6 class FrmStylesController {
7 7
8 8 /**
9 - * @var string $post_type
9 + * @var string
10 10 */
11 11 public static $post_type = 'frm_styles';
12 12
13 13 /**
14 - * @var string $screen
14 + * @var string
15 15 */
16 16 public static $screen = 'formidable_page_formidable-styles';
17 17
18 18 /**
19 - * @var string|null $message
19 + * @var string|null
20 20 */
21 21 private static $message;
22 22
23 23 public static function load_pro_hooks() {
@@ -95,9 +95,9 @@
95 95 *
96 96 * @return void
97 97 */
98 98 private static function disable_form_css() {
99 - add_filter( 'get_frm_stylesheet', '__return_false' );
99 + add_filter( 'get_frm_stylesheet', '__return_empty_array' );
100 100 }
101 101
102 102 /**
103 103 * Removing this action prevents front end JavaScript from loading.
@@ -119,8 +119,9 @@
119 119 if ( ! FrmAppHelper::is_style_editor_page() ) {
120 120 return;
121 121 }
122 122
123 + FrmStyleComponent::register_assets();
123 124 self::load_pro_hooks();
124 125
125 126 $version = FrmAppHelper::plugin_version();
126 127 wp_enqueue_script( 'jquery-ui-datepicker' );
@@ -152,9 +153,9 @@
152 153 'frm_update_settings',
153 154 /**
154 155 * Update the form data on the "Manage Styles" tab after global settings are saved.
155 156 */
156 - function() {
157 + function () {
157 158 self::manage_styles();
158 159 }
159 160 );
160 161 }
@@ -191,9 +192,9 @@
191 192 wp_register_style( $css_key, $file, array(), $this_version );
192 193 }
193 194
194 195 $load_on_all = ! FrmAppHelper::is_admin() && 'all' === $frm_settings->load_style;
195 - if ( $load_on_all || $register != 'register' ) {
196 + if ( $load_on_all || $register !== 'register' ) {
196 197 wp_enqueue_style( $css_key );
197 198 }
198 199 unset( $css_key, $file );
199 200 }
@@ -200,9 +201,9 @@
200 201
201 202 if ( $frm_settings->load_style === 'all' ) {
202 203 $frm_vars['css_loaded'] = true;
203 204 }
204 - }
205 + }//end if
205 206 unset( $css );
206 207
207 208 add_filter( 'style_loader_tag', 'FrmStylesController::add_tags_to_css', 10, 2 );
208 209 }
@@ -264,14 +265,17 @@
264 265
265 266 return $this_version;
266 267 }
267 268
269 + /**
270 + * @param string $tag
271 + * @param string $handle
272 + * @return string
273 + */
268 274 public static function add_tags_to_css( $tag, $handle ) {
269 - if ( ( 'formidable' == $handle || 'jquery-theme' == $handle ) && strpos( $tag, ' property=' ) === false ) {
275 + if ( ( 'formidable' === $handle || 'jquery-theme' === $handle ) && strpos( $tag, ' property=' ) === false ) {
270 276 $frm_settings = FrmAppHelper::get_settings();
271 - if ( $frm_settings->use_html ) {
272 - $tag = str_replace( ' type="', ' property="stylesheet" type="', $tag );
273 - }
277 + $tag = str_replace( ' type="', ' property="stylesheet" type="', $tag );
274 278 }
275 279
276 280 return $tag;
277 281 }
@@ -320,9 +324,15 @@
320 324 self::setup_styles_and_scripts_for_styler();
321 325
322 326 $style_id = self::get_style_id_for_styler();
323 327 if ( ! $style_id ) {
324 - wp_die( esc_html__( 'Invalid route', 'formidable' ), esc_html__( 'Invalid route', 'formidable' ), 400 );
328 + $error_args = array(
329 + 'title' => __( 'No styles', 'formidable' ),
330 + 'body' => __( 'You must have a style to use the Visual Styler.', 'formidable' ),
331 + 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
332 + );
333 + FrmAppController::show_error_modal( $error_args );
334 + return;
325 335 }
326 336
327 337 $form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 );
328 338 if ( ! $form_id ) {
@@ -329,10 +339,17 @@
329 339 $form_id = self::get_form_id_for_style( $style_id );
330 340 }
331 341
332 342 $form = FrmForm::getOne( $form_id );
343 +
333 344 if ( ! is_object( $form ) ) {
334 - wp_die( esc_html__( 'Invalid route', 'formidable' ), esc_html__( 'Invalid route', 'formidable' ), 400 );
345 + $error_args = array(
346 + 'title' => __( 'No forms', 'formidable' ),
347 + 'body' => __( 'You must have a form to use the Visual Styler.', 'formidable' ),
348 + 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
349 + );
350 + FrmAppController::show_error_modal( $error_args );
351 + return;
335 352 }
336 353
337 354 $frm_style = new FrmStyle( $style_id );
338 355 $active_style = $frm_style->get_one();
@@ -342,11 +359,9 @@
342 359
343 360 /**
344 361 * @since 6.0
345 362 *
346 - * @param array {
347 - * @type stdClass $form
348 - * }
363 + * @param array{form:\stdClass} $data
349 364 */
350 365 do_action( 'frm_before_render_style_page', compact( 'form' ) );
351 366
352 367 self::render_style_page( $active_style, $form, $default_style );
@@ -399,11 +414,12 @@
399 414
400 415 if ( ! $form_id ) {
401 416 // TODO: Show a message why a random form is being shown (because no form is assigned to the style).
402 417 // Fallback to any form.
403 - $where = array(
418 + $where = array(
404 419 'status' => 'published',
405 - 'parent_form_id' => array( null, 0 ), // Make sure it's not a repeater.
420 + // Make sure it's not a repeater.
421 + 'parent_form_id' => array( null, 0 ),
406 422 );
407 423 $form_id = FrmDb::get_var( 'frm_forms', $where, 'id' );
408 424 }
409 425
@@ -417,9 +433,9 @@
417 433 */
418 434 private static function disable_admin_page_styling_on_submit_buttons() {
419 435 add_filter(
420 436 'frm_submit_button_class',
421 - function( $classes ) {
437 + function ( $classes ) {
422 438 $classes[] = 'frm_no_style_button';
423 439 return $classes;
424 440 }
425 441 );
@@ -463,15 +479,15 @@
463 479 * @param int $style_id
464 480 */
465 481 $style_id = apply_filters( 'frm_saved_form_style_id', $style_id );
466 482
467 - if ( ! $style_id && '0' !== FrmAppHelper::get_post_param( 'style_id', 'sanitize_text_field', '' ) ) {
483 + if ( ! $style_id && '0' !== FrmAppHelper::get_post_param( 'style_id', '', 'sanitize_text_field' ) ) {
468 484 // "0" is a special value used for the enable/disable toggle.
469 485 wp_die( esc_html__( 'Invalid style value', 'formidable' ), esc_html__( 'Invalid style value', 'formidable' ), 400 );
470 486 return;
471 487 }
472 488
473 - $form_id = FrmAppHelper::get_post_param( 'form_id', 'absint', 0 );
489 + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
474 490 if ( ! $form_id ) {
475 491 wp_die( esc_html__( 'No form specified', 'formidable' ), esc_html__( 'No form specified', 'formidable' ), 400 );
476 492 return;
477 493 }
@@ -489,9 +505,10 @@
489 505 if ( $style_id === $default_style->ID && empty( $form->options['chat'] ) ) {
490 506 $style_id = 1;
491 507 }
492 508
493 - $form->options['custom_style'] = (string) $style_id; // We want to save a string for consistency. FrmStylesHelper::get_form_count_for_style expects the custom style ID is a string.
509 + // We want to save a string for consistency. FrmStylesHelper::get_form_count_for_style expects the custom style ID is a string.
510 + $form->options['custom_style'] = (string) $style_id;
494 511
495 512 global $wpdb;
496 513 $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) );
497 514
@@ -533,8 +550,9 @@
533 550 wp_print_styles( 'formidable_style' );
534 551
535 552 wp_print_styles( 'formidable' );
536 553 wp_enqueue_script( 'formidable_style' );
554 + wp_set_script_translations( 'formidable_style', 'formidable' );
537 555 }
538 556
539 557 /**
540 558 * Render the style page (with a more limited and typed scope than calling it from self::style directly).
@@ -541,9 +559,8 @@
541 559 *
542 560 * @since 6.0
543 561 *
544 562 * @param stdClass|WP_Post $active_style
545 - * @param array<WP_Post> $styles
546 563 * @param stdClass $form
547 564 * @param WP_Post $default_style
548 565 * @return void
549 566 */
@@ -548,13 +565,15 @@
548 565 * @return void
549 566 */
550 567 private static function render_style_page( $active_style, $form, $default_style ) {
551 568 $style_views_path = self::get_views_path();
552 - $view = FrmAppHelper::simple_get( 'frm_action', 'sanitize_text_field', 'list' ); // edit, list (default), new_style.
553 - $frm_style = new FrmStyle( $active_style->ID );
569 + // Edit, list (default), new_style.
570 + $view = FrmAppHelper::simple_get( 'frm_action', 'sanitize_text_field', 'list' );
571 + $frm_style = new FrmStyle( $active_style->ID );
554 572
555 573 if ( 'new_style' !== $view && ! FrmAppHelper::simple_get( 'form' ) && ! FrmAppHelper::simple_get( 'style_id' ) ) {
556 - $view = 'edit'; // Have the Appearance > Forms link fallback to the edit view. Otherwise we want to use 'list' as the default.
574 + // Have the Appearance > Forms link fallback to the edit view. Otherwise we want to use 'list' as the default.
575 + $view = 'edit';
557 576 }
558 577
559 578 if ( in_array( $view, array( 'edit', 'new_style', 'duplicate' ), true ) ) {
560 579 self::add_meta_boxes();
@@ -617,21 +636,21 @@
617 636 * Filter form classes so the form uses the preview style, not the form's active style.
618 637 *
619 638 * @since 6.0
620 639 *
621 - * @param WP_Post|stdClass $style A new style is not a WP_Post object.
640 + * @param stdClass|WP_Post $style A new style is not a WP_Post object.
622 641 * @return void
623 642 */
624 643 private static function force_form_style( $style ) {
625 644 add_filter(
626 645 'frm_add_form_style_class',
627 - function( $class ) use ( $style ) {
628 - $split = array_filter(
646 + function ( $class ) use ( $style ) {
647 + $split = array_filter(
629 648 explode( ' ', $class ),
630 649 /**
631 650 * @param string $class
632 651 */
633 - function( $class ) {
652 + function ( $class ) {
634 653 return $class && 0 !== strpos( $class, 'frm_style_' );
635 654 }
636 655 );
637 656 $split[] = 'frm_style_' . $style->post_name;
@@ -648,9 +667,8 @@
648 667 * @return void
649 668 */
650 669 public static function save_style() {
651 670 $frm_style = new FrmStyle();
652 - $message = '';
653 671 $post_id = FrmAppHelper::get_post_param( 'ID', false, 'sanitize_title' );
654 672 $style_nonce = FrmAppHelper::get_post_param( 'frm_style', '', 'sanitize_text_field' );
655 673
656 674 if ( $post_id === false || ! wp_verify_nonce( $style_nonce, 'frm_style_nonce' ) ) {
@@ -661,9 +679,10 @@
661 679
662 680 $id = $frm_style->update( $post_id );
663 681 if ( ! $post_id && $id ) {
664 682 self::maybe_redirect_after_save( $id );
665 - $post_id = reset( $id ); // Set the post id to the new style so it will be loaded for editing.
683 + // Set the post id to the new style so it will be loaded for editing.
684 + $post_id = reset( $id );
666 685 }
667 686
668 687 self::$message = __( 'Your styling settings have been saved.', 'formidable' );
669 688 }
@@ -706,9 +725,9 @@
706 725 return;
707 726 }
708 727
709 728 parse_str( $query, $parsed_query );
710 - $form_id = ! empty( $parsed_query['form'] ) ? absint( $parsed_query['form'] ) : 0;
729 + $form_id = ! empty( $parsed_query['form'] ) ? absint( $parsed_query['form'] ) : 0;
711 730
712 731 $style = new stdClass();
713 732 $style->ID = end( $ids );
714 733 wp_safe_redirect( esc_url_raw( FrmStylesHelper::get_edit_url( $style, $form_id ) ) );
@@ -725,8 +744,9 @@
725 744 public static function manage( $message = '', $forms = array() ) {
726 745 $frm_style = new FrmStyle();
727 746 $styles = $frm_style->get_all();
728 747 $default_style = $frm_style->get_default_style( $styles );
748 + $frm_settings = FrmAppHelper::get_settings();
729 749
730 750 if ( ! $forms ) {
731 751 $forms = FrmForm::get_published_forms();
732 752 }
@@ -744,14 +764,14 @@
744 764 global $wpdb;
745 765
746 766 $forms = FrmForm::get_published_forms();
747 767 foreach ( $forms as $form ) {
748 - $new_style = ( isset( $_POST['style'] ) && isset( $_POST['style'][ $form->id ] ) ) ? sanitize_text_field( wp_unslash( $_POST['style'][ $form->id ] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
749 - $previous_style = ( isset( $_POST['prev_style'] ) && isset( $_POST['prev_style'][ $form->id ] ) ) ? sanitize_text_field( wp_unslash( $_POST['prev_style'][ $form->id ] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
750 - if ( $new_style == $previous_style ) {
768 + if ( ! isset( $_POST['style'] ) || ! isset( $_POST['style'][ $form->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
751 769 continue;
752 770 }
753 771
772 + $new_style = sanitize_text_field( wp_unslash( $_POST['style'][ $form->id ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
773 +
754 774 $form->options['custom_style'] = $new_style;
755 775 $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) );
756 776 unset( $form );
757 777 }
@@ -885,22 +905,26 @@
885 905 echo json_encode( $defaults );
886 906 wp_die();
887 907 }
888 908
889 - $frm_style = new FrmStyle();
890 - $defaults = $frm_style->get_defaults();
891 - $default_post_content = FrmAppHelper::prepare_and_encode( $defaults );
892 - $where = array(
909 + $frm_style = new FrmStyle();
910 + $default_template_style = $frm_style->get_default_template_style( $style_id );
911 + $where = array(
893 912 'ID' => $style_id,
894 913 'post_type' => self::$post_type,
895 914 );
915 +
916 + $style_object = $frm_style->get_new();
917 + $style_object->post_content = json_decode( $default_template_style, true );
918 +
896 919 global $wpdb;
897 - $wpdb->update( $wpdb->posts, array( 'post_content' => $default_post_content ), $where );
920 + $wpdb->update( $wpdb->posts, array( 'post_content' => $default_template_style ), $where );
898 921
899 - $frm_style->save_settings(); // Save the settings after resetting to default or the old style will still appear.
922 + // Save the settings after resetting to default or the old style will still appear.
923 + $frm_style->save_settings();
900 924
901 925 $data = array(
902 - 'style' => FrmStylesCardHelper::get_style_param_for_card( $frm_style->get_new() ),
926 + 'style' => FrmStylesCardHelper::get_style_param_for_card( $style_object ),
903 927 );
904 928 wp_send_json_success( $data );
905 929 wp_die();
906 930 }
@@ -915,12 +939,15 @@
915 939 public static function change_styling() {
916 940 FrmAppHelper::permission_check( 'frm_change_settings' );
917 941 check_ajax_referer( 'frm_ajax', 'nonce' );
918 942
919 - $frm_style = new FrmStyle();
920 - $defaults = false; // Intentionally avoid defaults here so nothing gets removed from our style.
921 - $style = '';
943 + $is_loaded_via_ajax = true;
944 + $frm_style = new FrmStyle();
922 945
946 + // Intentionally avoid defaults here so nothing gets removed from our style.
947 + $defaults = array();
948 + $style = '';
949 +
923 950 echo '<style type="text/css">';
924 951 include FrmAppHelper::plugin_path() . '/css/_single_theme.css.php';
925 952 echo '</style>';
926 953 wp_die();
@@ -1025,9 +1052,9 @@
1025 1052 }
1026 1053
1027 1054 /**
1028 1055 * Add an extra style rule to hide a broken style warning.
1029 - * To avoid cluttering the front end with any unecessary styles this is only added when the referer URL matches the styler.
1056 + * To avoid cluttering the front end with any unnecessary styles this is only added when the referer URL matches the styler.
1030 1057 *
1031 1058 * @since 6.2.3
1032 1059 *
1033 1060 * @return void
@@ -1078,9 +1105,9 @@
1078 1105 return;
1079 1106 }
1080 1107
1081 1108 $frm_settings = FrmAppHelper::get_settings();
1082 - if ( $frm_settings->load_style != 'none' ) {
1109 + if ( $frm_settings->load_style !== 'none' ) {
1083 1110 wp_enqueue_style( 'formidable' );
1084 1111 $frm_vars['css_loaded'] = true;
1085 1112 }
1086 1113 }
@@ -1099,9 +1126,9 @@
1099 1126
1100 1127 /**
1101 1128 * Get the style post object for a target form.
1102 1129 *
1103 - * @param object|string|boolean $form
1130 + * @param bool|object|string $form
1104 1131 * @return WP_Post|null
1105 1132 */
1106 1133 public static function get_form_style( $form = 'default' ) {
1107 1134 $style = FrmFormsHelper::get_form_style( $form );
@@ -1134,12 +1161,11 @@
1134 1161 return $class;
1135 1162 }
1136 1163
1137 1164 /**
1165 + * @since 3.0
1138 1166 * @param object $style
1139 1167 * @param string $class
1140 - *
1141 - * @since 3.0
1142 1168 */
1143 1169 private static function maybe_add_rtl_class( $style, &$class ) {
1144 1170 $is_rtl = isset( $style->post_content['direction'] ) && 'rtl' === $style->post_content['direction'];
1145 1171 if ( $is_rtl ) {
@@ -1184,10 +1210,88 @@
1184 1210
1185 1211 return $important;
1186 1212 }
1187 1213
1188 - public static function do_accordion_sections( $screen, $context, $object ) {
1189 - return do_accordion_sections( $screen, $context, $object );
1214 + /**
1215 + * Duplicate of WordPress do_accordion_section function, it adds an additional svg icon support.
1216 + *
1217 + * @since 6.8.3
1218 + *
1219 + * @return int
1220 + */
1221 + public static function do_accordion_sections( $screen, $context, $data_object ) {
1222 + global $wp_meta_boxes;
1223 +
1224 + // the symbol id from icons.svg
1225 + $icon_ids = array(
1226 + 'ranking-fields-style' => 'frm_chart_bar_icon',
1227 + 'section-fields-style' => 'frm-form-title-style',
1228 + );
1229 +
1230 + wp_enqueue_script( 'accordion' );
1231 +
1232 + if ( empty( $screen ) ) {
1233 + $screen = get_current_screen();
1234 + } elseif ( is_string( $screen ) ) {
1235 + $screen = convert_to_screen( $screen );
1236 + }
1237 +
1238 + $page = $screen->id;
1239 +
1240 + ?>
1241 + <div id="side-sortables" class="accordion-container">
1242 + <ul class="outer-border">
1243 + <?php
1244 + $i = 0;
1245 + $first_open = false;
1246 +
1247 + if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
1248 + foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
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 + }
1254 +
1255 + ++$i;
1256 + $icon_id = array_key_exists( $box['id'], $icon_ids ) ? $icon_ids[ $box['id'] ] : 'frm-' . $box['id'];
1257 +
1258 + $open_class = '';
1259 + if ( ! $first_open ) {
1260 + $first_open = true;
1261 + $open_class = 'open';
1262 + }
1263 +
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
1287 + }//end foreach
1288 + }//end if
1289 + ?>
1290 + </ul><!-- .outer-border -->
1291 + </div><!-- .accordion-container -->
1292 + <?php
1293 + return $i;
1190 1294 }
1191 1295
1192 1296 /**
1193 1297 * Rename a style via an AJAX action.