PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.2.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.2.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/FrmFormsController.php +12 -150 6.5.36.2.2 View file →
@@ -4,18 +4,8 @@
4 4 }
5 5
6 6 class FrmFormsController {
7 7
8 - /**
9 - * Track the form that opened the redirect URL in a new tab. This is used to check if we should show the default
10 - * message in the currect tab.
11 - *
12 - * @since 6.2
13 - *
14 - * @var array Keys are form IDs and values are 1.
15 - */
16 - private static $redirected_in_new_tab = array();
17 -
18 8 public static function menu() {
19 9 $menu_label = __( 'Forms', 'formidable' );
20 10 if ( ! FrmAppHelper::pro_is_installed() ) {
21 11 $menu_label .= ' (Lite)';
@@ -397,29 +387,13 @@
397 387 add_filter( 'is_active_sidebar', '__return_false' );
398 388 FrmStylesController::enqueue_css( 'enqueue', true );
399 389
400 390 if ( false === get_template_part( 'page' ) ) {
401 - if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) {
402 - add_filter( 'body_class', 'FrmFormsController::preview_block_theme_body_classnames' );
403 - }
404 391 self::fallback_when_page_template_part_is_not_supported_by_theme();
405 392 }
406 393 }
407 394
408 395 /**
409 - * Add padding to the body for block themes.
410 - *
411 - * @since 6.5.2
412 - *
413 - * @param array $classes The body classes list.
414 - * @return array
415 - */
416 - public static function preview_block_theme_body_classnames( $classes ) {
417 - $classes[] = 'has-global-padding';
418 - return $classes;
419 - }
420 -
421 - /**
422 396 * Not every theme supports get_template_part( 'page' ).
423 397 * When this is not supported, false is returned, and we can handle a fallback.
424 398 */
425 399 private static function fallback_when_page_template_part_is_not_supported_by_theme() {
@@ -905,14 +879,14 @@
905 879 * @return array<string,string>
906 880 */
907 881 public static function get_columns( $columns ) {
908 882 $columns['cb'] = '<input type="checkbox" />';
909 - $columns['name'] = esc_html__( 'Form Title', 'formidable' );
910 - $columns['entries'] = esc_html__( 'Entries', 'formidable' );
883 + $columns['name'] = __( 'Form Title', 'formidable' );
884 + $columns['entries'] = __( 'Entries', 'formidable' );
911 885 $columns['id'] = 'ID';
912 - $columns['form_key'] = esc_html__( 'Key', 'formidable' );
913 - $columns['shortcode'] = esc_html__( 'Actions', 'formidable' );
914 - $columns['created_at'] = esc_html__( 'Date', 'formidable' );
886 + $columns['form_key'] = __( 'Key', 'formidable' );
887 + $columns['shortcode'] = __( 'Actions', 'formidable' );
888 + $columns['created_at'] = __( 'Date', 'formidable' );
915 889
916 890 add_screen_option(
917 891 'per_page',
918 892 array(
@@ -1285,21 +1259,8 @@
1285 1259 'screenshot' => 'chat.png',
1286 1260 )
1287 1261 ),
1288 1262 ),
1289 - 'abandonment' => array(
1290 - 'name' => __( 'Form Abandonment', 'formidable' ),
1291 - 'icon' => 'frm_icon_font frm_abandoned_icon',
1292 - 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1293 - 'data' => FrmAppHelper::get_upgrade_data_params(
1294 - 'abandonment',
1295 - array(
1296 - 'upgrade' => __( 'Form abandonment settings', 'formidable' ),
1297 - 'message' => __( 'Unlock the power of data capture to boost lead generation and master the art of form optimization.', 'formidable' ),
1298 - 'screenshot' => 'abandonment.png',
1299 - )
1300 - ),
1301 - ),
1302 1263 'html' => array(
1303 1264 'name' => __( 'Customize HTML', 'formidable' ),
1304 1265 'class' => __CLASS__,
1305 1266 'function' => 'html_settings',
@@ -1306,9 +1267,9 @@
1306 1267 'icon' => 'frm_icon_font frm_code_icon',
1307 1268 ),
1308 1269 );
1309 1270
1310 - foreach ( array( 'landing', 'chat', 'abandonment' ) as $feature ) {
1271 + foreach ( array( 'landing', 'chat' ) as $feature ) {
1311 1272 if ( ! FrmAppHelper::show_new_feature( $feature ) ) {
1312 1273 unset( $sections[ $feature ] );
1313 1274 }
1314 1275 }
@@ -1644,17 +1605,13 @@
1644 1605 * Replace any [form_name] shortcodes in a string.
1645 1606 *
1646 1607 * @since 5.5
1647 1608 *
1648 - * @param string|array $string
1609 + * @param string $string
1649 1610 * @param stdClass|string|int $form
1650 - * @return string|array
1611 + * @return string
1651 1612 */
1652 1613 public static function replace_form_name_shortcodes( $string, $form ) {
1653 - if ( ! is_string( $string ) ) {
1654 - return $string;
1655 - }
1656 -
1657 1614 if ( false === strpos( $string, '[form_name]' ) ) {
1658 1615 return $string;
1659 1616 }
1660 1617
@@ -2304,13 +2261,8 @@
2304 2261 if ( ! FrmOnSubmitHelper::form_has_migrated( $args['form'] ) ) {
2305 2262 return array();
2306 2263 }
2307 2264
2308 - // If a redirect action has already opened the URL in a new tab, we show the default message in the currect tab.
2309 - if ( ! empty( self::$redirected_in_new_tab[ $args['form']->id ] ) ) {
2310 - return array( FrmOnSubmitHelper::get_fallback_action_after_open_in_new_tab( $event ) );
2311 - }
2312 -
2313 2265 $entry = FrmEntry::getOne( $args['entry_id'], true );
2314 2266 $actions = FrmOnSubmitHelper::get_actions( $args['form']->id );
2315 2267 $met_actions = array();
2316 2268 $has_redirect = false;
@@ -2556,19 +2508,13 @@
2556 2508
2557 2509 $doing_ajax = FrmAppHelper::doing_ajax();
2558 2510
2559 2511 if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) { // Is AJAX submit and there is just one Redirect action runs.
2560 - echo json_encode( self::get_ajax_redirect_response_data( $args + compact( 'success_url' ) ) );
2512 + echo json_encode( array( 'redirect' => $success_url ) );
2561 2513 wp_die();
2562 2514 }
2563 2515
2564 2516 if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) ) { // Not AJAX submit, no headers sent, and there is just one Redirect action runs.
2565 - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2566 - self::print_open_in_new_tab_js_with_fallback_handler( $success_url, $args );
2567 - self::$redirected_in_new_tab[ $args['form']->id ] = 1;
2568 - return;
2569 - }
2570 -
2571 2517 wp_redirect( esc_url_raw( $success_url ) );
2572 2518 die(); // do not use wp_die or redirect fails
2573 2519 }
2574 2520
@@ -2576,63 +2522,8 @@
2576 2522 self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) );
2577 2523 }
2578 2524
2579 2525 /**
2580 - * Prints open in new tab js with fallback handler.
2581 - *
2582 - * @since 6.3.1
2583 - *
2584 - * @param string $success_url Success URL.
2585 - * @param array $args See {@see FrmFormsController::redirect_after_submit()}.
2586 - */
2587 - private static function print_open_in_new_tab_js_with_fallback_handler( $success_url, $args ) {
2588 - echo '<script>var newTab = window.open("' . esc_url_raw( $success_url ) . '", "_blank");';
2589 - echo 'if ( ! newTab ) {';
2590 -
2591 - $data = array(
2592 - 'formId' => intval( $args['form']->id ),
2593 - 'message' => self::get_redirect_fallback_message( $success_url, $args ),
2594 - );
2595 - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2596 - echo 'frmShowNewTabFallback = ' . FrmAppHelper::maybe_json_encode( $data ) . ';';
2597 - echo '}</script>';
2598 - }
2599 -
2600 - /**
2601 - * Gets response data for redirect action when AJAX submitting.
2602 - *
2603 - * @since 6.3.1
2604 - *
2605 - * @param array $args See {@see FrmFormsController::run_success_action()}.
2606 - * @return array
2607 - */
2608 - private static function get_ajax_redirect_response_data( $args ) {
2609 - $response_data = array( 'redirect' => $args['success_url'] );
2610 -
2611 - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2612 - $response_data['openInNewTab'] = 1;
2613 -
2614 - $args['message'] = FrmOnSubmitHelper::get_default_new_tab_msg();
2615 -
2616 - $args['form']->options['success_msg'] = $args['message'];
2617 - $args['form']->options['edit_msg'] = $args['message'];
2618 - if ( ! isset( $args['fields'] ) ) {
2619 - $args['fields'] = FrmField::get_all_for_form( $args['form']->id );
2620 - }
2621 -
2622 - $args['message'] = self::prepare_submit_message( $args['form'], $args['entry_id'], $args );
2623 -
2624 - ob_start();
2625 - self::show_lone_success_messsage( $args );
2626 - $response_data['content'] = ob_get_clean();
2627 -
2628 - $response_data['fallbackMsg'] = self::get_redirect_fallback_message( $args['success_url'], $args );
2629 - }
2630 -
2631 - return $response_data;
2632 - }
2633 -
2634 - /**
2635 2526 * Redirects after submitting using JS. This is used when showing message before redirecting.
2636 2527 *
2637 2528 * @since 6.0
2638 2529 *
@@ -2640,9 +2531,8 @@
2640 2531 */
2641 2532 private static function redirect_after_submit_using_js( $args ) {
2642 2533 $success_msg = FrmOnSubmitHelper::get_default_redirect_msg();
2643 2534 $redirect_msg = self::get_redirect_message( $args['success_url'], $success_msg, $args );
2644 - $success_url = esc_url_raw( $args['success_url'] );
2645 2535
2646 2536 /**
2647 2537 * Filters the delay time before redirecting when On Submit Redirect action is delayed.
2648 2538 *
@@ -2651,14 +2541,8 @@
2651 2541 * @param int $delay_time Delay time in miliseconds.
2652 2542 */
2653 2543 $delay_time = apply_filters( 'frm_redirect_delay_time', 8000 );
2654 2544
2655 - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2656 - $redirect_js = 'window.open("' . $success_url . '", "_blank")';
2657 - } else {
2658 - $redirect_js = 'window.location="' . $success_url . '";';
2659 - }
2660 -
2661 2545 add_filter( 'frm_use_wpautop', '__return_true' );
2662 2546
2663 2547 echo FrmAppHelper::maybe_kses( $redirect_msg ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2664 2548 echo '<script>';
@@ -2664,9 +2548,9 @@
2664 2548 echo '<script>';
2665 2549 if ( empty( $args['doing_ajax'] ) ) { // Not AJAX submit, delay JS until window.load.
2666 2550 echo 'window.onload=function(){';
2667 2551 }
2668 - echo 'setTimeout(function(){' . $redirect_js . '}, ' . intval( $delay_time ) . ');'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2552 + echo 'setTimeout(function(){window.location="' . esc_url_raw( $args['success_url'] ) . '";}, ' . intval( $delay_time ) . ');';
2669 2553 if ( empty( $args['doing_ajax'] ) ) {
2670 2554 echo '};';
2671 2555 }
2672 2556 echo '</script>';
@@ -2680,9 +2564,10 @@
2680 2564 * @param array $args
2681 2565 */
2682 2566 private static function get_redirect_message( $success_url, $success_msg, $args ) {
2683 2567 $redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg" role="status">' . $success_msg . '<br/>' .
2684 - self::get_redirect_fallback_message( $success_url, $args ) .
2568 + /* translators: %1$s: Start link HTML, %2$s: End link HTML */
2569 + sprintf( __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ), '<a href="' . esc_url( $success_url ) . '">', '</a>' ) .
2685 2570 '</div></div>';
2686 2571
2687 2572 $redirect_args = array(
2688 2573 'entry_id' => $args['entry_id'],
@@ -2690,31 +2575,8 @@
2690 2575 'form' => $args['form'],
2691 2576 );
2692 2577
2693 2578 return apply_filters( 'frm_redirect_msg', $redirect_msg, $redirect_args );
2694 - }
2695 -
2696 - /**
2697 - * Gets fallback message when redirecting failed.
2698 - *
2699 - * @since 6.3.1
2700 - *
2701 - * @param string $success_url Redirect URL.
2702 - * @param array $args Contains `form` object.
2703 - * @return string
2704 - */
2705 - private static function get_redirect_fallback_message( $success_url, $args ) {
2706 - $target = '';
2707 - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2708 - $target = ' target="_blank"';
2709 - }
2710 -
2711 - return sprintf(
2712 - /* translators: %1$s: Start link HTML, %2$s: End link HTML */
2713 - __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ),
2714 - '<a href="' . esc_url( $success_url ) . '"' . $target . '>',
2715 - '</a>'
2716 - );
2717 2579 }
2718 2580
2719 2581 /**
2720 2582 * Prepare to show the success message and empty form after submit