PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/controllers/FrmAppController.php +359 -177 6.25 → trunk View file →
@@ -9,8 +9,9 @@
9 9 * @return void
10 10 */
11 11 public static function menu() {
12 12 FrmAppHelper::maybe_add_permissions();
13 +
13 14 if ( ! current_user_can( 'frm_view_forms' ) ) {
14 15 return;
15 16 }
16 17
@@ -31,8 +32,10 @@
31 32 }
32 33
33 34 /**
34 35 * @since 3.05
36 + *
37 + * @return string
35 38 */
36 39 private static function menu_icon() {
37 40 $icon = FrmAppHelper::svg_logo(
38 41 array(
@@ -46,8 +49,12 @@
46 49 }
47 50
48 51 /**
49 52 * @since 3.0
53 + *
54 + * @param string $classes
55 + *
56 + * @return string
50 57 */
51 58 public static function add_admin_class( $classes ) {
52 59 if ( self::is_white_page() ) {
53 60 $classes .= ' frm-white-body ';
@@ -53,17 +60,20 @@
53 60 $classes .= ' frm-white-body ';
54 61 $classes .= self::get_os();
55 62
56 63 $page = str_replace( 'formidable-', '', FrmAppHelper::simple_get( 'page', 'sanitize_title' ) );
57 - if ( empty( $page ) || $page === 'formidable' ) {
64 +
65 + if ( ! $page || $page === 'formidable' ) {
58 66 $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
59 - if ( in_array( $action, array( 'settings', 'edit', 'list' ) ) ) {
67 +
68 + if ( in_array( $action, array( 'settings', 'edit', 'list' ), true ) ) {
60 69 $page .= $action;
61 70 } else {
62 71 $page = $action;
63 72 }
64 73 }
65 - if ( ! empty( $page ) ) {
74 +
75 + if ( $page ) {
66 76 $classes .= ' frm-admin-page-' . $page;
67 77 }
68 78 }
69 79
@@ -71,16 +81,17 @@
71 81 $classes .= ' frm-grey-body ';
72 82 }
73 83
74 84 if ( FrmAppHelper::is_full_screen() ) {
75 - $full_screen_on = self::get_full_screen_setting();
76 - $add_class = '';
77 - if ( $full_screen_on ) {
85 + $add_class = '';
86 +
87 + if ( self::get_full_screen_setting() ) {
78 88 $add_class = ' frm-full-screen is-fullscreen-mode';
79 89
80 90 // Load the CSS for .is-fullscreen-mode.
81 91 wp_enqueue_style( 'wp-edit-post' );
82 92 }
93 +
83 94 $classes .= apply_filters( 'frm_admin_full_screen_class', $add_class );
84 95 }
85 96
86 97 if ( ! FrmAppHelper::pro_is_installed() ) {
@@ -103,10 +114,10 @@
103 114 */
104 115 private static function get_full_screen_setting() {
105 116 global $wpdb;
106 117 $meta_key = $wpdb->get_blog_prefix() . 'persisted_preferences';
118 + $prefs = get_user_meta( get_current_user_id(), $meta_key, true );
107 119
108 - $prefs = get_user_meta( get_current_user_id(), $meta_key, true );
109 120 if ( $prefs && isset( $prefs['core/edit-post']['fullscreenMode'] ) ) {
110 121 return $prefs['core/edit-post']['fullscreenMode'];
111 122 }
112 123
@@ -120,20 +131,24 @@
120 131 */
121 132 private static function get_os() {
122 133 $agent = strtolower( FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' ) );
123 134 $os = '';
124 - if ( strpos( $agent, 'mac' ) !== false ) {
135 +
136 + if ( str_contains( $agent, 'mac' ) ) {
125 137 $os = ' osx';
126 - } elseif ( strpos( $agent, 'linux' ) !== false ) {
138 + } elseif ( str_contains( $agent, 'linux' ) ) {
127 139 $os = ' linux';
128 - } elseif ( strpos( $agent, 'windows' ) !== false ) {
140 + } elseif ( str_contains( $agent, 'windows' ) ) {
129 141 $os = ' windows';
130 142 }
143 +
131 144 return $os;
132 145 }
133 146
134 147 /**
135 148 * @since 3.0
149 + *
150 + * @return bool
136 151 */
137 152 private static function is_white_page() {
138 153 $white_pages = array(
139 154 'formidable',
@@ -149,17 +164,10 @@
149 164 FrmFormTemplatesController::PAGE_SLUG,
150 165 FrmOnboardingWizardController::PAGE_SLUG,
151 166 );
152 167
153 - if ( ! class_exists( 'FrmTransHooksController', false ) && ! FrmTransLiteAppHelper::should_fallback_to_paypal() ) {
154 - // Only consider the payments page as a "white page" when the Payments submodule is off.
155 - // Otherwise this causes a lot of styling issues when the Stripe add-on (or Authorize.Net) is active.
156 -
157 - // Add an extra check to avoid white page styling on the PayPal "edit" action.
158 - // We fallback to the PayPal add on for the "edit" action since Stripe Lite does not have an edit view.
159 - if ( ! in_array( FrmAppHelper::simple_get( 'action' ), array( 'edit', 'new' ), true ) || ! is_callable( 'FrmPaymentsController::route' ) ) {
160 - $white_pages[] = 'formidable-payments';
161 - }
168 + if ( self::is_white_payments_page() ) {
169 + $white_pages[] = 'formidable-payments';
162 170 }
163 171
164 172 $is_white_page = self::is_page_in_list( $white_pages ) || self::is_grey_page() || FrmAppHelper::is_view_builder_page();
165 173
@@ -169,11 +177,25 @@
169 177 * @since 5.3
170 178 *
171 179 * @param bool $is_white_page
172 180 */
173 - $is_white_page = apply_filters( 'frm_is_white_page', $is_white_page );
181 + return apply_filters( 'frm_is_white_page', $is_white_page );
182 + }
174 183
175 - return $is_white_page;
184 + /**
185 + * Check if the payments page should be styled as a white page.
186 + * Fallback to the Stripe, Authorize.Net, or PayPal add on for the "edit" action since
187 + * Stripe Lite does not have an edit view. Also fallback for bulk deleting, since that
188 + * isn't built into Lite. The pages we fall back to should not be styled as white pages.
189 + *
190 + * @since 6.27
191 + *
192 + * @return bool
193 + */
194 + private static function is_white_payments_page() {
195 + $action = FrmAppHelper::simple_get( 'action', 'sanitize_title' );
196 + $on_edit_page = in_array( $action, array( 'edit', 'new' ), true );
197 + return ! $on_edit_page && 'bulk_delete' !== $action;
176 198 }
177 199
178 200 /**
179 201 * Add a grey bg instead of white.
@@ -196,8 +218,9 @@
196 218 *
197 219 * @since 6.8
198 220 *
199 221 * @param bool $is_grey_page
222 + *
200 223 * @return bool
201 224 */
202 225 return apply_filters( 'frm_is_grey_page', $is_grey_page );
203 226 }
@@ -205,8 +228,9 @@
205 228 /**
206 229 * @since 6.8
207 230 *
208 231 * @param array $pages A list of page names to check.
232 + *
209 233 * @return bool
210 234 */
211 235 private static function is_page_in_list( $pages ) {
212 236 $get_page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
@@ -230,13 +254,15 @@
230 254 * @return void
231 255 */
232 256 public static function get_form_nav( $form, $show_nav = false, $title = 'show' ) {
233 257 $show_nav = FrmAppHelper::get_param( 'show_nav', $show_nav, 'get', 'absint' );
234 - if ( empty( $show_nav ) || ! $form ) {
258 +
259 + if ( ! $show_nav || ! $form ) {
235 260 return;
236 261 }
237 262
238 263 FrmForm::maybe_get_form( $form );
264 +
239 265 if ( ! is_object( $form ) ) {
240 266 return;
241 267 }
242 268
@@ -250,21 +276,21 @@
250 276 /**
251 277 * @return string
252 278 */
253 279 private static function get_current_page() {
254 - $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
255 - $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title', 'None' );
256 - $current_page = isset( $_GET['page'] ) ? $page : $post_type;
257 -
258 280 if ( FrmAppHelper::is_view_builder_page() ) {
259 - $current_page = 'frm_display';
281 + return 'frm_display';
260 282 }
261 283
262 - return $current_page;
284 + $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
285 + $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title', 'None' );
286 +
287 + return isset( $_GET['page'] ) ? $page : $post_type;
263 288 }
264 289
265 290 /**
266 291 * @param object $form
292 + *
267 293 * @return array
268 294 */
269 295 private static function get_form_nav_items( $form ) {
270 296 $id = $form->parent_form_id ? $form->parent_form_id : $form->id;
@@ -340,8 +366,9 @@
340 366 /**
341 367 * Adds a settings link to the plugins page
342 368 *
343 369 * @param array $links
370 + *
344 371 * @return array
345 372 */
346 373 public static function settings_link( $links ) {
347 374 $settings = array();
@@ -346,28 +373,38 @@
346 373 public static function settings_link( $links ) {
347 374 $settings = array();
348 375
349 376 if ( ! FrmAppHelper::pro_is_installed() ) {
350 - if ( FrmAddonsController::is_license_expired() ) {
377 + $is_expired = FrmAddonsController::is_license_expired();
378 +
379 + if ( $is_expired ) {
351 380 $label = __( 'Renew', 'formidable' );
352 381 } else {
353 382 $label = FrmSalesApi::get_best_sale_value( 'plugin_page_cta_text' );
383 +
354 384 if ( ! $label ) {
355 385 $label = __( 'Upgrade to Pro', 'formidable' );
356 386 }
357 387 }
358 388
359 - $upgrade_link = FrmSalesApi::get_best_sale_value( 'plugin_page_cta_link' );
389 + $upgrade_content = $is_expired ? 'renew' : 'upgrade';
390 + $upgrade_link = FrmSalesApi::get_best_sale_value( 'plugin_page_cta_link' );
391 +
392 + $utm = array(
393 + 'campaign' => 'plugin-row',
394 + 'content' => $upgrade_content,
395 + );
396 +
360 397 if ( $upgrade_link ) {
361 - $upgrade_link = FrmAppHelper::maybe_add_missing_utm( $upgrade_link, array( 'medium' => 'plugin-row' ) );
398 + $upgrade_link = FrmAppHelper::maybe_add_missing_utm( $upgrade_link, $utm );
362 399 } else {
363 - $upgrade_link = FrmAppHelper::admin_upgrade_link( 'plugin-row' );
400 + $upgrade_link = FrmAppHelper::admin_upgrade_link( $utm );
364 401 }
365 402
366 403 $settings[] = '<a href="' . esc_url( $upgrade_link ) . '" target="_blank" rel="noopener"><b style="color:#1da867;font-weight:700;">' . esc_html( $label ) . '</b></a>';
367 - }
404 + }//end if
368 405
369 - $settings[] = '<a href="' . esc_url( admin_url( 'admin.php?page=formidable' ) ) . '">' . __( 'Build a Form', 'formidable' ) . '</a>';
406 + $settings[] = '<a href="' . esc_url( admin_url( 'admin.php?page=formidable' ) ) . '">' . esc_html__( 'Build a Form', 'formidable' ) . '</a>';
370 407
371 408 return array_merge( $settings, $links );
372 409 }
373 410
@@ -375,9 +412,9 @@
375 412 * @return void
376 413 */
377 414 public static function pro_get_started_headline() {
378 415 self::review_request();
379 - FrmAppHelper::min_pro_version_notice( '6.0' );
416 + FrmAppHelper::min_pro_version_notice( '6.20' );
380 417 }
381 418
382 419 /**
383 420 * Add admin notices as needed for reviews
@@ -452,8 +489,9 @@
452 489 *
453 490 * @param string $form_key
454 491 * @param string $title
455 492 * @param string $description
493 + *
456 494 * @return void
457 495 */
458 496 public static function api_email_form( $form_key, $title = '', $description = '' ) {
459 497 $user = wp_get_current_user();
@@ -500,12 +538,14 @@
500 538 * @return void
501 539 */
502 540 public static function install_js_fallback() {
503 541 FrmAppHelper::load_admin_wide_js();
542 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
504 543 ?>
505 544 <div id="frm_install_message"></div>
506 545 <script>jQuery(document).ready( frm_install_now );</script>
507 546 <?php
547 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
508 548 }
509 549
510 550 /**
511 551 * Check if the database is outdated
@@ -510,8 +550,9 @@
510 550 /**
511 551 * Check if the database is outdated
512 552 *
513 553 * @since 2.0.1
554 + *
514 555 * @return bool
515 556 */
516 557 public static function needs_update() {
517 558 $needs_upgrade = self::compare_for_update(
@@ -522,9 +563,9 @@
522 563 )
523 564 );
524 565
525 566 if ( ! $needs_upgrade ) {
526 - $needs_upgrade = apply_filters( 'frm_db_needs_upgrade', $needs_upgrade );
567 + return apply_filters( 'frm_db_needs_upgrade', $needs_upgrade );
527 568 }
528 569
529 570 return $needs_upgrade;
530 571 }
@@ -534,23 +575,27 @@
534 575 *
535 576 * @since 3.0.04
536 577 *
537 578 * @param array $atts
579 + *
538 580 * @return bool
539 581 */
540 582 public static function compare_for_update( $atts ) {
541 583 $db_version = get_option( $atts['option'] );
542 584
543 - if ( strpos( $db_version, '-' ) === false ) {
544 - $needs_upgrade = true;
545 - } else {
546 - $last_upgrade = explode( '-', $db_version );
547 - $needs_db_upgrade = (int) $last_upgrade[1] < (int) $atts['new_db_version'];
548 - $new_version = version_compare( $last_upgrade[0], $atts['new_plugin_version'], '<' );
549 - $needs_upgrade = $needs_db_upgrade || $new_version;
585 + if ( ! str_contains( $db_version, '-' ) ) {
586 + return true;
550 587 }
551 588
552 - return $needs_upgrade;
589 + $last_upgrade = explode( '-', $db_version );
590 + $needs_db_upgrade = (int) $last_upgrade[1] < (int) $atts['new_db_version'];
591 +
592 + if ( $needs_db_upgrade ) {
593 + return true;
594 + }
595 +
596 + // New plugin version.
597 + return version_compare( $last_upgrade[0], $atts['new_plugin_version'], '<' );
553 598 }
554 599
555 600 /**
556 601 * Check for database update and trigger js loading
@@ -579,17 +624,13 @@
579 624
580 625 if ( 'formidable-pro-upgrade' === FrmAppHelper::get_param( 'page' ) && ! FrmAppHelper::pro_is_installed() && current_user_can( 'frm_view_forms' ) ) {
581 626 $redirect = FrmSalesApi::get_best_sale_value( 'menu_cta_link' );
582 627 $utm = array(
583 - 'medium' => 'upgrade',
584 - 'content' => 'submenu-upgrade',
628 + 'campaign' => 'upgrade',
629 + 'content' => 'submenu-upgrade',
585 630 );
586 631
587 - if ( $redirect ) {
588 - $redirect = FrmAppHelper::maybe_add_missing_utm( $redirect, $utm );
589 - } else {
590 - $redirect = FrmAppHelper::admin_upgrade_link( $utm );
591 - }
632 + $redirect = $redirect ? FrmAppHelper::maybe_add_missing_utm( $redirect, $utm ) : FrmAppHelper::admin_upgrade_link( $utm );
592 633
593 634 wp_redirect( $redirect );
594 635 die();
595 636 }
@@ -601,29 +642,32 @@
601 642 self::network_upgrade_site();
602 643 }
603 644
604 645 if ( ! FrmAppHelper::doing_ajax() ) {
605 - // don't continue during ajax calls
646 + // Don't continue during ajax calls
606 647 self::admin_js();
607 648 }
608 649
609 650 self::trigger_page_load_hooks();
610 651
611 - if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
612 - // Redirect to the "Form Templates" page if the 'frm_action' parameter matches specific actions.
613 - // This provides backward compatibility for old addons that use legacy modal templates.
614 - $action = FrmAppHelper::get_param( 'frm_action' );
615 - $trigger_name_modal = FrmAppHelper::get_param( 'triggerNewFormModal' );
616 - if ( $trigger_name_modal || in_array( $action, array( 'add_new', 'list_templates' ), true ) ) {
617 - $application_id = FrmAppHelper::simple_get( 'applicationId', 'absint' );
618 - $url_param = $application_id ? '&applicationId=' . $application_id : '';
652 + if ( ! FrmAppHelper::is_admin_page( 'formidable' ) ) {
653 + return;
654 + }
619 655
620 - wp_safe_redirect( admin_url( 'admin.php?page=' . FrmFormTemplatesController::PAGE_SLUG . $url_param ) );
621 - exit;
622 - }
656 + // Redirect to the "Form Templates" page if the 'frm_action' parameter matches specific actions.
657 + // This provides backward compatibility for old addons that use legacy modal templates.
658 + $action = FrmAppHelper::get_param( 'frm_action' );
659 + $trigger_name_modal = FrmAppHelper::get_param( 'triggerNewFormModal' );
623 660
624 - FrmInbox::maybe_disable_screen_options();
661 + if ( $trigger_name_modal || in_array( $action, array( 'add_new', 'list_templates' ), true ) ) {
662 + $application_id = FrmAppHelper::simple_get( 'applicationId', 'absint' );
663 + $url_param = $application_id ? '&applicationId=' . $application_id : '';
664 +
665 + wp_safe_redirect( admin_url( 'admin.php?page=' . FrmFormTemplatesController::PAGE_SLUG . $url_param ) );
666 + exit;
625 667 }
668 +
669 + FrmInbox::maybe_disable_screen_options();
626 670 }
627 671
628 672 /**
629 673 * Get the current page and check for a possible function to trigger.
@@ -634,9 +678,10 @@
634 678 * @return void
635 679 */
636 680 private static function trigger_page_load_hooks() {
637 681 $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
638 - if ( strpos( $page, 'formidable-' ) !== 0 ) {
682 +
683 + if ( ! str_starts_with( $page, 'formidable-' ) ) {
639 684 // Only trigger hooks on Formidable pages.
640 685 return;
641 686 }
642 687
@@ -642,8 +687,9 @@
642 687
643 688 $page = str_replace( array( 'formidable-', '-' ), array( '', ' ' ), $page );
644 689 $page = str_replace( ' ', '', ucwords( $page ) );
645 690 $class = 'Frm' . $page . 'Controller';
691 +
646 692 if ( class_exists( $class ) && method_exists( $class, 'load_page' ) ) {
647 693 call_user_func( array( $class, 'load_page' ) );
648 694 }
649 695 }
@@ -651,13 +697,14 @@
651 697 /**
652 698 * @return void
653 699 */
654 700 public static function admin_js() {
655 - $plugin_url = FrmAppHelper::plugin_url();
656 - $version = FrmAppHelper::plugin_version();
701 + $plugin_url = FrmAppHelper::plugin_url();
702 + $version = FrmAppHelper::plugin_version();
703 + $is_pro_min_v6_28 = FrmAppHelper::pro_is_installed() && FrmAppHelper::meets_min_pro_version( '6.28' );
704 + $frm_components_dependencies = $is_pro_min_v6_28 ? array( 'formidable_admin', 'formidable-pro-web-components' ) : array( 'formidable_admin' );
657 705
658 706 FrmAppHelper::load_admin_wide_js();
659 -
660 707 // Register component assets early to ensure they can be enqueued later in controllers.
661 708 wp_register_style( 'formidable-animations', $plugin_url . '/css/admin/animations.css', array(), $version );
662 709
663 710 if ( class_exists( 'FrmOverlayController' ) ) {
@@ -673,10 +720,10 @@
673 720 wp_register_style( 'formidable-grids', $plugin_url . '/css/frm_grids.css', array(), $version );
674 721
675 722 wp_register_script( 'formidable_dom', $plugin_url . '/js/admin/dom.js', array( 'jquery', 'jquery-ui-dialog', 'wp-i18n' ), $version, true );
676 723 wp_register_script( 'formidable_embed', $plugin_url . '/js/admin/embed.js', array( 'formidable_dom', 'jquery-ui-autocomplete' ), $version, true );
677 - self::register_popper1();
678 - wp_register_script( 'bootstrap_tooltip', $plugin_url . '/js/bootstrap.min.js', array( 'jquery', 'popper' ), '4.6.1', true );
724 + self::register_popper2();
725 + wp_register_script( 'bootstrap_tooltip', $plugin_url . '/js/bootstrap.min.js', array( 'jquery', 'popper' ), '5.0.2', true );
679 726
680 727 $settings_js_vars = array(
681 728 'currencies' => FrmCurrencyHelper::get_currencies(),
682 729 );
@@ -681,51 +728,36 @@
681 728 'currencies' => FrmCurrencyHelper::get_currencies(),
682 729 );
683 730 wp_register_script( 'formidable_settings', $plugin_url . '/js/admin/settings.js', array(), $version, true );
684 731 wp_localize_script( 'formidable_settings', 'frmSettings', $settings_js_vars );
732 + wp_register_script( 'formidable-web-components', $plugin_url . '/js/formidable-web-components.js', $frm_components_dependencies, $version, true );
685 733
686 734 if ( self::should_show_floating_links() ) {
687 735 self::enqueue_floating_links( $plugin_url, $version );
688 736 }
689 737
690 - $dependencies = array(
691 - 'formidable_admin_global',
692 - 'jquery',
693 - 'jquery-ui-core',
694 - 'jquery-ui-draggable',
695 - 'jquery-ui-sortable',
696 - 'bootstrap_tooltip',
697 - 'bootstrap-multiselect',
698 - 'wp-i18n',
699 - // Required in WP versions older than 5.7
700 - 'wp-hooks',
701 - 'formidable_dom',
702 - 'formidable_embed',
738 + wp_register_script( 'formidable_admin', $plugin_url . '/js/formidable_admin.js', self::get_admin_js_dependencies(), $version, true );
739 +
740 + wp_register_script(
741 + 'formidable_forms_list',
742 + $plugin_url . '/js/admin/forms-list.js',
743 + array(
744 + 'formidable_dom',
745 + ),
746 + $version,
747 + true
703 748 );
704 749
705 - if ( FrmAppHelper::is_style_editor_page( 'edit' ) ) {
706 - // We only need to load the color picker when editing styles.
707 - $dependencies[] = 'wp-color-picker';
708 - }
709 -
710 - wp_register_script( 'formidable_admin', $plugin_url . '/js/formidable_admin.js', $dependencies, $version, true );
711 -
712 750 if ( FrmAppHelper::on_form_listing_page() ) {
713 751 // For the existing page dropdown in the Form embed modal.
714 752 wp_enqueue_script( 'jquery-ui-autocomplete' );
753 + wp_enqueue_script( 'formidable_forms_list' );
715 754 }
716 755
717 - wp_register_script( 'bootstrap-multiselect', $plugin_url . '/js/bootstrap-multiselect.js', array( 'jquery', 'bootstrap_tooltip', 'popper' ), '1.1.1', true );
756 + wp_register_script( 'bootstrap-multiselect', $plugin_url . '/js/bootstrap-multiselect.js', array( 'jquery', 'bootstrap_tooltip', 'popper' ), '2.0', true );
718 757
719 758 if ( ! class_exists( 'FrmTransHooksController', false ) ) {
720 - /**
721 - * Gateway fields are included for add-on compatibility but we do not want it to be visible.
722 - * They do however need to be visible when the payments submodule is active.
723 - */
724 - wp_add_inline_style(
725 - 'formidable-admin',
726 - '#frm_builder_page li[data-ftype="gateway"] { display: none; }'
727 - );
759 + FrmTransLiteAppController::hide_gateway_fields_in_builder();
728 760 }
729 761
730 762 $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
731 763 $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' );
@@ -730,14 +762,15 @@
730 762 $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
731 763 $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' );
732 764
733 765 global $pagenow;
734 - if ( strpos( $page, 'formidable' ) === 0 || ( $pagenow === 'edit.php' && $post_type === 'frm_display' ) ) {
766 +
767 + if ( str_starts_with( $page, 'formidable' ) || ( $pagenow === 'edit.php' && $post_type === 'frm_display' ) ) {
735 768 self::enqueue_global_settings_scripts( $page );
736 769
737 770 wp_enqueue_script( 'admin-widgets' );
738 771 wp_enqueue_style( 'widgets' );
739 - self::maybe_deregister_popper2();
772 + self::maybe_deregister_popper1();
740 773 wp_enqueue_script( 'formidable_admin' );
741 774 wp_set_script_translations( 'formidable_admin', 'formidable' );
742 775 wp_enqueue_script( 'formidable_embed' );
743 776 wp_set_script_translations( 'formidable_embed', 'formidable' );
@@ -744,8 +777,9 @@
744 777 FrmAppHelper::localize_script( 'admin' );
745 778
746 779 wp_enqueue_style( 'formidable-animations' );
747 780 wp_enqueue_style( 'formidable-admin' );
781 +
748 782 if ( 'formidable-styles' !== $page && 'formidable-styles2' !== $page ) {
749 783 wp_enqueue_style( 'formidable-grids' );
750 784 self::maybe_enqueue_dropzone_css( $page );
751 785 } else {
@@ -761,8 +795,9 @@
761 795 wp_enqueue_script( 'formidable_entries' );
762 796 }
763 797
764 798 do_action( 'frm_enqueue_builder_scripts' );
799 + self::maybe_enqueue_legacy_paypal_assets();
765 800 self::include_upgrade_overlay();
766 801 self::include_info_overlay();
767 802 } elseif ( FrmAppHelper::is_view_builder_page() ) {
768 803 if ( isset( $_REQUEST['post_type'] ) ) {
@@ -768,11 +803,13 @@
768 803 if ( isset( $_REQUEST['post_type'] ) ) {
769 804 $post_type = sanitize_title( wp_unslash( $_REQUEST['post_type'] ) );
770 805 } elseif ( isset( $_REQUEST['post'] ) && absint( $_REQUEST['post'] ) ) {
771 806 $post = get_post( absint( wp_unslash( $_REQUEST['post'] ) ) );
807 +
772 808 if ( ! $post ) {
773 809 return;
774 810 }
811 +
775 812 $post_type = $post->post_type;
776 813 } else {
777 814 return;
778 815 }
@@ -790,8 +827,37 @@
790 827 self::enqueue_builder_assets( $plugin_url, $version );
791 828 }
792 829
793 830 /**
831 + * @since 6.27
832 + *
833 + * @return array
834 + */
835 + private static function get_admin_js_dependencies() {
836 + $dependencies = array(
837 + 'formidable_admin_global',
838 + 'jquery',
839 + 'jquery-ui-core',
840 + 'jquery-ui-draggable',
841 + 'jquery-ui-sortable',
842 + 'bootstrap_tooltip',
843 + 'bootstrap-multiselect',
844 + 'wp-i18n',
845 + // Required in WP versions older than 5.7
846 + 'wp-hooks',
847 + 'formidable_dom',
848 + 'formidable_embed',
849 + );
850 +
851 + if ( FrmAppHelper::is_style_editor_page( 'edit' ) ) {
852 + // We only need to load the color picker when editing styles.
853 + $dependencies[] = 'wp-color-picker';
854 + }
855 +
856 + return $dependencies;
857 + }
858 +
859 + /**
794 860 * Enqueue the Form Builder assets.
795 861 *
796 862 * @since 6.24
797 863 *
@@ -796,8 +862,9 @@
796 862 * @since 6.24
797 863 *
798 864 * @param string $plugin_url The plugin URL.
799 865 * @param string $version The plugin version.
866 + *
800 867 * @return void
801 868 */
802 869 private static function enqueue_builder_assets( $plugin_url, $version ) {
803 870 wp_register_style( 'formidable-settings-components', $plugin_url . '/css/admin/frm-settings-components.css', array( 'formidable-admin', 'formidable-grids' ), $version );
@@ -814,14 +881,18 @@
814 881 /**
815 882 * Enqueues global settings scripts.
816 883 *
817 884 * @param string $page The `page` param in URL.
885 + *
886 + * @return void
818 887 */
819 888 private static function enqueue_global_settings_scripts( $page ) {
820 - if ( 'formidable-settings' === $page ) {
821 - wp_enqueue_style( 'wp-color-picker' );
822 - wp_enqueue_script( 'formidable_settings' );
889 + if ( 'formidable-settings' !== $page ) {
890 + return;
823 891 }
892 +
893 + wp_enqueue_style( 'wp-color-picker' );
894 + wp_enqueue_script( 'formidable_settings' );
824 895 }
825 896
826 897 /**
827 898 * Avoid loading dropzone CSS on the form list page. It isn't required there.
@@ -828,8 +899,9 @@
828 899 *
829 900 * @since 6.11
830 901 *
831 902 * @param string $page
903 + *
832 904 * @return void
833 905 */
834 906 private static function maybe_enqueue_dropzone_css( $page ) {
835 907 if ( ! FrmAppHelper::pro_is_installed() ) {
@@ -836,8 +908,9 @@
836 908 return;
837 909 }
838 910
839 911 $should_avoid_loading_dropzone = 'formidable' === $page && ! FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
912 +
840 913 if ( ! $should_avoid_loading_dropzone ) {
841 914 wp_enqueue_style( 'formidable-dropzone' );
842 915 }
843 916 }
@@ -854,12 +927,18 @@
854 927 if ( ! FrmAppHelper::is_formidable_branding() ) {
855 928 return false;
856 929 }
857 930
858 - return FrmAppHelper::is_formidable_admin() &&
859 - ! FrmAppHelper::is_style_editor_page() &&
860 - ! FrmAppHelper::is_admin_page( 'formidable-views-editor' ) &&
861 - ! FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
931 + $should_show = FrmAppHelper::is_formidable_admin() && ! FrmAppHelper::is_style_editor_page() && ! FrmAppHelper::is_admin_page( 'formidable-views-editor' ) && ! FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
932 +
933 + /**
934 + * Filters whether the floating links should be displayed.
935 + *
936 + * @since 6.25.1
937 + *
938 + * @param bool $should_show Whether the floating links should be shown.
939 + */
940 + return apply_filters( 'frm_should_show_floating_links', $should_show );
862 941 }
863 942
864 943 /**
865 944 * @since 6.3.2
@@ -877,8 +956,29 @@
877 956 FrmUsageController::load_scripts();
878 957 }
879 958
880 959 /**
960 + * Enqueue legacy PayPal action settings styles when the PayPal add-on is active.
961 + *
962 + * @since 6.31
963 + *
964 + * @return void
965 + */
966 + private static function maybe_enqueue_legacy_paypal_assets() {
967 + if ( ! FrmAppHelper::is_form_builder_page() || ! class_exists( 'FrmPaymentsController' ) ) {
968 + return;
969 + }
970 +
971 + wp_register_style(
972 + 'formidable-legacy-paypal',
973 + FrmAppHelper::plugin_url() . '/css/admin/frm-legacy-paypal.css',
974 + array( 'formidable-admin' ),
975 + FrmAppHelper::plugin_version()
976 + );
977 + wp_enqueue_style( 'formidable-legacy-paypal' );
978 + }
979 +
980 + /**
881 981 * Enqueue required assets for the Legacy Views editor (Views v4.x).
882 982 *
883 983 * @since 6.1.2
884 984 *
@@ -886,9 +986,9 @@
886 986 */
887 987 private static function enqueue_legacy_views_assets() {
888 988 wp_enqueue_style( 'formidable-grids' );
889 989 wp_enqueue_script( 'jquery-ui-draggable' );
890 - self::maybe_deregister_popper2();
990 + self::maybe_deregister_popper1();
891 991 wp_enqueue_script( 'formidable_admin' );
892 992 wp_add_inline_style(
893 993 'formidable-admin',
894 994 '
@@ -911,21 +1011,21 @@
911 1011 }
912 1012 '
913 1013 );
914 1014 wp_enqueue_style( 'formidable-admin' );
915 - wp_enqueue_script( 'formidable_legacy_views', FrmAppHelper::plugin_url() . '/js/admin/legacy-views.js', array( 'jquery', 'formidable_admin' ), FrmAppHelper::plugin_version() );
1015 + wp_enqueue_script( 'formidable_legacy_views', FrmAppHelper::plugin_url() . '/js/admin/legacy-views.js', array( 'jquery', 'formidable_admin' ), FrmAppHelper::plugin_version() ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
916 1016 FrmAppHelper::localize_script( 'admin' );
917 1017 self::include_info_overlay();
918 1018 }
919 1019
920 1020 /**
921 - * Fix a Duplicator Pro conflict because it uses Popper 2. See issue #3459.
1021 + * Unregister Popper if the registered version is outdated.
922 1022 *
923 - * @since 5.2.02.01
1023 + * @since 6.26
924 1024 *
925 1025 * @return void
926 1026 */
927 - private static function maybe_deregister_popper2() {
1027 + private static function maybe_deregister_popper1() {
928 1028 global $wp_scripts;
929 1029
930 1030 if ( ! array_key_exists( 'popper', $wp_scripts->registered ) ) {
931 1031 return;
@@ -931,26 +1031,29 @@
931 1031 return;
932 1032 }
933 1033
934 1034 $popper = $wp_scripts->registered['popper'];
935 - if ( version_compare( $popper->ver, '2.0', '>=' ) ) {
936 - wp_deregister_script( 'popper' );
937 - self::register_popper1();
1035 +
1036 + if ( ! version_compare( $popper->ver, '2.0', '<' ) ) {
1037 + return;
938 1038 }
1039 +
1040 + wp_deregister_script( 'popper' );
1041 + self::register_popper2();
939 1042 }
940 1043
941 1044 /**
942 - * Register Popper required for Bootstrap 4.
1045 + * Register Popper required for Bootstrap 5.
943 1046 *
944 - * @since 5.2.02.01
1047 + * @since 6.26
945 1048 *
946 1049 * @return void
947 1050 */
948 - private static function register_popper1() {
1051 + private static function register_popper2() {
949 1052 if ( ! self::should_register_popper() ) {
950 1053 return;
951 1054 }
952 - wp_register_script( 'popper', FrmAppHelper::plugin_url() . '/js/popper.min.js', array( 'jquery' ), '1.16.0', true );
1055 + wp_register_script( 'popper', FrmAppHelper::plugin_url() . '/js/popper.min.js', array(), '2.11.8', true );
953 1056 }
954 1057
955 1058 /**
956 1059 * Only register popper on Formidable pages.
@@ -963,8 +1066,9 @@
963 1066 private static function should_register_popper() {
964 1067 global $pagenow;
965 1068
966 1069 $post_id = FrmAppHelper::simple_get( 'post', 'absint' );
1070 +
967 1071 if ( 'post.php' === $pagenow && $post_id && 'frm_display' === get_post_type( $post_id ) ) {
968 1072 return true;
969 1073 }
970 1074
@@ -969,14 +1073,16 @@
969 1073 }
970 1074
971 1075 $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' );
972 1076 $is_views_post_type = 'frm_display' === $post_type;
1077 +
973 1078 if ( in_array( $pagenow, array( 'post-new.php', 'edit.php' ), true ) && $is_views_post_type ) {
974 1079 return true;
975 1080 }
976 1081
977 1082 $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
978 - if ( strpos( $page, 'formidable' ) === 0 ) {
1083 +
1084 + if ( str_starts_with( $page, 'formidable' ) ) {
979 1085 return true;
980 1086 }
981 1087
982 1088 return in_array( $pagenow, array( 'term.php', 'edit-tags.php' ), true ) && FrmAppHelper::simple_get( 'taxonomy' ) === 'frm_application';
@@ -990,13 +1096,15 @@
990 1096 * @return void
991 1097 */
992 1098 private static function maybe_force_formidable_block_on_gutenberg_page() {
993 1099 global $pagenow;
1100 +
994 1101 if ( 'post.php' !== $pagenow ) {
995 1102 return;
996 1103 }
997 1104
998 1105 $form_id = FrmAppHelper::simple_get( 'frmForm', 'absint' );
1106 +
999 1107 if ( ! $form_id ) {
1000 1108 return;
1001 1109 }
1002 1110
@@ -1063,8 +1171,10 @@
1063 1171 * Make sure the install is only being run when we tell it to.
1064 1172 * We don't want to run manually by people calling the API.
1065 1173 *
1066 1174 * @since 4.06.02
1175 + *
1176 + * @return bool
1067 1177 */
1068 1178 public static function can_update_db() {
1069 1179 return get_transient( 'frm_updating_api' );
1070 1180 }
@@ -1094,9 +1204,9 @@
1094 1204 $response = rest_do_request( $request );
1095 1205 }
1096 1206
1097 1207 if ( $response->is_error() ) {
1098 - // if the remove post fails, use javascript instead
1208 + // If the remove post fails, use javascript instead
1099 1209 add_action( 'admin_notices', 'FrmAppController::install_js_fallback' );
1100 1210 }
1101 1211 }
1102 1212
@@ -1106,14 +1216,17 @@
1106 1216 *
1107 1217 * @return void
1108 1218 */
1109 1219 private static function maybe_add_wp_site_health() {
1110 - if ( ! class_exists( 'WP_Site_Health' ) ) {
1111 - $wp_site_health_path = ABSPATH . 'wp-admin/includes/class-wp-site-health.php';
1112 - if ( file_exists( $wp_site_health_path ) ) {
1113 - require_once $wp_site_health_path;
1114 - }
1220 + if ( class_exists( 'WP_Site_Health' ) ) {
1221 + return;
1115 1222 }
1223 +
1224 + $wp_site_health_path = ABSPATH . 'wp-admin/includes/class-wp-site-health.php';
1225 +
1226 + if ( file_exists( $wp_site_health_path ) ) {
1227 + require_once $wp_site_health_path;
1228 + }
1116 1229 }
1117 1230
1118 1231 /**
1119 1232 * @since 3.0
@@ -1121,12 +1234,14 @@
1121 1234 * @return true
1122 1235 */
1123 1236 public static function api_install() {
1124 1237 delete_transient( 'frm_updating_api' );
1238 +
1125 1239 if ( self::needs_update() ) {
1126 1240 $running = get_option( 'frm_install_running' );
1241 +
1127 1242 if ( false === $running || $running < strtotime( '-5 minutes' ) ) {
1128 - update_option( 'frm_install_running', time(), 'no' );
1243 + update_option( 'frm_install_running', time(), false );
1129 1244 self::install();
1130 1245 delete_option( 'frm_install_running' );
1131 1246 }
1132 1247 }
@@ -1174,8 +1289,13 @@
1174 1289
1175 1290 wp_die();
1176 1291 }
1177 1292
1293 + /**
1294 + * @param array $tables
1295 + *
1296 + * @return array
1297 + */
1178 1298 public static function drop_tables( $tables ) {
1179 1299 global $wpdb;
1180 1300 $tables[] = $wpdb->prefix . 'frm_fields';
1181 1301 $tables[] = $wpdb->prefix . 'frm_forms';
@@ -1209,9 +1329,9 @@
1209 1329 }
1210 1330
1211 1331 /**
1212 1332 * The payment cron is unscheduled when Formidable is deactivated.
1213 - * We need to add it back again on activation if Stripe is configured.
1333 + * We need to add it back again on activation if any payment gateway is configured.
1214 1334 *
1215 1335 * @since 6.5
1216 1336 *
1217 1337 * @return void
@@ -1216,9 +1336,13 @@
1216 1336 *
1217 1337 * @return void
1218 1338 */
1219 1339 private static function maybe_activate_payment_cron() {
1220 - if ( ! FrmStrpLiteConnectHelper::stripe_connect_is_setup() ) {
1340 + $stripe_connected = FrmStrpLiteConnectHelper::at_least_one_mode_is_setup();
1341 + $square_connected = FrmSquareLiteConnectHelper::at_least_one_mode_is_setup();
1342 + $paypal_connected = FrmPayPalLiteConnectHelper::at_least_one_mode_is_setup();
1343 +
1344 + if ( ! $stripe_connected && ! $square_connected && ! $paypal_connected ) {
1221 1345 return;
1222 1346 }
1223 1347
1224 1348 FrmTransLiteAppController::maybe_schedule_cron();
@@ -1223,14 +1347,15 @@
1223 1347
1224 1348 FrmTransLiteAppController::maybe_schedule_cron();
1225 1349 }
1226 1350
1351 + /**
1352 + * @param string $text
1353 + *
1354 + * @return string
1355 + */
1227 1356 public static function set_footer_text( $text ) {
1228 - if ( FrmAppHelper::is_formidable_admin() ) {
1229 - $text = '';
1230 - }
1231 -
1232 - return $text;
1357 + return FrmAppHelper::is_formidable_admin() ? '' : $text;
1233 1358 }
1234 1359
1235 1360 /**
1236 1361 * Add admin footer links.
@@ -1240,8 +1365,9 @@
1240 1365 * @return void
1241 1366 */
1242 1367 public static function add_admin_footer_links() {
1243 1368 FrmFormsController::include_device_too_small_message();
1369 +
1244 1370 if ( self::should_show_footer_links() ) {
1245 1371 include FrmAppHelper::plugin_path() . '/classes/views/shared/admin-footer-links.php';
1246 1372 }
1247 1373 }
@@ -1256,8 +1382,9 @@
1256 1382 private static function should_show_footer_links() {
1257 1383 $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' );
1258 1384 $is_formidable_page = FrmAppHelper::is_formidable_admin() || 'frm_logs' === $post_type;
1259 1385 $show_footer_links = $is_formidable_page;
1386 +
1260 1387 if ( FrmAppHelper::is_full_screen() || ! FrmAppHelper::is_formidable_branding() ) {
1261 1388 $show_footer_links = false;
1262 1389 }
1263 1390
@@ -1266,8 +1393,9 @@
1266 1393 *
1267 1394 * @since 6.7
1268 1395 *
1269 1396 * @param bool $show_footer_links
1397 + *
1270 1398 * @return bool
1271 1399 */
1272 1400 return apply_filters( 'frm_show_footer_links', $show_footer_links );
1273 1401 }
@@ -1290,12 +1418,14 @@
1290 1418 'cancel_url' => '',
1291 1419 'cancel_classes' => '',
1292 1420 'continue_url' => '',
1293 1421 'continue_classes' => '',
1422 + 'continue_target' => '',
1294 1423 'icon' => 'frm_lock_simple',
1295 1424 );
1296 1425
1297 1426 $error_args = wp_parse_args( $error_args, $defaults );
1427 +
1298 1428 if ( ! isset( $error_args['cancel_text'] ) && ! empty( $error_args['cancel_url'] ) ) {
1299 1429 $error_args['cancel_text'] = __( 'Cancel', 'formidable' );
1300 1430 }
1301 1431
@@ -1312,8 +1442,9 @@
1312 1442 * @since 6.4
1313 1443 *
1314 1444 * @param string $plugin_url URL of the plugin.
1315 1445 * @param string $version Current version of the plugin.
1446 + *
1316 1447 * @return void
1317 1448 */
1318 1449 private static function enqueue_floating_links( $plugin_url, $version ) {
1319 1450 if ( ! $plugin_url || ! $version ) {
@@ -1333,10 +1464,20 @@
1333 1464 if ( function_exists( 'wp_set_script_translations' ) ) {
1334 1465 wp_set_script_translations( 's11-floating-links-config', 's11-' );
1335 1466 }
1336 1467
1468 + $upgrade_utm = array(
1469 + 'campaign' => 'floating-links',
1470 + 'content' => 'floating-links-upgrade',
1471 + );
1472 + $docs_utm = array(
1473 + 'campaign' => 'floating-links',
1474 + 'content' => 'floating-links-docs',
1475 + );
1337 1476 $floating_links_data = array(
1338 - 'proIsInstalled' => FrmAppHelper::pro_is_installed(),
1477 + 'proIsInstalled' => FrmAppHelper::pro_is_installed(),
1478 + 'upgradeUrl' => FrmAppHelper::admin_upgrade_link( $upgrade_utm ),
1479 + 'documentationUrl' => FrmAppHelper::admin_upgrade_link( $docs_utm, 'knowledgebase/' ),
1339 1480 );
1340 1481 wp_localize_script( 's11-floating-links-config', 's11FloatingLinksData', $floating_links_data );
1341 1482
1342 1483 /**
@@ -1354,8 +1495,9 @@
1354 1495 * @return bool
1355 1496 */
1356 1497 private static function in_our_pages() {
1357 1498 global $current_screen, $pagenow;
1499 +
1358 1500 if ( FrmAppHelper::is_formidable_admin() ) {
1359 1501 return true;
1360 1502 }
1361 1503
@@ -1362,13 +1504,9 @@
1362 1504 if ( ! empty( $current_screen->post_type ) && 'frm_logs' === $current_screen->post_type ) {
1363 1505 return true;
1364 1506 }
1365 1507
1366 - if ( in_array( $pagenow, array( 'term.php', 'edit-tags.php' ), true ) && 'frm_application' === FrmAppHelper::simple_get( 'taxonomy' ) ) {
1367 - return true;
1368 - }
1369 -
1370 - return false;
1508 + return in_array( $pagenow, array( 'term.php', 'edit-tags.php' ), true ) && 'frm_application' === FrmAppHelper::simple_get( 'taxonomy' );
1371 1509 }
1372 1510
1373 1511 /**
1374 1512 * Handles actions related to the current screen.
@@ -1404,8 +1542,9 @@
1404 1542 foreach ( $actions as $action ) {
1405 1543 if ( empty( $wp_filter[ $action ]->callbacks ) ) {
1406 1544 continue;
1407 1545 }
1546 +
1408 1547 foreach ( $wp_filter[ $action ]->callbacks as $priority => $callbacks ) {
1409 1548 foreach ( $callbacks as $callback_name => $callback ) {
1410 1549 if ( self::is_our_callback_string( $callback_name ) || self::is_our_callback_array( $callback ) ) {
1411 1550 continue;
@@ -1421,14 +1560,18 @@
1421 1560 *
1422 1561 * @return void
1423 1562 */
1424 1563 private static function remember_custom_sort() {
1425 - $screen = get_current_screen();
1426 - if ( ! $screen ) {
1564 + $meta_key = self::get_sort_pref_user_meta_key();
1565 +
1566 + if ( false === $meta_key ) {
1427 1567 return;
1428 1568 }
1429 1569
1430 - if ( ! FrmAppHelper::is_admin_list_page() && ! FrmAppHelper::is_admin_list_page( 'formidable-entries' ) ) {
1570 + $is_form_list = FrmAppHelper::is_admin_list_page();
1571 + $is_entry_list = FrmAppHelper::is_admin_list_page( 'formidable-entries' );
1572 +
1573 + if ( ! $is_form_list && ! $is_entry_list ) {
1431 1574 return;
1432 1575 }
1433 1576
1434 1577 $orderby = FrmAppHelper::get_param( 'orderby' );
@@ -1436,29 +1579,37 @@
1436 1579 if ( ! $orderby ) {
1437 1580 return;
1438 1581 }
1439 1582
1440 - $user_id = get_current_user_id();
1441 - $meta_key = 'frm_preferred_list_sort_' . $screen->id;
1442 - $order = FrmAppHelper::get_param( 'order' );
1443 -
1444 - $new_sort = array(
1583 + $user_id = get_current_user_id();
1584 + $order = FrmAppHelper::get_param( 'order' );
1585 + $new_sort = array(
1445 1586 'orderby' => $orderby,
1446 1587 'order' => $order,
1447 1588 );
1589 + $previous_meta = get_user_meta( $user_id, $meta_key, true );
1590 + $current_sort = $previous_meta;
1591 + $form_id = $is_entry_list ? FrmAppHelper::simple_get( 'form', 'absint' ) : 0;
1448 1592
1449 - $current_sort = get_user_meta( $user_id, $meta_key, true );
1593 + if ( is_array( $current_sort ) && $form_id && is_int( $form_id ) && isset( $current_sort[ $form_id ] ) ) {
1594 + $current_sort = $current_sort[ $form_id ];
1595 + }
1450 1596
1451 - if ( $new_sort !== $current_sort ) {
1452 - update_user_meta(
1453 - $user_id,
1454 - $meta_key,
1455 - array(
1456 - 'orderby' => $orderby,
1457 - 'order' => $order,
1458 - )
1459 - );
1597 + if ( $new_sort === $current_sort ) {
1598 + return;
1460 1599 }
1600 +
1601 + $new_meta = $new_sort;
1602 +
1603 + if ( $is_entry_list && $form_id && is_int( $form_id ) ) {
1604 + // Index meta by form ID.
1605 + $temp_meta = is_array( $previous_meta ) ? $previous_meta : array();
1606 + $temp_meta[ $form_id ] = $new_meta;
1607 + $new_meta = $temp_meta;
1608 + unset( $temp_meta );
1609 + }
1610 +
1611 + update_user_meta( $user_id, $meta_key, $new_meta );
1461 1612 }
1462 1613
1463 1614 /**
1464 1615 * Retrieve and apply any saved sorting preferences for the current screen.
@@ -1464,32 +1615,52 @@
1464 1615 * Retrieve and apply any saved sorting preferences for the current screen.
1465 1616 *
1466 1617 * @since 6.19
1467 1618 *
1468 - * @param string &$orderby Reference to the current 'orderby' parameter.
1469 - * @param string &$order Reference to the current 'order' parameter.
1619 + * @param string $orderby Reference to the current 'orderby' parameter.
1620 + * @param string $order Reference to the current 'order' parameter.
1621 + *
1470 1622 * @return void
1471 1623 */
1472 1624 public static function apply_saved_sort_preference( &$orderby, &$order ) {
1473 - if ( ! function_exists( 'get_current_screen' ) ) {
1625 + $meta_key = self::get_sort_pref_user_meta_key();
1626 +
1627 + if ( false === $meta_key ) {
1474 1628 return;
1475 1629 }
1476 1630
1477 - $screen = get_current_screen();
1478 - if ( ! $screen ) {
1631 + $preferred_list_sort = get_user_meta( get_current_user_id(), $meta_key, true );
1632 + $form_id = FrmAppHelper::simple_get( 'form', 'absint' );
1633 +
1634 + if ( is_array( $preferred_list_sort ) && $form_id && is_int( $form_id ) && isset( $preferred_list_sort[ $form_id ] ) ) {
1635 + $preferred_list_sort = $preferred_list_sort[ $form_id ];
1636 + }
1637 +
1638 + if ( ! is_array( $preferred_list_sort ) || empty( $preferred_list_sort['orderby'] ) ) {
1479 1639 return;
1480 1640 }
1481 1641
1482 - $user_id = get_current_user_id();
1483 - $preferred_list_sort = get_user_meta( $user_id, 'frm_preferred_list_sort_' . $screen->id, true );
1642 + $orderby = $preferred_list_sort['orderby'];
1484 1643
1485 - if ( is_array( $preferred_list_sort ) && ! empty( $preferred_list_sort['orderby'] ) ) {
1486 - $orderby = $preferred_list_sort['orderby'];
1644 + if ( ! empty( $preferred_list_sort['order'] ) ) {
1645 + $order = $preferred_list_sort['order'];
1646 + }
1647 + }
1487 1648
1488 - if ( ! empty( $preferred_list_sort['order'] ) ) {
1489 - $order = $preferred_list_sort['order'];
1490 - }
1649 + /**
1650 + * Get a simple user meta key that only includes the screen ID.
1651 + *
1652 + * @since 6.25.1
1653 + *
1654 + * @return false|string
1655 + */
1656 + private static function get_sort_pref_user_meta_key() {
1657 + if ( ! function_exists( 'get_current_screen' ) ) {
1658 + return false;
1491 1659 }
1660 +
1661 + $screen = get_current_screen();
1662 + return $screen ? 'frm_preferred_list_sort_' . $screen->id : false;
1492 1663 }
1493 1664
1494 1665 /**
1495 1666 * Validate that the callback name is ours not from third-party.
@@ -1509,12 +1680,9 @@
1509 1680 *
1510 1681 * @return bool
1511 1682 */
1512 1683 private static function is_our_callback_array( $callback ) {
1513 - return ! empty( $callback['function'] ) &&
1514 - is_array( $callback['function'] ) &&
1515 - ! empty( $callback['function'][0] ) &&
1516 - self::is_our_callback_string( is_object( $callback['function'][0] ) ? get_class( $callback['function'][0] ) : $callback['function'][0] );
1684 + return ! empty( $callback['function'] ) && is_array( $callback['function'] ) && ! empty( $callback['function'][0] ) && self::is_our_callback_string( is_object( $callback['function'][0] ) ? get_class( $callback['function'][0] ) : $callback['function'][0] ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
1517 1685 }
1518 1686
1519 1687 /**
1520 1688 * In some cases, the DB tables may fail to install.
@@ -1525,10 +1693,9 @@
1525 1693 */
1526 1694 private static function add_missing_tables() {
1527 1695 FrmAppHelper::permission_check( 'frm_view_forms' );
1528 1696
1529 - $inbox = new FrmInbox();
1530 - $error = $inbox->check_for_error();
1697 + $error = FrmInbox::check_for_error();
1531 1698
1532 1699 if ( ! $error || 'failed-to-create-tables' !== $error['key'] ) {
1533 1700 // Confirm the inbox item with this CTA exists.
1534 1701 wp_safe_redirect( admin_url( 'admin.php?page=formidable' ) );
@@ -1560,6 +1727,21 @@
1560 1727 FrmAppHelper::permission_check( 'frm_view_forms' );
1561 1728 check_ajax_referer( 'frm_ajax', 'nonce' );
1562 1729 update_user_option( get_current_user_id(), 'frm_ignore_small_screen_warning', true );
1563 1730 wp_send_json_success();
1731 + }
1732 +
1733 + /**
1734 + * Enqueue the components scripts.
1735 + *
1736 + * @since 6.28
1737 + *
1738 + * @return void
1739 + */
1740 + public static function enqueue_components_scripts() {
1741 + if ( is_callable( array( 'FrmProFormsController', 'enqueue_pro_web_components_script' ) ) ) {
1742 + FrmProFormsController::enqueue_pro_web_components_script();
1743 + }
1744 +
1745 + wp_enqueue_script( 'formidable-web-components' );
1564 1746 }
1565 1747 }