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