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 +760 -253 6.25.1 → trunk View file →
@@ -26,11 +26,13 @@
26 26 private static $formidable_tinymce_button;
27 27
28 28 public static function menu() {
29 29 $menu_label = __( 'Forms', 'formidable' );
30 +
30 31 if ( ! FrmAppHelper::pro_is_installed() ) {
31 32 $menu_label .= ' (Lite)';
32 33 }
34 +
33 35 add_submenu_page( 'formidable', 'Formidable | ' . $menu_label, $menu_label, 'frm_view_forms', 'formidable', 'FrmFormsController::route' );
34 36
35 37 self::maybe_load_listing_hooks();
36 38 }
@@ -45,8 +47,15 @@
45 47 add_filter( 'manage_toplevel_page_formidable_columns', 'FrmFormsController::get_columns', 0 );
46 48 add_filter( 'manage_toplevel_page_formidable_sortable_columns', 'FrmFormsController::get_sortable_columns' );
47 49 }
48 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 + */
49 58 public static function head() {
50 59 if ( wp_is_mobile() ) {
51 60 wp_enqueue_script( 'jquery-touch-punch' );
52 61 }
@@ -64,10 +73,10 @@
64 73 */
65 74 public static function logic_tip() {
66 75 $images_url = FrmAppHelper::plugin_url() . '/images/';
67 76 $data_message = __( 'Only show the fields you need and create branching forms. Upgrade to get conditional logic and question branching.', 'formidable' );
68 - $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' ) . '"/>';
69 - 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
70 79 esc_html_e( 'Conditional Logic', 'formidable' );
71 80 FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown8_icon', array( 'aria-hidden' => 'true' ) );
72 81 echo '</a>';
73 82 }
@@ -76,12 +85,15 @@
76 85 * By default, Divi processes form shortcodes on the edit post page.
77 86 * Now that won't do.
78 87 *
79 88 * @since 3.01
89 + *
90 + * @param array $shortcodes List of shortcodes to process.
91 + *
92 + * @return array
80 93 */
81 94 public static function prevent_divi_conflict( $shortcodes ) {
82 95 $shortcodes[] = 'formidable';
83 -
84 96 return $shortcodes;
85 97 }
86 98
87 99 /**
@@ -92,12 +104,14 @@
92 104
93 105 $message = '';
94 106 $params = FrmForm::list_page_params();
95 107 $errors = self::process_bulk_form_actions( array() );
108 +
96 109 if ( isset( $errors['message'] ) ) {
97 110 $message = $errors['message'];
98 111 unset( $errors['message'] );
99 112 }
113 +
100 114 $errors = apply_filters( 'frm_admin_list_form_action', $errors );
101 115
102 116 self::display_forms_list( $params, $message, $errors );
103 117 }
@@ -107,12 +121,14 @@
107 121 *
108 122 * @since 2.02.11
109 123 *
110 124 * @param int|object $form
125 + *
111 126 * @return void
112 127 */
113 128 private static function create_default_email_action( $form ) {
114 129 FrmForm::maybe_get_form( $form );
130 +
115 131 if ( ! is_object( $form ) ) {
116 132 return;
117 133 }
118 134
@@ -117,15 +133,17 @@
117 133 }
118 134
119 135 $create_email = apply_filters( 'frm_create_default_email_action', true, $form );
120 136
121 - if ( $create_email ) {
122 - /**
123 - * @var FrmFormAction
124 - */
125 - $action_control = FrmFormActionsController::get_form_actions( 'email' );
126 - $action_control->create( $form->id );
137 + if ( ! $create_email ) {
138 + return;
127 139 }
140 +
141 + /**
142 + * @var FrmFormAction
143 + */
144 + $action_control = FrmFormActionsController::get_form_actions( 'email' );
145 + $action_control->create( $form->id );
128 146 }
129 147
130 148 /**
131 149 * Create the default On submit action
@@ -132,12 +150,14 @@
132 150 *
133 151 * @since 6.0.0
134 152 *
135 153 * @param int|object $form Form object or ID.
154 + *
136 155 * @return void
137 156 */
138 157 private static function create_default_on_submit_action( $form ) {
139 158 FrmForm::maybe_get_form( $form );
159 +
140 160 if ( ! is_object( $form ) ) {
141 161 return;
142 162 }
143 163
@@ -150,15 +170,17 @@
150 170 * @param object $form Form object.
151 171 */
152 172 $create = apply_filters( 'frm_create_default_on_submit_action', true, $form );
153 173
154 - if ( $create ) {
155 - /**
156 - * @var FrmFormAction
157 - */
158 - $action_control = FrmFormActionsController::get_form_actions( FrmOnSubmitAction::$slug );
159 - $action_control->create( $form->id );
174 + if ( ! $create ) {
175 + return;
160 176 }
177 +
178 + /**
179 + * @var FrmFormAction
180 + */
181 + $action_control = FrmFormActionsController::get_form_actions( FrmOnSubmitAction::$slug );
182 + $action_control->create( $form->id );
161 183 }
162 184
163 185 /**
164 186 * Creates submit button field.
@@ -165,12 +187,14 @@
165 187 *
166 188 * @since 6.9
167 189 *
168 190 * @param int|object $form Form ID or object.
191 + *
169 192 * @return void
170 193 */
171 194 private static function create_submit_button_field( $form ) {
172 195 FrmForm::maybe_get_form( $form );
196 +
173 197 if ( ! is_object( $form ) ) {
174 198 return;
175 199 }
176 200
@@ -193,8 +217,10 @@
193 217 );
194 218 }
195 219
196 220 /**
221 + * @param array|false $values
222 + *
197 223 * @return void
198 224 */
199 225 public static function edit( $values = false ) {
200 226 FrmAppHelper::permission_check( 'frm_edit_forms' );
@@ -206,8 +232,9 @@
206 232
207 233 /**
208 234 * @param mixed $id
209 235 * @param string $message
236 + *
210 237 * @return void
211 238 */
212 239 public static function settings( $id = false, $message = '' ) {
213 240 FrmAppHelper::permission_check( 'frm_edit_forms' );
@@ -235,10 +262,9 @@
235 262 FrmAppController::show_error_modal( $error_args );
236 263 return;
237 264 }
238 265
239 - $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
240 -
266 + $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
241 267 $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
242 268 $warnings = FrmFormsHelper::check_for_warnings( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
243 269
244 270 if ( count( $errors ) > 0 ) {
@@ -247,17 +273,22 @@
247 273 }
248 274
249 275 do_action( 'frm_before_update_form_settings', $id );
250 276
251 - $antispam_was_on = self::antispam_was_on( $id );
277 + $antispam_was_on = self::antispam_was_on( $id ); // phpcs:ignore Formidable.CodeAnalysis.InlineSingleUseVariable
252 278
253 279 FrmForm::update( $id, $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
254 280
255 281 $antispam_is_on = ! empty( $_POST['options']['antispam'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
282 +
256 283 if ( $antispam_is_on !== $antispam_was_on ) {
257 284 FrmAntiSpam::clear_caches();
258 285 }
259 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 +
260 291 $message = __( 'Settings Successfully Updated', 'formidable' );
261 292
262 293 self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) );
263 294 }
@@ -263,8 +294,9 @@
263 294 }
264 295
265 296 /**
266 297 * @param int $form_id
298 + *
267 299 * @return bool
268 300 */
269 301 private static function antispam_was_on( $form_id ) {
270 302 $form = FrmForm::getOne( $form_id );
@@ -271,12 +303,52 @@
271 303 return ! empty( $form->options['antispam'] );
272 304 }
273 305
274 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 + *
275 314 * @return void
276 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 + /**
345 + * @param array $values
346 + *
347 + * @return void
348 + */
277 349 public static function update( $values = array() ) {
278 - if ( empty( $values ) ) {
350 + if ( ! $values ) {
279 351 $values = $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing
280 352 }
281 353
282 354 // Set radio button and checkbox meta equal to "other" value.
@@ -285,8 +357,9 @@
285 357 }
286 358
287 359 $errors = FrmForm::validate( $values );
288 360 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form', 'frm_save_form_nonce' );
361 +
289 362 if ( $permission_error !== false ) {
290 363 $errors['form'] = $permission_error;
291 364 }
292 365
@@ -336,12 +409,14 @@
336 409 *
337 410 * @since 6.8
338 411 *
339 412 * @param int $form_id
413 + *
340 414 * @return void
341 415 */
342 416 private static function maybe_remove_draft_option_from_fields( $form_id ) {
343 417 $draft_field_ids_csv = FrmAppHelper::get_post_param( 'draft_fields', '', 'sanitize_text_field' );
418 +
344 419 if ( ! $draft_field_ids_csv ) {
345 420 // If the draft_fields input is empty there are no new fields in the session.
346 421 return;
347 422 }
@@ -346,8 +421,9 @@
346 421 return;
347 422 }
348 423
349 424 $draft_field_ids = array_filter( explode( ',', $draft_field_ids_csv ), 'is_numeric' );
425 +
350 426 if ( ! $draft_field_ids ) {
351 427 // Exit early if the draft fields input is invalid. It should be a CSV of integer values.
352 428 return;
353 429 }
@@ -352,8 +428,9 @@
352 428 return;
353 429 }
354 430
355 431 $draft_field_rows = FrmFieldsHelper::get_draft_field_results( $form_id, $draft_field_ids );
432 +
356 433 foreach ( $draft_field_rows as $row ) {
357 434 $row->field_options['draft'] = 0;
358 435 FrmField::update( $row->id, array( 'field_options' => $row->field_options ) );
359 436 }
@@ -366,8 +443,9 @@
366 443 *
367 444 * @since 3.06.01
368 445 *
369 446 * @param array $values
447 + *
370 448 * @return bool
371 449 */
372 450 private static function is_too_long( $values ) {
373 451 return empty( $values['frm_end'] );
@@ -403,8 +481,9 @@
403 481 * @return string|null
404 482 */
405 483 public static function page_preview() {
406 484 $params = FrmForm::list_page_params();
485 +
407 486 if ( ! $params['form'] || is_numeric( $params['form'] ) ) {
408 487 return null;
409 488 }
410 489
@@ -410,8 +489,9 @@
410 489
411 490 self::maybe_block_preview( $params['form'] );
412 491
413 492 $form = FrmForm::getOne( $params['form'] );
493 +
414 494 if ( ! $form ) {
415 495 return null;
416 496 }
417 497
@@ -424,8 +504,9 @@
424 504 * @return void
425 505 */
426 506 public static function show_page_preview() {
427 507 $preview = self::page_preview();
508 +
428 509 if ( is_null( $preview ) ) {
429 510 wp_die(
430 511 '<h1>' . esc_html__( 'Form key is invalid', 'formidable' ) . '</h1>',
431 512 '<p>' . esc_html__( 'Form key is invalid', 'formidable' ) . '</p>',
@@ -455,8 +536,9 @@
455 536 add_filter( 'frm_filter_final_form', 'FrmTestModeController::maybe_add_test_mode_container', 99 );
456 537 }
457 538
458 539 $include_theme = FrmAppHelper::get_param( 'theme', '', 'get', 'absint' );
540 +
459 541 if ( $include_theme ) {
460 542 self::set_preview_query();
461 543 self::load_theme_preview();
462 544 } else {
@@ -479,8 +561,9 @@
479 561 'post_type' => 'page',
480 562 );
481 563
482 564 $page_for_posts = get_option( 'page_for_posts' );
565 +
483 566 if ( is_numeric( $page_for_posts ) ) {
484 567 // Avoid querying for the "Posts Page" or "Blog Page" so we don't display 10 forms.
485 568 $page_query['post__not_in'] = array( $page_for_posts );
486 569 }
@@ -485,13 +568,15 @@
485 568 $page_query['post__not_in'] = array( $page_for_posts );
486 569 }
487 570
488 571 $random_page = get_posts( $page_query );
572 +
489 573 if ( ! $random_page ) {
490 574 return;
491 575 }
492 576
493 577 $random_page = reset( $random_page );
578 +
494 579 if ( ! is_a( $random_page, 'WP_Post' ) ) {
495 580 // The return type can also be int.
496 581 return;
497 582 }
@@ -513,8 +598,9 @@
513 598 *
514 599 * @since 5.5.2
515 600 *
516 601 * @param WP_Post $page The page object.
602 + *
517 603 * @return void
518 604 */
519 605 private static function set_post_global( $page ) {
520 606 global $post;
@@ -533,14 +619,16 @@
533 619 add_action( 'loop_no_results', 'FrmFormsController::show_page_preview' );
534 620 add_filter( 'is_active_sidebar', '__return_false' );
535 621 FrmStylesController::enqueue_css( 'enqueue', true );
536 622
537 - if ( false === get_template_part( 'page' ) ) {
538 - if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) {
539 - add_filter( 'body_class', 'FrmFormsController::preview_block_theme_body_classnames' );
540 - }
541 - self::fallback_when_page_template_part_is_not_supported_by_theme();
623 + if ( false !== get_template_part( 'page' ) ) {
624 + return;
542 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();
543 631 }
544 632
545 633 /**
546 634 * Add padding to the body for block themes.
@@ -547,8 +635,9 @@
547 635 *
548 636 * @since 6.5.2
549 637 *
550 638 * @param array $classes The body classes list.
639 + *
551 640 * @return array
552 641 */
553 642 public static function preview_block_theme_body_classnames( $classes ) {
554 643 $classes[] = 'has-global-padding';
@@ -561,25 +650,27 @@
561 650 *
562 651 * @return void
563 652 */
564 653 private static function fallback_when_page_template_part_is_not_supported_by_theme() {
565 - if ( have_posts() ) {
566 - the_post();
567 - self::get_template( 'header' );
654 + if ( ! have_posts() ) {
655 + return;
656 + }
568 657
569 - // add some generic class names to the container to add some natural padding to the content.
570 - // .entry-content catches the WordPress TwentyTwenty theme.
571 - // .container catches Customizr content.
572 - echo '<div class="container entry-content">';
573 - the_content();
574 - echo '</div>';
658 + the_post();
659 + self::get_template( 'header' );
575 660
576 - // Prevent extra unexpected forms in the footer.
577 - // For some reason this happens in the Twenty Twenty Five theme.
578 - 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>';
579 667
580 - self::get_template( 'footer' );
581 - }
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' );
582 673 }
583 674
584 675 /**
585 676 * Calls core function to get a template part if it doesn't cause deprecation warnings. Otherwise skips the deprecation function call
@@ -585,9 +676,11 @@
585 676 * Calls core function to get a template part if it doesn't cause deprecation warnings. Otherwise skips the deprecation function call
586 677 * and renders required html fragments calling required functions.
587 678 *
588 679 * @since 6.7.1
680 + *
589 681 * @param string $template
682 + *
590 683 * @return void
591 684 */
592 685 private static function get_template( $template ) {
593 686 if ( self::should_try_getting_template( $template ) ) {
@@ -608,9 +701,11 @@
608 701 /**
609 702 * Returns true if calling a template function doesn't trigger deprecation warnings.
610 703 *
611 704 * @since 6.7.1
705 + *
612 706 * @param string $template
707 + *
613 708 * @return bool
614 709 */
615 710 private static function should_try_getting_template( $template ) {
616 711 $stylesheet_path = get_stylesheet_directory();
@@ -624,15 +719,15 @@
624 719 /**
625 720 * Set the page title for the theme preview page
626 721 *
627 722 * @since 3.0
723 + *
724 + * @param string $title
725 + *
726 + * @return string
628 727 */
629 728 public static function preview_page_title( $title ) {
630 - if ( in_the_loop() ) {
631 - $title = self::preview_title( $title );
632 - }
633 -
634 - return $title;
729 + return in_the_loop() ? self::preview_title( $title ) : $title;
635 730 }
636 731
637 732 /**
638 733 * Set the page title for the theme preview page.
@@ -639,8 +734,9 @@
639 734 *
640 735 * @since 3.0
641 736 *
642 737 * @param string $title
738 + *
643 739 * @return string
644 740 */
645 741 public static function preview_title( $title ) {
646 742 return __( 'Form Preview', 'formidable' );
@@ -651,8 +747,9 @@
651 747 *
652 748 * @since 3.0
653 749 *
654 750 * @param string $content
751 + *
655 752 * @return string
656 753 */
657 754 public static function preview_content( $content ) {
658 755 if ( in_the_loop() ) {
@@ -668,8 +765,10 @@
668 765 * @since 3.0
669 766 */
670 767 private static function load_direct_preview() {
671 768 $key = FrmAppHelper::simple_get( 'form', 'sanitize_title' );
769 +
770 + // phpcs:ignore Universal.Operators.StrictComparisons
672 771 if ( $key == '' ) {
673 772 $key = FrmAppHelper::get_post_param( 'form', '', 'sanitize_title' );
674 773 }
675 774
@@ -684,8 +783,9 @@
684 783
685 784 self::maybe_block_preview( $key );
686 785
687 786 $form = FrmForm::getAll( array( 'form_key' => $key ), '', 1 );
787 +
688 788 if ( ! $form ) {
689 789 $error = __( 'Form does not exist', 'formidable' );
690 790 wp_die(
691 791 '<h1>' . esc_html( $error ) . '</h1>',
@@ -709,19 +809,22 @@
709 809 *
710 810 * @since 6.20
711 811 *
712 812 * @param string $form_key Form key.
813 + *
713 814 * @return void
714 815 */
715 816 public static function maybe_block_preview( $form_key ) {
716 - if ( FrmFormsHelper::should_block_preview( $form_key ) ) {
717 - $error = __( 'You do not have permission to view this form', 'formidable' );
718 - wp_die(
719 - '<h1>' . esc_html( $error ) . '</h1>',
720 - '<p>' . esc_html( $error ) . '</p>',
721 - 403
722 - );
817 + if ( ! FrmFormsHelper::should_block_preview( $form_key ) ) {
818 + return;
723 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 + );
724 827 }
725 828
726 829 /**
727 830 * Some themes have a null $src value.
@@ -736,15 +839,13 @@
736 839 add_filter(
737 840 'script_loader_src',
738 841 /**
739 842 * @param string|null $src
843 + *
740 844 * @return string
741 845 */
742 846 function ( $src ) {
743 - if ( is_null( $src ) ) {
744 - $src = '';
745 - }
746 - return $src;
847 + return is_null( $src ) ? '' : $src;
747 848 }
748 849 );
749 850 }
750 851
@@ -753,8 +854,9 @@
753 854 }
754 855
755 856 /**
756 857 * @param array $ids
858 + *
757 859 * @return string
758 860 */
759 861 public static function bulk_untrash( $ids ) {
760 862 FrmAppHelper::permission_check( 'frm_edit_forms' );
@@ -766,11 +868,9 @@
766 868 return '';
767 869 }
768 870
769 871 /* translators: %1$s: Number of forms */
770 - $message = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
771 -
772 - return $message;
872 + return sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
773 873 }
774 874
775 875 /**
776 876 * @since 3.06
@@ -815,8 +915,9 @@
815 915 // Check nonce url.
816 916 check_admin_referer( $status . '_form_' . $params['id'] );
817 917
818 918 $count = 0;
919 +
819 920 if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) {
820 921 ++$count;
821 922 }
822 923
@@ -830,9 +931,9 @@
830 931 /* translators: %1$s: Number of forms */
831 932 $available_status['untrash']['message'] = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
832 933
833 934 /* translators: %1$s: Number of forms, %2$s: Start link HTML, %3$s: End link HTML */
834 - $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
835 936
836 937 $message = $available_status[ $status ]['message'];
837 938
838 939 self::display_forms_list( $params, $message );
@@ -839,8 +940,9 @@
839 940 }
840 941
841 942 /**
842 943 * @param array $ids
944 + *
843 945 * @return string
844 946 */
845 947 public static function bulk_trash( $ids ) {
846 948 FrmAppHelper::permission_check( 'frm_delete_forms' );
@@ -845,8 +947,9 @@
845 947 public static function bulk_trash( $ids ) {
846 948 FrmAppHelper::permission_check( 'frm_delete_forms' );
847 949
848 950 $count = 0;
951 +
849 952 foreach ( $ids as $id ) {
850 953 if ( FrmForm::trash( $id ) ) {
851 954 ++$count;
852 955 }
@@ -861,17 +964,16 @@
861 964 'param' => 'form_type',
862 965 'type' => 'request',
863 966 )
864 967 );
865 - $message = sprintf(
968 +
969 + return sprintf(
866 970 /* translators: %1$s: Number of forms, %2$s: Start link HTML, %3$s: End link HTML */
867 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' ),
868 972 $count,
869 - '<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
870 974 '</a>'
871 975 );
872 -
873 - return $message;
874 976 }
875 977
876 978 public static function destroy() {
877 979 FrmAppHelper::permission_check( 'frm_delete_forms' );
@@ -881,8 +983,9 @@
881 983 // Check nonce url.
882 984 check_admin_referer( 'destroy_form_' . $params['id'] );
883 985
884 986 $count = 0;
987 +
885 988 if ( FrmForm::destroy( $params['id'] ) ) {
886 989 ++$count;
887 990 }
888 991
@@ -893,8 +996,9 @@
893 996 }
894 997
895 998 /**
896 999 * @param array $ids
1000 + *
897 1001 * @return string
898 1002 */
899 1003 public static function bulk_destroy( $ids ) {
900 1004 FrmAppHelper::permission_check( 'frm_delete_forms' );
@@ -899,10 +1003,12 @@
899 1003 public static function bulk_destroy( $ids ) {
900 1004 FrmAppHelper::permission_check( 'frm_delete_forms' );
901 1005
902 1006 $count = 0;
1007 +
903 1008 foreach ( $ids as $id ) {
904 1009 $d = FrmForm::destroy( $id );
1010 +
905 1011 if ( $d ) {
906 1012 ++$count;
907 1013 }
908 1014 }
@@ -920,19 +1026,18 @@
920 1026 */
921 1027 public static function delete_all() {
922 1028 // Check nonce url.
923 1029 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' );
1030 +
924 1031 if ( $permission_error !== false ) {
925 1032 self::display_forms_list( array(), '', array( $permission_error ) );
926 -
927 1033 return;
928 1034 }
929 1035
930 1036 $count = FrmForm::scheduled_delete( time() );
931 1037 $url = remove_query_arg( array( 'delete_all' ) );
1038 + $url .= '&message=forms_permanently_deleted&forms_deleted=' . $count;
932 1039
933 - $url .= '&message=forms_permanently_deleted&forms_deleted=' . $count;
934 -
935 1040 wp_safe_redirect( $url );
936 1041 die();
937 1042 }
938 1043
@@ -1006,21 +1111,22 @@
1006 1111 *
1007 1112 * @return void
1008 1113 */
1009 1114 public static function insert_form_button() {
1010 - if ( current_user_can( 'frm_view_forms' ) ) {
1011 - // Store the result in memory and re-use it when this function is called multiple times.
1012 - // This helps speed up the form builder when there are a lot of HTML fields, where this
1013 - // button is inserted once per HTML field.
1014 - // In a form with 66 HTML fields, this saves 0.5 seconds on page load time, tested locally.
1015 - if ( ! isset( self::$formidable_tinymce_button ) ) {
1016 - FrmAppHelper::load_admin_wide_js();
1017 - $menu_name = FrmAppHelper::get_menu_name();
1018 - $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() );
1019 - 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>';
1020 - }
1021 - echo self::$formidable_tinymce_button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1115 + if ( ! current_user_can( 'frm_view_forms' ) ) {
1116 + return;
1022 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
1023 1129 }
1024 1130
1025 1131 /**
1026 1132 * @return void
@@ -1041,17 +1147,21 @@
1041 1147 $shortcodes = apply_filters( 'frm_popup_shortcodes', $shortcodes );
1042 1148
1043 1149 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/insert_form_popup.php';
1044 1150
1045 - if ( FrmAppHelper::is_form_builder_page() && ! class_exists( '_WP_Editors', false ) ) {
1046 - // initialize a wysiwyg so we have usable settings defined in tinyMCEPreInit.mceInit
1047 - require ABSPATH . WPINC . '/class-wp-editor.php';
1048 - ?>
1049 - <div class="frm_hidden">
1050 - <?php wp_editor( '', 'frm_description_placeholder', array() ); ?>
1051 - </div>
1052 - <?php
1151 + if ( ! FrmAppHelper::is_form_builder_page() || class_exists( '_WP_Editors', false ) ) {
1152 + return;
1053 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
1054 1164 }
1055 1165
1056 1166 /**
1057 1167 * Check the page being loaded, determine if this is a page that should include the form popup.
@@ -1063,8 +1173,9 @@
1063 1173 private static function should_insert_form_popup() {
1064 1174 if ( FrmAppHelper::is_form_builder_page() ) {
1065 1175 return true;
1066 1176 }
1177 +
1067 1178 $page = basename( FrmAppHelper::get_server_value( 'PHP_SELF' ) );
1068 1179 return in_array( $page, array( 'post.php', 'page.php', 'page-new.php', 'post-new.php' ), true );
1069 1180 }
1070 1181
@@ -1072,9 +1183,10 @@
1072 1183 FrmAppHelper::permission_check( 'frm_view_forms' );
1073 1184 check_ajax_referer( 'frm_ajax', 'nonce' );
1074 1185
1075 1186 $shortcode = FrmAppHelper::get_post_param( 'shortcode', '', 'sanitize_text_field' );
1076 - if ( empty( $shortcode ) ) {
1187 +
1188 + if ( ! $shortcode ) {
1077 1189 wp_die();
1078 1190 }
1079 1191
1080 1192 echo '<div id="sc-opts-' . esc_attr( $shortcode ) . '" class="frm_shortcode_option">';
@@ -1099,12 +1211,13 @@
1099 1211 'label' => __( 'Minimize form HTML', 'formidable' ),
1100 1212 ),
1101 1213 );
1102 1214 }
1215 +
1103 1216 $opts = apply_filters( 'frm_sc_popup_opts', $opts, $shortcode );
1104 1217
1105 1218 if ( isset( $opts['form_id'] ) && is_string( $opts['form_id'] ) ) {
1106 - // allow other shortcodes to use the required form id option
1219 + // Allow other shortcodes to use the required form id option
1107 1220 $form_id = $opts['form_id'];
1108 1221 unset( $opts['form_id'] );
1109 1222 }
1110 1223
@@ -1120,8 +1233,9 @@
1120 1233 *
1121 1234 * @param array $params
1122 1235 * @param string $message
1123 1236 * @param array $errors
1237 + *
1124 1238 * @return void
1125 1239 */
1126 1240 public static function display_forms_list( $params = array(), $message = '', $errors = array() ) {
1127 1241 FrmAppHelper::permission_check( 'frm_view_forms' );
@@ -1138,21 +1252,21 @@
1138 1252 * @param string $table_class Class name for List Helper.
1139 1253 */
1140 1254 $table_class = apply_filters( 'frm_forms_list_class', 'FrmFormsListHelper' );
1141 1255 $wp_list_table = new $table_class( compact( 'params' ) );
1256 + $pagenum = $wp_list_table->get_pagenum();
1142 1257
1143 - $pagenum = $wp_list_table->get_pagenum();
1144 -
1145 1258 $wp_list_table->prepare_items();
1146 1259
1147 1260 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
1261 +
1148 1262 if ( $pagenum > $total_pages && $total_pages > 0 ) {
1149 - wp_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) );
1263 + wp_safe_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) );
1150 1264 die();
1151 1265 }
1152 1266
1153 - $inbox = new FrmInbox();
1154 - $error = $inbox->check_for_error();
1267 + $error = FrmInbox::check_for_error();
1268 +
1155 1269 if ( $error ) {
1156 1270 $show_messages = array( $error['subject'] . '. ' . $error['message'] );
1157 1271 }
1158 1272
@@ -1160,8 +1274,9 @@
1160 1274 }
1161 1275
1162 1276 /**
1163 1277 * @param array<string,string> $columns
1278 + *
1164 1279 * @return array<string,string>
1165 1280 */
1166 1281 public static function get_columns( $columns ) {
1167 1282 $columns['cb'] = '<input type="checkbox" />';
@@ -1166,15 +1281,27 @@
1166 1281 public static function get_columns( $columns ) {
1167 1282 $columns['cb'] = '<input type="checkbox" />';
1168 1283 $columns['name'] = esc_html__( 'Form Title', 'formidable' );
1169 1284 $columns['entries'] = esc_html__( 'Entries', 'formidable' );
1285 + $columns['views'] = esc_html__( 'Views', 'formidable' );
1170 1286 $columns['id'] = 'ID';
1171 1287 $columns['form_key'] = esc_html__( 'Key', 'formidable' );
1172 - if ( 'trash' !== FrmAppHelper::simple_get( 'form_type' ) ) {
1288 +
1289 + if ( 'trash' !== FrmAppHelper::simple_get( 'form_type' ) && has_filter( 'frm_form_list_actions' ) ) {
1290 + // If there is any filters added, keep this column.
1173 1291 $columns['shortcode'] = esc_html__( 'Actions', 'formidable' );
1174 1292 }
1293 +
1175 1294 $columns['created_at'] = esc_html__( 'Date', 'formidable' );
1176 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 +
1177 1304 add_screen_option(
1178 1305 'per_page',
1179 1306 array(
1180 1307 'label' => __( 'Forms', 'formidable' ),
@@ -1200,8 +1327,9 @@
1200 1327 }
1201 1328
1202 1329 /**
1203 1330 * @param mixed $hidden_columns
1331 + *
1204 1332 * @return array
1205 1333 */
1206 1334 public static function hidden_columns( $hidden_columns ) {
1207 1335 if ( ! is_array( $hidden_columns ) ) {
@@ -1222,11 +1350,18 @@
1222 1350
1223 1351 return $hidden_columns;
1224 1352 }
1225 1353
1354 + /**
1355 + * @param mixed $save
1356 + * @param string $option
1357 + * @param int|string $value
1358 + *
1359 + * @return mixed
1360 + */
1226 1361 public static function save_per_page( $save, $option, $value ) {
1227 1362 if ( $option === 'formidable_page_formidable_per_page' ) {
1228 - $save = (int) $value;
1363 + return (int) $value;
1229 1364 }
1230 1365
1231 1366 return $save;
1232 1367 }
@@ -1235,8 +1370,9 @@
1235 1370 * @param int|string $id
1236 1371 * @param array $errors
1237 1372 * @param string $message
1238 1373 * @param bool $create_link
1374 + *
1239 1375 * @return void
1240 1376 */
1241 1377 private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
1242 1378 global $frm_vars;
@@ -1251,8 +1387,9 @@
1251 1387 'page' => 'formidable',
1252 1388 )
1253 1389 ),
1254 1390 );
1391 +
1255 1392 if ( ! $form ) {
1256 1393 FrmAppController::show_error_modal( $error_args );
1257 1394 return;
1258 1395 }
@@ -1274,15 +1411,14 @@
1274 1411 }
1275 1412
1276 1413 if ( $form->parent_form_id ) {
1277 1414 /* translators: %1$s: Start link HTML, %2$s: End link HTML */
1278 - 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
1279 1416 }
1280 1417
1281 1418 $frm_field_selection = FrmField::field_selection();
1419 + $fields = FrmField::get_all_for_form( $form->id );
1282 1420
1283 - $fields = FrmField::get_all_for_form( $form->id );
1284 -
1285 1421 // Automatically add end section fields if they don't exist (2.0 migration).
1286 1422 $reset_fields = false;
1287 1423 FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields );
1288 1424 FrmSubmitHelper::maybe_create_submit_field( $form, $fields, $reset_fields );
@@ -1306,9 +1442,10 @@
1306 1442 */
1307 1443 $values['fields'] = apply_filters( 'frm_fields_in_form_builder', $fields, compact( 'form' ) );
1308 1444
1309 1445 $edit_message = __( 'Form was successfully updated.', 'formidable' );
1310 - if ( $form->is_template && $message == $edit_message ) {
1446 +
1447 + if ( $form->is_template && $message === $edit_message ) {
1311 1448 $message = __( 'Template was successfully updated.', 'formidable' );
1312 1449 }
1313 1450
1314 1451 self::maybe_update_form_builder_message( $message );
@@ -1323,11 +1460,12 @@
1323 1460 }
1324 1461
1325 1462 /**
1326 1463 * @param array $fields
1464 + *
1327 1465 * @return array
1328 1466 */
1329 - public static function update_form_builder_fields( $fields, $form ) {
1467 + public static function update_form_builder_fields( $fields ) {
1330 1468 foreach ( $fields as $field ) {
1331 1469 $field->do_not_include_icons = true;
1332 1470 }
1333 1471 return $fields;
@@ -1332,8 +1470,13 @@
1332 1470 }
1333 1471 return $fields;
1334 1472 }
1335 1473
1474 + /**
1475 + * @param string $message
1476 + *
1477 + * @return void
1478 + */
1336 1479 public static function maybe_update_form_builder_message( &$message ) {
1337 1480 if ( 'form_duplicated' === FrmAppHelper::simple_get( 'message' ) ) {
1338 1481 $message = __( 'Form was Successfully Copied', 'formidable' );
1339 1482 }
@@ -1342,8 +1485,9 @@
1342 1485 /**
1343 1486 * @param int|string $id
1344 1487 * @param array $errors
1345 1488 * @param array|string $args
1489 + *
1346 1490 * @return void
1347 1491 */
1348 1492 public static function get_settings_vars( $id, $errors = array(), $args = array() ) {
1349 1493 FrmAppHelper::permission_check( 'frm_edit_forms' );
@@ -1365,13 +1509,12 @@
1365 1509 );
1366 1510 $args = array_merge( $defaults, $args );
1367 1511 $message = $args['message'];
1368 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 );
1369 1516
1370 - $form = FrmForm::getOne( $id );
1371 - $fields = FrmField::get_all_for_form( $id );
1372 - $values = FrmAppHelper::setup_edit_vars( $form, 'forms', $fields, true );
1373 -
1374 1517 /**
1375 1518 * Allows changing fields in the form settings.
1376 1519 *
1377 1520 * @since 5.0.04
@@ -1411,8 +1554,12 @@
1411 1554 }
1412 1555
1413 1556 /**
1414 1557 * @since 4.0
1558 + *
1559 + * @param array $atts
1560 + *
1561 + * @return void
1415 1562 */
1416 1563 public static function form_publish_button( $atts ) {
1417 1564 $values = $atts['values'];
1418 1565 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php';
@@ -1423,8 +1570,9 @@
1423 1570 *
1424 1571 * @since 4.0
1425 1572 *
1426 1573 * @param array $values
1574 + *
1427 1575 * @return array
1428 1576 */
1429 1577 private static function get_settings_tabs( $values ) {
1430 1578 $sections = array(
@@ -1431,19 +1579,24 @@
1431 1579 'advanced' => array(
1432 1580 'name' => __( 'General', 'formidable' ),
1433 1581 'title' => __( 'General Form Settings', 'formidable' ),
1434 1582 'function' => array( self::class, 'advanced_settings' ),
1435 - 'icon' => 'frm_icon_font frm_settings_icon',
1583 + 'icon' => 'frmfont frm_small_settings_icon',
1436 1584 ),
1437 1585 'email' => array(
1438 1586 'name' => __( 'Actions & Notifications', 'formidable' ),
1439 1587 'function' => array( 'FrmFormActionsController', 'email_settings' ),
1440 1588 'id' => 'frm_notification_settings',
1441 - 'icon' => 'frm_icon_font frm_mail_bulk_icon',
1589 + 'icon' => 'frmfont frm_notification_check_icon',
1442 1590 ),
1591 + 'spam' => array(
1592 + 'name' => __( 'Spam', 'formidable' ),
1593 + 'function' => array( self::class, 'spam_settings' ),
1594 + 'icon' => 'frmfont frm_shield_check2_icon',
1595 + ),
1443 1596 'permissions' => array(
1444 1597 'name' => __( 'Form Permissions', 'formidable' ),
1445 - 'icon' => 'frm_icon_font frm_lock_closed_icon',
1598 + 'icon' => 'frmfont frm_lock_closed2_icon',
1446 1599 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1447 1600 'data' => array(
1448 1601 'medium' => 'permissions',
1449 1602 'upgrade' => __( 'Form Permissions', 'formidable' ),
@@ -1448,18 +1601,20 @@
1448 1601 'medium' => 'permissions',
1449 1602 'upgrade' => __( 'Form Permissions', 'formidable' ),
1450 1603 'message' => __( 'Allow editing, protect forms and files, limit entries, and save drafts. Upgrade to get form and entry permissions.', 'formidable' ),
1451 1604 'screenshot' => 'permissions.png',
1605 + 'learn-more' => FrmAppHelper::get_doc_url( 'general-form-settings/#kb-form-permissions', 'form-permissions-settings' ),
1452 1606 ),
1453 1607 ),
1454 1608 'scheduling' => array(
1455 1609 'name' => __( 'Form Scheduling', 'formidable' ),
1456 - 'icon' => 'frm_icon_font frm_calendar_icon',
1610 + 'icon' => 'frmfont frm_schedule_icon',
1457 1611 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1458 1612 'data' => array(
1459 1613 'medium' => 'scheduling',
1460 1614 'upgrade' => __( 'Form scheduling settings', 'formidable' ),
1461 1615 'screenshot' => 'scheduling.png',
1616 + 'learn-more' => FrmAppHelper::get_doc_url( 'general-form-settings/#kb-form-scheduling', 'form-scheduling-settings' ),
1462 1617 ),
1463 1618 ),
1464 1619 'buttons' => array(
1465 1620 'name' => __( 'Buttons', 'formidable' ),
@@ -1464,19 +1619,19 @@
1464 1619 'buttons' => array(
1465 1620 'name' => __( 'Buttons', 'formidable' ),
1466 1621 'class' => self::class,
1467 1622 'function' => 'buttons_settings',
1468 - 'icon' => 'frm_icon_font frm_button_icon',
1623 + 'icon' => 'frmfont frm-buttons-style',
1469 1624 ),
1470 1625 'landing' => array(
1471 1626 'name' => __( 'Form Landing Page', 'formidable' ),
1472 - 'icon' => 'frm_icon_font frm_file_text_icon',
1627 + 'icon' => 'frmfont frm_cross_device_icon',
1473 1628 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1474 1629 'data' => FrmAppHelper::get_landing_page_upgrade_data_params(),
1475 1630 ),
1476 1631 'chat' => array(
1477 1632 'name' => __( 'Conversational Forms', 'formidable' ),
1478 - 'icon' => 'frm_icon_font frm_chat_forms_icon',
1633 + 'icon' => 'frmfont frm_chat_bubbles_icon',
1479 1634 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1480 1635 'data' => FrmAppHelper::get_upgrade_data_params(
1481 1636 'chat',
1482 1637 array(
@@ -1482,14 +1637,15 @@
1482 1637 array(
1483 1638 'upgrade' => __( 'Conversational Forms', 'formidable' ),
1484 1639 'message' => __( 'Ask one question at a time for automated conversations.', 'formidable' ),
1485 1640 'screenshot' => 'chat.png',
1641 + 'learn-more' => FrmAppHelper::get_doc_url( 'conversational-forms', 'conversational-forms-settings', false ),
1486 1642 )
1487 1643 ),
1488 1644 ),
1489 1645 'abandonment' => array(
1490 1646 'name' => __( 'Form Abandonment', 'formidable' ),
1491 - 'icon' => 'frm_icon_font frm_abandoned_icon',
1647 + 'icon' => 'frmfont frm_abandoned_icon',
1492 1648 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1493 1649 'data' => FrmAppHelper::get_upgrade_data_params(
1494 1650 'abandonment',
1495 1651 array(
@@ -1495,8 +1651,9 @@
1495 1651 array(
1496 1652 'upgrade' => __( 'Form abandonment settings', 'formidable' ),
1497 1653 'message' => __( 'Unlock the power of data capture to boost lead generation and master the art of form optimization.', 'formidable' ),
1498 1654 'screenshot' => 'abandonment.png',
1655 + 'learn-more' => FrmAppHelper::get_doc_url( 'features/form-abandonment-wordpress-plugin', 'form-abandonment-settings', false ),
1499 1656 )
1500 1657 ),
1501 1658 ),
1502 1659 'html' => array(
@@ -1502,9 +1659,9 @@
1502 1659 'html' => array(
1503 1660 'name' => __( 'Customize HTML', 'formidable' ),
1504 1661 'class' => self::class,
1505 1662 'function' => 'html_settings',
1506 - 'icon' => 'frm_icon_font frm_code_icon',
1663 + 'icon' => 'frmfont frm_code2_icon',
1507 1664 ),
1508 1665 );
1509 1666
1510 1667 if ( ! has_action( 'frm_add_form_style_tab_options' ) && ! has_action( 'frm_add_form_button_options' ) ) {
@@ -1510,14 +1667,8 @@
1510 1667 if ( ! has_action( 'frm_add_form_style_tab_options' ) && ! has_action( 'frm_add_form_button_options' ) ) {
1511 1668 unset( $sections['buttons'] );
1512 1669 }
1513 1670
1514 - foreach ( array( 'landing', 'chat', 'abandonment' ) as $feature ) {
1515 - if ( ! FrmAppHelper::show_new_feature( $feature ) ) {
1516 - unset( $sections[ $feature ] );
1517 - }
1518 - }
1519 -
1520 1671 $sections = apply_filters( 'frm_add_form_settings_section', $sections, $values );
1521 1672
1522 1673 foreach ( $sections as $key => $section ) {
1523 1674 $defaults = array(
@@ -1522,9 +1673,9 @@
1522 1673 foreach ( $sections as $key => $section ) {
1523 1674 $defaults = array(
1524 1675 'html_class' => '',
1525 1676 'name' => ucfirst( $key ),
1526 - 'icon' => 'frm_icon_font frm_settings_icon',
1677 + 'icon' => 'frmfont frm_settings_icon',
1527 1678 );
1528 1679
1529 1680 $section = array_merge( $defaults, $section );
1530 1681
@@ -1530,8 +1681,9 @@
1530 1681
1531 1682 if ( ! isset( $section['anchor'] ) ) {
1532 1683 $section['anchor'] = $key;
1533 1684 }
1685 +
1534 1686 $section['anchor'] .= '_settings';
1535 1687
1536 1688 if ( ! isset( $section['title'] ) ) {
1537 1689 $section['title'] = $section['name'];
@@ -1550,26 +1702,25 @@
1550 1702 /**
1551 1703 * @since 4.0
1552 1704 *
1553 1705 * @param array $values
1706 + *
1554 1707 * @return void
1555 1708 */
1556 1709 public static function advanced_settings( $values ) {
1557 1710 $first_h3 = 'frm_first_h3';
1558 -
1559 1711 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-advanced.php';
1560 1712 }
1561 1713
1562 1714 /**
1715 + * @since 6.33
1716 + *
1563 1717 * @param array $values
1718 + *
1564 1719 * @return void
1565 1720 */
1566 - public static function render_spam_settings( $values ) {
1567 - if ( function_exists( 'akismet_http_post' ) ) {
1568 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/akismet.php';
1569 - }
1570 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/stopforumspam.php';
1571 - 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';
1572 1723 }
1573 1724
1574 1725 /**
1575 1726 * @since 4.0
@@ -1574,8 +1725,9 @@
1574 1725 /**
1575 1726 * @since 4.0
1576 1727 *
1577 1728 * @param array $values
1729 + *
1578 1730 * @return void
1579 1731 */
1580 1732 public static function buttons_settings( $values ) {
1581 1733 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php';
@@ -1584,8 +1736,9 @@
1584 1736 /**
1585 1737 * @since 4.0
1586 1738 *
1587 1739 * @param array $values
1740 + *
1588 1741 * @return void
1589 1742 */
1590 1743 public static function html_settings( $values ) {
1591 1744 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php';
@@ -1596,8 +1749,9 @@
1596 1749 *
1597 1750 * @since 2.03.08
1598 1751 *
1599 1752 * @param array|bool $values
1753 + *
1600 1754 * @return void
1601 1755 */
1602 1756 private static function clean_submit_html( &$values ) {
1603 1757 if ( is_array( $values ) && isset( $values['submit_html'] ) ) {
@@ -1620,13 +1774,17 @@
1620 1774 return $classes;
1621 1775 }
1622 1776
1623 1777 /**
1778 + * @since 6.27 Added $template_path parameter.
1779 + *
1624 1780 * @param int|string $form_id
1625 1781 * @param string $class
1782 + * @param string $template_path The path to a template file to use instead of the default.
1783 + *
1626 1784 * @return void
1627 1785 */
1628 - public static function mb_tags_box( $form_id, $class = '' ) {
1786 + public static function mb_tags_box( $form_id, $class = '', $template_path = 'default' ) {
1629 1787 $fields = FrmField::get_all_for_form( $form_id, '', 'include' );
1630 1788
1631 1789 /**
1632 1790 * Allows modifying the list of fields in the tags box.
@@ -1635,23 +1793,30 @@
1635 1793 *
1636 1794 * @param array $fields The list of fields.
1637 1795 * @param array $args The arguments. Contains `form_id`.
1638 1796 */
1639 - $fields = apply_filters( 'frm_fields_in_tags_box', $fields, compact( 'form_id' ) );
1640 - $linked_forms = array();
1641 - $col = 'one';
1642 - $settings_tab = FrmAppHelper::is_admin_page( 'formidable' );
1643 -
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' );
1644 1801 $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() );
1645 - $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' ) );
1646 1804
1647 - $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 + }
1648 1809
1649 - include FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php';
1810 + include $template_path;
1650 1811 }
1651 1812
1652 1813 /**
1653 1814 * @since 3.04.01
1815 + *
1816 + * @param array $atts
1817 + *
1818 + * @return array
1654 1819 */
1655 1820 private static function advanced_helpers( $atts ) {
1656 1821 $advanced_helpers = array(
1657 1822 'default' => array(
@@ -1660,10 +1825,12 @@
1660 1825 ),
1661 1826 );
1662 1827
1663 1828 $user_fields = self::user_shortcodes();
1829 +
1664 1830 if ( $user_fields ) {
1665 1831 $user_helpers = array();
1832 +
1666 1833 foreach ( $user_fields as $uk => $uf ) {
1667 1834 $user_helpers[ '|user_id| show="' . $uk . '"' ] = $uf;
1668 1835 unset( $uk, $uf );
1669 1836 }
@@ -1684,12 +1851,132 @@
1684 1851 return apply_filters( 'frm_advanced_helpers', $advanced_helpers, $atts );
1685 1852 }
1686 1853
1687 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 + /**
1688 1973 * Get an array of the options to display in the advanced tab
1689 1974 * of the customization panel
1690 1975 *
1691 1976 * @since 2.0.6
1977 + *
1978 + * @return array
1692 1979 */
1693 1980 private static function get_advanced_shortcodes() {
1694 1981 $adv_shortcodes = array(
1695 1982 'x sep=", "' => array(
@@ -1706,17 +1993,18 @@
1706 1993 'label' => __( 'No Auto P', 'formidable' ),
1707 1994 'title' => __( 'Do not automatically add any paragraphs or line breaks', 'formidable' ),
1708 1995 ),
1709 1996 );
1710 - $adv_shortcodes = apply_filters( 'frm_advanced_shortcodes', $adv_shortcodes );
1711 1997
1712 1998 // __( 'Leave blank instead of defaulting to User Login', 'formidable' ) : blank=1
1713 1999
1714 - return $adv_shortcodes;
2000 + return apply_filters( 'frm_advanced_shortcodes', $adv_shortcodes );
1715 2001 }
1716 2002
1717 2003 /**
1718 2004 * @since 3.04.01
2005 + *
2006 + * @return array
1719 2007 */
1720 2008 private static function user_shortcodes() {
1721 2009 $options = array(
1722 2010 'ID' => __( 'User ID', 'formidable' ),
@@ -1735,10 +2023,15 @@
1735 2023 /**
1736 2024 * Get an array of the helper shortcodes to display in the customization panel
1737 2025 *
1738 2026 * @since 2.0.6
2027 + *
2028 + * @param bool $settings_tab
2029 + * @param int $form_id
2030 + *
2031 + * @return array
1739 2032 */
1740 - private static function get_shortcode_helpers( $settings_tab ) {
2033 + private static function get_shortcode_helpers( $settings_tab, $form_id = 0 ) {
1741 2034 $entry_shortcodes = array(
1742 2035 'id' => __( 'Entry ID', 'formidable' ),
1743 2036 'key' => __( 'Entry Key', 'formidable' ),
1744 2037 'post_id' => __( 'Post ID', 'formidable' ),
@@ -1751,8 +2044,9 @@
1751 2044 'form_name' => __( 'Form Name', 'formidable' ),
1752 2045 );
1753 2046
1754 2047 $entry_shortcodes = array_merge( FrmShortcodeHelper::get_contextual_shortcode_values(), $entry_shortcodes );
2048 +
1755 2049 if ( ! FrmAppHelper::pro_is_installed() ) {
1756 2050 unset( $entry_shortcodes['post_id'] );
1757 2051 }
1758 2052
@@ -1760,12 +2054,14 @@
1760 2054 * Use this hook to add or remove buttons in the helpers section
1761 2055 * in the customization panel
1762 2056 *
1763 2057 * @since 2.0.6
2058 + *
2059 + * @param array $entry_shortcodes
2060 + * @param bool $settings_tab
2061 + * @param int $form_id
1764 2062 */
1765 - $entry_shortcodes = apply_filters( 'frm_helper_shortcodes', $entry_shortcodes, $settings_tab );
1766 -
1767 - return $entry_shortcodes;
2063 + return apply_filters( 'frm_helper_shortcodes', $entry_shortcodes, $settings_tab, $form_id );
1768 2064 }
1769 2065
1770 2066 /**
1771 2067 * Insert the form class setting into the form.
@@ -1770,8 +2066,9 @@
1770 2066 /**
1771 2067 * Insert the form class setting into the form.
1772 2068 *
1773 2069 * @param stdClass $form
2070 + *
1774 2071 * @return void
1775 2072 */
1776 2073 public static function form_classes( $form ) {
1777 2074 if ( isset( $form->options['form_class'] ) ) {
@@ -1794,8 +2091,9 @@
1794 2091 * @param stdClass $form
1795 2092 */
1796 2093 public static function add_js_validate_form_to_global_vars( $form ) {
1797 2094 global $frm_vars;
2095 +
1798 2096 if ( ! isset( $frm_vars['js_validate_forms'] ) ) {
1799 2097 $frm_vars['js_validate_forms'] = array();
1800 2098 }
1801 2099 $frm_vars['js_validate_forms'][ $form->id ] = $form;
@@ -1818,8 +2116,9 @@
1818 2116 /**
1819 2117 * @param string $content
1820 2118 * @param int|stdClass|string $form
1821 2119 * @param false|int|stdClass|string $entry
2120 + *
1822 2121 * @return string
1823 2122 */
1824 2123 public static function filter_content( $content, $form, $entry = false ) {
1825 2124 $content = self::replace_form_name_shortcodes( $content, $form );
@@ -1824,8 +2123,9 @@
1824 2123 public static function filter_content( $content, $form, $entry = false ) {
1825 2124 $content = self::replace_form_name_shortcodes( $content, $form );
1826 2125
1827 2126 self::get_entry_by_param( $entry );
2127 +
1828 2128 if ( ! $entry ) {
1829 2129 return $content;
1830 2130 }
1831 2131
@@ -1841,11 +2141,10 @@
1841 2141 $form = $entry->parent_entry->form_id;
1842 2142 }
1843 2143
1844 2144 $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form );
1845 - $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
1846 2145
1847 - return $content;
2146 + return apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
1848 2147 }
1849 2148
1850 2149 /**
1851 2150 * Replace any [form_name] shortcodes in a string.
@@ -1853,8 +2152,9 @@
1853 2152 * @since 5.5
1854 2153 *
1855 2154 * @param array|string $string
1856 2155 * @param int|stdClass|string $form
2156 + *
1857 2157 * @return array|string
1858 2158 */
1859 2159 public static function replace_form_name_shortcodes( $string, $form ) {
1860 2160 if ( ! is_string( $string ) ) {
@@ -1860,9 +2160,9 @@
1860 2160 if ( ! is_string( $string ) ) {
1861 2161 return $string;
1862 2162 }
1863 2163
1864 - if ( false === strpos( $string, '[form_name]' ) ) {
2164 + if ( ! str_contains( $string, '[form_name]' ) ) {
1865 2165 return $string;
1866 2166 }
1867 2167
1868 2168 if ( ! is_object( $form ) ) {
@@ -1874,20 +2174,30 @@
1874 2174 }
1875 2175
1876 2176 /**
1877 2177 * @param false|int|stdClass|string $entry
2178 + *
1878 2179 * @return void
1879 2180 */
1880 2181 private static function get_entry_by_param( &$entry ) {
1881 - if ( ! $entry || ! is_object( $entry ) ) {
1882 - if ( ! $entry || ! is_numeric( $entry ) ) {
1883 - $entry = FrmAppHelper::get_post_param( 'id', false, 'sanitize_title' );
1884 - }
2182 + if ( $entry && is_object( $entry ) ) {
2183 + return;
2184 + }
1885 2185
1886 - FrmEntry::maybe_get_entry( $entry );
2186 + if ( ! $entry || ! is_numeric( $entry ) ) {
2187 + $entry = FrmAppHelper::get_post_param( 'id', false, 'sanitize_title' );
1887 2188 }
2189 +
2190 + FrmEntry::maybe_get_entry( $entry );
1888 2191 }
1889 2192
2193 + /**
2194 + * @param string $content
2195 + * @param false|object $entry
2196 + * @param array $shortcodes
2197 + *
2198 + * @return string
2199 + */
1890 2200 public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
1891 2201 return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes );
1892 2202 }
1893 2203
@@ -1892,8 +2202,9 @@
1892 2202 }
1893 2203
1894 2204 /**
1895 2205 * @param array $errors
2206 + *
1896 2207 * @return array
1897 2208 */
1898 2209 public static function process_bulk_form_actions( $errors ) {
1899 2210 if ( ! $_REQUEST ) {
@@ -1900,29 +2211,30 @@
1900 2211 return $errors;
1901 2212 }
1902 2213
1903 2214 $bulkaction = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
2215 +
2216 + // phpcs:ignore Universal.Operators.StrictComparisons
1904 2217 if ( $bulkaction == - 1 ) {
1905 2218 $bulkaction = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
1906 2219 }
1907 2220
1908 - if ( ! empty( $bulkaction ) && strpos( $bulkaction, 'bulk_' ) === 0 ) {
2221 + if ( $bulkaction && str_starts_with( $bulkaction, 'bulk_' ) ) {
1909 2222 FrmAppHelper::remove_get_action();
1910 -
1911 2223 $bulkaction = str_replace( 'bulk_', '', $bulkaction );
1912 2224 }
1913 2225
1914 2226 $ids = FrmAppHelper::get_param( 'item-action', '', 'get', 'sanitize_text_field' );
1915 - if ( empty( $ids ) ) {
2227 +
2228 + if ( ! $ids ) {
1916 2229 $errors[] = __( 'No forms were specified', 'formidable' );
1917 -
1918 2230 return $errors;
1919 2231 }
1920 2232
1921 2233 $permission_error = FrmAppHelper::permission_nonce_error( '', '_wpnonce', 'bulk-toplevel_page_formidable' );
2234 +
1922 2235 if ( $permission_error !== false ) {
1923 2236 $errors[] = $permission_error;
1924 -
1925 2237 return $errors;
1926 2238 }
1927 2239
1928 2240 if ( ! is_array( $ids ) ) {
@@ -1950,8 +2262,9 @@
1950 2262 /**
1951 2263 * Includes html that shows a message when the device is too small to use Formidable Forms admin pages.
1952 2264 *
1953 2265 * @since 6.20
2266 + *
1954 2267 * @return void
1955 2268 */
1956 2269 public static function include_device_too_small_message() {
1957 2270 if ( ! FrmAppHelper::is_formidable_admin() ) {
@@ -1960,12 +2273,13 @@
1960 2273
1961 2274 include FrmAppHelper::plugin_path() . '/classes/views/shared/small-device-message.php';
1962 2275 }
1963 2276
1964 - public static function route() {
2277 + public static function route() { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.MaxExceeded
1965 2278 $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
1966 2279 $vars = array();
1967 2280 FrmAppHelper::include_svg();
2281 +
1968 2282 if ( isset( $_POST['frm_compact_fields'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
1969 2283 FrmAppHelper::permission_check( 'frm_edit_forms' );
1970 2284
1971 2285 // Javascript needs to be allowed in some field settings.
@@ -1971,25 +2285,28 @@
1971 2285 // Javascript needs to be allowed in some field settings.
1972 2286 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
1973 2287 $json_vars = htmlspecialchars_decode( nl2br( str_replace( '&quot;', '"', wp_unslash( $_POST['frm_compact_fields'] ) ) ) );
1974 2288 $json_vars = json_decode( $json_vars, true );
1975 - if ( empty( $json_vars ) ) {
1976 - // json decoding failed so we should return an error message.
2289 +
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.
1977 2298 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
2299 +
1978 2300 if ( 'edit' === $action ) {
1979 2301 $action = 'update';
1980 2302 }
1981 2303
1982 2304 add_filter( 'frm_validate_form', 'FrmFormsController::json_error' );
1983 - } else {
1984 - $vars = FrmAppHelper::json_to_array( $json_vars );
1985 - $action = $vars[ $action ];
1986 - unset( $_REQUEST['frm_compact_fields'], $_POST['frm_compact_fields'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
1987 - $_REQUEST = array_merge( $_REQUEST, $vars ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
1988 - $_POST = array_merge( $_POST, $_REQUEST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
1989 2305 }
1990 2306 } else {
1991 2307 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
2308 +
1992 2309 if ( isset( $_REQUEST['delete_all'] ) ) {
1993 2310 // Override the action for this page.
1994 2311 $action = 'delete_all';
1995 2312 }
@@ -2009,34 +2326,38 @@
2009 2326 case 'update_settings':
2010 2327 return self::$action( $vars );
2011 2328 case 'lite-reports':
2012 2329 self::no_reports( $vars );
2013 - return;
2330 + return null;
2014 2331 case 'views':
2015 2332 self::no_views( $vars );
2016 - return;
2333 + return null;
2017 2334 default:
2018 2335 do_action( 'frm_form_action_' . $action );
2336 +
2019 2337 if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) {
2020 - return;
2338 + return null;
2021 2339 }
2022 2340
2023 2341 $action = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
2342 +
2343 + // phpcs:ignore Universal.Operators.StrictComparisons
2024 2344 if ( $action == - 1 ) {
2025 2345 $action = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
2026 2346 }
2027 2347
2028 - if ( strpos( $action, 'bulk_' ) === 0 ) {
2348 + if ( str_starts_with( $action, 'bulk_' ) ) {
2029 2349 FrmAppHelper::remove_get_action();
2030 2350
2031 2351 self::list_form();
2032 - return;
2352 + return null;
2033 2353 }
2034 2354
2035 2355 $message = FrmAppHelper::get_param( 'message' );
2356 +
2036 2357 if ( 'form_duplicate_error' === $message ) {
2037 2358 self::display_forms_list( array(), '', array( __( 'There was a problem duplicating the form', 'formidable' ) ) );
2038 - return;
2359 + return null;
2039 2360 }
2040 2361
2041 2362 if ( 'forms_permanently_deleted' === $message ) {
2042 2363 $count = FrmAppHelper::get_param( 'forms_deleted', 0, 'get', 'absint' );
@@ -2042,14 +2363,14 @@
2042 2363 $count = FrmAppHelper::get_param( 'forms_deleted', 0, 'get', 'absint' );
2043 2364 /* translators: %1$s: Number of forms */
2044 2365 $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
2045 2366 self::display_forms_list( array(), $message, '' );
2046 - return;
2367 + return null;
2047 2368 }
2048 2369
2049 2370 self::display_forms_list();
2050 2371
2051 - return;
2372 + return null;
2052 2373 }//end switch
2053 2374 }
2054 2375
2055 2376 /**
@@ -2068,10 +2389,10 @@
2068 2389
2069 2390 // Get posted data
2070 2391 $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
2071 2392 $name = FrmAppHelper::get_post_param( 'form_name', '', 'sanitize_text_field' );
2393 + $form = FrmForm::getOne( $form_id );
2072 2394
2073 - $form = FrmForm::getOne( $form_id );
2074 2395 if ( ! $form ) {
2075 2396 wp_send_json_error( __( 'Form not found', 'formidable' ) );
2076 2397 }
2077 2398
@@ -2076,9 +2397,10 @@
2076 2397 }
2077 2398
2078 2399 if ( $name === $form->name ) {
2079 2400 // Nothing to change so exit early.
2080 - wp_send_json_success();
2401 + $form_key = $form->form_key;
2402 + wp_send_json_success( compact( 'form_key' ) );
2081 2403 }
2082 2404
2083 2405 $to_update = array(
2084 2406 'name' => $name,
@@ -2083,14 +2405,14 @@
2083 2405 $to_update = array(
2084 2406 'name' => $name,
2085 2407 );
2086 2408
2087 - if ( '' !== $name ) {
2409 + if ( '' === $name ) {
2410 + $form_key = $form->form_key;
2411 + } else {
2088 2412 // Only update form_key if name is not empty.
2089 2413 $form_key = FrmAppHelper::get_unique_key( sanitize_title( $name ), 'frm_forms', 'form_key' );
2090 2414 $to_update['form_key'] = $form_key;
2091 - } else {
2092 - $form_key = $form->form_key;
2093 2415 }
2094 2416
2095 2417 FrmForm::update( $form_id, $to_update );
2096 2418
@@ -2096,11 +2418,15 @@
2096 2418
2097 2419 wp_send_json_success( compact( 'form_key' ) );
2098 2420 }
2099 2421
2422 + /**
2423 + * @param array $errors
2424 + *
2425 + * @return array
2426 + */
2100 2427 public static function json_error( $errors ) {
2101 2428 $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
2102 -
2103 2429 return $errors;
2104 2430 }
2105 2431
2106 2432 /**
@@ -2107,8 +2433,10 @@
2107 2433 * Add education about views.
2108 2434 *
2109 2435 * @since 4.07
2110 2436 *
2437 + * @param array $values
2438 + *
2111 2439 * @return void
2112 2440 */
2113 2441 public static function no_views( $values = array() ) {
2114 2442 FrmAppHelper::include_svg();
@@ -2122,8 +2450,10 @@
2122 2450 * Add education about reports.
2123 2451 *
2124 2452 * @since 4.07
2125 2453 *
2454 + * @param array $values
2455 + *
2126 2456 * @return void
2127 2457 */
2128 2458 public static function no_reports( $values = array() ) {
2129 2459 $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
@@ -2149,10 +2479,9 @@
2149 2479 /**
2150 2480 * @since 4.05.02
2151 2481 */
2152 2482 private static function move_menu_to_footer() {
2153 - $settings = FrmAppHelper::get_settings();
2154 - if ( empty( $settings->admin_bar ) ) {
2483 + if ( empty( FrmAppHelper::get_settings()->admin_bar ) ) {
2155 2484 remove_action( 'wp_body_open', 'wp_admin_bar_render', 0 );
2156 2485 }
2157 2486 }
2158 2487
@@ -2157,13 +2486,15 @@
2157 2486 }
2158 2487
2159 2488 public static function admin_bar_configure() {
2160 2489 global $frm_vars;
2490 +
2161 2491 if ( empty( $frm_vars['forms_loaded'] ) ) {
2162 2492 return;
2163 2493 }
2164 2494
2165 2495 $actions = array();
2496 +
2166 2497 foreach ( $frm_vars['forms_loaded'] as $form ) {
2167 2498 if ( is_object( $form ) ) {
2168 2499 $actions[ $form->id ] = $form->name;
2169 2500 }
@@ -2169,9 +2500,9 @@
2169 2500 }
2170 2501 unset( $form );
2171 2502 }
2172 2503
2173 - if ( empty( $actions ) ) {
2504 + if ( ! $actions ) {
2174 2505 return;
2175 2506 }
2176 2507
2177 2508 self::add_menu_to_admin_bar();
@@ -2197,8 +2528,12 @@
2197 2528 }
2198 2529
2199 2530 /**
2200 2531 * @since 2.05.07
2532 + *
2533 + * @param array $actions
2534 + *
2535 + * @return void
2201 2536 */
2202 2537 private static function add_forms_to_admin_bar( $actions ) {
2203 2538 global $wp_admin_bar;
2204 2539
@@ -2204,14 +2539,13 @@
2204 2539
2205 2540 asort( $actions );
2206 2541
2207 2542 foreach ( $actions as $form_id => $name ) {
2208 -
2209 2543 $wp_admin_bar->add_node(
2210 2544 array(
2211 2545 'parent' => 'frm-forms',
2212 2546 'id' => 'edit_form_' . $form_id,
2213 - 'title' => empty( $name ) ? FrmFormsHelper::get_no_title_text() : $name,
2547 + 'title' => $name ? $name : FrmFormsHelper::get_no_title_text(),
2214 2548 'href' => FrmForm::get_edit_link( $form_id ),
2215 2549 )
2216 2550 );
2217 2551 }
@@ -2220,12 +2554,14 @@
2220 2554 /**
2221 2555 * The formidable shortcode
2222 2556 *
2223 2557 * @param array $atts The params from the shortcode.
2558 + *
2224 2559 * @return string
2225 2560 */
2226 2561 public static function get_form_shortcode( $atts ) {
2227 2562 global $frm_vars;
2563 +
2228 2564 if ( ! empty( $frm_vars['skip_shortcode'] ) ) {
2229 2565 $sc = '[formidable';
2230 2566 $sc .= FrmAppHelper::array_to_html_params( $atts );
2231 2567 return $sc . ']';
@@ -2254,8 +2590,9 @@
2254 2590 * @since 5.2.01
2255 2591 *
2256 2592 * @param false|int|string $id
2257 2593 * @param false|string $key
2594 + *
2258 2595 * @return false|stdClass
2259 2596 */
2260 2597 private static function maybe_get_form_by_id_or_key( $id, $key ) {
2261 2598 if ( ! $id ) {
@@ -2269,8 +2606,9 @@
2269 2606 * @param false|string $key
2270 2607 * @param bool|int|string $title may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
2271 2608 * @param bool|int|string $description may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
2272 2609 * @param array $atts
2610 + *
2273 2611 * @return string
2274 2612 */
2275 2613 public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) {
2276 2614 $form = self::maybe_get_form_by_id_or_key( $id, $key );
@@ -2291,14 +2629,13 @@
2291 2629
2292 2630 add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
2293 2631 FrmAppHelper::trigger_hook_load( 'form', $form );
2294 2632
2295 - $form = apply_filters( 'frm_pre_display_form', $form );
2296 -
2633 + $form = apply_filters( 'frm_pre_display_form', $form );
2297 2634 $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) );
2298 2635
2299 2636 if ( self::is_viewable_draft_form( $form ) ) {
2300 - // don't show a draft form on a page
2637 + // Don't show a draft form on a page
2301 2638 $form = __( 'Please select a valid form', 'formidable' );
2302 2639 } elseif ( ! FrmForm::is_visible_to_user( $form ) ) {
2303 2640 $form = do_shortcode( $frm_settings->login_msg );
2304 2641 } else {
@@ -2318,16 +2655,18 @@
2318 2655 }
2319 2656
2320 2657 /**
2321 2658 * @param false|int|string $id
2659 + *
2322 2660 * @return false|stdClass
2323 2661 */
2324 2662 private static function maybe_get_form_to_show( $id ) {
2325 2663 $form = false;
2326 2664
2327 - if ( ! empty( $id ) ) {
2665 + if ( $id ) {
2328 2666 // Form id or key is set.
2329 2667 $form = FrmForm::getOne( $id );
2668 +
2330 2669 if ( ! $form || $form->parent_form_id || $form->status === 'trash' ) {
2331 2670 $form = false;
2332 2671 }
2333 2672 }
@@ -2334,12 +2673,25 @@
2334 2673
2335 2674 return $form;
2336 2675 }
2337 2676
2677 + /**
2678 + * @param object $form
2679 + *
2680 + * @return bool
2681 + */
2338 2682 private static function is_viewable_draft_form( $form ) {
2339 2683 return $form->status === 'draft' && current_user_can( 'frm_edit_forms' ) && ! FrmAppHelper::is_preview_page();
2340 2684 }
2341 2685
2686 + /**
2687 + * @param object $form
2688 + * @param bool $title
2689 + * @param bool $description
2690 + * @param array $atts
2691 + *
2692 + * @return string
2693 + */
2342 2694 public static function get_form( $form, $title, $description, $atts = array() ) {
2343 2695 ob_start();
2344 2696
2345 2697 do_action( 'frm_before_get_form', $atts );
@@ -2346,10 +2698,9 @@
2346 2698
2347 2699 self::get_form_contents( $form, $title, $description, $atts );
2348 2700 self::enqueue_scripts( FrmForm::get_params( $form ) );
2349 2701
2350 - $contents = ob_get_contents();
2351 - ob_end_clean();
2702 + $contents = ob_get_clean();
2352 2703
2353 2704 self::maybe_minimize_form( $atts, $contents );
2354 2705
2355 2706 return $contents;
@@ -2354,12 +2705,25 @@
2354 2705
2355 2706 return $contents;
2356 2707 }
2357 2708
2709 + /**
2710 + * @param array $params
2711 + *
2712 + * @return void
2713 + */
2358 2714 public static function enqueue_scripts( $params ) {
2359 2715 do_action( 'frm_enqueue_form_scripts', $params );
2360 2716 }
2361 2717
2718 + /**
2719 + * @param object $form
2720 + * @param bool $title
2721 + * @param bool $description
2722 + * @param array $atts
2723 + *
2724 + * @return void
2725 + */
2362 2726 public static function get_form_contents( $form, $title, $description, $atts ) {
2363 2727 $params = FrmForm::get_params( $form );
2364 2728 $errors = self::get_saved_errors( $form, $params );
2365 2729 $fields = FrmFieldsHelper::get_form_fields( $form->id, $errors );
@@ -2366,9 +2730,10 @@
2366 2730 $reset = false;
2367 2731 $pass_args = compact( 'form', 'fields', 'errors', 'title', 'description', 'reset' );
2368 2732
2369 2733 $pass_args['action'] = $params['action'];
2370 - $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;
2371 2736
2372 2737 if ( ! $handle_process_here ) {
2373 2738 FrmFormState::set_initial_value( 'title', $title );
2374 2739 FrmFormState::set_initial_value( 'description', $description );
@@ -2373,16 +2738,15 @@
2373 2738 FrmFormState::set_initial_value( 'title', $title );
2374 2739 FrmFormState::set_initial_value( 'description', $description );
2375 2740
2376 2741 do_action( 'frm_display_form_action', $params, $fields, $form, $title, $description );
2742 +
2377 2743 if ( apply_filters( 'frm_continue_to_new', true, $form->id, $params['action'] ) ) {
2378 2744 self::show_form_after_submit( $pass_args );
2379 2745 }
2380 - } elseif ( ! empty( $errors ) ) {
2746 + } elseif ( $errors ) {
2381 2747 self::show_form_after_submit( $pass_args );
2382 -
2383 2748 } else {
2384 -
2385 2749 do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description );
2386 2750
2387 2751 if ( apply_filters( 'frm_continue_to_create', true, $form->id ) ) {
2388 2752 $entry_id = self::just_created_entry( $form->id );
@@ -2405,13 +2769,19 @@
2405 2769 /**
2406 2770 * If the form was processed earlier (init), get the generated errors
2407 2771 *
2408 2772 * @since 2.05
2773 + *
2774 + * @param object $form
2775 + * @param array $params
2776 + *
2777 + * @return array
2409 2778 */
2410 2779 private static function get_saved_errors( $form, $params ) {
2411 2780 global $frm_vars;
2412 2781
2413 - 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 ] ) ) {
2414 2784 $errors = $frm_vars['created_entries'][ $form->id ]['errors'];
2415 2785 } else {
2416 2786 $errors = array();
2417 2787 }
@@ -2428,13 +2798,16 @@
2428 2798 }
2429 2799
2430 2800 /**
2431 2801 * @since 2.2.7
2802 + *
2803 + * @param int|string $form_id
2804 + *
2805 + * @return int
2432 2806 */
2433 2807 public static function just_created_entry( $form_id ) {
2434 2808 global $frm_vars;
2435 -
2436 - 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
2437 2810 }
2438 2811
2439 2812 /**
2440 2813 * Gets confirmation method.
@@ -2447,8 +2820,9 @@
2447 2820 *
2448 2821 * @type object $form Form object.
2449 2822 * @type int $entry_id Entry ID.
2450 2823 * }
2824 + *
2451 2825 * @return array|string
2452 2826 */
2453 2827 private static function get_confirmation_method( $atts ) {
2454 2828 $action = FrmOnSubmitHelper::current_event( $atts );
@@ -2456,8 +2830,9 @@
2456 2830 $method = ! empty( $atts['form']->options[ $opt ] ) ? $atts['form']->options[ $opt ] : 'message';
2457 2831
2458 2832 if ( ! empty( $atts['entry_id'] ) ) {
2459 2833 $met_actions = self::get_met_on_submit_actions( $atts, $action );
2834 +
2460 2835 if ( $met_actions ) {
2461 2836 $method = $met_actions;
2462 2837 }
2463 2838 }
@@ -2464,14 +2839,21 @@
2464 2839
2465 2840 $method = apply_filters( 'frm_success_filter', $method, $atts['form'], $action );
2466 2841
2467 2842 if ( $method !== 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
2468 - $method = 'message';
2843 + return 'message';
2469 2844 }
2470 2845
2471 2846 return $method;
2472 2847 }
2473 2848
2849 + /**
2850 + * @param object $form
2851 + * @param array $params
2852 + * @param array $args
2853 + *
2854 + * @return void
2855 + */
2474 2856 public static function maybe_trigger_redirect( $form, $params, $args ) {
2475 2857 if ( ! isset( $params['id'] ) ) {
2476 2858 global $frm_vars;
2477 2859 $params['id'] = $frm_vars['created_entries'][ $form->id ]['entry_id'];
@@ -2498,14 +2880,12 @@
2498 2880 * @param array $params See {@see FrmFormsController::maybe_trigger_redirect()}.
2499 2881 * @param array $args See {@see FrmFormsController::maybe_trigger_redirect()}.
2500 2882 */
2501 2883 public static function maybe_trigger_redirect_with_action( $conf_method, $form, $params, $args ) {
2502 - if ( is_array( $conf_method ) && 1 === count( $conf_method ) ) {
2503 - if ( 'redirect' === FrmOnSubmitHelper::get_action_type( $conf_method[0] ) && empty( $conf_method[0]->post_content['redirect_delay'] ) ) {
2504 - $event = FrmOnSubmitHelper::current_event( $params );
2505 - FrmOnSubmitHelper::populate_on_submit_data( $form->options, $conf_method[0], $event );
2506 - $conf_method = 'redirect';
2507 - }
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';
2508 2888 }
2509 2889
2510 2890 if ( 'redirect' === $conf_method ) {
2511 2891 self::trigger_redirect( $form, $params, $args );
@@ -2511,8 +2891,15 @@
2511 2891 self::trigger_redirect( $form, $params, $args );
2512 2892 }
2513 2893 }
2514 2894
2895 + /**
2896 + * @param object $form
2897 + * @param array $params
2898 + * @param array $args
2899 + *
2900 + * @return void
2901 + */
2515 2902 public static function trigger_redirect( $form, $params, $args ) {
2516 2903 $success_args = array(
2517 2904 'action' => $params['action'],
2518 2905 'conf_method' => 'redirect',
@@ -2571,8 +2958,9 @@
2571 2958 * @since 6.0
2572 2959 *
2573 2960 * @param array $args See {@see FrmFormsController::run_success_action()}.
2574 2961 * @param string $event Form event. Default is `create`.
2962 + *
2575 2963 * @return array Array of actions that meet the conditional logics.
2576 2964 */
2577 2965 public static function get_met_on_submit_actions( $args, $event = 'create' ) {
2578 2966 if ( ! FrmOnSubmitHelper::form_has_migrated( $args['form'] ) ) {
@@ -2599,13 +2987,11 @@
2599 2987 }
2600 2988
2601 2989 $action_type = FrmOnSubmitHelper::get_action_type( $action );
2602 2990
2603 - if ( 'redirect' === $action_type ) {
2604 - if ( $has_redirect ) {
2605 - // Do not process because we run the first redirect action only.
2606 - continue;
2607 - }
2991 + if ( 'redirect' === $action_type && $has_redirect ) {
2992 + // Do not process because we run the first redirect action only.
2993 + continue;
2608 2994 }
2609 2995
2610 2996 if ( ! self::is_valid_on_submit_action( $action, $args, $event ) ) {
2611 2997 continue;
@@ -2630,10 +3016,10 @@
2630 3016 * @param array $args See {@see FrmFormsController::run_success_action()}. `$args['event']` is also added.
2631 3017 */
2632 3018 $met_actions = apply_filters( 'frm_get_met_on_submit_actions', $met_actions, $args );
2633 3019
2634 - if ( empty( $met_actions ) ) {
2635 - $met_actions = array( FrmOnSubmitHelper::get_fallback_action( $event ) );
3020 + if ( ! $met_actions ) {
3021 + return array( FrmOnSubmitHelper::get_fallback_action( $event ) );
2636 3022 }
2637 3023
2638 3024 return $met_actions;
2639 3025 }
@@ -2645,8 +3031,9 @@
2645 3031 *
2646 3032 * @param object $action Form action object.
2647 3033 * @param array $args See {@see FrmFormsController::run_success_action()}.
2648 3034 * @param string $event Form event. Default is `create`.
3035 + *
2649 3036 * @return bool
2650 3037 */
2651 3038 private static function is_valid_on_submit_action( $action, $args, $event = 'create' ) {
2652 3039 $action_type = FrmOnSubmitHelper::get_action_type( $action );
@@ -2668,8 +3055,9 @@
2668 3055 return false;
2669 3056 }
2670 3057
2671 3058 $page = get_post( $action->post_content['success_page_id'] );
3059 +
2672 3060 if ( ! $page || 'trash' === $page->post_status ) {
2673 3061 return false;
2674 3062 }
2675 3063 }
@@ -2691,8 +3079,9 @@
2691 3079 'entry_id' => $args['entry_id'],
2692 3080 'action' => FrmOnSubmitHelper::current_event( $args ),
2693 3081 )
2694 3082 );
3083 +
2695 3084 if ( ! is_array( $args['conf_method'] ) ) {
2696 3085 self::run_success_action( $args );
2697 3086 return;
2698 3087 }
@@ -2719,8 +3108,9 @@
2719 3108 * @param array $args See {@see FrmFormsController::run_success_action()}.
2720 3109 */
2721 3110 public static function run_multi_on_submit_actions( $args ) {
2722 3111 $redirect_action = null;
3112 +
2723 3113 foreach ( $args['conf_method'] as $action ) {
2724 3114 if ( 'redirect' === FrmOnSubmitHelper::get_action_type( $action ) ) {
2725 3115 // We catch the redirect action to run it last.
2726 3116 $redirect_action = $action;
@@ -2731,13 +3121,15 @@
2731 3121
2732 3122 unset( $action );
2733 3123 }
2734 3124
2735 - if ( $redirect_action ) {
2736 - // Show script to delay the redirection.
2737 - $args['force_delay_redirect'] = true;
2738 - self::run_single_on_submit_action( $args, $redirect_action );
3125 + if ( ! $redirect_action ) {
3126 + return;
2739 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 );
2740 3132 }
2741 3133
2742 3134 /**
2743 3135 * Runs single On Submit action.
@@ -2758,8 +3150,9 @@
2758 3150 * @since 6.0
2759 3151 *
2760 3152 * @param array $args See {@see FrmFormsController::run_success_action()}.
2761 3153 * @param object $action On Submit action object.
3154 + *
2762 3155 * @return array
2763 3156 */
2764 3157 private static function get_run_success_action_args( $args, $action ) {
2765 3158 $new_args = $args;
@@ -2765,10 +3158,9 @@
2765 3158 $new_args = $args;
2766 3159
2767 3160 FrmOnSubmitHelper::populate_on_submit_data( $new_args['form']->options, $action, $args['action'] );
2768 3161
2769 - $opt = 'update' === $args['action'] ? 'edit_' : 'success_';
2770 -
3162 + $opt = 'update' === $args['action'] ? 'edit_' : 'success_';
2771 3163 $new_args['conf_method'] = $new_args['form']->options[ $opt . 'action' ];
2772 3164
2773 3165 /**
2774 3166 * Filters the run success action args.
@@ -2783,12 +3175,18 @@
2783 3175 }
2784 3176
2785 3177 /**
2786 3178 * @since 3.0
3179 + *
3180 + * @param array $args
3181 + *
3182 + * @return void
2787 3183 */
2788 3184 private static function load_page_after_submit( $args ) {
2789 3185 global $post;
2790 3186 $opt = $args['success_opt'];
3187 +
3188 + // phpcs:ignore Universal.Operators.StrictComparisons
2791 3189 if ( ! $post || $args['form']->options[ $opt . '_page_id' ] != $post->ID ) {
2792 3190 $page = get_post( $args['form']->options[ $opt . '_page_id' ] );
2793 3191 $old_post = $post;
2794 3192 $post = $page;
@@ -2812,8 +3210,9 @@
2812 3210 }
2813 3211
2814 3212 /**
2815 3213 * @since 3.0
3214 + *
2816 3215 * @param array $args See {@see FrmFormsController::run_success_action()}.
2817 3216 */
2818 3217 private static function redirect_after_submit( $args ) {
2819 3218 add_filter( 'frm_use_wpautop', '__return_false' );
@@ -2827,11 +3226,10 @@
2827 3226 FrmEntriesController::delete_entry_before_redirect( $success_url, $args['form'], $args );
2828 3227
2829 3228 add_filter( 'frm_redirect_url', 'FrmEntriesController::prepare_redirect_url' );
2830 3229 $success_url = apply_filters( 'frm_redirect_url', $success_url, $args['form'], $args );
3230 + $doing_ajax = FrmAppHelper::doing_ajax();
2831 3231
2832 - $doing_ajax = FrmAppHelper::doing_ajax();
2833 -
2834 3232 if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) {
2835 3233 // Is AJAX submit and there is just one Redirect action runs.
2836 3234 echo json_encode( self::get_ajax_redirect_response_data( $args + compact( 'success_url' ) ) );
2837 3235 wp_die();
@@ -2880,8 +3278,9 @@
2880 3278 *
2881 3279 * @since 6.3.1
2882 3280 *
2883 3281 * @param array $args See {@see FrmFormsController::run_success_action()}.
3282 + *
2884 3283 * @return array
2885 3284 */
2886 3285 private static function get_ajax_redirect_response_data( $args ) {
2887 3286 $response_data = array(
@@ -2904,8 +3303,9 @@
2904 3303 $args['message'] = FrmOnSubmitHelper::get_default_new_tab_msg();
2905 3304
2906 3305 $args['form']->options['success_msg'] = $args['message'];
2907 3306 $args['form']->options['edit_msg'] = $args['message'];
3307 +
2908 3308 if ( ! isset( $args['fields'] ) ) {
2909 3309 $args['fields'] = FrmField::get_all_for_form( $args['form']->id );
2910 3310 }
2911 3311
@@ -2957,13 +3357,15 @@
2957 3357 add_filter( 'frm_use_wpautop', '__return_true' );
2958 3358
2959 3359 echo FrmAppHelper::maybe_kses( $redirect_msg ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2960 3360 echo '<script>';
3361 +
2961 3362 if ( empty( $args['doing_ajax'] ) ) {
2962 3363 // Not AJAX submit, delay JS until window.load.
2963 3364 echo 'window.onload=function(){';
2964 3365 }
2965 3366 echo 'setTimeout(function(){' . $redirect_js . '}, ' . intval( $delay_time ) . ');'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3367 +
2966 3368 if ( empty( $args['doing_ajax'] ) ) {
2967 3369 echo '};';
2968 3370 }
2969 3371 echo '</script>';
@@ -2976,13 +3378,16 @@
2976 3378 * @param string $success_msg
2977 3379 * @param array $args
2978 3380 */
2979 3381 private static function get_redirect_message( $success_url, $success_msg, $args ) {
2980 - $success_msg = apply_filters( 'frm_content', $success_msg, $args['form'], $args['entry_id'] );
2981 - $success_msg = do_shortcode( FrmAppHelper::use_wpautop( $success_msg ) );
2982 - $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
2983 3387 self::get_redirect_fallback_message( $success_url, $args ) .
2984 3388 '</div></div>';
3389 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
2985 3390
2986 3391 $redirect_args = array(
2987 3392 'entry_id' => $args['entry_id'],
2988 3393 'form_id' => $args['form']->id,
@@ -2998,12 +3403,14 @@
2998 3403 * @since 6.3.1
2999 3404 *
3000 3405 * @param string $success_url Redirect URL.
3001 3406 * @param array $args Contains `form` object.
3407 + *
3002 3408 * @return string
3003 3409 */
3004 3410 private static function get_redirect_fallback_message( $success_url, $args ) {
3005 3411 $target = '';
3412 +
3006 3413 if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
3007 3414 $target = ' target="_blank"';
3008 3415 }
3009 3416
@@ -3018,8 +3425,12 @@
3018 3425 /**
3019 3426 * Prepare to show the success message and empty form after submit
3020 3427 *
3021 3428 * @since 2.05
3429 + *
3430 + * @param array $atts
3431 + *
3432 + * @return void
3022 3433 */
3023 3434 public static function show_message_after_save( $atts ) {
3024 3435 $atts['message'] = self::prepare_submit_message( $atts['form'], $atts['entry_id'], $atts );
3025 3436
@@ -3025,8 +3436,9 @@
3025 3436
3026 3437 if ( ! isset( $atts['form']->options['show_form'] ) || $atts['form']->options['show_form'] ) {
3027 3438 if ( isset( $atts['action'] ) && 'update' === $atts['action'] && is_callable( array( 'FrmProEntriesController', 'show_front_end_form_with_entry' ) ) ) {
3028 3439 $entry = FrmEntry::getOne( $atts['entry_id'] );
3440 +
3029 3441 if ( $entry ) {
3030 3442 // This is copied from the Pro plugin.
3031 3443 $atts['conf_message'] = FrmProEntriesController::confirmation( 'message', $atts['form'], $atts['form']->options, $entry->id, $atts );
3032 3444 $atts['show_form'] = FrmProEntriesController::is_form_displayed_after_edit( $atts['form'] );
@@ -3043,8 +3455,12 @@
3043 3455 /**
3044 3456 * Show an empty form
3045 3457 *
3046 3458 * @since 2.05
3459 + *
3460 + * @param array $args
3461 + *
3462 + * @return void
3047 3463 */
3048 3464 private static function show_form_after_submit( $args ) {
3049 3465 self::fill_atts_for_form_display( $args );
3050 3466
@@ -3063,12 +3479,11 @@
3063 3479 }
3064 3480 unset( $args );
3065 3481
3066 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;
3067 3485
3068 - $frm_settings = FrmAppHelper::get_settings();
3069 - $submit = $form->options['submit_value'] ?? $frm_settings->submit_value;
3070 -
3071 3486 global $frm_vars;
3072 3487 self::maybe_load_css( $form, $values['custom_style'], $frm_vars['load_css'] );
3073 3488
3074 3489 $message_placement = self::message_placement( $form, $message );
@@ -3076,25 +3491,36 @@
3076 3491 include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php';
3077 3492 }
3078 3493
3079 3494 /**
3495 + * Gets message placement.
3496 + *
3080 3497 * @since 4.05.02
3081 - * @return string - 'before', 'after', or 'submit'
3498 + * @since 6.26 This method changed from `private` to `public`.
3499 + *
3500 + * @param object $form Form object.
3501 + * @param string $message The message.
3502 + *
3503 + * @return string Accepts 'before', 'after', or 'submit'.
3082 3504 */
3083 - private static function message_placement( $form, $message ) {
3505 + public static function message_placement( $form, $message ) {
3084 3506 $place = 'before';
3085 3507
3086 3508 if ( $message && isset( $form->options['form_class'] ) ) {
3087 - if ( strpos( $form->options['form_class'], 'frm_below_success' ) !== false ) {
3509 + if ( str_contains( $form->options['form_class'], 'frm_below_success' ) ) {
3088 3510 $place = 'after';
3089 - } elseif ( strpos( $form->options['form_class'], 'frm_inline_success' ) !== false ) {
3511 + } elseif ( str_contains( $form->options['form_class'], 'frm_inline_success' ) ) {
3090 3512 $place = 'submit';
3091 3513 }
3092 3514 }
3093 3515
3094 3516 /**
3517 + * Filter the message placement.
3518 + *
3095 3519 * @since 4.05.02
3096 - * @return string - 'before' or 'after'
3520 + *
3521 + * @param string $place Accepts 'before', 'after', or 'submit'.
3522 + * @param array $args Args.
3097 3523 */
3098 3524 return apply_filters( 'frm_message_placement', $place, compact( 'form', 'message' ) );
3099 3525 }
3100 3526
@@ -3101,8 +3527,12 @@
3101 3527 /**
3102 3528 * Get all the values needed on the new.php entry page
3103 3529 *
3104 3530 * @since 2.05
3531 + *
3532 + * @param array $args
3533 + *
3534 + * @return void
3105 3535 */
3106 3536 private static function fill_atts_for_form_display( &$args ) {
3107 3537 if ( ! isset( $args['title'] ) && isset( $args['show_title'] ) ) {
3108 3538 $args['title'] = $args['show_title'];
@@ -3127,8 +3557,12 @@
3127 3557 /**
3128 3558 * Show the success message without the form
3129 3559 *
3130 3560 * @since 2.05
3561 + *
3562 + * @param array $atts
3563 + *
3564 + * @return void
3131 3565 */
3132 3566 private static function show_lone_success_message( $atts ) {
3133 3567 global $frm_vars;
3134 3568 $values = FrmEntriesHelper::setup_new_vars( $atts['fields'], $atts['form'], true );
@@ -3134,13 +3568,12 @@
3134 3568 $values = FrmEntriesHelper::setup_new_vars( $atts['fields'], $atts['form'], true );
3135 3569 self::maybe_load_css( $atts['form'], $values['custom_style'], $frm_vars['load_css'] );
3136 3570
3137 3571 $include_extra_container = 'frm_forms' . FrmFormsHelper::get_form_style_class( $values );
3572 + $errors = array();
3573 + $form = $atts['form'];
3574 + $message = $atts['message'];
3138 3575
3139 - $errors = array();
3140 - $form = $atts['form'];
3141 - $message = $atts['message'];
3142 -
3143 3576 include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php';
3144 3577 }
3145 3578
3146 3579 /**
@@ -3148,11 +3581,12 @@
3148 3581 *
3149 3582 * @since 2.05
3150 3583 * @since 6.0.x Added the third parameter.
3151 3584 *
3152 - * @param object $form Form object.
3153 - * @param int $entry_id Entry ID.
3154 - * @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()}.
3588 + *
3155 3589 * @return string
3156 3590 */
3157 3591 private static function prepare_submit_message( $form, $entry_id, $args = array() ) {
3158 3592 $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) );
@@ -3177,9 +3611,9 @@
3177 3611 public static function front_head() {
3178 3612 $version = FrmAppHelper::plugin_version();
3179 3613 $suffix = FrmAppHelper::js_suffix();
3180 3614
3181 - if ( ! empty( $suffix ) && self::has_combo_js_file() ) {
3615 + if ( $suffix && self::has_combo_js_file() ) {
3182 3616 wp_register_script( 'formidable', FrmAppHelper::plugin_url() . '/js/frm.min.js', array( 'jquery' ), $version, true );
3183 3617 } else {
3184 3618 wp_register_script( 'formidable', FrmAppHelper::plugin_url() . "/js/formidable{$suffix}.js", array( 'jquery' ), $version, true );
3185 3619 }
@@ -3186,9 +3620,9 @@
3186 3620
3187 3621 add_filter( 'script_loader_tag', 'FrmFormsController::defer_script_loading', 10, 2 );
3188 3622
3189 3623 if ( FrmAppHelper::is_admin() ) {
3190 - // don't load this in back-end
3624 + // Don't load this in back-end
3191 3625 return;
3192 3626 }
3193 3627
3194 3628 FrmAppHelper::localize_script( 'front' );
@@ -3201,8 +3635,15 @@
3201 3635 public static function has_combo_js_file() {
3202 3636 return is_readable( FrmAppHelper::plugin_path() . '/js/frm.min.js' );
3203 3637 }
3204 3638
3639 + /**
3640 + * @param object $form
3641 + * @param int|string $this_load
3642 + * @param bool $global_load
3643 + *
3644 + * @return void
3645 + */
3205 3646 public static function maybe_load_css( $form, $this_load, $global_load ) {
3206 3647 $load_css = FrmForm::is_form_loaded( $form, $this_load, $global_load );
3207 3648
3208 3649 if ( ! $load_css ) {
@@ -3232,8 +3673,9 @@
3232 3673 return;
3233 3674 }
3234 3675
3235 3676 global $wp_styles;
3677 +
3236 3678 if ( is_array( $wp_styles->queue ) && in_array( 'formidable', $wp_styles->queue, true ) ) {
3237 3679 wp_print_styles( 'formidable' );
3238 3680 }
3239 3681 }
@@ -3248,34 +3690,57 @@
3248 3690 private static function should_load_late() {
3249 3691 return ! function_exists( 'aioseo' );
3250 3692 }
3251 3693
3694 + /**
3695 + * @param string $tag
3696 + * @param string $handle
3697 + *
3698 + * @return string
3699 + */
3252 3700 public static function defer_script_loading( $tag, $handle ) {
3253 - if ( 'captcha-api' == $handle && ! strpos( $tag, 'defer' ) ) {
3254 - $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 );
3255 3703 }
3256 3704
3257 3705 return $tag;
3258 3706 }
3259 3707
3708 + /**
3709 + * @param string $location
3710 + *
3711 + * @return void
3712 + */
3260 3713 public static function footer_js( $location = 'footer' ) {
3261 3714 global $frm_vars;
3262 3715
3263 3716 FrmStylesController::enqueue_css();
3264 3717
3265 - if ( ! FrmAppHelper::is_admin() && $location !== 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
3266 - // load formidable js
3267 - wp_enqueue_script( 'formidable' );
3718 + if ( FrmAppHelper::is_admin() || $location === 'header' || empty( $frm_vars['forms_loaded'] ) ) {
3719 + return;
3720 + }
3268 3721
3269 - 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();
3270 3730 }
3271 3731 }
3272 3732
3273 3733 /**
3274 3734 * @since 2.0.8
3735 + *
3736 + * @param array $atts
3737 + * @param string $content
3738 + *
3739 + * @return void
3275 3740 */
3276 3741 private static function maybe_minimize_form( $atts, &$content ) {
3277 - // check if minimizing is turned on
3742 + // Check if minimizing is turned on
3278 3743 if ( self::is_minification_on( $atts ) ) {
3279 3744 $content = str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', $content );
3280 3745 }
3281 3746 }
@@ -3281,8 +3746,11 @@
3281 3746 }
3282 3747
3283 3748 /**
3284 3749 * @since 2.0.8
3750 + *
3751 + * @param array $atts
3752 + *
3285 3753 * @return bool
3286 3754 */
3287 3755 private static function is_minification_on( $atts ) {
3288 3756 return ! empty( $atts['minimize'] );
@@ -3294,11 +3762,13 @@
3294 3762 * @return void
3295 3763 */
3296 3764 public static function landing_page_preview_option() {
3297 3765 $dir = apply_filters( 'frm_landing_page_preview_option', false );
3766 +
3298 3767 if ( false === $dir || ! file_exists( $dir . 'landing-page-preview-option.php' ) ) {
3299 3768 $dir = self::get_form_views_path();
3300 3769 }
3770 +
3301 3771 include $dir . 'landing-page-preview-option.php';
3302 3772 }
3303 3773
3304 3774 /**
@@ -3324,13 +3794,15 @@
3324 3794
3325 3795 check_ajax_referer( 'frm_ajax', 'nonce' );
3326 3796
3327 3797 $type = FrmAppHelper::get_post_param( 'type', '', 'sanitize_text_field' );
3798 +
3328 3799 if ( ! $type || ! in_array( $type, array( 'form', 'view' ), true ) ) {
3329 3800 die( 0 );
3330 3801 }
3331 3802
3332 3803 $object_id = FrmAppHelper::get_post_param( 'object_id', '', 'absint' );
3804 +
3333 3805 if ( ! $object_id ) {
3334 3806 die( 0 );
3335 3807 }
3336 3808
@@ -3342,13 +3814,15 @@
3342 3814 $postarr['post_content'] = apply_filters( 'frm_create_page_with_' . $type . '_shortcode_content', '', $object_id );
3343 3815 }
3344 3816
3345 3817 $name = FrmAppHelper::get_post_param( 'name', '', 'sanitize_text_field' );
3818 +
3346 3819 if ( $name ) {
3347 3820 $postarr['post_title'] = $name;
3348 3821 }
3349 3822
3350 3823 $success = wp_insert_post( $postarr );
3824 +
3351 3825 if ( ! is_numeric( $success ) || ! $success ) {
3352 3826 die( 0 );
3353 3827 }
3354 3828
@@ -3362,8 +3836,9 @@
3362 3836 /**
3363 3837 * @since 5.3
3364 3838 *
3365 3839 * @param int $form_id
3840 + *
3366 3841 * @return string
3367 3842 */
3368 3843 private static function get_page_shortcode_content_for_form( $form_id ) {
3369 3844 $shortcode = '[formidable id="' . $form_id . '"]';
@@ -3383,9 +3858,9 @@
3383 3858 }
3384 3859
3385 3860 check_ajax_referer( 'frm_ajax', 'nonce' );
3386 3861
3387 - $html = FrmAppHelper::clip(
3862 + $html = FrmAppHelper::clip(
3388 3863 function () {
3389 3864 FrmAppHelper::maybe_autocomplete_pages_options(
3390 3865 array(
3391 3866 'field_name' => 'frm_page_dropdown',
@@ -3394,19 +3869,53 @@
3394 3869 )
3395 3870 );
3396 3871 }
3397 3872 );
3398 - $post_type_object = get_post_type_object( 'page' );
3399 3873 wp_send_json(
3400 3874 array(
3401 3875 'html' => $html,
3402 - '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 ) ),
3403 3877 )
3404 3878 );
3405 3879 }
3406 3880
3407 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 + /**
3408 3913 * @deprecated 4.0
3914 + *
3915 + * @param array $values
3916 + *
3917 + * @return void
3409 3918 */
3410 3919 public static function create( $values = array() ) {
3411 3920 _deprecated_function( __METHOD__, '4.0', 'FrmFormsController::update' );
3412 3921 self::update( $values );
@@ -3412,16 +3921,14 @@
3412 3921 self::update( $values );
3413 3922 }
3414 3923
3415 3924 /**
3416 - * Education for premium features.
3925 + * @deprecated 6.33
3417 3926 *
3418 - * @since 4.05
3419 - * @deprecated 6.16.3
3927 + * @param array $values
3420 3928 *
3421 3929 * @return void
3422 3930 */
3423 - public static function add_form_style_tab_options() {
3424 - _deprecated_function( __METHOD__, '6.16.3' );
3425 - 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' );
3426 3933 }
3427 3934 }