PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.7
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.7
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 +135 -177 6.3.26.7 View file →
@@ -282,9 +282,10 @@
282 282 $url = admin_url( 'admin.php?page=formidable' );
283 283 $message = 'form_duplicate_error';
284 284
285 285 if ( $form ) {
286 - $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) );
286 + $new_template = FrmAppHelper::simple_get( 'new_template' ) ? '&new_template=true' : '';
287 + $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) . $new_template );
287 288 $message = 'form_duplicated';
288 289 }
289 290
290 291 $url .= '&message=' . $message;
@@ -397,13 +398,29 @@
397 398 add_filter( 'is_active_sidebar', '__return_false' );
398 399 FrmStylesController::enqueue_css( 'enqueue', true );
399 400
400 401 if ( false === get_template_part( 'page' ) ) {
402 + if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) {
403 + add_filter( 'body_class', 'FrmFormsController::preview_block_theme_body_classnames' );
404 + }
401 405 self::fallback_when_page_template_part_is_not_supported_by_theme();
402 406 }
403 407 }
404 408
405 409 /**
410 + * Add padding to the body for block themes.
411 + *
412 + * @since 6.5.2
413 + *
414 + * @param array $classes The body classes list.
415 + * @return array
416 + */
417 + public static function preview_block_theme_body_classnames( $classes ) {
418 + $classes[] = 'has-global-padding';
419 + return $classes;
420 + }
421 +
422 + /**
406 423 * Not every theme supports get_template_part( 'page' ).
407 424 * When this is not supported, false is returned, and we can handle a fallback.
408 425 */
409 426 private static function fallback_when_page_template_part_is_not_supported_by_theme() {
@@ -680,9 +697,9 @@
680 697 self::create_default_on_submit_action( $form_id );
681 698 self::create_default_email_action( $form_id );
682 699
683 700 $response = array(
684 - 'redirect' => FrmForm::get_edit_link( $form_id ),
701 + 'redirect' => FrmForm::get_edit_link( $form_id ) . '&new_template=true',
685 702 );
686 703
687 704 echo wp_json_encode( $response );
688 705 wp_die();
@@ -688,46 +705,13 @@
688 705 wp_die();
689 706 }
690 707
691 708 /**
692 - * Create a custom template from a form
693 - *
694 - * @since 3.06
695 - */
696 - public static function build_template() {
697 - global $wpdb;
698 -
699 - FrmAppHelper::permission_check( 'frm_edit_forms' );
700 - check_ajax_referer( 'frm_ajax', 'nonce' );
701 -
702 - $form_id = FrmAppHelper::get_param( 'xml', '', 'post', 'absint' );
703 - $new_form_id = FrmForm::duplicate( $form_id, 1, true );
704 - if ( ! $new_form_id ) {
705 - $response = array(
706 - 'message' => __( 'There was an error creating a template.', 'formidable' ),
707 - );
708 - } else {
709 - $new_values = self::get_modal_values();
710 - $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $new_form_id ) );
711 - if ( $query_results ) {
712 - FrmForm::clear_form_cache();
713 - }
714 -
715 - $response = array(
716 - 'redirect' => admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . $new_form_id ) . '&_wpnonce=' . wp_create_nonce(),
717 - );
718 - }
719 -
720 - echo wp_json_encode( $response );
721 - wp_die();
722 - }
723 -
724 - /**
725 709 * Before creating a new form, get the name and description from the modal.
726 710 *
727 711 * @since 4.0
728 712 */
729 - private static function get_modal_values() {
713 + public static function get_modal_values() {
730 714 $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' );
731 715 $desc = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' );
732 716
733 717 return array(
@@ -889,14 +873,14 @@
889 873 * @return array<string,string>
890 874 */
891 875 public static function get_columns( $columns ) {
892 876 $columns['cb'] = '<input type="checkbox" />';
893 - $columns['name'] = __( 'Form Title', 'formidable' );
894 - $columns['entries'] = __( 'Entries', 'formidable' );
877 + $columns['name'] = esc_html__( 'Form Title', 'formidable' );
878 + $columns['entries'] = esc_html__( 'Entries', 'formidable' );
895 879 $columns['id'] = 'ID';
896 - $columns['form_key'] = __( 'Key', 'formidable' );
897 - $columns['shortcode'] = __( 'Actions', 'formidable' );
898 - $columns['created_at'] = __( 'Date', 'formidable' );
880 + $columns['form_key'] = esc_html__( 'Key', 'formidable' );
881 + $columns['shortcode'] = esc_html__( 'Actions', 'formidable' );
882 + $columns['created_at'] = esc_html__( 'Date', 'formidable' );
899 883
900 884 add_screen_option(
901 885 'per_page',
902 886 array(
@@ -950,147 +934,43 @@
950 934
951 935 return $save;
952 936 }
953 937
954 - /**
955 - * @return bool
956 - */
957 - public static function expired() {
958 - global $frm_expired;
959 - return $frm_expired;
960 - }
938 + private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
939 + global $frm_vars;
961 940
962 - /**
963 - * Get data from api before rendering it so that we can flag the modal as expired
964 - *
965 - * @return void
966 - */
967 - public static function before_list_templates() {
968 - global $frm_templates;
969 - global $frm_expired;
970 - global $frm_license_type;
971 -
972 - $api = new FrmFormTemplateApi();
973 - $frm_templates = $api->get_api_info();
974 - $expired = false;
975 - $license_type = '';
976 - if ( isset( $frm_templates['error'] ) ) {
977 - $error = $frm_templates['error']['message'];
978 - $error = str_replace( 'utm_medium=addons', 'utm_medium=form-templates', $error );
979 - $expired = 'expired' === $frm_templates['error']['code'];
980 - $license_type = isset( $frm_templates['error']['type'] ) ? $frm_templates['error']['type'] : '';
981 - unset( $frm_templates['error'] );
982 - }
983 -
984 - $frm_expired = $expired;
985 - $frm_license_type = $license_type;
986 - }
987 -
988 - /**
989 - * @return void
990 - */
991 - public static function list_templates() {
992 - global $frm_templates;
993 - global $frm_license_type;
994 -
995 - $templates = $frm_templates;
996 - $custom_templates = array();
997 - $templates_by_category = array();
998 -
999 - self::add_user_templates( $custom_templates );
1000 -
1001 - foreach ( $templates as $template ) {
1002 - if ( ! isset( $template['categories'] ) ) {
1003 - continue;
1004 - }
1005 -
1006 - foreach ( $template['categories'] as $category ) {
1007 - if ( ! isset( $templates_by_category[ $category ] ) ) {
1008 - $templates_by_category[ $category ] = array();
1009 - }
1010 -
1011 - $templates_by_category[ $category ][] = $template;
1012 - }
1013 - }
1014 - unset( $template );
1015 -
1016 - // Subcategories that are included elsewhere.
1017 - $redundant_cats = array( 'PayPal', 'Stripe', 'Twilio' );
1018 -
1019 - $categories = array_keys( $templates_by_category );
1020 - $categories = array_diff( $categories, FrmFormsHelper::ignore_template_categories() );
1021 - $categories = array_diff( $categories, $redundant_cats );
1022 - sort( $categories );
1023 -
1024 - array_walk(
1025 - $custom_templates,
1026 - function( &$template ) {
1027 - $template['custom'] = true;
1028 - }
941 + $form = FrmForm::getOne( $id );
942 + $error_args = array(
943 + 'title' => __( 'You can\'t edit the form', 'formidable' ),
944 + 'body' => __( 'You are trying to edit a form that does not exist', 'formidable' ),
945 + 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
946 + 'continue_url' => add_query_arg(
947 + array(
948 + 'page' => 'formidable',
949 + )
950 + ),
1029 951 );
1030 -
1031 - $my_templates_translation = __( 'My Templates', 'formidable' );
1032 - $categories = array_merge( array( $my_templates_translation ), $categories );
1033 - $pricing = FrmAppHelper::admin_upgrade_link( 'form-templates' );
1034 - $license_type = $frm_license_type;
1035 - $args = compact( 'pricing', 'license_type' );
1036 - $where = apply_filters( 'frm_forms_dropdown', array(), '' );
1037 - $forms = FrmForm::get_published_forms( $where );
1038 - $view_path = FrmAppHelper::plugin_path() . '/classes/views/frm-forms/';
1039 -
1040 - $templates_by_category[ $my_templates_translation ] = $custom_templates;
1041 -
1042 - unset( $pricing, $license_type, $where );
1043 - wp_enqueue_script( 'accordion' ); // register accordion for template groups
1044 - require $view_path . 'list-templates.php';
1045 - }
1046 -
1047 - /**
1048 - * @since 4.03.01
1049 - */
1050 - private static function get_template_categories( $templates ) {
1051 - $categories = array();
1052 - foreach ( $templates as $template ) {
1053 - if ( isset( $template['categories'] ) ) {
1054 - $categories = array_merge( $categories, $template['categories'] );
1055 - }
952 + if ( ! $form ) {
953 + FrmAppController::show_error_modal( $error_args );
954 + return;
1056 955 }
1057 - $exclude_cats = FrmFormsHelper::ignore_template_categories();
1058 - $categories = array_unique( $categories );
1059 - $categories = array_diff( $categories, $exclude_cats );
1060 - sort( $categories );
1061 - return $categories;
1062 - }
1063 956
1064 - private static function add_user_templates( &$templates ) {
1065 - $user_templates = array(
1066 - 'is_template' => 1,
1067 - 'default_template' => 0,
1068 - );
1069 - $user_templates = FrmForm::getAll( $user_templates, 'name' );
1070 - foreach ( $user_templates as $template ) {
1071 - $template = array(
1072 - 'id' => $template->id,
1073 - 'name' => $template->name,
1074 - 'key' => $template->form_key,
1075 - 'description' => $template->description,
1076 - 'url' => wp_nonce_url( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template->id ) ) ),
1077 - 'released' => $template->created_at,
1078 - 'installed' => 1,
957 + if ( 'trash' === $form->status ) {
958 + $error_args['body'] = __( 'The form you\'re trying to edit is in trash. You must restore it first before you can make changes', 'formidable' );
959 + $error_args['continue_url'] = add_query_arg(
960 + array(
961 + 'page' => 'formidable',
962 + '_wpnonce' => wp_create_nonce( 'untrash_form_' . $id ),
963 + 'form_type' => 'trash',
964 + 'frm_action' => 'untrash',
965 + 'id' => $id,
966 + )
1079 967 );
1080 - array_unshift( $templates, $template );
1081 - unset( $template );
968 + $error_args['continue_text'] = __( 'Restore form', 'formidable' );
969 + FrmAppController::show_error_modal( $error_args );
970 + return;
1082 971 }
1083 - }
1084 972
1085 - private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
1086 - global $frm_vars;
1087 -
1088 - $form = FrmForm::getOne( $id );
1089 - if ( ! $form ) {
1090 - wp_die( esc_html__( 'You are trying to edit a form that does not exist.', 'formidable' ) );
1091 - }
1092 -
1093 973 if ( $form->parent_form_id ) {
1094 974 /* translators: %1$s: Start link HTML, %2$s: End link HTML */
1095 975 wp_die( sprintf( esc_html__( 'You are trying to edit a child form. Please edit from %1$shere%2$s', 'formidable' ), '<a href="' . esc_url( FrmForm::get_edit_link( $form->parent_form_id ) ) . '">', '</a>' ) );
1096 976 }
@@ -1269,8 +1149,21 @@
1269 1149 'screenshot' => 'chat.png',
1270 1150 )
1271 1151 ),
1272 1152 ),
1153 + 'abandonment' => array(
1154 + 'name' => __( 'Form Abandonment', 'formidable' ),
1155 + 'icon' => 'frm_icon_font frm_abandoned_icon',
1156 + 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1157 + 'data' => FrmAppHelper::get_upgrade_data_params(
1158 + 'abandonment',
1159 + array(
1160 + 'upgrade' => __( 'Form abandonment settings', 'formidable' ),
1161 + 'message' => __( 'Unlock the power of data capture to boost lead generation and master the art of form optimization.', 'formidable' ),
1162 + 'screenshot' => 'abandonment.png',
1163 + )
1164 + ),
1165 + ),
1273 1166 'html' => array(
1274 1167 'name' => __( 'Customize HTML', 'formidable' ),
1275 1168 'class' => __CLASS__,
1276 1169 'function' => 'html_settings',
@@ -1277,9 +1170,9 @@
1277 1170 'icon' => 'frm_icon_font frm_code_icon',
1278 1171 ),
1279 1172 );
1280 1173
1281 - foreach ( array( 'landing', 'chat' ) as $feature ) {
1174 + foreach ( array( 'landing', 'chat', 'abandonment' ) as $feature ) {
1282 1175 if ( ! FrmAppHelper::show_new_feature( $feature ) ) {
1283 1176 unset( $sections[ $feature ] );
1284 1177 }
1285 1178 }
@@ -1791,8 +1684,33 @@
1791 1684 return;
1792 1685 }
1793 1686 }
1794 1687
1688 + /**
1689 + * Rename a form.
1690 + *
1691 + * Handles the AJAX request for renaming a form.
1692 + *
1693 + * @since 6.7
1694 + *
1695 + * @return void
1696 + */
1697 + public static function rename_form() {
1698 + // Check permission and nonce
1699 + FrmAppHelper::permission_check( 'frm_edit_forms' );
1700 + check_ajax_referer( 'frm_ajax', 'nonce' );
1701 +
1702 + // Get posted data
1703 + $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
1704 + $name = FrmAppHelper::get_post_param( 'form_name', '', 'sanitize_text_field' );
1705 +
1706 + // Update the form name and form key.
1707 + $form_key = FrmAppHelper::get_unique_key( sanitize_title( $name ), 'frm_forms', 'form_key' );
1708 + FrmForm::update( $form_id, compact( 'name', 'form_key' ) );
1709 +
1710 + wp_send_json_success( compact( 'form_key' ) );
1711 + }
1712 +
1795 1713 public static function json_error( $errors ) {
1796 1714 $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
1797 1715
1798 1716 return $errors;
@@ -2549,9 +2467,9 @@
2549 2467
2550 2468 /**
2551 2469 * Prints open in new tab js with fallback handler.
2552 2470 *
2553 - * @since 6.x
2471 + * @since 6.3.1
2554 2472 *
2555 2473 * @param string $success_url Success URL.
2556 2474 * @param array $args See {@see FrmFormsController::redirect_after_submit()}.
2557 2475 */
@@ -2570,9 +2488,9 @@
2570 2488
2571 2489 /**
2572 2490 * Gets response data for redirect action when AJAX submitting.
2573 2491 *
2574 - * @since 6.x
2492 + * @since 6.3.1
2575 2493 *
2576 2494 * @param array $args See {@see FrmFormsController::run_success_action()}.
2577 2495 * @return array
2578 2496 */
@@ -2666,9 +2584,9 @@
2666 2584
2667 2585 /**
2668 2586 * Gets fallback message when redirecting failed.
2669 2587 *
2670 - * @since 6.x
2588 + * @since 6.3.1
2671 2589 *
2672 2590 * @param string $success_url Redirect URL.
2673 2591 * @param array $args Contains `form` object.
2674 2592 * @return string
@@ -3121,6 +3039,46 @@
3121 3039 * @since 3.06
3122 3040 */
3123 3041 public static function add_new() {
3124 3042 _deprecated_function( __FUNCTION__, '4.08' );
3043 + }
3044 +
3045 + /**
3046 + * Create a custom template from a form
3047 + *
3048 + * @since 3.06
3049 + * @deprecated x.x
3050 + */
3051 + public static function build_template() {
3052 + _deprecated_function( __METHOD__, 'x.x' );
3053 + }
3054 +
3055 + /**
3056 + * @deprecated x.x
3057 + *
3058 + * @return bool
3059 + */
3060 + public static function expired() {
3061 + _deprecated_function( __METHOD__, 'x.x' );
3062 + return FrmAddonsController::is_license_expired();
3063 + }
3064 +
3065 + /**
3066 + * Get data from api before rendering it so that we can flag the modal as expired
3067 + *
3068 + * @deprecated x.x
3069 + *
3070 + * @return void
3071 + */
3072 + public static function before_list_templates() {
3073 + _deprecated_function( __METHOD__, 'x.x' );
3074 + }
3075 +
3076 + /**
3077 + * @deprecated x.x
3078 + *
3079 + * @return void
3080 + */
3081 + public static function list_templates() {
3082 + _deprecated_function( __METHOD__, 'x.x' );
3125 3083 }
3126 3084 }