PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
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 +213 -117 6.26 → trunk View file →
@@ -20,8 +20,17 @@
20 20 */
21 21 private static $message;
22 22
23 23 /**
24 + * Cache of the active style object keyed by form ID.
25 + *
26 + * @since 6.32
27 + *
28 + * @var array
29 + */
30 + private static $active_style = array();
31 +
32 + /**
24 33 * @return void
25 34 */
26 35 public static function load_pro_hooks() {
27 36 if ( FrmAppHelper::pro_is_installed() ) {
@@ -73,10 +82,10 @@
73 82 *
74 83 * @return void
75 84 */
76 85 public static function menu() {
77 - add_submenu_page( 'formidable', 'Formidable | ' . __( 'Styles', 'formidable' ), __( 'Styles', 'formidable' ), 'frm_change_settings', 'formidable-styles', 'FrmStylesController::route' );
78 - add_submenu_page( 'themes.php', 'Formidable | ' . __( 'Styles', 'formidable' ), __( 'Forms', 'formidable' ), 'frm_change_settings', 'formidable-styles2', 'FrmStylesController::route' );
86 + add_submenu_page( 'formidable', 'Formidable | ' . __( 'Styles', 'formidable' ), __( 'Styles', 'formidable' ), 'frm_change_settings', 'formidable-styles', 'FrmStylesController::route' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
87 + add_submenu_page( 'themes.php', 'Formidable | ' . __( 'Styles', 'formidable' ), __( 'Forms', 'formidable' ), 'frm_change_settings', 'formidable-styles2', 'FrmStylesController::route' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
79 88 }
80 89
81 90 /**
82 91 * Remove filters for the visual styler preview.
@@ -134,14 +143,14 @@
134 143 if ( FrmAppHelper::is_style_editor_page( 'edit' ) ) {
135 144 wp_enqueue_style( 'wp-color-picker' );
136 145 }
137 146
138 - wp_enqueue_style( 'frm-custom-theme', admin_url( 'admin-ajax.php?action=frmpro_css' ), array(), $version );
147 + wp_enqueue_style( 'frm-custom-theme', admin_url( 'admin-ajax.php?action=frmpro_css&frm_scope_custom_css=1' ), array(), $version );
139 148
140 149 $style = apply_filters( 'frm_style_head', false );
141 150
142 151 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 );
152 + 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
144 153 }
145 154 }
146 155
147 156 /**
@@ -237,16 +246,18 @@
237 246 *
238 247 * @return void
239 248 */
240 249 private static function get_url_to_custom_style( &$stylesheet_urls ) {
241 - $file_name = '/css/' . self::get_file_name();
250 + $add_css_to_uploads_dir = FrmStyle::add_css_to_uploads_dir();
251 + $file_path = FrmStyle::get_generated_css_file_path( $add_css_to_uploads_dir ) . '/' . self::get_file_name();
242 252
243 - if ( is_readable( FrmAppHelper::plugin_path() . $file_name ) ) {
244 - $url = FrmAppHelper::plugin_url() . $file_name;
245 - } else {
246 - $url = admin_url( 'admin-ajax.php?action=frmpro_css' );
253 + if ( ! is_readable( $file_path ) ) {
254 + $stylesheet_urls['formidable'] = admin_url( 'admin-ajax.php?action=frmpro_css' );
255 + return;
247 256 }
248 - $stylesheet_urls['formidable'] = $url;
257 +
258 + $base_url = $add_css_to_uploads_dir ? wp_upload_dir()['baseurl'] . '/formidable/css/' : FrmAppHelper::plugin_url() . '/css/';
259 + $stylesheet_urls['formidable'] = $base_url . self::get_file_name();
249 260 }
250 261
251 262 /**
252 263 * Use a different stylesheet per site in a multisite install
@@ -256,15 +267,12 @@
256 267 * @return string
257 268 */
258 269 public static function get_file_name() {
259 270 if ( is_multisite() ) {
260 - $blog_id = get_current_blog_id();
261 - $name = 'formidableforms' . absint( $blog_id ) . '.css';
262 - } else {
263 - $name = 'formidableforms.css';
271 + return 'formidableforms' . absint( get_current_blog_id() ) . '.css';
264 272 }
265 273
266 - return $name;
274 + return 'formidableforms.css';
267 275 }
268 276
269 277 /**
270 278 * @param string $css_key
@@ -272,19 +280,15 @@
272 280 *
273 281 * @return string
274 282 */
275 283 private static function get_css_version( $css_key, $version ) {
276 - if ( 'formidable' === $css_key ) {
277 - $this_version = get_option( 'frm_last_style_update' );
284 + if ( 'formidable' !== $css_key ) {
285 + return $version;
286 + }
278 287
279 - if ( ! $this_version ) {
280 - $this_version = $version;
281 - }
282 - } else {
283 - $this_version = $version;
284 - }
288 + $this_version = get_option( 'frm_last_style_update' );
285 289
286 - return $this_version;
290 + return $this_version ? $this_version : $version;
287 291 }
288 292
289 293 /**
290 294 * @param string $tag
@@ -292,11 +296,10 @@
292 296 *
293 297 * @return string
294 298 */
295 299 public static function add_tags_to_css( $tag, $handle ) {
296 - if ( ( 'formidable' === $handle || 'jquery-theme' === $handle ) && strpos( $tag, ' property=' ) === false ) {
297 - $frm_settings = FrmAppHelper::get_settings();
298 - $tag = str_replace( ' type="', ' property="stylesheet" type="', $tag );
300 + if ( ( 'formidable' === $handle || 'jquery-theme' === $handle ) && ! str_contains( $tag, ' property=' ) ) {
301 + return str_replace( ' type="', ' property="stylesheet" type="', $tag );
299 302 }
300 303
301 304 return $tag;
302 305 }
@@ -346,9 +349,9 @@
346 349
347 350 $style_id = self::get_style_id_for_styler();
348 351
349 352 if ( ! $style_id ) {
350 - $error_args = array(
353 + $error_args = array(
351 354 'title' => __( 'No styles', 'formidable' ),
352 355 'body' => __( 'You must have a style to use the Visual Styler.', 'formidable' ),
353 356 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
354 357 );
@@ -364,9 +367,9 @@
364 367
365 368 $form = FrmForm::getOne( $form_id );
366 369
367 370 if ( ! is_object( $form ) ) {
368 - $error_args = array(
371 + $error_args = array(
369 372 'title' => __( 'No forms', 'formidable' ),
370 373 'body' => __( 'You must have a form to use the Visual Styler.', 'formidable' ),
371 374 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
372 375 );
@@ -373,11 +376,10 @@
373 376 FrmAppController::show_error_modal( $error_args );
374 377 return;
375 378 }
376 379
377 - $frm_style = new FrmStyle( $style_id );
378 - $active_style = $frm_style->get_one();
379 - $default_style = self::get_default_style();
380 + $frm_style = new FrmStyle( $style_id );
381 + $active_style = $frm_style->get_one();
380 382
381 383 self::disable_admin_page_styling_on_submit_buttons();
382 384
383 385 /**
@@ -386,9 +388,9 @@
386 388 * @param array{form:\stdClass} $data
387 389 */
388 390 do_action( 'frm_before_render_style_page', compact( 'form' ) );
389 391
390 - self::render_style_page( $active_style, $form, $default_style );
392 + self::render_style_page( $active_style, $form, self::get_default_style() );
391 393 }
392 394
393 395 /**
394 396 * @since 6.0
@@ -439,9 +441,8 @@
439 441 )
440 442 );
441 443
442 444 if ( ! $form_id ) {
443 - // TODO: Show a message why a random form is being shown (because no form is assigned to the style).
444 445 // Fallback to any form.
445 446 $where = array(
446 447 'status' => 'published',
447 448 // Make sure it's not a repeater.
@@ -473,11 +474,10 @@
473 474 *
474 475 * @return WP_Post
475 476 */
476 477 private static function get_default_style() {
477 - $frm_style = new FrmStyle( 'default' );
478 - $default_style = $frm_style->get_one();
479 - return $default_style;
478 + $frm_style = new FrmStyle( 'default' );
479 + return $frm_style->get_one();
480 480 }
481 481
482 482 /**
483 483 * Save style for form (from Styler list page) via a POST action.
@@ -533,11 +533,10 @@
533 533
534 534 // If the default style is selected, use the "Always use default" legacy option instead of the default style.
535 535 // There's also a check here for conversational forms.
536 536 // Without the check it isn't possible to select "Default" because "Always use default" will convert to "Lines" dynamically.
537 - $default_style = self::get_default_style();
538 537
539 - if ( $style_id === $default_style->ID && empty( $form->options['chat'] ) ) {
538 + if ( $style_id === self::get_default_style()->ID && empty( $form->options['chat'] ) ) {
540 539 $style_id = 1;
541 540 }
542 541
543 542 // We want to save a string for consistency. FrmStylesHelper::get_form_count_for_style expects the custom style ID is a string.
@@ -634,22 +633,44 @@
634 633 $style = $active_style;
635 634 break;
636 635
637 636 case 'duplicate':
638 - $style = clone $active_style;
639 - $new_style = $frm_style->get_new();
637 + $style = clone $active_style;
638 + $new_style = $frm_style->get_new();
639 + $new_name = self::get_new_style_post_name( $new_style->post_name );
640 +
641 + // The single style custom CSS is nested under the old style's scope. Re-scope it to the
642 + // new style's scope so it unnests correctly for display and re-nests correctly on save.
643 + if ( ! empty( $style->post_content['single_style_custom_css'] ) ) {
644 + $css_scope_helper = new FrmCssScopeHelper();
645 + $unnested_css = $css_scope_helper->unnest( $style->post_content['single_style_custom_css'], 'frm_style_' . $style->post_name ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
646 + $style->post_content['single_style_custom_css'] = $css_scope_helper->nest( $unnested_css, 'frm_style_' . $new_name );
647 + }
648 +
640 649 $style->ID = $new_style->ID;
641 - $style->post_name = $new_style->post_name;
642 - unset( $new_style );
650 + $style->post_name = $new_name;
651 + unset( $new_style, $new_name );
643 652 break;
644 653
645 654 case 'new_style':
646 - $style = $frm_style->get_new();
655 + $style = $frm_style->get_new();
656 + $style->post_name = self::get_new_style_post_name( $style->post_name );
647 657 break;
648 - }
658 + }//end switch
649 659
650 660 if ( in_array( $view, array( 'duplicate', 'new_style' ), true ) ) {
651 - $style->post_title = FrmAppHelper::simple_get( 'style_name' );
661 + // A new or duplicated style has no ID yet, so the Rename modal updates the post_title input
662 + // instead of calling an endpoint. Prefer that posted title over $_GET['style_name'] when present.
663 + $posted_title = '';
664 +
665 + // phpcs:ignore WordPress.Security.NonceVerification.Missing
666 + if ( isset( $_POST['frm_style_setting']['post_title'] ) ) {
667 + // The nonce is verified in FrmStylesController::save_style before this renders.
668 + // phpcs:ignore WordPress.Security.NonceVerification.Missing
669 + $posted_title = sanitize_text_field( wp_unslash( $_POST['frm_style_setting']['post_title'] ) );
670 + }
671 +
672 + $style->post_title = '' !== $posted_title ? $posted_title : FrmAppHelper::simple_get( 'style_name' );
652 673 $style->menu_order = 0;
653 674 }
654 675
655 676 if ( ! isset( $style ) ) {
@@ -673,8 +694,27 @@
673 694 include $style_views_path . 'show.php';
674 695 }
675 696
676 697 /**
698 + * Derive the temporary post_name (CSS scope slug) for a new or duplicated style from the chosen
699 + * style name so the displayed scope matches the slug WordPress will store on save.
700 + *
701 + * Falls back to the auto-generated key when no style name was provided so the scope is never empty.
702 + *
703 + * @since 6.32
704 + *
705 + * @param string $fallback The auto-generated post_name to use when no style name is chosen.
706 + *
707 + * @return string
708 + */
709 + private static function get_new_style_post_name( $fallback ) {
710 + $style_name = FrmAppHelper::simple_get( 'style_name' );
711 + $slug = $style_name ? sanitize_title( $style_name ) : '';
712 +
713 + return $slug ? $slug : $fallback;
714 + }
715 +
716 + /**
677 717 * @since 6.0
678 718 *
679 719 * @return string
680 720 */
@@ -700,9 +740,9 @@
700 740 /**
701 741 * @param string $class
702 742 */
703 743 function ( $class ) {
704 - return $class && 0 !== strpos( $class, 'frm_style_' );
744 + return $class && ! str_starts_with( $class, 'frm_style_' );
705 745 }
706 746 );
707 747 $split[] = 'frm_style_' . $style->post_name;
708 748 return implode( ' ', $split );
@@ -717,8 +757,10 @@
717 757 *
718 758 * @return void
719 759 */
720 760 public static function save_style() {
761 + FrmAppHelper::permission_check( 'frm_change_settings' );
762 +
721 763 $frm_style = new FrmStyle();
722 764 $post_id = FrmAppHelper::get_post_param( 'ID', false, 'sanitize_title' );
723 765 $style_nonce = FrmAppHelper::get_post_param( 'frm_style', '', 'sanitize_text_field' );
724 766
@@ -766,17 +808,16 @@
766 808 *
767 809 * @return void
768 810 */
769 811 private static function maybe_redirect_after_save( $ids ) {
770 - $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
771 - $parsed = parse_url( $referer );
772 - $query = $parsed['query'];
773 -
812 + $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
813 + $parsed = parse_url( $referer );
814 + $query = $parsed['query'];
774 815 $current_action = false;
775 816 $actions_to_redirect = array( 'duplicate', 'new_style' );
776 817
777 818 foreach ( $actions_to_redirect as $action ) {
778 - if ( false !== strpos( $query, 'frm_action=' . $action ) ) {
819 + if ( str_contains( $query, 'frm_action=' . $action ) ) {
779 820 $current_action = $action;
780 821 break;
781 822 }
782 823 }
@@ -786,10 +827,9 @@
786 827 return;
787 828 }
788 829
789 830 parse_str( $query, $parsed_query );
790 - $form_id = ! empty( $parsed_query['form'] ) ? absint( $parsed_query['form'] ) : 0;
791 -
831 + $form_id = ! empty( $parsed_query['form'] ) ? absint( $parsed_query['form'] ) : 0;
792 832 $style = new stdClass();
793 833 $style->ID = end( $ids );
794 834 wp_safe_redirect( esc_url_raw( FrmStylesHelper::get_edit_url( $style, $form_id ) ) );
795 835 die();
@@ -853,17 +893,18 @@
853 893 $settings = self::enqueue_codemirror( $id, $extra_args['placeholder'] ?? '' );
854 894 $id = $settings ? $id : 'frm_custom_css_box';
855 895 $show_errors = $extra_args['show_errors'] ?? true;
856 896 $custom_css = $extra_args['custom_css'] ?? self::get_custom_css();
857 - $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' );
897 + $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
858 898 $textarea_params = ! empty( $extra_args['textarea_params'] ) ? $extra_args['textarea_params'] : array(
859 899 'name' => 'frm_custom_css',
860 900 'id' => $id,
861 901 );
862 902
863 - if ( ! empty( $settings ) ) {
903 + if ( $settings ) {
864 904 $textarea_params['class'] = 'hide-if-js';
865 905 }
906 +
866 907 include FrmAppHelper::plugin_path() . '/classes/views/styles/custom_css.php';
867 908 }
868 909
869 910 /**
@@ -875,11 +916,15 @@
875 916 *
876 917 * @return string
877 918 */
878 919 public static function get_custom_css( $single_style_settings = null ) {
879 - // If the single style settings are passed, return the custom CSS from the single style settings.
880 - if ( ! empty( $single_style_settings['single_style_custom_css'] ) && ! empty( $single_style_settings['enable_style_custom_css'] ) ) {
881 - return $single_style_settings['single_style_custom_css'];
920 + if ( $single_style_settings ) {
921 + // If the single style settings are passed, return the custom CSS from the single style settings.
922 + if ( ! empty( $single_style_settings['single_style_custom_css'] ) && ! empty( $single_style_settings['enable_style_custom_css'] ) ) {
923 + return $single_style_settings['single_style_custom_css'];
924 + }
925 +
926 + return '';
882 927 }
883 928
884 929 $settings = FrmAppHelper::get_settings();
885 930
@@ -887,13 +932,12 @@
887 932 return $settings->custom_css;
888 933 }
889 934
890 935 // If it does not exist, check the default style as a fallback.
891 - $frm_style = new FrmStyle();
892 - $style = $frm_style->get_default_style();
893 - $custom_css = $style->post_content['custom_css'];
936 + $frm_style = new FrmStyle();
937 + $style = $frm_style->get_default_style();
894 938
895 - return $custom_css;
939 + return $style->post_content['custom_css'];
896 940 }
897 941
898 942 /**
899 943 * Enqueue assets for codemirror, built into WordPress since 4.9.
@@ -990,10 +1034,9 @@
990 1034 if ( ! $style_id ) {
991 1035 // A style ID is not sent when resetting on the edit page.
992 1036 // Instead of resetting the style, send the defaults back so the inputs can be updated with JavaScript.
993 1037 $frm_style = new FrmStyle();
994 - $defaults = $frm_style->get_defaults();
995 - echo json_encode( $defaults );
1038 + echo json_encode( $frm_style->get_defaults() );
996 1039 wp_die();
997 1040 }
998 1041
999 1042 $frm_style = new FrmStyle();
@@ -1046,9 +1089,9 @@
1046 1089 /**
1047 1090 * @return void
1048 1091 */
1049 1092 public static function add_meta_boxes() {
1050 - // setup meta boxes
1093 + // Setup meta boxes
1051 1094 $meta_boxes = array(
1052 1095 'general' => __( 'General', 'formidable' ),
1053 1096 'form-title' => __( 'Form Title', 'formidable' ),
1054 1097 'form-description' => __( 'Form Description', 'formidable' ),
@@ -1152,9 +1195,9 @@
1152 1195 */
1153 1196 public static function maybe_hide_sample_form_error_message() {
1154 1197 $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
1155 1198
1156 - if ( false !== strpos( $referer, 'admin.php?page=formidable-styles' ) ) {
1199 + if ( str_contains( $referer, 'admin.php?page=formidable-styles' ) ) {
1157 1200 echo '#frm_broken_styles_warning { display: none; }';
1158 1201 }
1159 1202 }
1160 1203
@@ -1194,9 +1237,9 @@
1194 1237 */
1195 1238 public static function enqueue_style() {
1196 1239 global $frm_vars;
1197 1240
1198 - if ( isset( $frm_vars['css_loaded'] ) && $frm_vars['css_loaded'] ) {
1241 + if ( ! empty( $frm_vars['css_loaded'] ) ) {
1199 1242 // The CSS has already been loaded.
1200 1243 return;
1201 1244 }
1202 1245
@@ -1201,12 +1244,14 @@
1201 1244 }
1202 1245
1203 1246 $frm_settings = FrmAppHelper::get_settings();
1204 1247
1205 - if ( $frm_settings->load_style !== 'none' ) {
1206 - wp_enqueue_style( 'formidable' );
1207 - $frm_vars['css_loaded'] = true;
1248 + if ( $frm_settings->load_style === 'none' ) {
1249 + return;
1208 1250 }
1251 +
1252 + wp_enqueue_style( 'formidable' );
1253 + $frm_vars['css_loaded'] = true;
1209 1254 }
1210 1255
1211 1256 /**
1212 1257 * Get the stylesheets for the form settings page
@@ -1214,11 +1259,9 @@
1214 1259 * @return array<WP_Post>
1215 1260 */
1216 1261 public static function get_style_opts() {
1217 1262 $frm_style = new FrmStyle();
1218 - $styles = $frm_style->get_all();
1219 -
1220 - return $styles;
1263 + return $frm_style->get_all();
1221 1264 }
1222 1265
1223 1266 /**
1224 1267 * Get the style post object for a target form.
@@ -1229,9 +1272,10 @@
1229 1272 */
1230 1273 public static function get_form_style( $form = 'default' ) {
1231 1274 $style = FrmFormsHelper::get_form_style( $form );
1232 1275
1233 - if ( empty( $style ) || 1 == $style ) {
1276 + // phpcs:ignore Universal.Operators.StrictComparisons
1277 + if ( ! $style || 1 == $style ) {
1234 1278 $style = 'default';
1235 1279 }
1236 1280
1237 1281 $frm_style = new FrmStyle( $style );
@@ -1238,8 +1282,52 @@
1238 1282 return $frm_style->get_one();
1239 1283 }
1240 1284
1241 1285 /**
1286 + * Get the active style object for a field's form.
1287 + *
1288 + * @since 6.32
1289 + *
1290 + * @param array|int $field The 'field' array.
1291 + *
1292 + * @return object
1293 + */
1294 + public static function get_active_style( $field ) {
1295 + if ( ! is_array( $field ) ) {
1296 + return new stdClass();
1297 + }
1298 +
1299 + $form_id = $field['parent_form_id'] ?? $field['form_id'];
1300 +
1301 + if ( isset( self::$active_style[ $form_id ] ) ) {
1302 + return self::$active_style[ $form_id ];
1303 + }
1304 +
1305 + $active_style = self::get_form_style( $form_id );
1306 +
1307 + if ( ! is_object( $active_style ) ) {
1308 + $active_style = new stdClass();
1309 + }
1310 +
1311 + self::$active_style[ $form_id ] = $active_style;
1312 +
1313 + return self::$active_style[ $form_id ];
1314 + }
1315 +
1316 + /**
1317 + * Get the style setting key that stores the alignment for a field type.
1318 + *
1319 + * @since 6.32
1320 + *
1321 + * @param string $field_type
1322 + *
1323 + * @return string
1324 + */
1325 + public static function get_align_key_for_style_settings( $field_type ) {
1326 + return 'checkbox' === $field_type ? 'check_align' : 'radio_align';
1327 + }
1328 +
1329 + /**
1242 1330 * @param string $class
1243 1331 * @param string $style
1244 1332 *
1245 1333 * @return string
@@ -1244,8 +1332,9 @@
1244 1332 *
1245 1333 * @return string
1246 1334 */
1247 1335 public static function get_form_style_class( $class, $style ) {
1336 + // phpcs:ignore Universal.Operators.StrictComparisons
1248 1337 if ( 1 == $style ) {
1249 1338 $style = 'default';
1250 1339 }
1251 1340
@@ -1287,8 +1376,10 @@
1287 1376
1288 1377 if ( $style && isset( $style->post_content[ $val ] ) ) {
1289 1378 return $style->post_content[ $val ];
1290 1379 }
1380 +
1381 + return null;
1291 1382 }
1292 1383
1293 1384 /**
1294 1385 * @param array $default_styles
@@ -1305,13 +1396,14 @@
1305 1396
1306 1397 foreach ( $default_styles as $name => $val ) {
1307 1398 $setting = $name;
1308 1399
1309 - if ( 'border_width' == $name ) {
1400 + if ( 'border_width' === $name ) {
1310 1401 $setting = 'field_border_width';
1311 - } elseif ( 'alt_bg_color' == $name ) {
1402 + } elseif ( 'alt_bg_color' === $name ) {
1312 1403 $setting = 'bg_color_active';
1313 1404 }
1405 +
1314 1406 $default_styles[ $name ] = $style->post_content[ $setting ];
1315 1407 unset( $name, $val );
1316 1408 }
1317 1409
@@ -1323,12 +1415,10 @@
1323 1415 * @param array $field
1324 1416 *
1325 1417 * @return string
1326 1418 */
1327 - public static function &important_style( $important, $field ) {
1328 - $important = self::get_style_val( 'important_style', $field['form_id'] );
1329 -
1330 - return $important;
1419 + public static function important_style( $important, $field ) {
1420 + return self::get_style_val( 'important_style', $field['form_id'] );
1331 1421 }
1332 1422
1333 1423 /**
1334 1424 * Duplicate of WordPress do_accordion_section function, it adds an additional svg icon support.
@@ -1340,12 +1430,12 @@
1340 1430 * @param mixed $data_object Data object passed to callbacks.
1341 1431 *
1342 1432 * @return int
1343 1433 */
1344 - public static function do_accordion_sections( $screen, $context, $data_object ) {
1434 + public static function do_accordion_sections( $screen, $context, $data_object ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
1345 1435 global $wp_meta_boxes;
1346 1436
1347 - // the symbol id from icons.svg
1437 + // The symbol id from icons.svg
1348 1438 $icon_ids = array(
1349 1439 'ranking-fields-style' => 'frm_chart_bar_icon',
1350 1440 'section-fields-style' => 'frm-form-title-style',
1351 1441 );
@@ -1351,9 +1441,9 @@
1351 1441 );
1352 1442
1353 1443 wp_enqueue_script( 'accordion' );
1354 1444
1355 - if ( empty( $screen ) ) {
1445 + if ( ! $screen ) {
1356 1446 $screen = get_current_screen();
1357 1447 } elseif ( is_string( $screen ) ) {
1358 1448 $screen = convert_to_screen( $screen );
1359 1449 }
@@ -1359,8 +1449,9 @@
1359 1449 }
1360 1450
1361 1451 $page = $screen->id;
1362 1452
1453 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
1363 1454 ?>
1364 1455 <div id="side-sortables" class="accordion-container">
1365 1456 <ul class="outer-border">
1366 1457 <?php
@@ -1368,45 +1459,46 @@
1368 1459 $first_open = false;
1369 1460
1370 1461 if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
1371 1462 foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
1372 - if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
1373 - foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
1374 - if ( false === $box || ! $box['title'] ) {
1375 - continue;
1376 - }
1463 + if ( ! isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
1464 + continue;
1465 + }
1377 1466
1378 - ++$i;
1379 - $icon_id = array_key_exists( $box['id'], $icon_ids ) ? $icon_ids[ $box['id'] ] : 'frm-' . $box['id'];
1467 + foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
1468 + if ( false === $box || ! $box['title'] ) {
1469 + continue;
1470 + }
1380 1471
1381 - $open_class = '';
1472 + ++$i;
1473 + $icon_id = array_key_exists( $box['id'], $icon_ids ) ? $icon_ids[ $box['id'] ] : 'frm-' . $box['id'];
1474 + $open_class = '';
1382 1475
1383 - if ( ! $first_open ) {
1384 - $first_open = true;
1385 - $open_class = 'open';
1386 - }
1476 + if ( ! $first_open ) {
1477 + $first_open = true;
1478 + $open_class = 'open';
1479 + }
1387 1480
1388 - $accordion_content_id = 'frm_style_section_' . $box['id'];
1389 - ?>
1390 - <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'] ); ?>">
1391 - <h3 class="accordion-section-title hndle">
1392 - <?php
1393 - FrmAppHelper::icon_by_class( 'frmfont ' . $icon_id . ' frm_svg24' );
1394 - echo esc_html( $box['title'] );
1395 - ?>
1396 - <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'] ); ?>">
1397 - <?php FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown8_icon' ); ?>
1398 - </button>
1399 - </h3>
1400 - <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>" id="<?php echo esc_attr( $accordion_content_id ); ?>">
1401 - <div class="inside">
1402 - <?php call_user_func( $box['callback'], $data_object, $box ); ?>
1403 - </div><!-- .inside -->
1404 - </div><!-- .accordion-section-content -->
1405 - </li><!-- .accordion-section -->
1406 - <?php
1407 - }//end foreach
1408 - }//end if
1481 + $accordion_content_id = 'frm_style_section_' . $box['id'];
1482 + ?>
1483 + <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 ?>
1484 + <h3 class="accordion-section-title hndle">
1485 + <?php
1486 + FrmAppHelper::icon_by_class( 'frmfont ' . $icon_id . ' frm_svg24' );
1487 + echo esc_html( $box['title'] );
1488 + ?>
1489 + <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 ?>
1490 + <?php FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown8_icon' ); ?>
1491 + </button>
1492 + </h3>
1493 + <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>" id="<?php echo esc_attr( $accordion_content_id ); ?>">
1494 + <div class="inside">
1495 + <?php call_user_func( $box['callback'], $data_object, $box ); ?>
1496 + </div><!-- .inside -->
1497 + </div><!-- .accordion-section-content -->
1498 + </li><!-- .accordion-section -->
1499 + <?php
1500 + }//end foreach
1409 1501 }//end foreach
1410 1502 }//end if
1411 1503 ?>
1412 1504 </ul><!-- .outer-border -->
@@ -1411,8 +1503,9 @@
1411 1503 ?>
1412 1504 </ul><!-- .outer-border -->
1413 1505 </div><!-- .accordion-container -->
1414 1506 <?php
1507 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
1415 1508 return $i;
1416 1509 }
1417 1510
1418 1511 /**
@@ -1443,8 +1536,11 @@
1443 1536 wp_send_json_error( $data, 400 );
1444 1537 die();
1445 1538 }
1446 1539
1540 + /**
1541 + * @var WP_Post|null $post
1542 + */
1447 1543 $post = get_post( $style_id );
1448 1544
1449 1545 if ( ! $post || $post->post_type !== self::$post_type ) {
1450 1546 $data = array(