PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.13
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.13
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 +120 -39 6.36.13 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() {
@@ -152,9 +152,9 @@
152 152 'frm_update_settings',
153 153 /**
154 154 * Update the form data on the "Manage Styles" tab after global settings are saved.
155 155 */
156 - function() {
156 + function () {
157 157 self::manage_styles();
158 158 }
159 159 );
160 160 }
@@ -191,9 +191,9 @@
191 191 wp_register_style( $css_key, $file, array(), $this_version );
192 192 }
193 193
194 194 $load_on_all = ! FrmAppHelper::is_admin() && 'all' === $frm_settings->load_style;
195 - if ( $load_on_all || $register != 'register' ) {
195 + if ( $load_on_all || $register !== 'register' ) {
196 196 wp_enqueue_style( $css_key );
197 197 }
198 198 unset( $css_key, $file );
199 199 }
@@ -200,9 +200,9 @@
200 200
201 201 if ( $frm_settings->load_style === 'all' ) {
202 202 $frm_vars['css_loaded'] = true;
203 203 }
204 - }
204 + }//end if
205 205 unset( $css );
206 206
207 207 add_filter( 'style_loader_tag', 'FrmStylesController::add_tags_to_css', 10, 2 );
208 208 }
@@ -264,14 +264,17 @@
264 264
265 265 return $this_version;
266 266 }
267 267
268 + /**
269 + * @param string $tag
270 + * @param string $handle
271 + * @return string
272 + */
268 273 public static function add_tags_to_css( $tag, $handle ) {
269 - if ( ( 'formidable' == $handle || 'jquery-theme' == $handle ) && strpos( $tag, ' property=' ) === false ) {
274 + if ( ( 'formidable' === $handle || 'jquery-theme' === $handle ) && strpos( $tag, ' property=' ) === false ) {
270 275 $frm_settings = FrmAppHelper::get_settings();
271 - if ( $frm_settings->use_html ) {
272 - $tag = str_replace( ' type="', ' property="stylesheet" type="', $tag );
273 - }
276 + $tag = str_replace( ' type="', ' property="stylesheet" type="', $tag );
274 277 }
275 278
276 279 return $tag;
277 280 }
@@ -399,11 +402,12 @@
399 402
400 403 if ( ! $form_id ) {
401 404 // TODO: Show a message why a random form is being shown (because no form is assigned to the style).
402 405 // Fallback to any form.
403 - $where = array(
406 + $where = array(
404 407 'status' => 'published',
405 - 'parent_form_id' => array( null, 0 ), // Make sure it's not a repeater.
408 + // Make sure it's not a repeater.
409 + 'parent_form_id' => array( null, 0 ),
406 410 );
407 411 $form_id = FrmDb::get_var( 'frm_forms', $where, 'id' );
408 412 }
409 413
@@ -417,9 +421,9 @@
417 421 */
418 422 private static function disable_admin_page_styling_on_submit_buttons() {
419 423 add_filter(
420 424 'frm_submit_button_class',
421 - function( $classes ) {
425 + function ( $classes ) {
422 426 $classes[] = 'frm_no_style_button';
423 427 return $classes;
424 428 }
425 429 );
@@ -463,15 +467,15 @@
463 467 * @param int $style_id
464 468 */
465 469 $style_id = apply_filters( 'frm_saved_form_style_id', $style_id );
466 470
467 - if ( ! $style_id && '0' !== FrmAppHelper::get_post_param( 'style_id', 'sanitize_text_field', '' ) ) {
471 + if ( ! $style_id && '0' !== FrmAppHelper::get_post_param( 'style_id', '', 'sanitize_text_field' ) ) {
468 472 // "0" is a special value used for the enable/disable toggle.
469 473 wp_die( esc_html__( 'Invalid style value', 'formidable' ), esc_html__( 'Invalid style value', 'formidable' ), 400 );
470 474 return;
471 475 }
472 476
473 - $form_id = FrmAppHelper::get_post_param( 'form_id', 'absint', 0 );
477 + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
474 478 if ( ! $form_id ) {
475 479 wp_die( esc_html__( 'No form specified', 'formidable' ), esc_html__( 'No form specified', 'formidable' ), 400 );
476 480 return;
477 481 }
@@ -489,9 +493,10 @@
489 493 if ( $style_id === $default_style->ID && empty( $form->options['chat'] ) ) {
490 494 $style_id = 1;
491 495 }
492 496
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.
497 + // We want to save a string for consistency. FrmStylesHelper::get_form_count_for_style expects the custom style ID is a string.
498 + $form->options['custom_style'] = (string) $style_id;
494 499
495 500 global $wpdb;
496 501 $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) );
497 502
@@ -533,8 +538,9 @@
533 538 wp_print_styles( 'formidable_style' );
534 539
535 540 wp_print_styles( 'formidable' );
536 541 wp_enqueue_script( 'formidable_style' );
542 + wp_set_script_translations( 'formidable_style', 'formidable' );
537 543 }
538 544
539 545 /**
540 546 * Render the style page (with a more limited and typed scope than calling it from self::style directly).
@@ -541,9 +547,8 @@
541 547 *
542 548 * @since 6.0
543 549 *
544 550 * @param stdClass|WP_Post $active_style
545 - * @param array<WP_Post> $styles
546 551 * @param stdClass $form
547 552 * @param WP_Post $default_style
548 553 * @return void
549 554 */
@@ -548,13 +553,15 @@
548 553 * @return void
549 554 */
550 555 private static function render_style_page( $active_style, $form, $default_style ) {
551 556 $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 );
557 + // Edit, list (default), new_style.
558 + $view = FrmAppHelper::simple_get( 'frm_action', 'sanitize_text_field', 'list' );
559 + $frm_style = new FrmStyle( $active_style->ID );
554 560
555 561 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.
562 + // Have the Appearance > Forms link fallback to the edit view. Otherwise we want to use 'list' as the default.
563 + $view = 'edit';
557 564 }
558 565
559 566 if ( in_array( $view, array( 'edit', 'new_style', 'duplicate' ), true ) ) {
560 567 self::add_meta_boxes();
@@ -617,21 +624,21 @@
617 624 * Filter form classes so the form uses the preview style, not the form's active style.
618 625 *
619 626 * @since 6.0
620 627 *
621 - * @param WP_Post|stdClass $style A new style is not a WP_Post object.
628 + * @param stdClass|WP_Post $style A new style is not a WP_Post object.
622 629 * @return void
623 630 */
624 631 private static function force_form_style( $style ) {
625 632 add_filter(
626 633 'frm_add_form_style_class',
627 - function( $class ) use ( $style ) {
628 - $split = array_filter(
634 + function ( $class ) use ( $style ) {
635 + $split = array_filter(
629 636 explode( ' ', $class ),
630 637 /**
631 638 * @param string $class
632 639 */
633 - function( $class ) {
640 + function ( $class ) {
634 641 return $class && 0 !== strpos( $class, 'frm_style_' );
635 642 }
636 643 );
637 644 $split[] = 'frm_style_' . $style->post_name;
@@ -648,9 +655,8 @@
648 655 * @return void
649 656 */
650 657 public static function save_style() {
651 658 $frm_style = new FrmStyle();
652 - $message = '';
653 659 $post_id = FrmAppHelper::get_post_param( 'ID', false, 'sanitize_title' );
654 660 $style_nonce = FrmAppHelper::get_post_param( 'frm_style', '', 'sanitize_text_field' );
655 661
656 662 if ( $post_id === false || ! wp_verify_nonce( $style_nonce, 'frm_style_nonce' ) ) {
@@ -661,9 +667,10 @@
661 667
662 668 $id = $frm_style->update( $post_id );
663 669 if ( ! $post_id && $id ) {
664 670 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.
671 + // Set the post id to the new style so it will be loaded for editing.
672 + $post_id = reset( $id );
666 673 }
667 674
668 675 self::$message = __( 'Your styling settings have been saved.', 'formidable' );
669 676 }
@@ -706,9 +713,9 @@
706 713 return;
707 714 }
708 715
709 716 parse_str( $query, $parsed_query );
710 - $form_id = ! empty( $parsed_query['form'] ) ? absint( $parsed_query['form'] ) : 0;
717 + $form_id = ! empty( $parsed_query['form'] ) ? absint( $parsed_query['form'] ) : 0;
711 718
712 719 $style = new stdClass();
713 720 $style->ID = end( $ids );
714 721 wp_safe_redirect( esc_url_raw( FrmStylesHelper::get_edit_url( $style, $form_id ) ) );
@@ -744,10 +751,10 @@
744 751 global $wpdb;
745 752
746 753 $forms = FrmForm::get_published_forms();
747 754 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
755 + $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
756 + $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 757 if ( $new_style == $previous_style ) {
751 758 continue;
752 759 }
753 760
@@ -895,9 +902,10 @@
895 902 );
896 903 global $wpdb;
897 904 $wpdb->update( $wpdb->posts, array( 'post_content' => $default_post_content ), $where );
898 905
899 - $frm_style->save_settings(); // Save the settings after resetting to default or the old style will still appear.
906 + // Save the settings after resetting to default or the old style will still appear.
907 + $frm_style->save_settings();
900 908
901 909 $data = array(
902 910 'style' => FrmStylesCardHelper::get_style_param_for_card( $frm_style->get_new() ),
903 911 );
@@ -916,11 +924,13 @@
916 924 FrmAppHelper::permission_check( 'frm_change_settings' );
917 925 check_ajax_referer( 'frm_ajax', 'nonce' );
918 926
919 927 $frm_style = new FrmStyle();
920 - $defaults = false; // Intentionally avoid defaults here so nothing gets removed from our style.
921 - $style = '';
922 928
929 + // Intentionally avoid defaults here so nothing gets removed from our style.
930 + $defaults = array();
931 + $style = '';
932 +
923 933 echo '<style type="text/css">';
924 934 include FrmAppHelper::plugin_path() . '/css/_single_theme.css.php';
925 935 echo '</style>';
926 936 wp_die();
@@ -1025,9 +1035,9 @@
1025 1035 }
1026 1036
1027 1037 /**
1028 1038 * 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.
1039 + * To avoid cluttering the front end with any unnecessary styles this is only added when the referer URL matches the styler.
1030 1040 *
1031 1041 * @since 6.2.3
1032 1042 *
1033 1043 * @return void
@@ -1078,9 +1088,9 @@
1078 1088 return;
1079 1089 }
1080 1090
1081 1091 $frm_settings = FrmAppHelper::get_settings();
1082 - if ( $frm_settings->load_style != 'none' ) {
1092 + if ( $frm_settings->load_style !== 'none' ) {
1083 1093 wp_enqueue_style( 'formidable' );
1084 1094 $frm_vars['css_loaded'] = true;
1085 1095 }
1086 1096 }
@@ -1099,9 +1109,9 @@
1099 1109
1100 1110 /**
1101 1111 * Get the style post object for a target form.
1102 1112 *
1103 - * @param object|string|boolean $form
1113 + * @param bool|object|string $form
1104 1114 * @return WP_Post|null
1105 1115 */
1106 1116 public static function get_form_style( $form = 'default' ) {
1107 1117 $style = FrmFormsHelper::get_form_style( $form );
@@ -1134,12 +1144,11 @@
1134 1144 return $class;
1135 1145 }
1136 1146
1137 1147 /**
1148 + * @since 3.0
1138 1149 * @param object $style
1139 1150 * @param string $class
1140 - *
1141 - * @since 3.0
1142 1151 */
1143 1152 private static function maybe_add_rtl_class( $style, &$class ) {
1144 1153 $is_rtl = isset( $style->post_content['direction'] ) && 'rtl' === $style->post_content['direction'];
1145 1154 if ( $is_rtl ) {
@@ -1184,10 +1193,82 @@
1184 1193
1185 1194 return $important;
1186 1195 }
1187 1196
1188 - public static function do_accordion_sections( $screen, $context, $object ) {
1189 - return do_accordion_sections( $screen, $context, $object );
1197 + /**
1198 + * Duplicate of WordPress do_accordion_section function, it adds an additional svg icon support.
1199 + *
1200 + * @since 6.8.3
1201 + *
1202 + * @return int
1203 + */
1204 + public static function do_accordion_sections( $screen, $context, $data_object ) {
1205 + global $wp_meta_boxes;
1206 +
1207 + // the symbol id from icons.svg
1208 + $icon_ids = array(
1209 + 'ranking-fields-style' => 'frm_chart_bar_icon',
1210 + 'section-fields-style' => 'frm-form-title-style',
1211 + );
1212 +
1213 + wp_enqueue_script( 'accordion' );
1214 +
1215 + if ( empty( $screen ) ) {
1216 + $screen = get_current_screen();
1217 + } elseif ( is_string( $screen ) ) {
1218 + $screen = convert_to_screen( $screen );
1219 + }
1220 +
1221 + $page = $screen->id;
1222 +
1223 + ?>
1224 + <div id="side-sortables" class="accordion-container">
1225 + <ul class="outer-border">
1226 + <?php
1227 + $i = 0;
1228 + $first_open = false;
1229 +
1230 + if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
1231 + foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
1232 + if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
1233 + foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
1234 + if ( false === $box || ! $box['title'] ) {
1235 + continue;
1236 + }
1237 +
1238 + ++$i;
1239 + $icon_id = array_key_exists( $box['id'], $icon_ids ) ? $icon_ids[ $box['id'] ] : 'frm-' . $box['id'];
1240 +
1241 + $open_class = '';
1242 + if ( ! $first_open ) {
1243 + $first_open = true;
1244 + $open_class = 'open';
1245 + }
1246 + ?>
1247 + <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'] ); ?>">
1248 + <h3 class="accordion-section-title hndle" tabindex="0">
1249 + <?php
1250 + FrmAppHelper::icon_by_class( 'frmfont ' . $icon_id );
1251 + echo esc_html( $box['title'] );
1252 + FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown8_icon' );
1253 + ?>
1254 + </h3>
1255 + <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>">
1256 + <div class="inside">
1257 + <?php call_user_func( $box['callback'], $data_object, $box ); ?>
1258 + </div><!-- .inside -->
1259 + </div><!-- .accordion-section-content -->
1260 + </li><!-- .accordion-section -->
1261 + <?php
1262 + }//end foreach
1263 + }//end if
1264 + }//end foreach
1265 + }//end if
1266 + ?>
1267 + </ul><!-- .outer-border -->
1268 + </div><!-- .accordion-container -->
1269 + <?php
1270 + return $i;
1190 1271 }
1191 1272
1192 1273 /**
1193 1274 * Rename a style via an AJAX action.