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