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/FrmFormsController.php +457 -245 6.26 → trunk View file →
@@ -30,8 +30,9 @@
30 30
31 31 if ( ! FrmAppHelper::pro_is_installed() ) {
32 32 $menu_label .= ' (Lite)';
33 33 }
34 +
34 35 add_submenu_page( 'formidable', 'Formidable | ' . $menu_label, $menu_label, 'frm_view_forms', 'formidable', 'FrmFormsController::route' );
35 36
36 37 self::maybe_load_listing_hooks();
37 38 }
@@ -46,8 +47,15 @@
46 47 add_filter( 'manage_toplevel_page_formidable_columns', 'FrmFormsController::get_columns', 0 );
47 48 add_filter( 'manage_toplevel_page_formidable_sortable_columns', 'FrmFormsController::get_sortable_columns' );
48 49 }
49 50
51 + /**
52 + * Runs on admin head of the formidable forms page.
53 + *
54 + * @since 6.32 This adds screen options.
55 + *
56 + * @return void
57 + */
50 58 public static function head() {
51 59 if ( wp_is_mobile() ) {
52 60 wp_enqueue_script( 'jquery-touch-punch' );
53 61 }
@@ -65,10 +73,10 @@
65 73 */
66 74 public static function logic_tip() {
67 75 $images_url = FrmAppHelper::plugin_url() . '/images/';
68 76 $data_message = __( 'Only show the fields you need and create branching forms. Upgrade to get conditional logic and question branching.', 'formidable' );
69 - $data_message .= ' <img src="' . esc_url( $images_url ) . '/survey-logic.png" srcset="' . esc_url( $images_url ) . '[email protected] 2x" alt="' . esc_attr__( 'Conditional Logic options', 'formidable' ) . '"/>';
70 - echo '<a href="javascript:void(0)" class="frm_noallow frm_show_upgrade frm_add_logic_link frm-collapsed frm-flex-justify" data-upgrade="' . esc_attr__( 'Conditional Logic options', 'formidable' ) . '" data-message="' . esc_attr( $data_message ) . '" data-medium="builder" data-content="logic">';
77 + $data_message .= ' <img src="' . esc_url( $images_url ) . '/survey-logic.png" srcset="' . esc_url( $images_url ) . '[email protected] 2x" alt="' . esc_attr__( 'Conditional Logic options', 'formidable' ) . '"/>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
78 + echo '<a href="javascript:void(0)" class="frm_noallow frm_show_upgrade frm_add_logic_link frm-collapsed frm-flex-justify" data-upgrade="' . esc_attr__( 'Conditional Logic options', 'formidable' ) . '" data-message="' . esc_attr( $data_message ) . '" data-medium="builder" data-content="logic">'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
71 79 esc_html_e( 'Conditional Logic', 'formidable' );
72 80 FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown8_icon', array( 'aria-hidden' => 'true' ) );
73 81 echo '</a>';
74 82 }
@@ -84,9 +92,8 @@
84 92 * @return array
85 93 */
86 94 public static function prevent_divi_conflict( $shortcodes ) {
87 95 $shortcodes[] = 'formidable';
88 -
89 96 return $shortcodes;
90 97 }
91 98
92 99 /**
@@ -126,15 +133,17 @@
126 133 }
127 134
128 135 $create_email = apply_filters( 'frm_create_default_email_action', true, $form );
129 136
130 - if ( $create_email ) {
131 - /**
132 - * @var FrmFormAction
133 - */
134 - $action_control = FrmFormActionsController::get_form_actions( 'email' );
135 - $action_control->create( $form->id );
137 + if ( ! $create_email ) {
138 + return;
136 139 }
140 +
141 + /**
142 + * @var FrmFormAction
143 + */
144 + $action_control = FrmFormActionsController::get_form_actions( 'email' );
145 + $action_control->create( $form->id );
137 146 }
138 147
139 148 /**
140 149 * Create the default On submit action
@@ -161,15 +170,17 @@
161 170 * @param object $form Form object.
162 171 */
163 172 $create = apply_filters( 'frm_create_default_on_submit_action', true, $form );
164 173
165 - if ( $create ) {
166 - /**
167 - * @var FrmFormAction
168 - */
169 - $action_control = FrmFormActionsController::get_form_actions( FrmOnSubmitAction::$slug );
170 - $action_control->create( $form->id );
174 + if ( ! $create ) {
175 + return;
171 176 }
177 +
178 + /**
179 + * @var FrmFormAction
180 + */
181 + $action_control = FrmFormActionsController::get_form_actions( FrmOnSubmitAction::$slug );
182 + $action_control->create( $form->id );
172 183 }
173 184
174 185 /**
175 186 * Creates submit button field.
@@ -251,10 +262,9 @@
251 262 FrmAppController::show_error_modal( $error_args );
252 263 return;
253 264 }
254 265
255 - $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
256 -
266 + $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
257 267 $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
258 268 $warnings = FrmFormsHelper::check_for_warnings( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
259 269
260 270 if ( count( $errors ) > 0 ) {
@@ -263,9 +273,9 @@
263 273 }
264 274
265 275 do_action( 'frm_before_update_form_settings', $id );
266 276
267 - $antispam_was_on = self::antispam_was_on( $id );
277 + $antispam_was_on = self::antispam_was_on( $id ); // phpcs:ignore Formidable.CodeAnalysis.InlineSingleUseVariable
268 278
269 279 FrmForm::update( $id, $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
270 280
271 281 $antispam_is_on = ! empty( $_POST['options']['antispam'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
@@ -273,8 +283,12 @@
273 283 if ( $antispam_is_on !== $antispam_was_on ) {
274 284 FrmAntiSpam::clear_caches();
275 285 }
276 286
287 + // Handle captcha field inclusion
288 + $include_captcha = isset( $_POST['frm_include_captcha'] ) && '1' === $_POST['frm_include_captcha']; // phpcs:ignore WordPress.Security.NonceVerification.Missing
289 + self::handle_captcha_field( $id, $include_captcha );
290 +
277 291 $message = __( 'Settings Successfully Updated', 'formidable' );
278 292
279 293 self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) );
280 294 }
@@ -289,14 +303,52 @@
289 303 return ! empty( $form->options['antispam'] );
290 304 }
291 305
292 306 /**
307 + * Handle captcha field inclusion in form
308 + *
309 + * @since 6.33
310 + *
311 + * @param int $form_id Form ID.
312 + * @param bool $include_captcha Whether to include captcha field.
313 + *
314 + * @return void
315 + */
316 + private static function handle_captcha_field( $form_id, $include_captcha ) {
317 + $form_fields = FrmField::get_all_for_form( $form_id, '', 'exclude' );
318 + $captcha_field_id = 0;
319 + $submit_field_order = 0;
320 +
321 + foreach ( $form_fields as $field ) {
322 + if ( 'captcha' === $field->type ) {
323 + $captcha_field_id = $field->id;
324 + break;
325 + }
326 +
327 + if ( 'submit' === $field->type ) {
328 + $submit_field_order = $field->field_order;
329 + }
330 + }
331 +
332 + if ( $include_captcha && ! $captcha_field_id ) {
333 + // Create captcha field just before submit button
334 + $field_values = FrmFieldsHelper::setup_new_vars( 'captcha', $form_id );
335 + $field_values['name'] = __( 'Captcha', 'formidable' );
336 + $field_values['field_order'] = $submit_field_order > 0 ? $submit_field_order - 1 : 0;
337 + FrmField::create( $field_values );
338 + } elseif ( ! $include_captcha && $captcha_field_id ) {
339 + // Delete captcha field
340 + FrmField::destroy( $captcha_field_id );
341 + }
342 + }
343 +
344 + /**
293 345 * @param array $values
294 346 *
295 347 * @return void
296 348 */
297 349 public static function update( $values = array() ) {
298 - if ( empty( $values ) ) {
350 + if ( ! $values ) {
299 351 $values = $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing
300 352 }
301 353
302 354 // Set radio button and checkbox meta equal to "other" value.
@@ -567,14 +619,16 @@
567 619 add_action( 'loop_no_results', 'FrmFormsController::show_page_preview' );
568 620 add_filter( 'is_active_sidebar', '__return_false' );
569 621 FrmStylesController::enqueue_css( 'enqueue', true );
570 622
571 - if ( false === get_template_part( 'page' ) ) {
572 - if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) {
573 - add_filter( 'body_class', 'FrmFormsController::preview_block_theme_body_classnames' );
574 - }
575 - self::fallback_when_page_template_part_is_not_supported_by_theme();
623 + if ( false !== get_template_part( 'page' ) ) {
624 + return;
576 625 }
626 +
627 + if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) {
628 + add_filter( 'body_class', 'FrmFormsController::preview_block_theme_body_classnames' );
629 + }
630 + self::fallback_when_page_template_part_is_not_supported_by_theme();
577 631 }
578 632
579 633 /**
580 634 * Add padding to the body for block themes.
@@ -596,25 +650,27 @@
596 650 *
597 651 * @return void
598 652 */
599 653 private static function fallback_when_page_template_part_is_not_supported_by_theme() {
600 - if ( have_posts() ) {
601 - the_post();
602 - self::get_template( 'header' );
654 + if ( ! have_posts() ) {
655 + return;
656 + }
603 657
604 - // add some generic class names to the container to add some natural padding to the content.
605 - // .entry-content catches the WordPress TwentyTwenty theme.
606 - // .container catches Customizr content.
607 - echo '<div class="container entry-content">';
608 - the_content();
609 - echo '</div>';
658 + the_post();
659 + self::get_template( 'header' );
610 660
611 - // Prevent extra unexpected forms in the footer.
612 - // For some reason this happens in the Twenty Twenty Five theme.
613 - add_filter( 'frm_filter_final_form', '__return_empty_string' );
661 + // Add some generic class names to the container to add some natural padding to the content.
662 + // .entry-content catches the WordPress TwentyTwenty theme.
663 + // .container catches Customizr content.
664 + echo '<div class="container entry-content">';
665 + the_content();
666 + echo '</div>';
614 667
615 - self::get_template( 'footer' );
616 - }
668 + // Prevent extra unexpected forms in the footer.
669 + // For some reason this happens in the Twenty Twenty Five theme.
670 + add_filter( 'frm_filter_final_form', '__return_empty_string' );
671 +
672 + self::get_template( 'footer' );
617 673 }
618 674
619 675 /**
620 676 * Calls core function to get a template part if it doesn't cause deprecation warnings. Otherwise skips the deprecation function call
@@ -669,13 +725,9 @@
669 725 *
670 726 * @return string
671 727 */
672 728 public static function preview_page_title( $title ) {
673 - if ( in_the_loop() ) {
674 - $title = self::preview_title( $title );
675 - }
676 -
677 - return $title;
729 + return in_the_loop() ? self::preview_title( $title ) : $title;
678 730 }
679 731
680 732 /**
681 733 * Set the page title for the theme preview page.
@@ -714,8 +766,9 @@
714 766 */
715 767 private static function load_direct_preview() {
716 768 $key = FrmAppHelper::simple_get( 'form', 'sanitize_title' );
717 769
770 + // phpcs:ignore Universal.Operators.StrictComparisons
718 771 if ( $key == '' ) {
719 772 $key = FrmAppHelper::get_post_param( 'form', '', 'sanitize_title' );
720 773 }
721 774
@@ -760,16 +813,18 @@
760 813 *
761 814 * @return void
762 815 */
763 816 public static function maybe_block_preview( $form_key ) {
764 - if ( FrmFormsHelper::should_block_preview( $form_key ) ) {
765 - $error = __( 'You do not have permission to view this form', 'formidable' );
766 - wp_die(
767 - '<h1>' . esc_html( $error ) . '</h1>',
768 - '<p>' . esc_html( $error ) . '</p>',
769 - 403
770 - );
817 + if ( ! FrmFormsHelper::should_block_preview( $form_key ) ) {
818 + return;
771 819 }
820 +
821 + $error = __( 'You do not have permission to view this form', 'formidable' );
822 + wp_die(
823 + '<h1>' . esc_html( $error ) . '</h1>',
824 + '<p>' . esc_html( $error ) . '</p>',
825 + 403
826 + );
772 827 }
773 828
774 829 /**
775 830 * Some themes have a null $src value.
@@ -788,12 +843,9 @@
788 843 *
789 844 * @return string
790 845 */
791 846 function ( $src ) {
792 - if ( is_null( $src ) ) {
793 - $src = '';
794 - }
795 - return $src;
847 + return is_null( $src ) ? '' : $src;
796 848 }
797 849 );
798 850 }
799 851
@@ -816,11 +868,9 @@
816 868 return '';
817 869 }
818 870
819 871 /* translators: %1$s: Number of forms */
820 - $message = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
821 -
822 - return $message;
872 + return sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
823 873 }
824 874
825 875 /**
826 876 * @since 3.06
@@ -881,9 +931,9 @@
881 931 /* translators: %1$s: Number of forms */
882 932 $available_status['untrash']['message'] = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
883 933
884 934 /* translators: %1$s: Number of forms, %2$s: Start link HTML, %3$s: End link HTML */
885 - $available_status['trash']['message'] = sprintf( _n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), $count, '<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=untrash&form_type=' . $form_type . '&id=' . $params['id'], 'untrash_form_' . $params['id'] ) ) . '">', '</a>' );
935 + $available_status['trash']['message'] = sprintf( _n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), $count, '<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=untrash&form_type=' . $form_type . '&id=' . $params['id'], 'untrash_form_' . $params['id'] ) ) . '">', '</a>' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
886 936
887 937 $message = $available_status[ $status ]['message'];
888 938
889 939 self::display_forms_list( $params, $message );
@@ -914,17 +964,16 @@
914 964 'param' => 'form_type',
915 965 'type' => 'request',
916 966 )
917 967 );
918 - $message = sprintf(
968 +
969 + return sprintf(
919 970 /* translators: %1$s: Number of forms, %2$s: Start link HTML, %3$s: End link HTML */
920 971 _n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ),
921 972 $count,
922 - '<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=list&action=bulk_untrash&form_type=' . $current_page . '&item-action=' . implode( ',', $ids ), 'bulk-toplevel_page_formidable' ) ) . '">',
973 + '<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=list&action=bulk_untrash&form_type=' . $current_page . '&item-action=' . implode( ',', $ids ), 'bulk-toplevel_page_formidable' ) ) . '">', // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
923 974 '</a>'
924 975 );
925 -
926 - return $message;
927 976 }
928 977
929 978 public static function destroy() {
930 979 FrmAppHelper::permission_check( 'frm_delete_forms' );
@@ -980,17 +1029,15 @@
980 1029 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' );
981 1030
982 1031 if ( $permission_error !== false ) {
983 1032 self::display_forms_list( array(), '', array( $permission_error ) );
984 -
985 1033 return;
986 1034 }
987 1035
988 1036 $count = FrmForm::scheduled_delete( time() );
989 1037 $url = remove_query_arg( array( 'delete_all' ) );
1038 + $url .= '&message=forms_permanently_deleted&forms_deleted=' . $count;
990 1039
991 - $url .= '&message=forms_permanently_deleted&forms_deleted=' . $count;
992 -
993 1040 wp_safe_redirect( $url );
994 1041 die();
995 1042 }
996 1043
@@ -1064,21 +1111,22 @@
1064 1111 *
1065 1112 * @return void
1066 1113 */
1067 1114 public static function insert_form_button() {
1068 - if ( current_user_can( 'frm_view_forms' ) ) {
1069 - // Store the result in memory and re-use it when this function is called multiple times.
1070 - // This helps speed up the form builder when there are a lot of HTML fields, where this
1071 - // button is inserted once per HTML field.
1072 - // In a form with 66 HTML fields, this saves 0.5 seconds on page load time, tested locally.
1073 - if ( ! isset( self::$formidable_tinymce_button ) ) {
1074 - FrmAppHelper::load_admin_wide_js();
1075 - $menu_name = FrmAppHelper::get_menu_name();
1076 - $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() );
1077 - self::$formidable_tinymce_button = '<a href="#TB_inline?width=50&height=50&inlineId=frm_insert_form" class="thickbox button add_media frm_insert_form" title="' . esc_attr__( 'Add forms and content', 'formidable' ) . '">' . FrmAppHelper::kses( $icon, 'all' ) . ' ' . esc_html( $menu_name ) . '</a>';
1078 - }
1079 - echo self::$formidable_tinymce_button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1115 + if ( ! current_user_can( 'frm_view_forms' ) ) {
1116 + return;
1080 1117 }
1118 +
1119 + // Store the result in memory and re-use it when this function is called multiple times.
1120 + // This helps speed up the form builder when there are a lot of HTML fields, where this
1121 + // Button is inserted once per HTML field.
1122 + // In a form with 66 HTML fields, this saves 0.5 seconds on page load time, tested locally.
1123 + if ( ! isset( self::$formidable_tinymce_button ) ) {
1124 + FrmAppHelper::load_admin_wide_js();
1125 + $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() );
1126 + self::$formidable_tinymce_button = '<a href="#TB_inline?width=50&height=50&inlineId=frm_insert_form" class="thickbox button add_media frm_insert_form" title="' . esc_attr__( 'Add forms and content', 'formidable' ) . '">' . FrmAppHelper::kses( $icon, 'all' ) . ' ' . esc_html( FrmAppHelper::get_menu_name() ) . '</a>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
1127 + }
1128 + echo self::$formidable_tinymce_button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1081 1129 }
1082 1130
1083 1131 /**
1084 1132 * @return void
@@ -1099,17 +1147,21 @@
1099 1147 $shortcodes = apply_filters( 'frm_popup_shortcodes', $shortcodes );
1100 1148
1101 1149 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/insert_form_popup.php';
1102 1150
1103 - if ( FrmAppHelper::is_form_builder_page() && ! class_exists( '_WP_Editors', false ) ) {
1104 - // initialize a wysiwyg so we have usable settings defined in tinyMCEPreInit.mceInit
1105 - require ABSPATH . WPINC . '/class-wp-editor.php';
1106 - ?>
1107 - <div class="frm_hidden">
1108 - <?php wp_editor( '', 'frm_description_placeholder', array() ); ?>
1109 - </div>
1110 - <?php
1151 + if ( ! FrmAppHelper::is_form_builder_page() || class_exists( '_WP_Editors', false ) ) {
1152 + return;
1111 1153 }
1154 +
1155 + // Initialize a wysiwyg so we have usable settings defined in tinyMCEPreInit.mceInit
1156 + require ABSPATH . WPINC . '/class-wp-editor.php';
1157 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
1158 + ?>
1159 + <div class="frm_hidden">
1160 + <?php wp_editor( '', 'frm_description_placeholder', array() ); ?>
1161 + </div>
1162 + <?php
1163 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
1112 1164 }
1113 1165
1114 1166 /**
1115 1167 * Check the page being loaded, determine if this is a page that should include the form popup.
@@ -1132,9 +1184,9 @@
1132 1184 check_ajax_referer( 'frm_ajax', 'nonce' );
1133 1185
1134 1186 $shortcode = FrmAppHelper::get_post_param( 'shortcode', '', 'sanitize_text_field' );
1135 1187
1136 - if ( empty( $shortcode ) ) {
1188 + if ( ! $shortcode ) {
1137 1189 wp_die();
1138 1190 }
1139 1191
1140 1192 echo '<div id="sc-opts-' . esc_attr( $shortcode ) . '" class="frm_shortcode_option">';
@@ -1163,9 +1215,9 @@
1163 1215
1164 1216 $opts = apply_filters( 'frm_sc_popup_opts', $opts, $shortcode );
1165 1217
1166 1218 if ( isset( $opts['form_id'] ) && is_string( $opts['form_id'] ) ) {
1167 - // allow other shortcodes to use the required form id option
1219 + // Allow other shortcodes to use the required form id option
1168 1220 $form_id = $opts['form_id'];
1169 1221 unset( $opts['form_id'] );
1170 1222 }
1171 1223
@@ -1200,22 +1252,20 @@
1200 1252 * @param string $table_class Class name for List Helper.
1201 1253 */
1202 1254 $table_class = apply_filters( 'frm_forms_list_class', 'FrmFormsListHelper' );
1203 1255 $wp_list_table = new $table_class( compact( 'params' ) );
1256 + $pagenum = $wp_list_table->get_pagenum();
1204 1257
1205 - $pagenum = $wp_list_table->get_pagenum();
1206 -
1207 1258 $wp_list_table->prepare_items();
1208 1259
1209 1260 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
1210 1261
1211 1262 if ( $pagenum > $total_pages && $total_pages > 0 ) {
1212 - wp_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) );
1263 + wp_safe_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) );
1213 1264 die();
1214 1265 }
1215 1266
1216 - $inbox = new FrmInbox();
1217 - $error = $inbox->check_for_error();
1267 + $error = FrmInbox::check_for_error();
1218 1268
1219 1269 if ( $error ) {
1220 1270 $show_messages = array( $error['subject'] . '. ' . $error['message'] );
1221 1271 }
@@ -1231,16 +1281,27 @@
1231 1281 public static function get_columns( $columns ) {
1232 1282 $columns['cb'] = '<input type="checkbox" />';
1233 1283 $columns['name'] = esc_html__( 'Form Title', 'formidable' );
1234 1284 $columns['entries'] = esc_html__( 'Entries', 'formidable' );
1285 + $columns['views'] = esc_html__( 'Views', 'formidable' );
1235 1286 $columns['id'] = 'ID';
1236 1287 $columns['form_key'] = esc_html__( 'Key', 'formidable' );
1237 1288
1238 - if ( 'trash' !== FrmAppHelper::simple_get( 'form_type' ) ) {
1289 + if ( 'trash' !== FrmAppHelper::simple_get( 'form_type' ) && has_filter( 'frm_form_list_actions' ) ) {
1290 + // If there is any filters added, keep this column.
1239 1291 $columns['shortcode'] = esc_html__( 'Actions', 'formidable' );
1240 1292 }
1293 +
1241 1294 $columns['created_at'] = esc_html__( 'Date', 'formidable' );
1242 1295
1296 + if ( 'trash' !== FrmAppHelper::simple_get( 'form_type' ) ) {
1297 + $columns['embeds'] = esc_html__( 'Embeds', 'formidable' );
1298 + $columns['settings'] = '<div class="frm-forms-list-settings-btn-wrapper"><a href="#" class="frm-forms-list-settings-btn">';
1299 + $columns['settings'] .= FrmAppHelper::icon_by_class( 'frmfont frm_settings_icon', array( 'echo' => false ) );
1300 + $columns['settings'] .= '<span class="screen-reader-text">' . esc_html__( 'List settings', 'formidable' ) . '</span>';
1301 + $columns['settings'] .= '</a></div>';
1302 + }
1303 +
1243 1304 add_screen_option(
1244 1305 'per_page',
1245 1306 array(
1246 1307 'label' => __( 'Forms', 'formidable' ),
@@ -1298,9 +1359,9 @@
1298 1359 * @return mixed
1299 1360 */
1300 1361 public static function save_per_page( $save, $option, $value ) {
1301 1362 if ( $option === 'formidable_page_formidable_per_page' ) {
1302 - $save = (int) $value;
1363 + return (int) $value;
1303 1364 }
1304 1365
1305 1366 return $save;
1306 1367 }
@@ -1350,15 +1411,14 @@
1350 1411 }
1351 1412
1352 1413 if ( $form->parent_form_id ) {
1353 1414 /* translators: %1$s: Start link HTML, %2$s: End link HTML */
1354 - 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>' ) );
1415 + 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>' ) ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
1355 1416 }
1356 1417
1357 1418 $frm_field_selection = FrmField::field_selection();
1419 + $fields = FrmField::get_all_for_form( $form->id );
1358 1420
1359 - $fields = FrmField::get_all_for_form( $form->id );
1360 -
1361 1421 // Automatically add end section fields if they don't exist (2.0 migration).
1362 1422 $reset_fields = false;
1363 1423 FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields );
1364 1424 FrmSubmitHelper::maybe_create_submit_field( $form, $fields, $reset_fields );
@@ -1383,9 +1443,9 @@
1383 1443 $values['fields'] = apply_filters( 'frm_fields_in_form_builder', $fields, compact( 'form' ) );
1384 1444
1385 1445 $edit_message = __( 'Form was successfully updated.', 'formidable' );
1386 1446
1387 - if ( $form->is_template && $message == $edit_message ) {
1447 + if ( $form->is_template && $message === $edit_message ) {
1388 1448 $message = __( 'Template was successfully updated.', 'formidable' );
1389 1449 }
1390 1450
1391 1451 self::maybe_update_form_builder_message( $message );
@@ -1449,13 +1509,12 @@
1449 1509 );
1450 1510 $args = array_merge( $defaults, $args );
1451 1511 $message = $args['message'];
1452 1512 $warnings = $args['warnings'];
1513 + $form = FrmForm::getOne( $id );
1514 + $fields = FrmField::get_all_for_form( $id );
1515 + $values = FrmAppHelper::setup_edit_vars( $form, 'forms', $fields, true );
1453 1516
1454 - $form = FrmForm::getOne( $id );
1455 - $fields = FrmField::get_all_for_form( $id );
1456 - $values = FrmAppHelper::setup_edit_vars( $form, 'forms', $fields, true );
1457 -
1458 1517 /**
1459 1518 * Allows changing fields in the form settings.
1460 1519 *
1461 1520 * @since 5.0.04
@@ -1520,19 +1579,24 @@
1520 1579 'advanced' => array(
1521 1580 'name' => __( 'General', 'formidable' ),
1522 1581 'title' => __( 'General Form Settings', 'formidable' ),
1523 1582 'function' => array( self::class, 'advanced_settings' ),
1524 - 'icon' => 'frm_icon_font frm_settings_icon',
1583 + 'icon' => 'frmfont frm_small_settings_icon',
1525 1584 ),
1526 1585 'email' => array(
1527 1586 'name' => __( 'Actions & Notifications', 'formidable' ),
1528 1587 'function' => array( 'FrmFormActionsController', 'email_settings' ),
1529 1588 'id' => 'frm_notification_settings',
1530 - 'icon' => 'frm_icon_font frm_mail_bulk_icon',
1589 + 'icon' => 'frmfont frm_notification_check_icon',
1531 1590 ),
1591 + 'spam' => array(
1592 + 'name' => __( 'Spam', 'formidable' ),
1593 + 'function' => array( self::class, 'spam_settings' ),
1594 + 'icon' => 'frmfont frm_shield_check2_icon',
1595 + ),
1532 1596 'permissions' => array(
1533 1597 'name' => __( 'Form Permissions', 'formidable' ),
1534 - 'icon' => 'frm_icon_font frm_lock_closed_icon',
1598 + 'icon' => 'frmfont frm_lock_closed2_icon',
1535 1599 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1536 1600 'data' => array(
1537 1601 'medium' => 'permissions',
1538 1602 'upgrade' => __( 'Form Permissions', 'formidable' ),
@@ -1542,9 +1606,9 @@
1542 1606 ),
1543 1607 ),
1544 1608 'scheduling' => array(
1545 1609 'name' => __( 'Form Scheduling', 'formidable' ),
1546 - 'icon' => 'frm_icon_font frm_calendar_icon',
1610 + 'icon' => 'frmfont frm_schedule_icon',
1547 1611 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1548 1612 'data' => array(
1549 1613 'medium' => 'scheduling',
1550 1614 'upgrade' => __( 'Form scheduling settings', 'formidable' ),
@@ -1555,19 +1619,19 @@
1555 1619 'buttons' => array(
1556 1620 'name' => __( 'Buttons', 'formidable' ),
1557 1621 'class' => self::class,
1558 1622 'function' => 'buttons_settings',
1559 - 'icon' => 'frm_icon_font frm_button_icon',
1623 + 'icon' => 'frmfont frm-buttons-style',
1560 1624 ),
1561 1625 'landing' => array(
1562 1626 'name' => __( 'Form Landing Page', 'formidable' ),
1563 - 'icon' => 'frm_icon_font frm_file_text_icon',
1627 + 'icon' => 'frmfont frm_cross_device_icon',
1564 1628 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1565 1629 'data' => FrmAppHelper::get_landing_page_upgrade_data_params(),
1566 1630 ),
1567 1631 'chat' => array(
1568 1632 'name' => __( 'Conversational Forms', 'formidable' ),
1569 - 'icon' => 'frm_icon_font frm_chat_forms_icon',
1633 + 'icon' => 'frmfont frm_chat_bubbles_icon',
1570 1634 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1571 1635 'data' => FrmAppHelper::get_upgrade_data_params(
1572 1636 'chat',
1573 1637 array(
@@ -1579,9 +1643,9 @@
1579 1643 ),
1580 1644 ),
1581 1645 'abandonment' => array(
1582 1646 'name' => __( 'Form Abandonment', 'formidable' ),
1583 - 'icon' => 'frm_icon_font frm_abandoned_icon',
1647 + 'icon' => 'frmfont frm_abandoned_icon',
1584 1648 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1585 1649 'data' => FrmAppHelper::get_upgrade_data_params(
1586 1650 'abandonment',
1587 1651 array(
@@ -1595,9 +1659,9 @@
1595 1659 'html' => array(
1596 1660 'name' => __( 'Customize HTML', 'formidable' ),
1597 1661 'class' => self::class,
1598 1662 'function' => 'html_settings',
1599 - 'icon' => 'frm_icon_font frm_code_icon',
1663 + 'icon' => 'frmfont frm_code2_icon',
1600 1664 ),
1601 1665 );
1602 1666
1603 1667 if ( ! has_action( 'frm_add_form_style_tab_options' ) && ! has_action( 'frm_add_form_button_options' ) ) {
@@ -1609,9 +1673,9 @@
1609 1673 foreach ( $sections as $key => $section ) {
1610 1674 $defaults = array(
1611 1675 'html_class' => '',
1612 1676 'name' => ucfirst( $key ),
1613 - 'icon' => 'frm_icon_font frm_settings_icon',
1677 + 'icon' => 'frmfont frm_settings_icon',
1614 1678 );
1615 1679
1616 1680 $section = array_merge( $defaults, $section );
1617 1681
@@ -1617,8 +1681,9 @@
1617 1681
1618 1682 if ( ! isset( $section['anchor'] ) ) {
1619 1683 $section['anchor'] = $key;
1620 1684 }
1685 +
1621 1686 $section['anchor'] .= '_settings';
1622 1687
1623 1688 if ( ! isset( $section['title'] ) ) {
1624 1689 $section['title'] = $section['name'];
@@ -1642,23 +1707,20 @@
1642 1707 * @return void
1643 1708 */
1644 1709 public static function advanced_settings( $values ) {
1645 1710 $first_h3 = 'frm_first_h3';
1646 -
1647 1711 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-advanced.php';
1648 1712 }
1649 1713
1650 1714 /**
1715 + * @since 6.33
1716 + *
1651 1717 * @param array $values
1652 1718 *
1653 1719 * @return void
1654 1720 */
1655 - public static function render_spam_settings( $values ) {
1656 - if ( function_exists( 'akismet_http_post' ) ) {
1657 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/akismet.php';
1658 - }
1659 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/stopforumspam.php';
1660 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/antispam.php';
1721 + public static function spam_settings( $values ) {
1722 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings.php';
1661 1723 }
1662 1724
1663 1725 /**
1664 1726 * @since 4.0
@@ -1712,14 +1774,17 @@
1712 1774 return $classes;
1713 1775 }
1714 1776
1715 1777 /**
1778 + * @since 6.27 Added $template_path parameter.
1779 + *
1716 1780 * @param int|string $form_id
1717 1781 * @param string $class
1782 + * @param string $template_path The path to a template file to use instead of the default.
1718 1783 *
1719 1784 * @return void
1720 1785 */
1721 - public static function mb_tags_box( $form_id, $class = '' ) {
1786 + public static function mb_tags_box( $form_id, $class = '', $template_path = 'default' ) {
1722 1787 $fields = FrmField::get_all_for_form( $form_id, '', 'include' );
1723 1788
1724 1789 /**
1725 1790 * Allows modifying the list of fields in the tags box.
@@ -1728,19 +1793,22 @@
1728 1793 *
1729 1794 * @param array $fields The list of fields.
1730 1795 * @param array $args The arguments. Contains `form_id`.
1731 1796 */
1732 - $fields = apply_filters( 'frm_fields_in_tags_box', $fields, compact( 'form_id' ) );
1733 - $linked_forms = array();
1734 - $col = 'one';
1735 - $settings_tab = FrmAppHelper::is_admin_page( 'formidable' );
1736 -
1797 + $fields = apply_filters( 'frm_fields_in_tags_box', $fields, compact( 'form_id' ) );
1798 + $linked_forms = array();
1799 + $col = 'one';
1800 + $settings_tab = FrmAppHelper::is_admin_page( 'formidable' );
1737 1801 $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() );
1738 - $entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
1802 + $entry_shortcodes = self::get_shortcode_helpers( $settings_tab, $form_id );
1803 + $advanced_helpers = self::advanced_helpers( compact( 'fields', 'form_id' ) );
1739 1804
1740 - $advanced_helpers = self::advanced_helpers( compact( 'fields', 'form_id' ) );
1805 + if ( 'default' === $template_path || ! file_exists( $template_path ) ) {
1806 + include FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php';
1807 + return;
1808 + }
1741 1809
1742 - include FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php';
1810 + include $template_path;
1743 1811 }
1744 1812
1745 1813 /**
1746 1814 * @since 3.04.01
@@ -1783,8 +1851,126 @@
1783 1851 return apply_filters( 'frm_advanced_helpers', $advanced_helpers, $atts );
1784 1852 }
1785 1853
1786 1854 /**
1855 + * Adds a shortcode for each part of a multi-part field to the field shortcode list,
1856 + * so a single part can be used on its own, like [25 show=first] for a Name field.
1857 + *
1858 + * @since 6.35
1859 + *
1860 + * @param array $atts Includes 'field'.
1861 + *
1862 + * @return void
1863 + */
1864 + public static function field_part_shortcodes( $atts ) {
1865 + $field = $atts['field'];
1866 +
1867 + foreach ( self::get_field_parts( $field ) as $part => $label ) {
1868 + FrmFormsHelper::insert_opt_html(
1869 + array(
1870 + 'id' => $field->id . ' show=' . $part,
1871 + 'key' => $field->field_key . ' show=' . $part,
1872 + // Keep the part label and the option out of the truncated text so they stay readable.
1873 + 'key_label' => $field->field_key,
1874 + 'key_suffix' => ' show=' . $part,
1875 + 'name' => $field->name,
1876 + 'name_suffix' => ' (' . $label . ')',
1877 + 'type' => $field->type,
1878 + 'class' => 'frm-customize-list dropdown-item',
1879 + )
1880 + );
1881 + unset( $part, $label );
1882 + }
1883 + }
1884 +
1885 + /**
1886 + * Gets the parts of a multi-part field that can be shown on their own with a show= shortcode option.
1887 + *
1888 + * @since 6.35
1889 + *
1890 + * @param stdClass $field
1891 + *
1892 + * @return array Part labels keyed by the show= option value.
1893 + */
1894 + private static function get_field_parts( $field ) {
1895 + $parts = array();
1896 +
1897 + if ( 'name' === $field->type ) {
1898 + $parts = self::get_name_field_parts( $field );
1899 + } elseif ( 'address' === $field->type ) {
1900 + $parts = self::get_address_field_parts( $field );
1901 + }
1902 +
1903 + /**
1904 + * Allows add-ons to add the parts of their own multi-part fields.
1905 + *
1906 + * @since 6.35
1907 + *
1908 + * @param array $parts Part labels keyed by the show= option value.
1909 + * @param stdClass $field The field the parts belong to.
1910 + */
1911 + return apply_filters( 'frm_field_parts_for_shortcodes', $parts, $field );
1912 + }
1913 +
1914 + /**
1915 + * Gets the parts of a Name field that are in use. Only the parts included in the
1916 + * selected name layout hold a value, so the rest would always show as blank.
1917 + *
1918 + * @since 6.35
1919 + *
1920 + * @param stdClass $field
1921 + *
1922 + * @return array Part labels keyed by the show= option value, in layout order.
1923 + */
1924 + private static function get_name_field_parts( $field ) {
1925 + $labels = array(
1926 + 'first' => __( 'First', 'formidable' ),
1927 + 'middle' => __( 'Middle', 'formidable' ),
1928 + 'last' => __( 'Last', 'formidable' ),
1929 + );
1930 + $layout = FrmField::get_option( $field, 'name_layout' );
1931 +
1932 + if ( ! $layout ) {
1933 + $layout = 'first_last';
1934 + }
1935 +
1936 + // The layout option names the parts in use, in display order, like first_middle_last.
1937 + $parts = array();
1938 +
1939 + foreach ( explode( '_', $layout ) as $part ) {
1940 + if ( isset( $labels[ $part ] ) ) {
1941 + $parts[ $part ] = $labels[ $part ];
1942 + }
1943 + unset( $part );
1944 + }
1945 +
1946 + return $parts;
1947 + }
1948 +
1949 + /**
1950 + * Gets the parts of an Address field that are in use. The address type decides which
1951 + * parts are on the form, so the rest would always show as blank.
1952 + *
1953 + * @since 6.35
1954 + *
1955 + * @param stdClass $field
1956 + *
1957 + * @return array Part labels keyed by the show= option value.
1958 + */
1959 + private static function get_address_field_parts( $field ) {
1960 + $parts = FrmFieldAddress::get_part_labels();
1961 + $address_type = FrmField::get_option( $field, 'address_type' );
1962 +
1963 + if ( in_array( $address_type, array( 'us', 'generic' ), true ) ) {
1964 + unset( $parts['country'] );
1965 + } elseif ( 'europe' === $address_type ) {
1966 + unset( $parts['state'] );
1967 + }
1968 +
1969 + return $parts;
1970 + }
1971 +
1972 + /**
1787 1973 * Get an array of the options to display in the advanced tab
1788 1974 * of the customization panel
1789 1975 *
1790 1976 * @since 2.0.6
@@ -1807,13 +1993,12 @@
1807 1993 'label' => __( 'No Auto P', 'formidable' ),
1808 1994 'title' => __( 'Do not automatically add any paragraphs or line breaks', 'formidable' ),
1809 1995 ),
1810 1996 );
1811 - $adv_shortcodes = apply_filters( 'frm_advanced_shortcodes', $adv_shortcodes );
1812 1997
1813 1998 // __( 'Leave blank instead of defaulting to User Login', 'formidable' ) : blank=1
1814 1999
1815 - return $adv_shortcodes;
2000 + return apply_filters( 'frm_advanced_shortcodes', $adv_shortcodes );
1816 2001 }
1817 2002
1818 2003 /**
1819 2004 * @since 3.04.01
@@ -1840,12 +2025,13 @@
1840 2025 *
1841 2026 * @since 2.0.6
1842 2027 *
1843 2028 * @param bool $settings_tab
2029 + * @param int $form_id
1844 2030 *
1845 2031 * @return array
1846 2032 */
1847 - private static function get_shortcode_helpers( $settings_tab ) {
2033 + private static function get_shortcode_helpers( $settings_tab, $form_id = 0 ) {
1848 2034 $entry_shortcodes = array(
1849 2035 'id' => __( 'Entry ID', 'formidable' ),
1850 2036 'key' => __( 'Entry Key', 'formidable' ),
1851 2037 'post_id' => __( 'Post ID', 'formidable' ),
@@ -1871,12 +2057,11 @@
1871 2057 * @since 2.0.6
1872 2058 *
1873 2059 * @param array $entry_shortcodes
1874 2060 * @param bool $settings_tab
2061 + * @param int $form_id
1875 2062 */
1876 - $entry_shortcodes = apply_filters( 'frm_helper_shortcodes', $entry_shortcodes, $settings_tab );
1877 -
1878 - return $entry_shortcodes;
2063 + return apply_filters( 'frm_helper_shortcodes', $entry_shortcodes, $settings_tab, $form_id );
1879 2064 }
1880 2065
1881 2066 /**
1882 2067 * Insert the form class setting into the form.
@@ -1956,11 +2141,10 @@
1956 2141 $form = $entry->parent_entry->form_id;
1957 2142 }
1958 2143
1959 2144 $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form );
1960 - $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
1961 2145
1962 - return $content;
2146 + return apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
1963 2147 }
1964 2148
1965 2149 /**
1966 2150 * Replace any [form_name] shortcodes in a string.
@@ -1976,9 +2160,9 @@
1976 2160 if ( ! is_string( $string ) ) {
1977 2161 return $string;
1978 2162 }
1979 2163
1980 - if ( false === strpos( $string, '[form_name]' ) ) {
2164 + if ( ! str_contains( $string, '[form_name]' ) ) {
1981 2165 return $string;
1982 2166 }
1983 2167
1984 2168 if ( ! is_object( $form ) ) {
@@ -1994,15 +2178,17 @@
1994 2178 *
1995 2179 * @return void
1996 2180 */
1997 2181 private static function get_entry_by_param( &$entry ) {
1998 - if ( ! $entry || ! is_object( $entry ) ) {
1999 - if ( ! $entry || ! is_numeric( $entry ) ) {
2000 - $entry = FrmAppHelper::get_post_param( 'id', false, 'sanitize_title' );
2001 - }
2182 + if ( $entry && is_object( $entry ) ) {
2183 + return;
2184 + }
2002 2185
2003 - FrmEntry::maybe_get_entry( $entry );
2186 + if ( ! $entry || ! is_numeric( $entry ) ) {
2187 + $entry = FrmAppHelper::get_post_param( 'id', false, 'sanitize_title' );
2004 2188 }
2189 +
2190 + FrmEntry::maybe_get_entry( $entry );
2005 2191 }
2006 2192
2007 2193 /**
2008 2194 * @param string $content
@@ -2026,23 +2212,22 @@
2026 2212 }
2027 2213
2028 2214 $bulkaction = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
2029 2215
2216 + // phpcs:ignore Universal.Operators.StrictComparisons
2030 2217 if ( $bulkaction == - 1 ) {
2031 2218 $bulkaction = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
2032 2219 }
2033 2220
2034 - if ( ! empty( $bulkaction ) && strpos( $bulkaction, 'bulk_' ) === 0 ) {
2221 + if ( $bulkaction && str_starts_with( $bulkaction, 'bulk_' ) ) {
2035 2222 FrmAppHelper::remove_get_action();
2036 -
2037 2223 $bulkaction = str_replace( 'bulk_', '', $bulkaction );
2038 2224 }
2039 2225
2040 2226 $ids = FrmAppHelper::get_param( 'item-action', '', 'get', 'sanitize_text_field' );
2041 2227
2042 - if ( empty( $ids ) ) {
2228 + if ( ! $ids ) {
2043 2229 $errors[] = __( 'No forms were specified', 'formidable' );
2044 -
2045 2230 return $errors;
2046 2231 }
2047 2232
2048 2233 $permission_error = FrmAppHelper::permission_nonce_error( '', '_wpnonce', 'bulk-toplevel_page_formidable' );
@@ -2048,9 +2233,8 @@
2048 2233 $permission_error = FrmAppHelper::permission_nonce_error( '', '_wpnonce', 'bulk-toplevel_page_formidable' );
2049 2234
2050 2235 if ( $permission_error !== false ) {
2051 2236 $errors[] = $permission_error;
2052 -
2053 2237 return $errors;
2054 2238 }
2055 2239
2056 2240 if ( ! is_array( $ids ) ) {
@@ -2089,9 +2273,9 @@
2089 2273
2090 2274 include FrmAppHelper::plugin_path() . '/classes/views/shared/small-device-message.php';
2091 2275 }
2092 2276
2093 - public static function route() {
2277 + public static function route() { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.MaxExceeded
2094 2278 $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
2095 2279 $vars = array();
2096 2280 FrmAppHelper::include_svg();
2097 2281
@@ -2102,10 +2286,16 @@
2102 2286 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
2103 2287 $json_vars = htmlspecialchars_decode( nl2br( str_replace( '&quot;', '"', wp_unslash( $_POST['frm_compact_fields'] ) ) ) );
2104 2288 $json_vars = json_decode( $json_vars, true );
2105 2289
2106 - if ( empty( $json_vars ) ) {
2107 - // json decoding failed so we should return an error message.
2290 + if ( $json_vars ) {
2291 + $vars = FrmAppHelper::json_to_array( $json_vars );
2292 + $action = $vars[ $action ];
2293 + unset( $_REQUEST['frm_compact_fields'], $_POST['frm_compact_fields'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
2294 + $_REQUEST = array_merge( $_REQUEST, $vars ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
2295 + $_POST = array_merge( $_POST, $_REQUEST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
2296 + } else {
2297 + // Json decoding failed so we should return an error message.
2108 2298 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
2109 2299
2110 2300 if ( 'edit' === $action ) {
2111 2301 $action = 'update';
@@ -2111,14 +2301,8 @@
2111 2301 $action = 'update';
2112 2302 }
2113 2303
2114 2304 add_filter( 'frm_validate_form', 'FrmFormsController::json_error' );
2115 - } else {
2116 - $vars = FrmAppHelper::json_to_array( $json_vars );
2117 - $action = $vars[ $action ];
2118 - unset( $_REQUEST['frm_compact_fields'], $_POST['frm_compact_fields'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
2119 - $_REQUEST = array_merge( $_REQUEST, $vars ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
2120 - $_POST = array_merge( $_POST, $_REQUEST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
2121 2305 }
2122 2306 } else {
2123 2307 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
2124 2308
@@ -2142,30 +2326,31 @@
2142 2326 case 'update_settings':
2143 2327 return self::$action( $vars );
2144 2328 case 'lite-reports':
2145 2329 self::no_reports( $vars );
2146 - return;
2330 + return null;
2147 2331 case 'views':
2148 2332 self::no_views( $vars );
2149 - return;
2333 + return null;
2150 2334 default:
2151 2335 do_action( 'frm_form_action_' . $action );
2152 2336
2153 2337 if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) {
2154 - return;
2338 + return null;
2155 2339 }
2156 2340
2157 2341 $action = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
2158 2342
2343 + // phpcs:ignore Universal.Operators.StrictComparisons
2159 2344 if ( $action == - 1 ) {
2160 2345 $action = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
2161 2346 }
2162 2347
2163 - if ( strpos( $action, 'bulk_' ) === 0 ) {
2348 + if ( str_starts_with( $action, 'bulk_' ) ) {
2164 2349 FrmAppHelper::remove_get_action();
2165 2350
2166 2351 self::list_form();
2167 - return;
2352 + return null;
2168 2353 }
2169 2354
2170 2355 $message = FrmAppHelper::get_param( 'message' );
2171 2356
@@ -2170,9 +2355,9 @@
2170 2355 $message = FrmAppHelper::get_param( 'message' );
2171 2356
2172 2357 if ( 'form_duplicate_error' === $message ) {
2173 2358 self::display_forms_list( array(), '', array( __( 'There was a problem duplicating the form', 'formidable' ) ) );
2174 - return;
2359 + return null;
2175 2360 }
2176 2361
2177 2362 if ( 'forms_permanently_deleted' === $message ) {
2178 2363 $count = FrmAppHelper::get_param( 'forms_deleted', 0, 'get', 'absint' );
@@ -2178,14 +2363,14 @@
2178 2363 $count = FrmAppHelper::get_param( 'forms_deleted', 0, 'get', 'absint' );
2179 2364 /* translators: %1$s: Number of forms */
2180 2365 $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
2181 2366 self::display_forms_list( array(), $message, '' );
2182 - return;
2367 + return null;
2183 2368 }
2184 2369
2185 2370 self::display_forms_list();
2186 2371
2187 - return;
2372 + return null;
2188 2373 }//end switch
2189 2374 }
2190 2375
2191 2376 /**
@@ -2204,11 +2389,10 @@
2204 2389
2205 2390 // Get posted data
2206 2391 $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
2207 2392 $name = FrmAppHelper::get_post_param( 'form_name', '', 'sanitize_text_field' );
2393 + $form = FrmForm::getOne( $form_id );
2208 2394
2209 - $form = FrmForm::getOne( $form_id );
2210 -
2211 2395 if ( ! $form ) {
2212 2396 wp_send_json_error( __( 'Form not found', 'formidable' ) );
2213 2397 }
2214 2398
@@ -2213,9 +2397,10 @@
2213 2397 }
2214 2398
2215 2399 if ( $name === $form->name ) {
2216 2400 // Nothing to change so exit early.
2217 - wp_send_json_success();
2401 + $form_key = $form->form_key;
2402 + wp_send_json_success( compact( 'form_key' ) );
2218 2403 }
2219 2404
2220 2405 $to_update = array(
2221 2406 'name' => $name,
@@ -2220,14 +2405,14 @@
2220 2405 $to_update = array(
2221 2406 'name' => $name,
2222 2407 );
2223 2408
2224 - if ( '' !== $name ) {
2409 + if ( '' === $name ) {
2410 + $form_key = $form->form_key;
2411 + } else {
2225 2412 // Only update form_key if name is not empty.
2226 2413 $form_key = FrmAppHelper::get_unique_key( sanitize_title( $name ), 'frm_forms', 'form_key' );
2227 2414 $to_update['form_key'] = $form_key;
2228 - } else {
2229 - $form_key = $form->form_key;
2230 2415 }
2231 2416
2232 2417 FrmForm::update( $form_id, $to_update );
2233 2418
@@ -2240,9 +2425,8 @@
2240 2425 * @return array
2241 2426 */
2242 2427 public static function json_error( $errors ) {
2243 2428 $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
2244 -
2245 2429 return $errors;
2246 2430 }
2247 2431
2248 2432 /**
@@ -2295,11 +2479,9 @@
2295 2479 /**
2296 2480 * @since 4.05.02
2297 2481 */
2298 2482 private static function move_menu_to_footer() {
2299 - $settings = FrmAppHelper::get_settings();
2300 -
2301 - if ( empty( $settings->admin_bar ) ) {
2483 + if ( empty( FrmAppHelper::get_settings()->admin_bar ) ) {
2302 2484 remove_action( 'wp_body_open', 'wp_admin_bar_render', 0 );
2303 2485 }
2304 2486 }
2305 2487
@@ -2318,9 +2500,9 @@
2318 2500 }
2319 2501 unset( $form );
2320 2502 }
2321 2503
2322 - if ( empty( $actions ) ) {
2504 + if ( ! $actions ) {
2323 2505 return;
2324 2506 }
2325 2507
2326 2508 self::add_menu_to_admin_bar();
@@ -2357,14 +2539,13 @@
2357 2539
2358 2540 asort( $actions );
2359 2541
2360 2542 foreach ( $actions as $form_id => $name ) {
2361 -
2362 2543 $wp_admin_bar->add_node(
2363 2544 array(
2364 2545 'parent' => 'frm-forms',
2365 2546 'id' => 'edit_form_' . $form_id,
2366 - 'title' => empty( $name ) ? FrmFormsHelper::get_no_title_text() : $name,
2547 + 'title' => $name ? $name : FrmFormsHelper::get_no_title_text(),
2367 2548 'href' => FrmForm::get_edit_link( $form_id ),
2368 2549 )
2369 2550 );
2370 2551 }
@@ -2448,14 +2629,13 @@
2448 2629
2449 2630 add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
2450 2631 FrmAppHelper::trigger_hook_load( 'form', $form );
2451 2632
2452 - $form = apply_filters( 'frm_pre_display_form', $form );
2453 -
2633 + $form = apply_filters( 'frm_pre_display_form', $form );
2454 2634 $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) );
2455 2635
2456 2636 if ( self::is_viewable_draft_form( $form ) ) {
2457 - // don't show a draft form on a page
2637 + // Don't show a draft form on a page
2458 2638 $form = __( 'Please select a valid form', 'formidable' );
2459 2639 } elseif ( ! FrmForm::is_visible_to_user( $form ) ) {
2460 2640 $form = do_shortcode( $frm_settings->login_msg );
2461 2641 } else {
@@ -2481,9 +2661,9 @@
2481 2661 */
2482 2662 private static function maybe_get_form_to_show( $id ) {
2483 2663 $form = false;
2484 2664
2485 - if ( ! empty( $id ) ) {
2665 + if ( $id ) {
2486 2666 // Form id or key is set.
2487 2667 $form = FrmForm::getOne( $id );
2488 2668
2489 2669 if ( ! $form || $form->parent_form_id || $form->status === 'trash' ) {
@@ -2518,10 +2698,9 @@
2518 2698
2519 2699 self::get_form_contents( $form, $title, $description, $atts );
2520 2700 self::enqueue_scripts( FrmForm::get_params( $form ) );
2521 2701
2522 - $contents = ob_get_contents();
2523 - ob_end_clean();
2702 + $contents = ob_get_clean();
2524 2703
2525 2704 self::maybe_minimize_form( $atts, $contents );
2526 2705
2527 2706 return $contents;
@@ -2551,9 +2730,10 @@
2551 2730 $reset = false;
2552 2731 $pass_args = compact( 'form', 'fields', 'errors', 'title', 'description', 'reset' );
2553 2732
2554 2733 $pass_args['action'] = $params['action'];
2555 - $handle_process_here = $params['action'] === 'create' && $params['posted_form_id'] == $form->id && $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing
2734 + // phpcs:ignore WordPress.Security.NonceVerification.Missing, Universal.Operators.StrictComparisons
2735 + $handle_process_here = $params['action'] === 'create' && $params['posted_form_id'] == $form->id && $_POST;
2556 2736
2557 2737 if ( ! $handle_process_here ) {
2558 2738 FrmFormState::set_initial_value( 'title', $title );
2559 2739 FrmFormState::set_initial_value( 'description', $description );
@@ -2562,13 +2742,11 @@
2562 2742
2563 2743 if ( apply_filters( 'frm_continue_to_new', true, $form->id, $params['action'] ) ) {
2564 2744 self::show_form_after_submit( $pass_args );
2565 2745 }
2566 - } elseif ( ! empty( $errors ) ) {
2746 + } elseif ( $errors ) {
2567 2747 self::show_form_after_submit( $pass_args );
2568 -
2569 2748 } else {
2570 -
2571 2749 do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description );
2572 2750
2573 2751 if ( apply_filters( 'frm_continue_to_create', true, $form->id ) ) {
2574 2752 $entry_id = self::just_created_entry( $form->id );
@@ -2600,9 +2778,10 @@
2600 2778 */
2601 2779 private static function get_saved_errors( $form, $params ) {
2602 2780 global $frm_vars;
2603 2781
2604 - if ( $params['posted_form_id'] == $form->id && $_POST && isset( $frm_vars['created_entries'][ $form->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
2782 + // phpcs:ignore WordPress.Security.NonceVerification.Missing, Universal.Operators.StrictComparisons
2783 + if ( $params['posted_form_id'] == $form->id && $_POST && isset( $frm_vars['created_entries'][ $form->id ] ) ) {
2605 2784 $errors = $frm_vars['created_entries'][ $form->id ]['errors'];
2606 2785 } else {
2607 2786 $errors = array();
2608 2787 }
@@ -2626,10 +2805,9 @@
2626 2805 * @return int
2627 2806 */
2628 2807 public static function just_created_entry( $form_id ) {
2629 2808 global $frm_vars;
2630 -
2631 - return isset( $frm_vars['created_entries'] ) && isset( $frm_vars['created_entries'][ $form_id ] ) && isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ? $frm_vars['created_entries'][ $form_id ]['entry_id'] : 0;
2809 + return isset( $frm_vars['created_entries'] ) && isset( $frm_vars['created_entries'][ $form_id ] ) && isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ? $frm_vars['created_entries'][ $form_id ]['entry_id'] : 0; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
2632 2810 }
2633 2811
2634 2812 /**
2635 2813 * Gets confirmation method.
@@ -2661,9 +2839,9 @@
2661 2839
2662 2840 $method = apply_filters( 'frm_success_filter', $method, $atts['form'], $action );
2663 2841
2664 2842 if ( $method !== 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
2665 - $method = 'message';
2843 + return 'message';
2666 2844 }
2667 2845
2668 2846 return $method;
2669 2847 }
@@ -2702,14 +2880,12 @@
2702 2880 * @param array $params See {@see FrmFormsController::maybe_trigger_redirect()}.
2703 2881 * @param array $args See {@see FrmFormsController::maybe_trigger_redirect()}.
2704 2882 */
2705 2883 public static function maybe_trigger_redirect_with_action( $conf_method, $form, $params, $args ) {
2706 - if ( is_array( $conf_method ) && 1 === count( $conf_method ) ) {
2707 - if ( 'redirect' === FrmOnSubmitHelper::get_action_type( $conf_method[0] ) && empty( $conf_method[0]->post_content['redirect_delay'] ) ) {
2708 - $event = FrmOnSubmitHelper::current_event( $params );
2709 - FrmOnSubmitHelper::populate_on_submit_data( $form->options, $conf_method[0], $event );
2710 - $conf_method = 'redirect';
2711 - }
2884 + if ( is_array( $conf_method ) && 1 === count( $conf_method ) && 'redirect' === FrmOnSubmitHelper::get_action_type( $conf_method[0] ) && empty( $conf_method[0]->post_content['redirect_delay'] ) ) { // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
2885 + $event = FrmOnSubmitHelper::current_event( $params );
2886 + FrmOnSubmitHelper::populate_on_submit_data( $form->options, $conf_method[0], $event );
2887 + $conf_method = 'redirect';
2712 2888 }
2713 2889
2714 2890 if ( 'redirect' === $conf_method ) {
2715 2891 self::trigger_redirect( $form, $params, $args );
@@ -2811,13 +2987,11 @@
2811 2987 }
2812 2988
2813 2989 $action_type = FrmOnSubmitHelper::get_action_type( $action );
2814 2990
2815 - if ( 'redirect' === $action_type ) {
2816 - if ( $has_redirect ) {
2817 - // Do not process because we run the first redirect action only.
2818 - continue;
2819 - }
2991 + if ( 'redirect' === $action_type && $has_redirect ) {
2992 + // Do not process because we run the first redirect action only.
2993 + continue;
2820 2994 }
2821 2995
2822 2996 if ( ! self::is_valid_on_submit_action( $action, $args, $event ) ) {
2823 2997 continue;
@@ -2842,10 +3016,10 @@
2842 3016 * @param array $args See {@see FrmFormsController::run_success_action()}. `$args['event']` is also added.
2843 3017 */
2844 3018 $met_actions = apply_filters( 'frm_get_met_on_submit_actions', $met_actions, $args );
2845 3019
2846 - if ( empty( $met_actions ) ) {
2847 - $met_actions = array( FrmOnSubmitHelper::get_fallback_action( $event ) );
3020 + if ( ! $met_actions ) {
3021 + return array( FrmOnSubmitHelper::get_fallback_action( $event ) );
2848 3022 }
2849 3023
2850 3024 return $met_actions;
2851 3025 }
@@ -2947,13 +3121,15 @@
2947 3121
2948 3122 unset( $action );
2949 3123 }
2950 3124
2951 - if ( $redirect_action ) {
2952 - // Show script to delay the redirection.
2953 - $args['force_delay_redirect'] = true;
2954 - self::run_single_on_submit_action( $args, $redirect_action );
3125 + if ( ! $redirect_action ) {
3126 + return;
2955 3127 }
3128 +
3129 + // Show script to delay the redirection.
3130 + $args['force_delay_redirect'] = true;
3131 + self::run_single_on_submit_action( $args, $redirect_action );
2956 3132 }
2957 3133
2958 3134 /**
2959 3135 * Runs single On Submit action.
@@ -2982,10 +3158,9 @@
2982 3158 $new_args = $args;
2983 3159
2984 3160 FrmOnSubmitHelper::populate_on_submit_data( $new_args['form']->options, $action, $args['action'] );
2985 3161
2986 - $opt = 'update' === $args['action'] ? 'edit_' : 'success_';
2987 -
3162 + $opt = 'update' === $args['action'] ? 'edit_' : 'success_';
2988 3163 $new_args['conf_method'] = $new_args['form']->options[ $opt . 'action' ];
2989 3164
2990 3165 /**
2991 3166 * Filters the run success action args.
@@ -3009,8 +3184,9 @@
3009 3184 private static function load_page_after_submit( $args ) {
3010 3185 global $post;
3011 3186 $opt = $args['success_opt'];
3012 3187
3188 + // phpcs:ignore Universal.Operators.StrictComparisons
3013 3189 if ( ! $post || $args['form']->options[ $opt . '_page_id' ] != $post->ID ) {
3014 3190 $page = get_post( $args['form']->options[ $opt . '_page_id' ] );
3015 3191 $old_post = $post;
3016 3192 $post = $page;
@@ -3050,11 +3226,10 @@
3050 3226 FrmEntriesController::delete_entry_before_redirect( $success_url, $args['form'], $args );
3051 3227
3052 3228 add_filter( 'frm_redirect_url', 'FrmEntriesController::prepare_redirect_url' );
3053 3229 $success_url = apply_filters( 'frm_redirect_url', $success_url, $args['form'], $args );
3230 + $doing_ajax = FrmAppHelper::doing_ajax();
3054 3231
3055 - $doing_ajax = FrmAppHelper::doing_ajax();
3056 -
3057 3232 if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) {
3058 3233 // Is AJAX submit and there is just one Redirect action runs.
3059 3234 echo json_encode( self::get_ajax_redirect_response_data( $args + compact( 'success_url' ) ) );
3060 3235 wp_die();
@@ -3203,13 +3378,16 @@
3203 3378 * @param string $success_msg
3204 3379 * @param array $args
3205 3380 */
3206 3381 private static function get_redirect_message( $success_url, $success_msg, $args ) {
3207 - $success_msg = apply_filters( 'frm_content', $success_msg, $args['form'], $args['entry_id'] );
3208 - $success_msg = do_shortcode( FrmAppHelper::use_wpautop( $success_msg ) );
3209 - $redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg" role="status">' . $success_msg . '<br/>' .
3382 + $success_msg = apply_filters( 'frm_content', $success_msg, $args['form'], $args['entry_id'] );
3383 + $success_msg = do_shortcode( FrmAppHelper::use_wpautop( $success_msg ) );
3384 +
3385 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
3386 + $redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg" role="status">' . $success_msg . '<br/>' . // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
3210 3387 self::get_redirect_fallback_message( $success_url, $args ) .
3211 3388 '</div></div>';
3389 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
3212 3390
3213 3391 $redirect_args = array(
3214 3392 'entry_id' => $args['entry_id'],
3215 3393 'form_id' => $args['form']->id,
@@ -3301,12 +3479,11 @@
3301 3479 }
3302 3480 unset( $args );
3303 3481
3304 3482 $include_form_tag = apply_filters( 'frm_include_form_tag', true, $form );
3483 + $frm_settings = FrmAppHelper::get_settings();
3484 + $submit = $form->options['submit_value'] ?? $frm_settings->submit_value;
3305 3485
3306 - $frm_settings = FrmAppHelper::get_settings();
3307 - $submit = $form->options['submit_value'] ?? $frm_settings->submit_value;
3308 -
3309 3486 global $frm_vars;
3310 3487 self::maybe_load_css( $form, $values['custom_style'], $frm_vars['load_css'] );
3311 3488
3312 3489 $message_placement = self::message_placement( $form, $message );
@@ -3328,11 +3505,11 @@
3328 3505 public static function message_placement( $form, $message ) {
3329 3506 $place = 'before';
3330 3507
3331 3508 if ( $message && isset( $form->options['form_class'] ) ) {
3332 - if ( strpos( $form->options['form_class'], 'frm_below_success' ) !== false ) {
3509 + if ( str_contains( $form->options['form_class'], 'frm_below_success' ) ) {
3333 3510 $place = 'after';
3334 - } elseif ( strpos( $form->options['form_class'], 'frm_inline_success' ) !== false ) {
3511 + } elseif ( str_contains( $form->options['form_class'], 'frm_inline_success' ) ) {
3335 3512 $place = 'submit';
3336 3513 }
3337 3514 }
3338 3515
@@ -3391,13 +3568,12 @@
3391 3568 $values = FrmEntriesHelper::setup_new_vars( $atts['fields'], $atts['form'], true );
3392 3569 self::maybe_load_css( $atts['form'], $values['custom_style'], $frm_vars['load_css'] );
3393 3570
3394 3571 $include_extra_container = 'frm_forms' . FrmFormsHelper::get_form_style_class( $values );
3572 + $errors = array();
3573 + $form = $atts['form'];
3574 + $message = $atts['message'];
3395 3575
3396 - $errors = array();
3397 - $form = $atts['form'];
3398 - $message = $atts['message'];
3399 -
3400 3576 include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php';
3401 3577 }
3402 3578
3403 3579 /**
@@ -3405,11 +3581,11 @@
3405 3581 *
3406 3582 * @since 2.05
3407 3583 * @since 6.0.x Added the third parameter.
3408 3584 *
3409 - * @param object $form Form object.
3410 - * @param int $entry_id Entry ID.
3411 - * @param array $args See {@see FrmFormsController::run_success_action()}.
3585 + * @param object $form Form object.
3586 + * @param int|string $entry_id Entry ID.
3587 + * @param array $args See {@see FrmFormsController::run_success_action()}.
3412 3588 *
3413 3589 * @return string
3414 3590 */
3415 3591 private static function prepare_submit_message( $form, $entry_id, $args = array() ) {
@@ -3435,9 +3611,9 @@
3435 3611 public static function front_head() {
3436 3612 $version = FrmAppHelper::plugin_version();
3437 3613 $suffix = FrmAppHelper::js_suffix();
3438 3614
3439 - if ( ! empty( $suffix ) && self::has_combo_js_file() ) {
3615 + if ( $suffix && self::has_combo_js_file() ) {
3440 3616 wp_register_script( 'formidable', FrmAppHelper::plugin_url() . '/js/frm.min.js', array( 'jquery' ), $version, true );
3441 3617 } else {
3442 3618 wp_register_script( 'formidable', FrmAppHelper::plugin_url() . "/js/formidable{$suffix}.js", array( 'jquery' ), $version, true );
3443 3619 }
@@ -3444,9 +3620,9 @@
3444 3620
3445 3621 add_filter( 'script_loader_tag', 'FrmFormsController::defer_script_loading', 10, 2 );
3446 3622
3447 3623 if ( FrmAppHelper::is_admin() ) {
3448 - // don't load this in back-end
3624 + // Don't load this in back-end
3449 3625 return;
3450 3626 }
3451 3627
3452 3628 FrmAppHelper::localize_script( 'front' );
@@ -3521,10 +3697,10 @@
3521 3697 *
3522 3698 * @return string
3523 3699 */
3524 3700 public static function defer_script_loading( $tag, $handle ) {
3525 - if ( 'captcha-api' === $handle && ! strpos( $tag, 'defer' ) ) {
3526 - $tag = str_replace( ' src', ' defer="defer" async="async" src', $tag );
3701 + if ( 'captcha-api' === $handle && ! str_contains( $tag, 'defer' ) ) {
3702 + return str_replace( ' src', ' defer="defer" async="async" src', $tag );
3527 3703 }
3528 3704
3529 3705 return $tag;
3530 3706 }
@@ -3538,13 +3714,20 @@
3538 3714 global $frm_vars;
3539 3715
3540 3716 FrmStylesController::enqueue_css();
3541 3717
3542 - if ( ! FrmAppHelper::is_admin() && $location !== 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
3543 - // load formidable js
3544 - wp_enqueue_script( 'formidable' );
3718 + if ( FrmAppHelper::is_admin() || $location === 'header' || empty( $frm_vars['forms_loaded'] ) ) {
3719 + return;
3720 + }
3545 3721
3546 - FrmHoneypot::maybe_print_honeypot_js();
3722 + // Load formidable js
3723 + wp_enqueue_script( 'formidable' );
3724 +
3725 + FrmHoneypot::maybe_print_honeypot_js();
3726 +
3727 + if ( ! method_exists( 'FrmProFormsHelper', 'load_currency_js' ) ) {
3728 + // Load currency JS if Pro is not installed.
3729 + FrmFormsHelper::load_currency_js();
3547 3730 }
3548 3731 }
3549 3732
3550 3733 /**
@@ -3555,9 +3738,9 @@
3555 3738 *
3556 3739 * @return void
3557 3740 */
3558 3741 private static function maybe_minimize_form( $atts, &$content ) {
3559 - // check if minimizing is turned on
3742 + // Check if minimizing is turned on
3560 3743 if ( self::is_minification_on( $atts ) ) {
3561 3744 $content = str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', $content );
3562 3745 }
3563 3746 }
@@ -3583,8 +3766,9 @@
3583 3766
3584 3767 if ( false === $dir || ! file_exists( $dir . 'landing-page-preview-option.php' ) ) {
3585 3768 $dir = self::get_form_views_path();
3586 3769 }
3770 +
3587 3771 include $dir . 'landing-page-preview-option.php';
3588 3772 }
3589 3773
3590 3774 /**
@@ -3674,9 +3858,9 @@
3674 3858 }
3675 3859
3676 3860 check_ajax_referer( 'frm_ajax', 'nonce' );
3677 3861
3678 - $html = FrmAppHelper::clip(
3862 + $html = FrmAppHelper::clip(
3679 3863 function () {
3680 3864 FrmAppHelper::maybe_autocomplete_pages_options(
3681 3865 array(
3682 3866 'field_name' => 'frm_page_dropdown',
@@ -3685,18 +3869,48 @@
3685 3869 )
3686 3870 );
3687 3871 }
3688 3872 );
3689 - $post_type_object = get_post_type_object( 'page' );
3690 3873 wp_send_json(
3691 3874 array(
3692 3875 'html' => $html,
3693 - 'edit_page_url' => admin_url( sprintf( $post_type_object->_edit_link . '&action=edit', 0 ) ),
3876 + 'edit_page_url' => admin_url( sprintf( get_post_type_object( 'page' )->_edit_link . '&action=edit', 0 ) ),
3694 3877 )
3695 3878 );
3696 3879 }
3697 3880
3698 3881 /**
3882 + * Prints necessary templates for the forms list page.
3883 + *
3884 + * @since 6.32
3885 + *
3886 + * @return void
3887 + */
3888 + public static function print_forms_list_templates() {
3889 + if ( ! FrmAppHelper::on_form_listing_page() ) {
3890 + return;
3891 + }
3892 +
3893 + $screen = get_current_screen();
3894 +
3895 + if ( ! $screen ) {
3896 + return;
3897 + }
3898 +
3899 + $columns = get_column_headers( $screen );
3900 + $hidden = get_hidden_columns( $screen );
3901 + $skip_cols = array( 'cb', 'name', 'settings' );
3902 + $per_page = get_user_option( 'formidable_page_formidable_per_page' );
3903 + $show_screen_options = $screen->show_screen_options();
3904 +
3905 + if ( $per_page < 1 ) {
3906 + $per_page = 20;
3907 + }
3908 +
3909 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/forms-list-settings.php';
3910 + }
3911 +
3912 + /**
3699 3913 * @deprecated 4.0
3700 3914 *
3701 3915 * @param array $values
3702 3916 *
@@ -3707,16 +3921,14 @@
3707 3921 self::update( $values );
3708 3922 }
3709 3923
3710 3924 /**
3711 - * Education for premium features.
3925 + * @deprecated 6.33
3712 3926 *
3713 - * @since 4.05
3714 - * @deprecated 6.16.3
3927 + * @param array $values
3715 3928 *
3716 3929 * @return void
3717 3930 */
3718 - public static function add_form_style_tab_options() {
3719 - _deprecated_function( __METHOD__, '6.16.3' );
3720 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php';
3931 + public static function render_spam_settings( $values ) {
3932 + _deprecated_function( __METHOD__, '6.33' );
3721 3933 }
3722 3934 }