| @@ -61,12 +61,12 @@ | ||
| 61 | 61 | $classes .= self::get_os(); |
| 62 | 62 | |
| 63 | 63 | $page = str_replace( 'formidable-', '', FrmAppHelper::simple_get( 'page', 'sanitize_title' ) ); |
| 64 | 64 | |
| 65 | - if ( empty( $page ) || $page === 'formidable' ) { | |
| 65 | + if ( ! $page || $page === 'formidable' ) { | |
| 66 | 66 | $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); |
| 67 | 67 | |
| 68 | - if ( in_array( $action, array( 'settings', 'edit', 'list' ) ) ) { | |
| 68 | + if ( in_array( $action, array( 'settings', 'edit', 'list' ), true ) ) { | |
| 69 | 69 | $page .= $action; |
| 70 | 70 | } else { |
| 71 | 71 | $page = $action; |
| 72 | 72 | } |
| @@ -71,9 +71,9 @@ | ||
| 71 | 71 | $page = $action; |
| 72 | 72 | } |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - if ( ! empty( $page ) ) { | |
| 75 | + if ( $page ) { | |
| 76 | 76 | $classes .= ' frm-admin-page-' . $page; |
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | |
| @@ -81,12 +81,11 @@ | ||
| 81 | 81 | $classes .= ' frm-grey-body '; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | if ( FrmAppHelper::is_full_screen() ) { |
| 85 | - $full_screen_on = self::get_full_screen_setting(); | |
| 86 | - $add_class = ''; | |
| 85 | + $add_class = ''; | |
| 87 | 86 | |
| 88 | - if ( $full_screen_on ) { | |
| 87 | + if ( self::get_full_screen_setting() ) { | |
| 89 | 88 | $add_class = ' frm-full-screen is-fullscreen-mode'; |
| 90 | 89 | |
| 91 | 90 | // Load the CSS for .is-fullscreen-mode. |
| 92 | 91 | wp_enqueue_style( 'wp-edit-post' ); |
| @@ -115,11 +114,10 @@ | ||
| 115 | 114 | */ |
| 116 | 115 | private static function get_full_screen_setting() { |
| 117 | 116 | global $wpdb; |
| 118 | 117 | $meta_key = $wpdb->get_blog_prefix() . 'persisted_preferences'; |
| 118 | + $prefs = get_user_meta( get_current_user_id(), $meta_key, true ); | |
| 119 | 119 | |
| 120 | - $prefs = get_user_meta( get_current_user_id(), $meta_key, true ); | |
| 121 | - | |
| 122 | 120 | if ( $prefs && isset( $prefs['core/edit-post']['fullscreenMode'] ) ) { |
| 123 | 121 | return $prefs['core/edit-post']['fullscreenMode']; |
| 124 | 122 | } |
| 125 | 123 | |
| @@ -134,15 +132,16 @@ | ||
| 134 | 132 | private static function get_os() { |
| 135 | 133 | $agent = strtolower( FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' ) ); |
| 136 | 134 | $os = ''; |
| 137 | 135 | |
| 138 | - if ( strpos( $agent, 'mac' ) !== false ) { | |
| 136 | + if ( str_contains( $agent, 'mac' ) ) { | |
| 139 | 137 | $os = ' osx'; |
| 140 | - } elseif ( strpos( $agent, 'linux' ) !== false ) { | |
| 138 | + } elseif ( str_contains( $agent, 'linux' ) ) { | |
| 141 | 139 | $os = ' linux'; |
| 142 | - } elseif ( strpos( $agent, 'windows' ) !== false ) { | |
| 140 | + } elseif ( str_contains( $agent, 'windows' ) ) { | |
| 143 | 141 | $os = ' windows'; |
| 144 | 142 | } |
| 143 | + | |
| 145 | 144 | return $os; |
| 146 | 145 | } |
| 147 | 146 | |
| 148 | 147 | /** |
| @@ -165,17 +164,10 @@ | ||
| 165 | 164 | FrmFormTemplatesController::PAGE_SLUG, |
| 166 | 165 | FrmOnboardingWizardController::PAGE_SLUG, |
| 167 | 166 | ); |
| 168 | 167 | |
| 169 | - if ( ! class_exists( 'FrmTransHooksController', false ) && ! FrmTransLiteAppHelper::should_fallback_to_paypal() ) { | |
| 170 | - // Only consider the payments page as a "white page" when the Payments submodule is off. | |
| 171 | - // Otherwise this causes a lot of styling issues when the Stripe add-on (or Authorize.Net) is active. | |
| 172 | - | |
| 173 | - // Add an extra check to avoid white page styling on the PayPal "edit" action. | |
| 174 | - // We fallback to the PayPal add on for the "edit" action since Stripe Lite does not have an edit view. | |
| 175 | - if ( ! in_array( FrmAppHelper::simple_get( 'action' ), array( 'edit', 'new' ), true ) || ! is_callable( 'FrmPaymentsController::route' ) ) { | |
| 176 | - $white_pages[] = 'formidable-payments'; | |
| 177 | - } | |
| 168 | + if ( self::is_white_payments_page() ) { | |
| 169 | + $white_pages[] = 'formidable-payments'; | |
| 178 | 170 | } |
| 179 | 171 | |
| 180 | 172 | $is_white_page = self::is_page_in_list( $white_pages ) || self::is_grey_page() || FrmAppHelper::is_view_builder_page(); |
| 181 | 173 | |
| @@ -185,11 +177,25 @@ | ||
| 185 | 177 | * @since 5.3 |
| 186 | 178 | * |
| 187 | 179 | * @param bool $is_white_page |
| 188 | 180 | */ |
| 189 | - $is_white_page = apply_filters( 'frm_is_white_page', $is_white_page ); | |
| 181 | + return apply_filters( 'frm_is_white_page', $is_white_page ); | |
| 182 | + } | |
| 190 | 183 | |
| 191 | - 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; | |
| 192 | 198 | } |
| 193 | 199 | |
| 194 | 200 | /** |
| 195 | 201 | * Add a grey bg instead of white. |
| @@ -249,9 +255,9 @@ | ||
| 249 | 255 | */ |
| 250 | 256 | public static function get_form_nav( $form, $show_nav = false, $title = 'show' ) { |
| 251 | 257 | $show_nav = FrmAppHelper::get_param( 'show_nav', $show_nav, 'get', 'absint' ); |
| 252 | 258 | |
| 253 | - if ( empty( $show_nav ) || ! $form ) { | |
| 259 | + if ( ! $show_nav || ! $form ) { | |
| 254 | 260 | return; |
| 255 | 261 | } |
| 256 | 262 | |
| 257 | 263 | FrmForm::maybe_get_form( $form ); |
| @@ -270,17 +276,16 @@ | ||
| 270 | 276 | /** |
| 271 | 277 | * @return string |
| 272 | 278 | */ |
| 273 | 279 | private static function get_current_page() { |
| 274 | - $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' ); | |
| 275 | - $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title', 'None' ); | |
| 276 | - $current_page = isset( $_GET['page'] ) ? $page : $post_type; | |
| 277 | - | |
| 278 | 280 | if ( FrmAppHelper::is_view_builder_page() ) { |
| 279 | - $current_page = 'frm_display'; | |
| 281 | + return 'frm_display'; | |
| 280 | 282 | } |
| 281 | 283 | |
| 282 | - 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; | |
| 283 | 288 | } |
| 284 | 289 | |
| 285 | 290 | /** |
| 286 | 291 | * @param object $form |
| @@ -368,9 +373,11 @@ | ||
| 368 | 373 | public static function settings_link( $links ) { |
| 369 | 374 | $settings = array(); |
| 370 | 375 | |
| 371 | 376 | if ( ! FrmAppHelper::pro_is_installed() ) { |
| 372 | - if ( FrmAddonsController::is_license_expired() ) { | |
| 377 | + $is_expired = FrmAddonsController::is_license_expired(); | |
| 378 | + | |
| 379 | + if ( $is_expired ) { | |
| 373 | 380 | $label = __( 'Renew', 'formidable' ); |
| 374 | 381 | } else { |
| 375 | 382 | $label = FrmSalesApi::get_best_sale_value( 'plugin_page_cta_text' ); |
| 376 | 383 | |
| @@ -378,20 +385,26 @@ | ||
| 378 | 385 | $label = __( 'Upgrade to Pro', 'formidable' ); |
| 379 | 386 | } |
| 380 | 387 | } |
| 381 | 388 | |
| 382 | - $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' ); | |
| 383 | 391 | |
| 392 | + $utm = array( | |
| 393 | + 'campaign' => 'plugin-row', | |
| 394 | + 'content' => $upgrade_content, | |
| 395 | + ); | |
| 396 | + | |
| 384 | 397 | if ( $upgrade_link ) { |
| 385 | - $upgrade_link = FrmAppHelper::maybe_add_missing_utm( $upgrade_link, array( 'medium' => 'plugin-row' ) ); | |
| 398 | + $upgrade_link = FrmAppHelper::maybe_add_missing_utm( $upgrade_link, $utm ); | |
| 386 | 399 | } else { |
| 387 | - $upgrade_link = FrmAppHelper::admin_upgrade_link( 'plugin-row' ); | |
| 400 | + $upgrade_link = FrmAppHelper::admin_upgrade_link( $utm ); | |
| 388 | 401 | } |
| 389 | 402 | |
| 390 | 403 | $settings[] = '<a href="' . esc_url( $upgrade_link ) . '" target="_blank" rel="noopener"><b style="color:#1da867;font-weight:700;">' . esc_html( $label ) . '</b></a>'; |
| 391 | 404 | }//end if |
| 392 | 405 | |
| 393 | - $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>'; | |
| 394 | 407 | |
| 395 | 408 | return array_merge( $settings, $links ); |
| 396 | 409 | } |
| 397 | 410 | |
| @@ -525,12 +538,14 @@ | ||
| 525 | 538 | * @return void |
| 526 | 539 | */ |
| 527 | 540 | public static function install_js_fallback() { |
| 528 | 541 | FrmAppHelper::load_admin_wide_js(); |
| 542 | + // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 529 | 543 | ?> |
| 530 | 544 | <div id="frm_install_message"></div> |
| 531 | 545 | <script>jQuery(document).ready( frm_install_now );</script> |
| 532 | 546 | <?php |
| 547 | + // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 533 | 548 | } |
| 534 | 549 | |
| 535 | 550 | /** |
| 536 | 551 | * Check if the database is outdated |
| @@ -548,9 +563,9 @@ | ||
| 548 | 563 | ) |
| 549 | 564 | ); |
| 550 | 565 | |
| 551 | 566 | if ( ! $needs_upgrade ) { |
| 552 | - $needs_upgrade = apply_filters( 'frm_db_needs_upgrade', $needs_upgrade ); | |
| 567 | + return apply_filters( 'frm_db_needs_upgrade', $needs_upgrade ); | |
| 553 | 568 | } |
| 554 | 569 | |
| 555 | 570 | return $needs_upgrade; |
| 556 | 571 | } |
| @@ -566,18 +581,21 @@ | ||
| 566 | 581 | */ |
| 567 | 582 | public static function compare_for_update( $atts ) { |
| 568 | 583 | $db_version = get_option( $atts['option'] ); |
| 569 | 584 | |
| 570 | - if ( strpos( $db_version, '-' ) === false ) { | |
| 571 | - $needs_upgrade = true; | |
| 572 | - } else { | |
| 573 | - $last_upgrade = explode( '-', $db_version ); | |
| 574 | - $needs_db_upgrade = (int) $last_upgrade[1] < (int) $atts['new_db_version']; | |
| 575 | - $new_version = version_compare( $last_upgrade[0], $atts['new_plugin_version'], '<' ); | |
| 576 | - $needs_upgrade = $needs_db_upgrade || $new_version; | |
| 585 | + if ( ! str_contains( $db_version, '-' ) ) { | |
| 586 | + return true; | |
| 577 | 587 | } |
| 578 | 588 | |
| 579 | - 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'], '<' ); | |
| 580 | 598 | } |
| 581 | 599 | |
| 582 | 600 | /** |
| 583 | 601 | * Check for database update and trigger js loading |
| @@ -610,13 +628,9 @@ | ||
| 610 | 628 | 'campaign' => 'upgrade', |
| 611 | 629 | 'content' => 'submenu-upgrade', |
| 612 | 630 | ); |
| 613 | 631 | |
| 614 | - if ( $redirect ) { | |
| 615 | - $redirect = FrmAppHelper::maybe_add_missing_utm( $redirect, $utm ); | |
| 616 | - } else { | |
| 617 | - $redirect = FrmAppHelper::admin_upgrade_link( $utm ); | |
| 618 | - } | |
| 632 | + $redirect = $redirect ? FrmAppHelper::maybe_add_missing_utm( $redirect, $utm ) : FrmAppHelper::admin_upgrade_link( $utm ); | |
| 619 | 633 | |
| 620 | 634 | wp_redirect( $redirect ); |
| 621 | 635 | die(); |
| 622 | 636 | } |
| @@ -628,30 +642,32 @@ | ||
| 628 | 642 | self::network_upgrade_site(); |
| 629 | 643 | } |
| 630 | 644 | |
| 631 | 645 | if ( ! FrmAppHelper::doing_ajax() ) { |
| 632 | - // don't continue during ajax calls | |
| 646 | + // Don't continue during ajax calls | |
| 633 | 647 | self::admin_js(); |
| 634 | 648 | } |
| 635 | 649 | |
| 636 | 650 | self::trigger_page_load_hooks(); |
| 637 | 651 | |
| 638 | - if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { | |
| 639 | - // Redirect to the "Form Templates" page if the 'frm_action' parameter matches specific actions. | |
| 640 | - // This provides backward compatibility for old addons that use legacy modal templates. | |
| 641 | - $action = FrmAppHelper::get_param( 'frm_action' ); | |
| 642 | - $trigger_name_modal = FrmAppHelper::get_param( 'triggerNewFormModal' ); | |
| 652 | + if ( ! FrmAppHelper::is_admin_page( 'formidable' ) ) { | |
| 653 | + return; | |
| 654 | + } | |
| 643 | 655 | |
| 644 | - if ( $trigger_name_modal || in_array( $action, array( 'add_new', 'list_templates' ), true ) ) { | |
| 645 | - $application_id = FrmAppHelper::simple_get( 'applicationId', 'absint' ); | |
| 646 | - $url_param = $application_id ? '&applicationId=' . $application_id : ''; | |
| 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' ); | |
| 647 | 660 | |
| 648 | - wp_safe_redirect( admin_url( 'admin.php?page=' . FrmFormTemplatesController::PAGE_SLUG . $url_param ) ); | |
| 649 | - exit; | |
| 650 | - } | |
| 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 : ''; | |
| 651 | 664 | |
| 652 | - FrmInbox::maybe_disable_screen_options(); | |
| 665 | + wp_safe_redirect( admin_url( 'admin.php?page=' . FrmFormTemplatesController::PAGE_SLUG . $url_param ) ); | |
| 666 | + exit; | |
| 653 | 667 | } |
| 668 | + | |
| 669 | + FrmInbox::maybe_disable_screen_options(); | |
| 654 | 670 | } |
| 655 | 671 | |
| 656 | 672 | /** |
| 657 | 673 | * Get the current page and check for a possible function to trigger. |
| @@ -663,9 +679,9 @@ | ||
| 663 | 679 | */ |
| 664 | 680 | private static function trigger_page_load_hooks() { |
| 665 | 681 | $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' ); |
| 666 | 682 | |
| 667 | - if ( strpos( $page, 'formidable-' ) !== 0 ) { | |
| 683 | + if ( ! str_starts_with( $page, 'formidable-' ) ) { | |
| 668 | 684 | // Only trigger hooks on Formidable pages. |
| 669 | 685 | return; |
| 670 | 686 | } |
| 671 | 687 | |
| @@ -681,13 +697,14 @@ | ||
| 681 | 697 | /** |
| 682 | 698 | * @return void |
| 683 | 699 | */ |
| 684 | 700 | public static function admin_js() { |
| 685 | - $plugin_url = FrmAppHelper::plugin_url(); | |
| 686 | - $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' ); | |
| 687 | 705 | |
| 688 | 706 | FrmAppHelper::load_admin_wide_js(); |
| 689 | - | |
| 690 | 707 | // Register component assets early to ensure they can be enqueued later in controllers. |
| 691 | 708 | wp_register_style( 'formidable-animations', $plugin_url . '/css/admin/animations.css', array(), $version ); |
| 692 | 709 | |
| 693 | 710 | if ( class_exists( 'FrmOverlayController' ) ) { |
| @@ -711,51 +728,36 @@ | ||
| 711 | 728 | 'currencies' => FrmCurrencyHelper::get_currencies(), |
| 712 | 729 | ); |
| 713 | 730 | wp_register_script( 'formidable_settings', $plugin_url . '/js/admin/settings.js', array(), $version, true ); |
| 714 | 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 ); | |
| 715 | 733 | |
| 716 | 734 | if ( self::should_show_floating_links() ) { |
| 717 | 735 | self::enqueue_floating_links( $plugin_url, $version ); |
| 718 | 736 | } |
| 719 | 737 | |
| 720 | - $dependencies = array( | |
| 721 | - 'formidable_admin_global', | |
| 722 | - 'jquery', | |
| 723 | - 'jquery-ui-core', | |
| 724 | - 'jquery-ui-draggable', | |
| 725 | - 'jquery-ui-sortable', | |
| 726 | - 'bootstrap_tooltip', | |
| 727 | - 'bootstrap-multiselect', | |
| 728 | - 'wp-i18n', | |
| 729 | - // Required in WP versions older than 5.7 | |
| 730 | - 'wp-hooks', | |
| 731 | - 'formidable_dom', | |
| 732 | - '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 | |
| 733 | 748 | ); |
| 734 | 749 | |
| 735 | - if ( FrmAppHelper::is_style_editor_page( 'edit' ) ) { | |
| 736 | - // We only need to load the color picker when editing styles. | |
| 737 | - $dependencies[] = 'wp-color-picker'; | |
| 738 | - } | |
| 739 | - | |
| 740 | - wp_register_script( 'formidable_admin', $plugin_url . '/js/formidable_admin.js', $dependencies, $version, true ); | |
| 741 | - | |
| 742 | 750 | if ( FrmAppHelper::on_form_listing_page() ) { |
| 743 | 751 | // For the existing page dropdown in the Form embed modal. |
| 744 | 752 | wp_enqueue_script( 'jquery-ui-autocomplete' ); |
| 753 | + wp_enqueue_script( 'formidable_forms_list' ); | |
| 745 | 754 | } |
| 746 | 755 | |
| 747 | 756 | wp_register_script( 'bootstrap-multiselect', $plugin_url . '/js/bootstrap-multiselect.js', array( 'jquery', 'bootstrap_tooltip', 'popper' ), '2.0', true ); |
| 748 | 757 | |
| 749 | 758 | if ( ! class_exists( 'FrmTransHooksController', false ) ) { |
| 750 | - /** | |
| 751 | - * Gateway fields are included for add-on compatibility but we do not want it to be visible. | |
| 752 | - * They do however need to be visible when the payments submodule is active. | |
| 753 | - */ | |
| 754 | - wp_add_inline_style( | |
| 755 | - 'formidable-admin', | |
| 756 | - '#frm_builder_page li[data-ftype="gateway"] { display: none; }' | |
| 757 | - ); | |
| 759 | + FrmTransLiteAppController::hide_gateway_fields_in_builder(); | |
| 758 | 760 | } |
| 759 | 761 | |
| 760 | 762 | $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' ); |
| 761 | 763 | $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' ); |
| @@ -761,9 +763,9 @@ | ||
| 761 | 763 | $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' ); |
| 762 | 764 | |
| 763 | 765 | global $pagenow; |
| 764 | 766 | |
| 765 | - if ( strpos( $page, 'formidable' ) === 0 || ( $pagenow === 'edit.php' && $post_type === 'frm_display' ) ) { | |
| 767 | + if ( str_starts_with( $page, 'formidable' ) || ( $pagenow === 'edit.php' && $post_type === 'frm_display' ) ) { | |
| 766 | 768 | self::enqueue_global_settings_scripts( $page ); |
| 767 | 769 | |
| 768 | 770 | wp_enqueue_script( 'admin-widgets' ); |
| 769 | 771 | wp_enqueue_style( 'widgets' ); |
| @@ -793,8 +795,9 @@ | ||
| 793 | 795 | wp_enqueue_script( 'formidable_entries' ); |
| 794 | 796 | } |
| 795 | 797 | |
| 796 | 798 | do_action( 'frm_enqueue_builder_scripts' ); |
| 799 | + self::maybe_enqueue_legacy_paypal_assets(); | |
| 797 | 800 | self::include_upgrade_overlay(); |
| 798 | 801 | self::include_info_overlay(); |
| 799 | 802 | } elseif ( FrmAppHelper::is_view_builder_page() ) { |
| 800 | 803 | if ( isset( $_REQUEST['post_type'] ) ) { |
| @@ -824,8 +827,37 @@ | ||
| 824 | 827 | self::enqueue_builder_assets( $plugin_url, $version ); |
| 825 | 828 | } |
| 826 | 829 | |
| 827 | 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 | + /** | |
| 828 | 860 | * Enqueue the Form Builder assets. |
| 829 | 861 | * |
| 830 | 862 | * @since 6.24 |
| 831 | 863 | * |
| @@ -853,12 +885,14 @@ | ||
| 853 | 885 | * |
| 854 | 886 | * @return void |
| 855 | 887 | */ |
| 856 | 888 | private static function enqueue_global_settings_scripts( $page ) { |
| 857 | - if ( 'formidable-settings' === $page ) { | |
| 858 | - wp_enqueue_style( 'wp-color-picker' ); | |
| 859 | - wp_enqueue_script( 'formidable_settings' ); | |
| 889 | + if ( 'formidable-settings' !== $page ) { | |
| 890 | + return; | |
| 860 | 891 | } |
| 892 | + | |
| 893 | + wp_enqueue_style( 'wp-color-picker' ); | |
| 894 | + wp_enqueue_script( 'formidable_settings' ); | |
| 861 | 895 | } |
| 862 | 896 | |
| 863 | 897 | /** |
| 864 | 898 | * Avoid loading dropzone CSS on the form list page. It isn't required there. |
| @@ -893,12 +927,9 @@ | ||
| 893 | 927 | if ( ! FrmAppHelper::is_formidable_branding() ) { |
| 894 | 928 | return false; |
| 895 | 929 | } |
| 896 | 930 | |
| 897 | - $should_show = FrmAppHelper::is_formidable_admin() && | |
| 898 | - ! FrmAppHelper::is_style_editor_page() && | |
| 899 | - ! FrmAppHelper::is_admin_page( 'formidable-views-editor' ) && | |
| 900 | - ! 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 | |
| 901 | 932 | |
| 902 | 933 | /** |
| 903 | 934 | * Filters whether the floating links should be displayed. |
| 904 | 935 | * |
| @@ -925,8 +956,29 @@ | ||
| 925 | 956 | FrmUsageController::load_scripts(); |
| 926 | 957 | } |
| 927 | 958 | |
| 928 | 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 | + /** | |
| 929 | 981 | * Enqueue required assets for the Legacy Views editor (Views v4.x). |
| 930 | 982 | * |
| 931 | 983 | * @since 6.1.2 |
| 932 | 984 | * |
| @@ -959,9 +1011,9 @@ | ||
| 959 | 1011 | } |
| 960 | 1012 | ' |
| 961 | 1013 | ); |
| 962 | 1014 | wp_enqueue_style( 'formidable-admin' ); |
| 963 | - 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 | |
| 964 | 1016 | FrmAppHelper::localize_script( 'admin' ); |
| 965 | 1017 | self::include_info_overlay(); |
| 966 | 1018 | } |
| 967 | 1019 | |
| @@ -980,12 +1032,14 @@ | ||
| 980 | 1032 | } |
| 981 | 1033 | |
| 982 | 1034 | $popper = $wp_scripts->registered['popper']; |
| 983 | 1035 | |
| 984 | - if ( version_compare( $popper->ver, '2.0', '<' ) ) { | |
| 985 | - wp_deregister_script( 'popper' ); | |
| 986 | - self::register_popper2(); | |
| 1036 | + if ( ! version_compare( $popper->ver, '2.0', '<' ) ) { | |
| 1037 | + return; | |
| 987 | 1038 | } |
| 1039 | + | |
| 1040 | + wp_deregister_script( 'popper' ); | |
| 1041 | + self::register_popper2(); | |
| 988 | 1042 | } |
| 989 | 1043 | |
| 990 | 1044 | /** |
| 991 | 1045 | * Register Popper required for Bootstrap 5. |
| @@ -1026,9 +1080,9 @@ | ||
| 1026 | 1080 | } |
| 1027 | 1081 | |
| 1028 | 1082 | $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' ); |
| 1029 | 1083 | |
| 1030 | - if ( strpos( $page, 'formidable' ) === 0 ) { | |
| 1084 | + if ( str_starts_with( $page, 'formidable' ) ) { | |
| 1031 | 1085 | return true; |
| 1032 | 1086 | } |
| 1033 | 1087 | |
| 1034 | 1088 | return in_array( $pagenow, array( 'term.php', 'edit-tags.php' ), true ) && FrmAppHelper::simple_get( 'taxonomy' ) === 'frm_application'; |
| @@ -1150,9 +1204,9 @@ | ||
| 1150 | 1204 | $response = rest_do_request( $request ); |
| 1151 | 1205 | } |
| 1152 | 1206 | |
| 1153 | 1207 | if ( $response->is_error() ) { |
| 1154 | - // if the remove post fails, use javascript instead | |
| 1208 | + // If the remove post fails, use javascript instead | |
| 1155 | 1209 | add_action( 'admin_notices', 'FrmAppController::install_js_fallback' ); |
| 1156 | 1210 | } |
| 1157 | 1211 | } |
| 1158 | 1212 | |
| @@ -1162,14 +1216,16 @@ | ||
| 1162 | 1216 | * |
| 1163 | 1217 | * @return void |
| 1164 | 1218 | */ |
| 1165 | 1219 | private static function maybe_add_wp_site_health() { |
| 1166 | - if ( ! class_exists( 'WP_Site_Health' ) ) { | |
| 1167 | - $wp_site_health_path = ABSPATH . 'wp-admin/includes/class-wp-site-health.php'; | |
| 1220 | + if ( class_exists( 'WP_Site_Health' ) ) { | |
| 1221 | + return; | |
| 1222 | + } | |
| 1168 | 1223 | |
| 1169 | - if ( file_exists( $wp_site_health_path ) ) { | |
| 1170 | - require_once $wp_site_health_path; | |
| 1171 | - } | |
| 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; | |
| 1172 | 1228 | } |
| 1173 | 1229 | } |
| 1174 | 1230 | |
| 1175 | 1231 | /** |
| @@ -1183,9 +1239,9 @@ | ||
| 1183 | 1239 | if ( self::needs_update() ) { |
| 1184 | 1240 | $running = get_option( 'frm_install_running' ); |
| 1185 | 1241 | |
| 1186 | 1242 | if ( false === $running || $running < strtotime( '-5 minutes' ) ) { |
| 1187 | - update_option( 'frm_install_running', time(), 'no' ); | |
| 1243 | + update_option( 'frm_install_running', time(), false ); | |
| 1188 | 1244 | self::install(); |
| 1189 | 1245 | delete_option( 'frm_install_running' ); |
| 1190 | 1246 | } |
| 1191 | 1247 | } |
| @@ -1273,9 +1329,9 @@ | ||
| 1273 | 1329 | } |
| 1274 | 1330 | |
| 1275 | 1331 | /** |
| 1276 | 1332 | * The payment cron is unscheduled when Formidable is deactivated. |
| 1277 | - * 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. | |
| 1278 | 1334 | * |
| 1279 | 1335 | * @since 6.5 |
| 1280 | 1336 | * |
| 1281 | 1337 | * @return void |
| @@ -1280,9 +1336,13 @@ | ||
| 1280 | 1336 | * |
| 1281 | 1337 | * @return void |
| 1282 | 1338 | */ |
| 1283 | 1339 | private static function maybe_activate_payment_cron() { |
| 1284 | - 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 ) { | |
| 1285 | 1345 | return; |
| 1286 | 1346 | } |
| 1287 | 1347 | |
| 1288 | 1348 | FrmTransLiteAppController::maybe_schedule_cron(); |
| @@ -1293,13 +1353,9 @@ | ||
| 1293 | 1353 | * |
| 1294 | 1354 | * @return string |
| 1295 | 1355 | */ |
| 1296 | 1356 | public static function set_footer_text( $text ) { |
| 1297 | - if ( FrmAppHelper::is_formidable_admin() ) { | |
| 1298 | - $text = ''; | |
| 1299 | - } | |
| 1300 | - | |
| 1301 | - return $text; | |
| 1357 | + return FrmAppHelper::is_formidable_admin() ? '' : $text; | |
| 1302 | 1358 | } |
| 1303 | 1359 | |
| 1304 | 1360 | /** |
| 1305 | 1361 | * Add admin footer links. |
| @@ -1362,8 +1418,9 @@ | ||
| 1362 | 1418 | 'cancel_url' => '', |
| 1363 | 1419 | 'cancel_classes' => '', |
| 1364 | 1420 | 'continue_url' => '', |
| 1365 | 1421 | 'continue_classes' => '', |
| 1422 | + 'continue_target' => '', | |
| 1366 | 1423 | 'icon' => 'frm_lock_simple', |
| 1367 | 1424 | ); |
| 1368 | 1425 | |
| 1369 | 1426 | $error_args = wp_parse_args( $error_args, $defaults ); |
| @@ -1447,13 +1504,9 @@ | ||
| 1447 | 1504 | if ( ! empty( $current_screen->post_type ) && 'frm_logs' === $current_screen->post_type ) { |
| 1448 | 1505 | return true; |
| 1449 | 1506 | } |
| 1450 | 1507 | |
| 1451 | - if ( in_array( $pagenow, array( 'term.php', 'edit-tags.php' ), true ) && 'frm_application' === FrmAppHelper::simple_get( 'taxonomy' ) ) { | |
| 1452 | - return true; | |
| 1453 | - } | |
| 1454 | - | |
| 1455 | - return false; | |
| 1508 | + return in_array( $pagenow, array( 'term.php', 'edit-tags.php' ), true ) && 'frm_application' === FrmAppHelper::simple_get( 'taxonomy' ); | |
| 1456 | 1509 | } |
| 1457 | 1510 | |
| 1458 | 1511 | /** |
| 1459 | 1512 | * Handles actions related to the current screen. |
| @@ -1540,21 +1593,23 @@ | ||
| 1540 | 1593 | if ( is_array( $current_sort ) && $form_id && is_int( $form_id ) && isset( $current_sort[ $form_id ] ) ) { |
| 1541 | 1594 | $current_sort = $current_sort[ $form_id ]; |
| 1542 | 1595 | } |
| 1543 | 1596 | |
| 1544 | - if ( $new_sort !== $current_sort ) { | |
| 1545 | - $new_meta = $new_sort; | |
| 1597 | + if ( $new_sort === $current_sort ) { | |
| 1598 | + return; | |
| 1599 | + } | |
| 1546 | 1600 | |
| 1547 | - if ( $is_entry_list && $form_id && is_int( $form_id ) ) { | |
| 1548 | - // Index meta by form ID. | |
| 1549 | - $temp_meta = is_array( $previous_meta ) ? $previous_meta : array(); | |
| 1550 | - $temp_meta[ $form_id ] = $new_meta; | |
| 1551 | - $new_meta = $temp_meta; | |
| 1552 | - unset( $temp_meta ); | |
| 1553 | - } | |
| 1601 | + $new_meta = $new_sort; | |
| 1554 | 1602 | |
| 1555 | - update_user_meta( $user_id, $meta_key, $new_meta ); | |
| 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 ); | |
| 1556 | 1609 | } |
| 1610 | + | |
| 1611 | + update_user_meta( $user_id, $meta_key, $new_meta ); | |
| 1557 | 1612 | } |
| 1558 | 1613 | |
| 1559 | 1614 | /** |
| 1560 | 1615 | * Retrieve and apply any saved sorting preferences for the current screen. |
| @@ -1560,10 +1615,10 @@ | ||
| 1560 | 1615 | * Retrieve and apply any saved sorting preferences for the current screen. |
| 1561 | 1616 | * |
| 1562 | 1617 | * @since 6.19 |
| 1563 | 1618 | * |
| 1564 | - * @param string &$orderby Reference to the current 'orderby' parameter. | |
| 1565 | - * @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. | |
| 1566 | 1621 | * |
| 1567 | 1622 | * @return void |
| 1568 | 1623 | */ |
| 1569 | 1624 | public static function apply_saved_sort_preference( &$orderby, &$order ) { |
| @@ -1572,10 +1627,9 @@ | ||
| 1572 | 1627 | if ( false === $meta_key ) { |
| 1573 | 1628 | return; |
| 1574 | 1629 | } |
| 1575 | 1630 | |
| 1576 | - $user_id = get_current_user_id(); | |
| 1577 | - $preferred_list_sort = get_user_meta( $user_id, $meta_key, true ); | |
| 1631 | + $preferred_list_sort = get_user_meta( get_current_user_id(), $meta_key, true ); | |
| 1578 | 1632 | $form_id = FrmAppHelper::simple_get( 'form', 'absint' ); |
| 1579 | 1633 | |
| 1580 | 1634 | if ( is_array( $preferred_list_sort ) && $form_id && is_int( $form_id ) && isset( $preferred_list_sort[ $form_id ] ) ) { |
| 1581 | 1635 | $preferred_list_sort = $preferred_list_sort[ $form_id ]; |
| @@ -1580,14 +1634,16 @@ | ||
| 1580 | 1634 | if ( is_array( $preferred_list_sort ) && $form_id && is_int( $form_id ) && isset( $preferred_list_sort[ $form_id ] ) ) { |
| 1581 | 1635 | $preferred_list_sort = $preferred_list_sort[ $form_id ]; |
| 1582 | 1636 | } |
| 1583 | 1637 | |
| 1584 | - if ( is_array( $preferred_list_sort ) && ! empty( $preferred_list_sort['orderby'] ) ) { | |
| 1585 | - $orderby = $preferred_list_sort['orderby']; | |
| 1638 | + if ( ! is_array( $preferred_list_sort ) || empty( $preferred_list_sort['orderby'] ) ) { | |
| 1639 | + return; | |
| 1640 | + } | |
| 1586 | 1641 | |
| 1587 | - if ( ! empty( $preferred_list_sort['order'] ) ) { | |
| 1588 | - $order = $preferred_list_sort['order']; | |
| 1589 | - } | |
| 1642 | + $orderby = $preferred_list_sort['orderby']; | |
| 1643 | + | |
| 1644 | + if ( ! empty( $preferred_list_sort['order'] ) ) { | |
| 1645 | + $order = $preferred_list_sort['order']; | |
| 1590 | 1646 | } |
| 1591 | 1647 | } |
| 1592 | 1648 | |
| 1593 | 1649 | /** |
| @@ -1624,12 +1680,9 @@ | ||
| 1624 | 1680 | * |
| 1625 | 1681 | * @return bool |
| 1626 | 1682 | */ |
| 1627 | 1683 | private static function is_our_callback_array( $callback ) { |
| 1628 | - return ! empty( $callback['function'] ) && | |
| 1629 | - is_array( $callback['function'] ) && | |
| 1630 | - ! empty( $callback['function'][0] ) && | |
| 1631 | - 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 | |
| 1632 | 1685 | } |
| 1633 | 1686 | |
| 1634 | 1687 | /** |
| 1635 | 1688 | * In some cases, the DB tables may fail to install. |
| @@ -1640,10 +1693,9 @@ | ||
| 1640 | 1693 | */ |
| 1641 | 1694 | private static function add_missing_tables() { |
| 1642 | 1695 | FrmAppHelper::permission_check( 'frm_view_forms' ); |
| 1643 | 1696 | |
| 1644 | - $inbox = new FrmInbox(); | |
| 1645 | - $error = $inbox->check_for_error(); | |
| 1697 | + $error = FrmInbox::check_for_error(); | |
| 1646 | 1698 | |
| 1647 | 1699 | if ( ! $error || 'failed-to-create-tables' !== $error['key'] ) { |
| 1648 | 1700 | // Confirm the inbox item with this CTA exists. |
| 1649 | 1701 | wp_safe_redirect( admin_url( 'admin.php?page=formidable' ) ); |
| @@ -1675,6 +1727,21 @@ | ||
| 1675 | 1727 | FrmAppHelper::permission_check( 'frm_view_forms' ); |
| 1676 | 1728 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 1677 | 1729 | update_user_option( get_current_user_id(), 'frm_ignore_small_screen_warning', true ); |
| 1678 | 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' ); | |
| 1679 | 1746 | } |
| 1680 | 1747 | } |