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