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 +775 -254 6.25 → 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
@@ -305,9 +378,9 @@
305 378 if ( self::is_too_long( $values ) ) {
306 379 $message .= '<br/> ' . sprintf(
307 380 /* translators: %1$s: Start link HTML, %2$s: end link HTML */
308 381 __( 'However, your form is very long and may be %1$sreaching server limits%2$s.', 'formidable' ),
309 - '<a href="https://formidableforms.com/knowledgebase/i-have-a-long-form-why-did-the-options-at-the-end-of-the-form-stop-saving/?utm_source=WordPress&utm_medium=builder&utm_campaign=liteplugin" target="_blank" rel="noopener">',
382 + '<a href="' . esc_url( self::get_form_too_long_docs_url() ) . '" target="_blank" rel="noopener">',
310 383 '</a>'
311 384 );
312 385 }
313 386
@@ -318,17 +391,32 @@
318 391 self::get_edit_vars( $id, array(), $message );
319 392 }
320 393
321 394 /**
395 + * @since 6.25.1
396 + *
397 + * @return string
398 + */
399 + private static function get_form_too_long_docs_url() {
400 + $utm = array(
401 + 'campaign' => 'builder',
402 + 'content' => 'form-too-long',
403 + );
404 + return FrmAppHelper::admin_upgrade_link( $utm, 'knowledgebase/i-have-a-long-form-why-did-the-options-at-the-end-of-the-form-stop-saving/' );
405 + }
406 +
407 + /**
322 408 * Remove the draft flag from any new fields from this current session.
323 409 *
324 410 * @since 6.8
325 411 *
326 412 * @param int $form_id
413 + *
327 414 * @return void
328 415 */
329 416 private static function maybe_remove_draft_option_from_fields( $form_id ) {
330 417 $draft_field_ids_csv = FrmAppHelper::get_post_param( 'draft_fields', '', 'sanitize_text_field' );
418 +
331 419 if ( ! $draft_field_ids_csv ) {
332 420 // If the draft_fields input is empty there are no new fields in the session.
333 421 return;
334 422 }
@@ -333,8 +421,9 @@
333 421 return;
334 422 }
335 423
336 424 $draft_field_ids = array_filter( explode( ',', $draft_field_ids_csv ), 'is_numeric' );
425 +
337 426 if ( ! $draft_field_ids ) {
338 427 // Exit early if the draft fields input is invalid. It should be a CSV of integer values.
339 428 return;
340 429 }
@@ -339,8 +428,9 @@
339 428 return;
340 429 }
341 430
342 431 $draft_field_rows = FrmFieldsHelper::get_draft_field_results( $form_id, $draft_field_ids );
432 +
343 433 foreach ( $draft_field_rows as $row ) {
344 434 $row->field_options['draft'] = 0;
345 435 FrmField::update( $row->id, array( 'field_options' => $row->field_options ) );
346 436 }
@@ -352,8 +442,10 @@
352 442 * were likely not saved either.
353 443 *
354 444 * @since 3.06.01
355 445 *
446 + * @param array $values
447 + *
356 448 * @return bool
357 449 */
358 450 private static function is_too_long( $values ) {
359 451 return empty( $values['frm_end'] );
@@ -389,8 +481,9 @@
389 481 * @return string|null
390 482 */
391 483 public static function page_preview() {
392 484 $params = FrmForm::list_page_params();
485 +
393 486 if ( ! $params['form'] || is_numeric( $params['form'] ) ) {
394 487 return null;
395 488 }
396 489
@@ -396,8 +489,9 @@
396 489
397 490 self::maybe_block_preview( $params['form'] );
398 491
399 492 $form = FrmForm::getOne( $params['form'] );
493 +
400 494 if ( ! $form ) {
401 495 return null;
402 496 }
403 497
@@ -410,8 +504,9 @@
410 504 * @return void
411 505 */
412 506 public static function show_page_preview() {
413 507 $preview = self::page_preview();
508 +
414 509 if ( is_null( $preview ) ) {
415 510 wp_die(
416 511 '<h1>' . esc_html__( 'Form key is invalid', 'formidable' ) . '</h1>',
417 512 '<p>' . esc_html__( 'Form key is invalid', 'formidable' ) . '</p>',
@@ -441,8 +536,9 @@
441 536 add_filter( 'frm_filter_final_form', 'FrmTestModeController::maybe_add_test_mode_container', 99 );
442 537 }
443 538
444 539 $include_theme = FrmAppHelper::get_param( 'theme', '', 'get', 'absint' );
540 +
445 541 if ( $include_theme ) {
446 542 self::set_preview_query();
447 543 self::load_theme_preview();
448 544 } else {
@@ -465,8 +561,9 @@
465 561 'post_type' => 'page',
466 562 );
467 563
468 564 $page_for_posts = get_option( 'page_for_posts' );
565 +
469 566 if ( is_numeric( $page_for_posts ) ) {
470 567 // Avoid querying for the "Posts Page" or "Blog Page" so we don't display 10 forms.
471 568 $page_query['post__not_in'] = array( $page_for_posts );
472 569 }
@@ -471,13 +568,15 @@
471 568 $page_query['post__not_in'] = array( $page_for_posts );
472 569 }
473 570
474 571 $random_page = get_posts( $page_query );
572 +
475 573 if ( ! $random_page ) {
476 574 return;
477 575 }
478 576
479 577 $random_page = reset( $random_page );
578 +
480 579 if ( ! is_a( $random_page, 'WP_Post' ) ) {
481 580 // The return type can also be int.
482 581 return;
483 582 }
@@ -499,8 +598,9 @@
499 598 *
500 599 * @since 5.5.2
501 600 *
502 601 * @param WP_Post $page The page object.
602 + *
503 603 * @return void
504 604 */
505 605 private static function set_post_global( $page ) {
506 606 global $post;
@@ -519,14 +619,16 @@
519 619 add_action( 'loop_no_results', 'FrmFormsController::show_page_preview' );
520 620 add_filter( 'is_active_sidebar', '__return_false' );
521 621 FrmStylesController::enqueue_css( 'enqueue', true );
522 622
523 - if ( false === get_template_part( 'page' ) ) {
524 - if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) {
525 - add_filter( 'body_class', 'FrmFormsController::preview_block_theme_body_classnames' );
526 - }
527 - self::fallback_when_page_template_part_is_not_supported_by_theme();
623 + if ( false !== get_template_part( 'page' ) ) {
624 + return;
528 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();
529 631 }
530 632
531 633 /**
532 634 * Add padding to the body for block themes.
@@ -533,8 +635,9 @@
533 635 *
534 636 * @since 6.5.2
535 637 *
536 638 * @param array $classes The body classes list.
639 + *
537 640 * @return array
538 641 */
539 642 public static function preview_block_theme_body_classnames( $classes ) {
540 643 $classes[] = 'has-global-padding';
@@ -547,25 +650,27 @@
547 650 *
548 651 * @return void
549 652 */
550 653 private static function fallback_when_page_template_part_is_not_supported_by_theme() {
551 - if ( have_posts() ) {
552 - the_post();
553 - self::get_template( 'header' );
654 + if ( ! have_posts() ) {
655 + return;
656 + }
554 657
555 - // add some generic class names to the container to add some natural padding to the content.
556 - // .entry-content catches the WordPress TwentyTwenty theme.
557 - // .container catches Customizr content.
558 - echo '<div class="container entry-content">';
559 - the_content();
560 - echo '</div>';
658 + the_post();
659 + self::get_template( 'header' );
561 660
562 - // Prevent extra unexpected forms in the footer.
563 - // For some reason this happens in the Twenty Twenty Five theme.
564 - 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>';
565 667
566 - self::get_template( 'footer' );
567 - }
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' );
568 673 }
569 674
570 675 /**
571 676 * Calls core function to get a template part if it doesn't cause deprecation warnings. Otherwise skips the deprecation function call
@@ -571,9 +676,11 @@
571 676 * Calls core function to get a template part if it doesn't cause deprecation warnings. Otherwise skips the deprecation function call
572 677 * and renders required html fragments calling required functions.
573 678 *
574 679 * @since 6.7.1
680 + *
575 681 * @param string $template
682 + *
576 683 * @return void
577 684 */
578 685 private static function get_template( $template ) {
579 686 if ( self::should_try_getting_template( $template ) ) {
@@ -594,9 +701,11 @@
594 701 /**
595 702 * Returns true if calling a template function doesn't trigger deprecation warnings.
596 703 *
597 704 * @since 6.7.1
705 + *
598 706 * @param string $template
707 + *
599 708 * @return bool
600 709 */
601 710 private static function should_try_getting_template( $template ) {
602 711 $stylesheet_path = get_stylesheet_directory();
@@ -610,15 +719,15 @@
610 719 /**
611 720 * Set the page title for the theme preview page
612 721 *
613 722 * @since 3.0
723 + *
724 + * @param string $title
725 + *
726 + * @return string
614 727 */
615 728 public static function preview_page_title( $title ) {
616 - if ( in_the_loop() ) {
617 - $title = self::preview_title( $title );
618 - }
619 -
620 - return $title;
729 + return in_the_loop() ? self::preview_title( $title ) : $title;
621 730 }
622 731
623 732 /**
624 733 * Set the page title for the theme preview page.
@@ -625,8 +734,9 @@
625 734 *
626 735 * @since 3.0
627 736 *
628 737 * @param string $title
738 + *
629 739 * @return string
630 740 */
631 741 public static function preview_title( $title ) {
632 742 return __( 'Form Preview', 'formidable' );
@@ -637,8 +747,9 @@
637 747 *
638 748 * @since 3.0
639 749 *
640 750 * @param string $content
751 + *
641 752 * @return string
642 753 */
643 754 public static function preview_content( $content ) {
644 755 if ( in_the_loop() ) {
@@ -654,8 +765,10 @@
654 765 * @since 3.0
655 766 */
656 767 private static function load_direct_preview() {
657 768 $key = FrmAppHelper::simple_get( 'form', 'sanitize_title' );
769 +
770 + // phpcs:ignore Universal.Operators.StrictComparisons
658 771 if ( $key == '' ) {
659 772 $key = FrmAppHelper::get_post_param( 'form', '', 'sanitize_title' );
660 773 }
661 774
@@ -670,8 +783,9 @@
670 783
671 784 self::maybe_block_preview( $key );
672 785
673 786 $form = FrmForm::getAll( array( 'form_key' => $key ), '', 1 );
787 +
674 788 if ( ! $form ) {
675 789 $error = __( 'Form does not exist', 'formidable' );
676 790 wp_die(
677 791 '<h1>' . esc_html( $error ) . '</h1>',
@@ -695,19 +809,22 @@
695 809 *
696 810 * @since 6.20
697 811 *
698 812 * @param string $form_key Form key.
813 + *
699 814 * @return void
700 815 */
701 816 public static function maybe_block_preview( $form_key ) {
702 - if ( FrmFormsHelper::should_block_preview( $form_key ) ) {
703 - $error = __( 'You do not have permission to view this form', 'formidable' );
704 - wp_die(
705 - '<h1>' . esc_html( $error ) . '</h1>',
706 - '<p>' . esc_html( $error ) . '</p>',
707 - 403
708 - );
817 + if ( ! FrmFormsHelper::should_block_preview( $form_key ) ) {
818 + return;
709 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 + );
710 827 }
711 828
712 829 /**
713 830 * Some themes have a null $src value.
@@ -722,15 +839,13 @@
722 839 add_filter(
723 840 'script_loader_src',
724 841 /**
725 842 * @param string|null $src
843 + *
726 844 * @return string
727 845 */
728 846 function ( $src ) {
729 - if ( is_null( $src ) ) {
730 - $src = '';
731 - }
732 - return $src;
847 + return is_null( $src ) ? '' : $src;
733 848 }
734 849 );
735 850 }
736 851
@@ -739,8 +854,9 @@
739 854 }
740 855
741 856 /**
742 857 * @param array $ids
858 + *
743 859 * @return string
744 860 */
745 861 public static function bulk_untrash( $ids ) {
746 862 FrmAppHelper::permission_check( 'frm_edit_forms' );
@@ -752,11 +868,9 @@
752 868 return '';
753 869 }
754 870
755 871 /* translators: %1$s: Number of forms */
756 - $message = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
757 -
758 - return $message;
872 + return sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
759 873 }
760 874
761 875 /**
762 876 * @since 3.06
@@ -801,8 +915,9 @@
801 915 // Check nonce url.
802 916 check_admin_referer( $status . '_form_' . $params['id'] );
803 917
804 918 $count = 0;
919 +
805 920 if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) {
806 921 ++$count;
807 922 }
808 923
@@ -816,9 +931,9 @@
816 931 /* translators: %1$s: Number of forms */
817 932 $available_status['untrash']['message'] = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
818 933
819 934 /* translators: %1$s: Number of forms, %2$s: Start link HTML, %3$s: End link HTML */
820 - $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
821 936
822 937 $message = $available_status[ $status ]['message'];
823 938
824 939 self::display_forms_list( $params, $message );
@@ -825,8 +940,9 @@
825 940 }
826 941
827 942 /**
828 943 * @param array $ids
944 + *
829 945 * @return string
830 946 */
831 947 public static function bulk_trash( $ids ) {
832 948 FrmAppHelper::permission_check( 'frm_delete_forms' );
@@ -831,8 +947,9 @@
831 947 public static function bulk_trash( $ids ) {
832 948 FrmAppHelper::permission_check( 'frm_delete_forms' );
833 949
834 950 $count = 0;
951 +
835 952 foreach ( $ids as $id ) {
836 953 if ( FrmForm::trash( $id ) ) {
837 954 ++$count;
838 955 }
@@ -847,17 +964,16 @@
847 964 'param' => 'form_type',
848 965 'type' => 'request',
849 966 )
850 967 );
851 - $message = sprintf(
968 +
969 + return sprintf(
852 970 /* translators: %1$s: Number of forms, %2$s: Start link HTML, %3$s: End link HTML */
853 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' ),
854 972 $count,
855 - '<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
856 974 '</a>'
857 975 );
858 -
859 - return $message;
860 976 }
861 977
862 978 public static function destroy() {
863 979 FrmAppHelper::permission_check( 'frm_delete_forms' );
@@ -867,8 +983,9 @@
867 983 // Check nonce url.
868 984 check_admin_referer( 'destroy_form_' . $params['id'] );
869 985
870 986 $count = 0;
987 +
871 988 if ( FrmForm::destroy( $params['id'] ) ) {
872 989 ++$count;
873 990 }
874 991
@@ -879,8 +996,9 @@
879 996 }
880 997
881 998 /**
882 999 * @param array $ids
1000 + *
883 1001 * @return string
884 1002 */
885 1003 public static function bulk_destroy( $ids ) {
886 1004 FrmAppHelper::permission_check( 'frm_delete_forms' );
@@ -885,10 +1003,12 @@
885 1003 public static function bulk_destroy( $ids ) {
886 1004 FrmAppHelper::permission_check( 'frm_delete_forms' );
887 1005
888 1006 $count = 0;
1007 +
889 1008 foreach ( $ids as $id ) {
890 1009 $d = FrmForm::destroy( $id );
1010 +
891 1011 if ( $d ) {
892 1012 ++$count;
893 1013 }
894 1014 }
@@ -906,19 +1026,18 @@
906 1026 */
907 1027 public static function delete_all() {
908 1028 // Check nonce url.
909 1029 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' );
1030 +
910 1031 if ( $permission_error !== false ) {
911 1032 self::display_forms_list( array(), '', array( $permission_error ) );
912 -
913 1033 return;
914 1034 }
915 1035
916 1036 $count = FrmForm::scheduled_delete( time() );
917 1037 $url = remove_query_arg( array( 'delete_all' ) );
1038 + $url .= '&message=forms_permanently_deleted&forms_deleted=' . $count;
918 1039
919 - $url .= '&message=forms_permanently_deleted&forms_deleted=' . $count;
920 -
921 1040 wp_safe_redirect( $url );
922 1041 die();
923 1042 }
924 1043
@@ -992,21 +1111,22 @@
992 1111 *
993 1112 * @return void
994 1113 */
995 1114 public static function insert_form_button() {
996 - if ( current_user_can( 'frm_view_forms' ) ) {
997 - // Store the result in memory and re-use it when this function is called multiple times.
998 - // This helps speed up the form builder when there are a lot of HTML fields, where this
999 - // button is inserted once per HTML field.
1000 - // In a form with 66 HTML fields, this saves 0.5 seconds on page load time, tested locally.
1001 - if ( ! isset( self::$formidable_tinymce_button ) ) {
1002 - FrmAppHelper::load_admin_wide_js();
1003 - $menu_name = FrmAppHelper::get_menu_name();
1004 - $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() );
1005 - 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>';
1006 - }
1007 - echo self::$formidable_tinymce_button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1115 + if ( ! current_user_can( 'frm_view_forms' ) ) {
1116 + return;
1008 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
1009 1129 }
1010 1130
1011 1131 /**
1012 1132 * @return void
@@ -1027,17 +1147,21 @@
1027 1147 $shortcodes = apply_filters( 'frm_popup_shortcodes', $shortcodes );
1028 1148
1029 1149 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/insert_form_popup.php';
1030 1150
1031 - if ( FrmAppHelper::is_form_builder_page() && ! class_exists( '_WP_Editors', false ) ) {
1032 - // initialize a wysiwyg so we have usable settings defined in tinyMCEPreInit.mceInit
1033 - require ABSPATH . WPINC . '/class-wp-editor.php';
1034 - ?>
1035 - <div class="frm_hidden">
1036 - <?php wp_editor( '', 'frm_description_placeholder', array() ); ?>
1037 - </div>
1038 - <?php
1151 + if ( ! FrmAppHelper::is_form_builder_page() || class_exists( '_WP_Editors', false ) ) {
1152 + return;
1039 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
1040 1164 }
1041 1165
1042 1166 /**
1043 1167 * Check the page being loaded, determine if this is a page that should include the form popup.
@@ -1049,8 +1173,9 @@
1049 1173 private static function should_insert_form_popup() {
1050 1174 if ( FrmAppHelper::is_form_builder_page() ) {
1051 1175 return true;
1052 1176 }
1177 +
1053 1178 $page = basename( FrmAppHelper::get_server_value( 'PHP_SELF' ) );
1054 1179 return in_array( $page, array( 'post.php', 'page.php', 'page-new.php', 'post-new.php' ), true );
1055 1180 }
1056 1181
@@ -1058,9 +1183,10 @@
1058 1183 FrmAppHelper::permission_check( 'frm_view_forms' );
1059 1184 check_ajax_referer( 'frm_ajax', 'nonce' );
1060 1185
1061 1186 $shortcode = FrmAppHelper::get_post_param( 'shortcode', '', 'sanitize_text_field' );
1062 - if ( empty( $shortcode ) ) {
1187 +
1188 + if ( ! $shortcode ) {
1063 1189 wp_die();
1064 1190 }
1065 1191
1066 1192 echo '<div id="sc-opts-' . esc_attr( $shortcode ) . '" class="frm_shortcode_option">';
@@ -1085,12 +1211,13 @@
1085 1211 'label' => __( 'Minimize form HTML', 'formidable' ),
1086 1212 ),
1087 1213 );
1088 1214 }
1215 +
1089 1216 $opts = apply_filters( 'frm_sc_popup_opts', $opts, $shortcode );
1090 1217
1091 1218 if ( isset( $opts['form_id'] ) && is_string( $opts['form_id'] ) ) {
1092 - // allow other shortcodes to use the required form id option
1219 + // Allow other shortcodes to use the required form id option
1093 1220 $form_id = $opts['form_id'];
1094 1221 unset( $opts['form_id'] );
1095 1222 }
1096 1223
@@ -1106,8 +1233,9 @@
1106 1233 *
1107 1234 * @param array $params
1108 1235 * @param string $message
1109 1236 * @param array $errors
1237 + *
1110 1238 * @return void
1111 1239 */
1112 1240 public static function display_forms_list( $params = array(), $message = '', $errors = array() ) {
1113 1241 FrmAppHelper::permission_check( 'frm_view_forms' );
@@ -1124,21 +1252,21 @@
1124 1252 * @param string $table_class Class name for List Helper.
1125 1253 */
1126 1254 $table_class = apply_filters( 'frm_forms_list_class', 'FrmFormsListHelper' );
1127 1255 $wp_list_table = new $table_class( compact( 'params' ) );
1256 + $pagenum = $wp_list_table->get_pagenum();
1128 1257
1129 - $pagenum = $wp_list_table->get_pagenum();
1130 -
1131 1258 $wp_list_table->prepare_items();
1132 1259
1133 1260 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
1261 +
1134 1262 if ( $pagenum > $total_pages && $total_pages > 0 ) {
1135 - wp_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) );
1263 + wp_safe_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) );
1136 1264 die();
1137 1265 }
1138 1266
1139 - $inbox = new FrmInbox();
1140 - $error = $inbox->check_for_error();
1267 + $error = FrmInbox::check_for_error();
1268 +
1141 1269 if ( $error ) {
1142 1270 $show_messages = array( $error['subject'] . '. ' . $error['message'] );
1143 1271 }
1144 1272
@@ -1146,8 +1274,9 @@
1146 1274 }
1147 1275
1148 1276 /**
1149 1277 * @param array<string,string> $columns
1278 + *
1150 1279 * @return array<string,string>
1151 1280 */
1152 1281 public static function get_columns( $columns ) {
1153 1282 $columns['cb'] = '<input type="checkbox" />';
@@ -1152,15 +1281,27 @@
1152 1281 public static function get_columns( $columns ) {
1153 1282 $columns['cb'] = '<input type="checkbox" />';
1154 1283 $columns['name'] = esc_html__( 'Form Title', 'formidable' );
1155 1284 $columns['entries'] = esc_html__( 'Entries', 'formidable' );
1285 + $columns['views'] = esc_html__( 'Views', 'formidable' );
1156 1286 $columns['id'] = 'ID';
1157 1287 $columns['form_key'] = esc_html__( 'Key', 'formidable' );
1158 - 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.
1159 1291 $columns['shortcode'] = esc_html__( 'Actions', 'formidable' );
1160 1292 }
1293 +
1161 1294 $columns['created_at'] = esc_html__( 'Date', 'formidable' );
1162 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 +
1163 1304 add_screen_option(
1164 1305 'per_page',
1165 1306 array(
1166 1307 'label' => __( 'Forms', 'formidable' ),
@@ -1186,8 +1327,9 @@
1186 1327 }
1187 1328
1188 1329 /**
1189 1330 * @param mixed $hidden_columns
1331 + *
1190 1332 * @return array
1191 1333 */
1192 1334 public static function hidden_columns( $hidden_columns ) {
1193 1335 if ( ! is_array( $hidden_columns ) ) {
@@ -1208,11 +1350,18 @@
1208 1350
1209 1351 return $hidden_columns;
1210 1352 }
1211 1353
1354 + /**
1355 + * @param mixed $save
1356 + * @param string $option
1357 + * @param int|string $value
1358 + *
1359 + * @return mixed
1360 + */
1212 1361 public static function save_per_page( $save, $option, $value ) {
1213 1362 if ( $option === 'formidable_page_formidable_per_page' ) {
1214 - $save = (int) $value;
1363 + return (int) $value;
1215 1364 }
1216 1365
1217 1366 return $save;
1218 1367 }
@@ -1221,8 +1370,9 @@
1221 1370 * @param int|string $id
1222 1371 * @param array $errors
1223 1372 * @param string $message
1224 1373 * @param bool $create_link
1374 + *
1225 1375 * @return void
1226 1376 */
1227 1377 private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
1228 1378 global $frm_vars;
@@ -1237,8 +1387,9 @@
1237 1387 'page' => 'formidable',
1238 1388 )
1239 1389 ),
1240 1390 );
1391 +
1241 1392 if ( ! $form ) {
1242 1393 FrmAppController::show_error_modal( $error_args );
1243 1394 return;
1244 1395 }
@@ -1260,15 +1411,14 @@
1260 1411 }
1261 1412
1262 1413 if ( $form->parent_form_id ) {
1263 1414 /* translators: %1$s: Start link HTML, %2$s: End link HTML */
1264 - 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
1265 1416 }
1266 1417
1267 1418 $frm_field_selection = FrmField::field_selection();
1419 + $fields = FrmField::get_all_for_form( $form->id );
1268 1420
1269 - $fields = FrmField::get_all_for_form( $form->id );
1270 -
1271 1421 // Automatically add end section fields if they don't exist (2.0 migration).
1272 1422 $reset_fields = false;
1273 1423 FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields );
1274 1424 FrmSubmitHelper::maybe_create_submit_field( $form, $fields, $reset_fields );
@@ -1292,9 +1442,10 @@
1292 1442 */
1293 1443 $values['fields'] = apply_filters( 'frm_fields_in_form_builder', $fields, compact( 'form' ) );
1294 1444
1295 1445 $edit_message = __( 'Form was successfully updated.', 'formidable' );
1296 - if ( $form->is_template && $message == $edit_message ) {
1446 +
1447 + if ( $form->is_template && $message === $edit_message ) {
1297 1448 $message = __( 'Template was successfully updated.', 'formidable' );
1298 1449 }
1299 1450
1300 1451 self::maybe_update_form_builder_message( $message );
@@ -1309,11 +1460,12 @@
1309 1460 }
1310 1461
1311 1462 /**
1312 1463 * @param array $fields
1464 + *
1313 1465 * @return array
1314 1466 */
1315 - public static function update_form_builder_fields( $fields, $form ) {
1467 + public static function update_form_builder_fields( $fields ) {
1316 1468 foreach ( $fields as $field ) {
1317 1469 $field->do_not_include_icons = true;
1318 1470 }
1319 1471 return $fields;
@@ -1318,8 +1470,13 @@
1318 1470 }
1319 1471 return $fields;
1320 1472 }
1321 1473
1474 + /**
1475 + * @param string $message
1476 + *
1477 + * @return void
1478 + */
1322 1479 public static function maybe_update_form_builder_message( &$message ) {
1323 1480 if ( 'form_duplicated' === FrmAppHelper::simple_get( 'message' ) ) {
1324 1481 $message = __( 'Form was Successfully Copied', 'formidable' );
1325 1482 }
@@ -1328,8 +1485,9 @@
1328 1485 /**
1329 1486 * @param int|string $id
1330 1487 * @param array $errors
1331 1488 * @param array|string $args
1489 + *
1332 1490 * @return void
1333 1491 */
1334 1492 public static function get_settings_vars( $id, $errors = array(), $args = array() ) {
1335 1493 FrmAppHelper::permission_check( 'frm_edit_forms' );
@@ -1351,13 +1509,12 @@
1351 1509 );
1352 1510 $args = array_merge( $defaults, $args );
1353 1511 $message = $args['message'];
1354 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 );
1355 1516
1356 - $form = FrmForm::getOne( $id );
1357 - $fields = FrmField::get_all_for_form( $id );
1358 - $values = FrmAppHelper::setup_edit_vars( $form, 'forms', $fields, true );
1359 -
1360 1517 /**
1361 1518 * Allows changing fields in the form settings.
1362 1519 *
1363 1520 * @since 5.0.04
@@ -1397,8 +1554,12 @@
1397 1554 }
1398 1555
1399 1556 /**
1400 1557 * @since 4.0
1558 + *
1559 + * @param array $atts
1560 + *
1561 + * @return void
1401 1562 */
1402 1563 public static function form_publish_button( $atts ) {
1403 1564 $values = $atts['values'];
1404 1565 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php';
@@ -1409,8 +1570,9 @@
1409 1570 *
1410 1571 * @since 4.0
1411 1572 *
1412 1573 * @param array $values
1574 + *
1413 1575 * @return array
1414 1576 */
1415 1577 private static function get_settings_tabs( $values ) {
1416 1578 $sections = array(
@@ -1417,19 +1579,24 @@
1417 1579 'advanced' => array(
1418 1580 'name' => __( 'General', 'formidable' ),
1419 1581 'title' => __( 'General Form Settings', 'formidable' ),
1420 1582 'function' => array( self::class, 'advanced_settings' ),
1421 - 'icon' => 'frm_icon_font frm_settings_icon',
1583 + 'icon' => 'frmfont frm_small_settings_icon',
1422 1584 ),
1423 1585 'email' => array(
1424 1586 'name' => __( 'Actions & Notifications', 'formidable' ),
1425 1587 'function' => array( 'FrmFormActionsController', 'email_settings' ),
1426 1588 'id' => 'frm_notification_settings',
1427 - 'icon' => 'frm_icon_font frm_mail_bulk_icon',
1589 + 'icon' => 'frmfont frm_notification_check_icon',
1428 1590 ),
1591 + 'spam' => array(
1592 + 'name' => __( 'Spam', 'formidable' ),
1593 + 'function' => array( self::class, 'spam_settings' ),
1594 + 'icon' => 'frmfont frm_shield_check2_icon',
1595 + ),
1429 1596 'permissions' => array(
1430 1597 'name' => __( 'Form Permissions', 'formidable' ),
1431 - 'icon' => 'frm_icon_font frm_lock_closed_icon',
1598 + 'icon' => 'frmfont frm_lock_closed2_icon',
1432 1599 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1433 1600 'data' => array(
1434 1601 'medium' => 'permissions',
1435 1602 'upgrade' => __( 'Form Permissions', 'formidable' ),
@@ -1434,18 +1601,20 @@
1434 1601 'medium' => 'permissions',
1435 1602 'upgrade' => __( 'Form Permissions', 'formidable' ),
1436 1603 'message' => __( 'Allow editing, protect forms and files, limit entries, and save drafts. Upgrade to get form and entry permissions.', 'formidable' ),
1437 1604 'screenshot' => 'permissions.png',
1605 + 'learn-more' => FrmAppHelper::get_doc_url( 'general-form-settings/#kb-form-permissions', 'form-permissions-settings' ),
1438 1606 ),
1439 1607 ),
1440 1608 'scheduling' => array(
1441 1609 'name' => __( 'Form Scheduling', 'formidable' ),
1442 - 'icon' => 'frm_icon_font frm_calendar_icon',
1610 + 'icon' => 'frmfont frm_schedule_icon',
1443 1611 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1444 1612 'data' => array(
1445 1613 'medium' => 'scheduling',
1446 1614 'upgrade' => __( 'Form scheduling settings', 'formidable' ),
1447 1615 'screenshot' => 'scheduling.png',
1616 + 'learn-more' => FrmAppHelper::get_doc_url( 'general-form-settings/#kb-form-scheduling', 'form-scheduling-settings' ),
1448 1617 ),
1449 1618 ),
1450 1619 'buttons' => array(
1451 1620 'name' => __( 'Buttons', 'formidable' ),
@@ -1450,19 +1619,19 @@
1450 1619 'buttons' => array(
1451 1620 'name' => __( 'Buttons', 'formidable' ),
1452 1621 'class' => self::class,
1453 1622 'function' => 'buttons_settings',
1454 - 'icon' => 'frm_icon_font frm_button_icon',
1623 + 'icon' => 'frmfont frm-buttons-style',
1455 1624 ),
1456 1625 'landing' => array(
1457 1626 'name' => __( 'Form Landing Page', 'formidable' ),
1458 - 'icon' => 'frm_icon_font frm_file_text_icon',
1627 + 'icon' => 'frmfont frm_cross_device_icon',
1459 1628 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1460 1629 'data' => FrmAppHelper::get_landing_page_upgrade_data_params(),
1461 1630 ),
1462 1631 'chat' => array(
1463 1632 'name' => __( 'Conversational Forms', 'formidable' ),
1464 - 'icon' => 'frm_icon_font frm_chat_forms_icon',
1633 + 'icon' => 'frmfont frm_chat_bubbles_icon',
1465 1634 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1466 1635 'data' => FrmAppHelper::get_upgrade_data_params(
1467 1636 'chat',
1468 1637 array(
@@ -1468,14 +1637,15 @@
1468 1637 array(
1469 1638 'upgrade' => __( 'Conversational Forms', 'formidable' ),
1470 1639 'message' => __( 'Ask one question at a time for automated conversations.', 'formidable' ),
1471 1640 'screenshot' => 'chat.png',
1641 + 'learn-more' => FrmAppHelper::get_doc_url( 'conversational-forms', 'conversational-forms-settings', false ),
1472 1642 )
1473 1643 ),
1474 1644 ),
1475 1645 'abandonment' => array(
1476 1646 'name' => __( 'Form Abandonment', 'formidable' ),
1477 - 'icon' => 'frm_icon_font frm_abandoned_icon',
1647 + 'icon' => 'frmfont frm_abandoned_icon',
1478 1648 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1479 1649 'data' => FrmAppHelper::get_upgrade_data_params(
1480 1650 'abandonment',
1481 1651 array(
@@ -1481,8 +1651,9 @@
1481 1651 array(
1482 1652 'upgrade' => __( 'Form abandonment settings', 'formidable' ),
1483 1653 'message' => __( 'Unlock the power of data capture to boost lead generation and master the art of form optimization.', 'formidable' ),
1484 1654 'screenshot' => 'abandonment.png',
1655 + 'learn-more' => FrmAppHelper::get_doc_url( 'features/form-abandonment-wordpress-plugin', 'form-abandonment-settings', false ),
1485 1656 )
1486 1657 ),
1487 1658 ),
1488 1659 'html' => array(
@@ -1488,9 +1659,9 @@
1488 1659 'html' => array(
1489 1660 'name' => __( 'Customize HTML', 'formidable' ),
1490 1661 'class' => self::class,
1491 1662 'function' => 'html_settings',
1492 - 'icon' => 'frm_icon_font frm_code_icon',
1663 + 'icon' => 'frmfont frm_code2_icon',
1493 1664 ),
1494 1665 );
1495 1666
1496 1667 if ( ! has_action( 'frm_add_form_style_tab_options' ) && ! has_action( 'frm_add_form_button_options' ) ) {
@@ -1496,14 +1667,8 @@
1496 1667 if ( ! has_action( 'frm_add_form_style_tab_options' ) && ! has_action( 'frm_add_form_button_options' ) ) {
1497 1668 unset( $sections['buttons'] );
1498 1669 }
1499 1670
1500 - foreach ( array( 'landing', 'chat', 'abandonment' ) as $feature ) {
1501 - if ( ! FrmAppHelper::show_new_feature( $feature ) ) {
1502 - unset( $sections[ $feature ] );
1503 - }
1504 - }
1505 -
1506 1671 $sections = apply_filters( 'frm_add_form_settings_section', $sections, $values );
1507 1672
1508 1673 foreach ( $sections as $key => $section ) {
1509 1674 $defaults = array(
@@ -1508,9 +1673,9 @@
1508 1673 foreach ( $sections as $key => $section ) {
1509 1674 $defaults = array(
1510 1675 'html_class' => '',
1511 1676 'name' => ucfirst( $key ),
1512 - 'icon' => 'frm_icon_font frm_settings_icon',
1677 + 'icon' => 'frmfont frm_settings_icon',
1513 1678 );
1514 1679
1515 1680 $section = array_merge( $defaults, $section );
1516 1681
@@ -1516,8 +1681,9 @@
1516 1681
1517 1682 if ( ! isset( $section['anchor'] ) ) {
1518 1683 $section['anchor'] = $key;
1519 1684 }
1685 +
1520 1686 $section['anchor'] .= '_settings';
1521 1687
1522 1688 if ( ! isset( $section['title'] ) ) {
1523 1689 $section['title'] = $section['name'];
@@ -1536,26 +1702,25 @@
1536 1702 /**
1537 1703 * @since 4.0
1538 1704 *
1539 1705 * @param array $values
1706 + *
1540 1707 * @return void
1541 1708 */
1542 1709 public static function advanced_settings( $values ) {
1543 1710 $first_h3 = 'frm_first_h3';
1544 -
1545 1711 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-advanced.php';
1546 1712 }
1547 1713
1548 1714 /**
1715 + * @since 6.33
1716 + *
1549 1717 * @param array $values
1718 + *
1550 1719 * @return void
1551 1720 */
1552 - public static function render_spam_settings( $values ) {
1553 - if ( function_exists( 'akismet_http_post' ) ) {
1554 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/akismet.php';
1555 - }
1556 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/stopforumspam.php';
1557 - 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';
1558 1723 }
1559 1724
1560 1725 /**
1561 1726 * @since 4.0
@@ -1560,8 +1725,9 @@
1560 1725 /**
1561 1726 * @since 4.0
1562 1727 *
1563 1728 * @param array $values
1729 + *
1564 1730 * @return void
1565 1731 */
1566 1732 public static function buttons_settings( $values ) {
1567 1733 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php';
@@ -1570,8 +1736,9 @@
1570 1736 /**
1571 1737 * @since 4.0
1572 1738 *
1573 1739 * @param array $values
1740 + *
1574 1741 * @return void
1575 1742 */
1576 1743 public static function html_settings( $values ) {
1577 1744 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php';
@@ -1582,8 +1749,9 @@
1582 1749 *
1583 1750 * @since 2.03.08
1584 1751 *
1585 1752 * @param array|bool $values
1753 + *
1586 1754 * @return void
1587 1755 */
1588 1756 private static function clean_submit_html( &$values ) {
1589 1757 if ( is_array( $values ) && isset( $values['submit_html'] ) ) {
@@ -1606,13 +1774,17 @@
1606 1774 return $classes;
1607 1775 }
1608 1776
1609 1777 /**
1778 + * @since 6.27 Added $template_path parameter.
1779 + *
1610 1780 * @param int|string $form_id
1611 1781 * @param string $class
1782 + * @param string $template_path The path to a template file to use instead of the default.
1783 + *
1612 1784 * @return void
1613 1785 */
1614 - public static function mb_tags_box( $form_id, $class = '' ) {
1786 + public static function mb_tags_box( $form_id, $class = '', $template_path = 'default' ) {
1615 1787 $fields = FrmField::get_all_for_form( $form_id, '', 'include' );
1616 1788
1617 1789 /**
1618 1790 * Allows modifying the list of fields in the tags box.
@@ -1621,23 +1793,30 @@
1621 1793 *
1622 1794 * @param array $fields The list of fields.
1623 1795 * @param array $args The arguments. Contains `form_id`.
1624 1796 */
1625 - $fields = apply_filters( 'frm_fields_in_tags_box', $fields, compact( 'form_id' ) );
1626 - $linked_forms = array();
1627 - $col = 'one';
1628 - $settings_tab = FrmAppHelper::is_admin_page( 'formidable' );
1629 -
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' );
1630 1801 $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() );
1631 - $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' ) );
1632 1804
1633 - $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 + }
1634 1809
1635 - include FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php';
1810 + include $template_path;
1636 1811 }
1637 1812
1638 1813 /**
1639 1814 * @since 3.04.01
1815 + *
1816 + * @param array $atts
1817 + *
1818 + * @return array
1640 1819 */
1641 1820 private static function advanced_helpers( $atts ) {
1642 1821 $advanced_helpers = array(
1643 1822 'default' => array(
@@ -1646,10 +1825,12 @@
1646 1825 ),
1647 1826 );
1648 1827
1649 1828 $user_fields = self::user_shortcodes();
1829 +
1650 1830 if ( $user_fields ) {
1651 1831 $user_helpers = array();
1832 +
1652 1833 foreach ( $user_fields as $uk => $uf ) {
1653 1834 $user_helpers[ '|user_id| show="' . $uk . '"' ] = $uf;
1654 1835 unset( $uk, $uf );
1655 1836 }
@@ -1670,12 +1851,132 @@
1670 1851 return apply_filters( 'frm_advanced_helpers', $advanced_helpers, $atts );
1671 1852 }
1672 1853
1673 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 + /**
1674 1973 * Get an array of the options to display in the advanced tab
1675 1974 * of the customization panel
1676 1975 *
1677 1976 * @since 2.0.6
1977 + *
1978 + * @return array
1678 1979 */
1679 1980 private static function get_advanced_shortcodes() {
1680 1981 $adv_shortcodes = array(
1681 1982 'x sep=", "' => array(
@@ -1692,17 +1993,18 @@
1692 1993 'label' => __( 'No Auto P', 'formidable' ),
1693 1994 'title' => __( 'Do not automatically add any paragraphs or line breaks', 'formidable' ),
1694 1995 ),
1695 1996 );
1696 - $adv_shortcodes = apply_filters( 'frm_advanced_shortcodes', $adv_shortcodes );
1697 1997
1698 1998 // __( 'Leave blank instead of defaulting to User Login', 'formidable' ) : blank=1
1699 1999
1700 - return $adv_shortcodes;
2000 + return apply_filters( 'frm_advanced_shortcodes', $adv_shortcodes );
1701 2001 }
1702 2002
1703 2003 /**
1704 2004 * @since 3.04.01
2005 + *
2006 + * @return array
1705 2007 */
1706 2008 private static function user_shortcodes() {
1707 2009 $options = array(
1708 2010 'ID' => __( 'User ID', 'formidable' ),
@@ -1721,10 +2023,15 @@
1721 2023 /**
1722 2024 * Get an array of the helper shortcodes to display in the customization panel
1723 2025 *
1724 2026 * @since 2.0.6
2027 + *
2028 + * @param bool $settings_tab
2029 + * @param int $form_id
2030 + *
2031 + * @return array
1725 2032 */
1726 - private static function get_shortcode_helpers( $settings_tab ) {
2033 + private static function get_shortcode_helpers( $settings_tab, $form_id = 0 ) {
1727 2034 $entry_shortcodes = array(
1728 2035 'id' => __( 'Entry ID', 'formidable' ),
1729 2036 'key' => __( 'Entry Key', 'formidable' ),
1730 2037 'post_id' => __( 'Post ID', 'formidable' ),
@@ -1737,8 +2044,9 @@
1737 2044 'form_name' => __( 'Form Name', 'formidable' ),
1738 2045 );
1739 2046
1740 2047 $entry_shortcodes = array_merge( FrmShortcodeHelper::get_contextual_shortcode_values(), $entry_shortcodes );
2048 +
1741 2049 if ( ! FrmAppHelper::pro_is_installed() ) {
1742 2050 unset( $entry_shortcodes['post_id'] );
1743 2051 }
1744 2052
@@ -1746,12 +2054,14 @@
1746 2054 * Use this hook to add or remove buttons in the helpers section
1747 2055 * in the customization panel
1748 2056 *
1749 2057 * @since 2.0.6
2058 + *
2059 + * @param array $entry_shortcodes
2060 + * @param bool $settings_tab
2061 + * @param int $form_id
1750 2062 */
1751 - $entry_shortcodes = apply_filters( 'frm_helper_shortcodes', $entry_shortcodes, $settings_tab );
1752 -
1753 - return $entry_shortcodes;
2063 + return apply_filters( 'frm_helper_shortcodes', $entry_shortcodes, $settings_tab, $form_id );
1754 2064 }
1755 2065
1756 2066 /**
1757 2067 * Insert the form class setting into the form.
@@ -1756,8 +2066,9 @@
1756 2066 /**
1757 2067 * Insert the form class setting into the form.
1758 2068 *
1759 2069 * @param stdClass $form
2070 + *
1760 2071 * @return void
1761 2072 */
1762 2073 public static function form_classes( $form ) {
1763 2074 if ( isset( $form->options['form_class'] ) ) {
@@ -1780,8 +2091,9 @@
1780 2091 * @param stdClass $form
1781 2092 */
1782 2093 public static function add_js_validate_form_to_global_vars( $form ) {
1783 2094 global $frm_vars;
2095 +
1784 2096 if ( ! isset( $frm_vars['js_validate_forms'] ) ) {
1785 2097 $frm_vars['js_validate_forms'] = array();
1786 2098 }
1787 2099 $frm_vars['js_validate_forms'][ $form->id ] = $form;
@@ -1804,8 +2116,9 @@
1804 2116 /**
1805 2117 * @param string $content
1806 2118 * @param int|stdClass|string $form
1807 2119 * @param false|int|stdClass|string $entry
2120 + *
1808 2121 * @return string
1809 2122 */
1810 2123 public static function filter_content( $content, $form, $entry = false ) {
1811 2124 $content = self::replace_form_name_shortcodes( $content, $form );
@@ -1810,8 +2123,9 @@
1810 2123 public static function filter_content( $content, $form, $entry = false ) {
1811 2124 $content = self::replace_form_name_shortcodes( $content, $form );
1812 2125
1813 2126 self::get_entry_by_param( $entry );
2127 +
1814 2128 if ( ! $entry ) {
1815 2129 return $content;
1816 2130 }
1817 2131
@@ -1827,11 +2141,10 @@
1827 2141 $form = $entry->parent_entry->form_id;
1828 2142 }
1829 2143
1830 2144 $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form );
1831 - $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
1832 2145
1833 - return $content;
2146 + return apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
1834 2147 }
1835 2148
1836 2149 /**
1837 2150 * Replace any [form_name] shortcodes in a string.
@@ -1839,8 +2152,9 @@
1839 2152 * @since 5.5
1840 2153 *
1841 2154 * @param array|string $string
1842 2155 * @param int|stdClass|string $form
2156 + *
1843 2157 * @return array|string
1844 2158 */
1845 2159 public static function replace_form_name_shortcodes( $string, $form ) {
1846 2160 if ( ! is_string( $string ) ) {
@@ -1846,9 +2160,9 @@
1846 2160 if ( ! is_string( $string ) ) {
1847 2161 return $string;
1848 2162 }
1849 2163
1850 - if ( false === strpos( $string, '[form_name]' ) ) {
2164 + if ( ! str_contains( $string, '[form_name]' ) ) {
1851 2165 return $string;
1852 2166 }
1853 2167
1854 2168 if ( ! is_object( $form ) ) {
@@ -1860,20 +2174,30 @@
1860 2174 }
1861 2175
1862 2176 /**
1863 2177 * @param false|int|stdClass|string $entry
2178 + *
1864 2179 * @return void
1865 2180 */
1866 2181 private static function get_entry_by_param( &$entry ) {
1867 - if ( ! $entry || ! is_object( $entry ) ) {
1868 - if ( ! $entry || ! is_numeric( $entry ) ) {
1869 - $entry = FrmAppHelper::get_post_param( 'id', false, 'sanitize_title' );
1870 - }
2182 + if ( $entry && is_object( $entry ) ) {
2183 + return;
2184 + }
1871 2185
1872 - FrmEntry::maybe_get_entry( $entry );
2186 + if ( ! $entry || ! is_numeric( $entry ) ) {
2187 + $entry = FrmAppHelper::get_post_param( 'id', false, 'sanitize_title' );
1873 2188 }
2189 +
2190 + FrmEntry::maybe_get_entry( $entry );
1874 2191 }
1875 2192
2193 + /**
2194 + * @param string $content
2195 + * @param false|object $entry
2196 + * @param array $shortcodes
2197 + *
2198 + * @return string
2199 + */
1876 2200 public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
1877 2201 return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes );
1878 2202 }
1879 2203
@@ -1878,8 +2202,9 @@
1878 2202 }
1879 2203
1880 2204 /**
1881 2205 * @param array $errors
2206 + *
1882 2207 * @return array
1883 2208 */
1884 2209 public static function process_bulk_form_actions( $errors ) {
1885 2210 if ( ! $_REQUEST ) {
@@ -1886,29 +2211,30 @@
1886 2211 return $errors;
1887 2212 }
1888 2213
1889 2214 $bulkaction = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
2215 +
2216 + // phpcs:ignore Universal.Operators.StrictComparisons
1890 2217 if ( $bulkaction == - 1 ) {
1891 2218 $bulkaction = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
1892 2219 }
1893 2220
1894 - if ( ! empty( $bulkaction ) && strpos( $bulkaction, 'bulk_' ) === 0 ) {
2221 + if ( $bulkaction && str_starts_with( $bulkaction, 'bulk_' ) ) {
1895 2222 FrmAppHelper::remove_get_action();
1896 -
1897 2223 $bulkaction = str_replace( 'bulk_', '', $bulkaction );
1898 2224 }
1899 2225
1900 2226 $ids = FrmAppHelper::get_param( 'item-action', '', 'get', 'sanitize_text_field' );
1901 - if ( empty( $ids ) ) {
2227 +
2228 + if ( ! $ids ) {
1902 2229 $errors[] = __( 'No forms were specified', 'formidable' );
1903 -
1904 2230 return $errors;
1905 2231 }
1906 2232
1907 2233 $permission_error = FrmAppHelper::permission_nonce_error( '', '_wpnonce', 'bulk-toplevel_page_formidable' );
2234 +
1908 2235 if ( $permission_error !== false ) {
1909 2236 $errors[] = $permission_error;
1910 -
1911 2237 return $errors;
1912 2238 }
1913 2239
1914 2240 if ( ! is_array( $ids ) ) {
@@ -1936,8 +2262,9 @@
1936 2262 /**
1937 2263 * Includes html that shows a message when the device is too small to use Formidable Forms admin pages.
1938 2264 *
1939 2265 * @since 6.20
2266 + *
1940 2267 * @return void
1941 2268 */
1942 2269 public static function include_device_too_small_message() {
1943 2270 if ( ! FrmAppHelper::is_formidable_admin() ) {
@@ -1946,12 +2273,13 @@
1946 2273
1947 2274 include FrmAppHelper::plugin_path() . '/classes/views/shared/small-device-message.php';
1948 2275 }
1949 2276
1950 - public static function route() {
2277 + public static function route() { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.MaxExceeded
1951 2278 $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
1952 2279 $vars = array();
1953 2280 FrmAppHelper::include_svg();
2281 +
1954 2282 if ( isset( $_POST['frm_compact_fields'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
1955 2283 FrmAppHelper::permission_check( 'frm_edit_forms' );
1956 2284
1957 2285 // Javascript needs to be allowed in some field settings.
@@ -1957,25 +2285,28 @@
1957 2285 // Javascript needs to be allowed in some field settings.
1958 2286 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
1959 2287 $json_vars = htmlspecialchars_decode( nl2br( str_replace( '&quot;', '"', wp_unslash( $_POST['frm_compact_fields'] ) ) ) );
1960 2288 $json_vars = json_decode( $json_vars, true );
1961 - if ( empty( $json_vars ) ) {
1962 - // 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.
1963 2298 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
2299 +
1964 2300 if ( 'edit' === $action ) {
1965 2301 $action = 'update';
1966 2302 }
1967 2303
1968 2304 add_filter( 'frm_validate_form', 'FrmFormsController::json_error' );
1969 - } else {
1970 - $vars = FrmAppHelper::json_to_array( $json_vars );
1971 - $action = $vars[ $action ];
1972 - unset( $_REQUEST['frm_compact_fields'], $_POST['frm_compact_fields'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
1973 - $_REQUEST = array_merge( $_REQUEST, $vars ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
1974 - $_POST = array_merge( $_POST, $_REQUEST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
1975 2305 }
1976 2306 } else {
1977 2307 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
2308 +
1978 2309 if ( isset( $_REQUEST['delete_all'] ) ) {
1979 2310 // Override the action for this page.
1980 2311 $action = 'delete_all';
1981 2312 }
@@ -1995,34 +2326,38 @@
1995 2326 case 'update_settings':
1996 2327 return self::$action( $vars );
1997 2328 case 'lite-reports':
1998 2329 self::no_reports( $vars );
1999 - return;
2330 + return null;
2000 2331 case 'views':
2001 2332 self::no_views( $vars );
2002 - return;
2333 + return null;
2003 2334 default:
2004 2335 do_action( 'frm_form_action_' . $action );
2336 +
2005 2337 if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) {
2006 - return;
2338 + return null;
2007 2339 }
2008 2340
2009 2341 $action = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
2342 +
2343 + // phpcs:ignore Universal.Operators.StrictComparisons
2010 2344 if ( $action == - 1 ) {
2011 2345 $action = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
2012 2346 }
2013 2347
2014 - if ( strpos( $action, 'bulk_' ) === 0 ) {
2348 + if ( str_starts_with( $action, 'bulk_' ) ) {
2015 2349 FrmAppHelper::remove_get_action();
2016 2350
2017 2351 self::list_form();
2018 - return;
2352 + return null;
2019 2353 }
2020 2354
2021 2355 $message = FrmAppHelper::get_param( 'message' );
2356 +
2022 2357 if ( 'form_duplicate_error' === $message ) {
2023 2358 self::display_forms_list( array(), '', array( __( 'There was a problem duplicating the form', 'formidable' ) ) );
2024 - return;
2359 + return null;
2025 2360 }
2026 2361
2027 2362 if ( 'forms_permanently_deleted' === $message ) {
2028 2363 $count = FrmAppHelper::get_param( 'forms_deleted', 0, 'get', 'absint' );
@@ -2028,14 +2363,14 @@
2028 2363 $count = FrmAppHelper::get_param( 'forms_deleted', 0, 'get', 'absint' );
2029 2364 /* translators: %1$s: Number of forms */
2030 2365 $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
2031 2366 self::display_forms_list( array(), $message, '' );
2032 - return;
2367 + return null;
2033 2368 }
2034 2369
2035 2370 self::display_forms_list();
2036 2371
2037 - return;
2372 + return null;
2038 2373 }//end switch
2039 2374 }
2040 2375
2041 2376 /**
@@ -2054,10 +2389,10 @@
2054 2389
2055 2390 // Get posted data
2056 2391 $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
2057 2392 $name = FrmAppHelper::get_post_param( 'form_name', '', 'sanitize_text_field' );
2393 + $form = FrmForm::getOne( $form_id );
2058 2394
2059 - $form = FrmForm::getOne( $form_id );
2060 2395 if ( ! $form ) {
2061 2396 wp_send_json_error( __( 'Form not found', 'formidable' ) );
2062 2397 }
2063 2398
@@ -2062,9 +2397,10 @@
2062 2397 }
2063 2398
2064 2399 if ( $name === $form->name ) {
2065 2400 // Nothing to change so exit early.
2066 - wp_send_json_success();
2401 + $form_key = $form->form_key;
2402 + wp_send_json_success( compact( 'form_key' ) );
2067 2403 }
2068 2404
2069 2405 $to_update = array(
2070 2406 'name' => $name,
@@ -2069,14 +2405,14 @@
2069 2405 $to_update = array(
2070 2406 'name' => $name,
2071 2407 );
2072 2408
2073 - if ( '' !== $name ) {
2409 + if ( '' === $name ) {
2410 + $form_key = $form->form_key;
2411 + } else {
2074 2412 // Only update form_key if name is not empty.
2075 2413 $form_key = FrmAppHelper::get_unique_key( sanitize_title( $name ), 'frm_forms', 'form_key' );
2076 2414 $to_update['form_key'] = $form_key;
2077 - } else {
2078 - $form_key = $form->form_key;
2079 2415 }
2080 2416
2081 2417 FrmForm::update( $form_id, $to_update );
2082 2418
@@ -2082,11 +2418,15 @@
2082 2418
2083 2419 wp_send_json_success( compact( 'form_key' ) );
2084 2420 }
2085 2421
2422 + /**
2423 + * @param array $errors
2424 + *
2425 + * @return array
2426 + */
2086 2427 public static function json_error( $errors ) {
2087 2428 $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
2088 -
2089 2429 return $errors;
2090 2430 }
2091 2431
2092 2432 /**
@@ -2093,8 +2433,10 @@
2093 2433 * Add education about views.
2094 2434 *
2095 2435 * @since 4.07
2096 2436 *
2437 + * @param array $values
2438 + *
2097 2439 * @return void
2098 2440 */
2099 2441 public static function no_views( $values = array() ) {
2100 2442 FrmAppHelper::include_svg();
@@ -2108,8 +2450,10 @@
2108 2450 * Add education about reports.
2109 2451 *
2110 2452 * @since 4.07
2111 2453 *
2454 + * @param array $values
2455 + *
2112 2456 * @return void
2113 2457 */
2114 2458 public static function no_reports( $values = array() ) {
2115 2459 $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
@@ -2135,10 +2479,9 @@
2135 2479 /**
2136 2480 * @since 4.05.02
2137 2481 */
2138 2482 private static function move_menu_to_footer() {
2139 - $settings = FrmAppHelper::get_settings();
2140 - if ( empty( $settings->admin_bar ) ) {
2483 + if ( empty( FrmAppHelper::get_settings()->admin_bar ) ) {
2141 2484 remove_action( 'wp_body_open', 'wp_admin_bar_render', 0 );
2142 2485 }
2143 2486 }
2144 2487
@@ -2143,13 +2486,15 @@
2143 2486 }
2144 2487
2145 2488 public static function admin_bar_configure() {
2146 2489 global $frm_vars;
2490 +
2147 2491 if ( empty( $frm_vars['forms_loaded'] ) ) {
2148 2492 return;
2149 2493 }
2150 2494
2151 2495 $actions = array();
2496 +
2152 2497 foreach ( $frm_vars['forms_loaded'] as $form ) {
2153 2498 if ( is_object( $form ) ) {
2154 2499 $actions[ $form->id ] = $form->name;
2155 2500 }
@@ -2155,9 +2500,9 @@
2155 2500 }
2156 2501 unset( $form );
2157 2502 }
2158 2503
2159 - if ( empty( $actions ) ) {
2504 + if ( ! $actions ) {
2160 2505 return;
2161 2506 }
2162 2507
2163 2508 self::add_menu_to_admin_bar();
@@ -2183,8 +2528,12 @@
2183 2528 }
2184 2529
2185 2530 /**
2186 2531 * @since 2.05.07
2532 + *
2533 + * @param array $actions
2534 + *
2535 + * @return void
2187 2536 */
2188 2537 private static function add_forms_to_admin_bar( $actions ) {
2189 2538 global $wp_admin_bar;
2190 2539
@@ -2190,14 +2539,13 @@
2190 2539
2191 2540 asort( $actions );
2192 2541
2193 2542 foreach ( $actions as $form_id => $name ) {
2194 -
2195 2543 $wp_admin_bar->add_node(
2196 2544 array(
2197 2545 'parent' => 'frm-forms',
2198 2546 'id' => 'edit_form_' . $form_id,
2199 - 'title' => empty( $name ) ? FrmFormsHelper::get_no_title_text() : $name,
2547 + 'title' => $name ? $name : FrmFormsHelper::get_no_title_text(),
2200 2548 'href' => FrmForm::get_edit_link( $form_id ),
2201 2549 )
2202 2550 );
2203 2551 }
@@ -2206,12 +2554,14 @@
2206 2554 /**
2207 2555 * The formidable shortcode
2208 2556 *
2209 2557 * @param array $atts The params from the shortcode.
2558 + *
2210 2559 * @return string
2211 2560 */
2212 2561 public static function get_form_shortcode( $atts ) {
2213 2562 global $frm_vars;
2563 +
2214 2564 if ( ! empty( $frm_vars['skip_shortcode'] ) ) {
2215 2565 $sc = '[formidable';
2216 2566 $sc .= FrmAppHelper::array_to_html_params( $atts );
2217 2567 return $sc . ']';
@@ -2240,8 +2590,9 @@
2240 2590 * @since 5.2.01
2241 2591 *
2242 2592 * @param false|int|string $id
2243 2593 * @param false|string $key
2594 + *
2244 2595 * @return false|stdClass
2245 2596 */
2246 2597 private static function maybe_get_form_by_id_or_key( $id, $key ) {
2247 2598 if ( ! $id ) {
@@ -2255,8 +2606,9 @@
2255 2606 * @param false|string $key
2256 2607 * @param bool|int|string $title may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
2257 2608 * @param bool|int|string $description may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
2258 2609 * @param array $atts
2610 + *
2259 2611 * @return string
2260 2612 */
2261 2613 public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) {
2262 2614 $form = self::maybe_get_form_by_id_or_key( $id, $key );
@@ -2277,14 +2629,13 @@
2277 2629
2278 2630 add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
2279 2631 FrmAppHelper::trigger_hook_load( 'form', $form );
2280 2632
2281 - $form = apply_filters( 'frm_pre_display_form', $form );
2282 -
2633 + $form = apply_filters( 'frm_pre_display_form', $form );
2283 2634 $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) );
2284 2635
2285 2636 if ( self::is_viewable_draft_form( $form ) ) {
2286 - // don't show a draft form on a page
2637 + // Don't show a draft form on a page
2287 2638 $form = __( 'Please select a valid form', 'formidable' );
2288 2639 } elseif ( ! FrmForm::is_visible_to_user( $form ) ) {
2289 2640 $form = do_shortcode( $frm_settings->login_msg );
2290 2641 } else {
@@ -2304,16 +2655,18 @@
2304 2655 }
2305 2656
2306 2657 /**
2307 2658 * @param false|int|string $id
2659 + *
2308 2660 * @return false|stdClass
2309 2661 */
2310 2662 private static function maybe_get_form_to_show( $id ) {
2311 2663 $form = false;
2312 2664
2313 - if ( ! empty( $id ) ) {
2665 + if ( $id ) {
2314 2666 // Form id or key is set.
2315 2667 $form = FrmForm::getOne( $id );
2668 +
2316 2669 if ( ! $form || $form->parent_form_id || $form->status === 'trash' ) {
2317 2670 $form = false;
2318 2671 }
2319 2672 }
@@ -2320,12 +2673,25 @@
2320 2673
2321 2674 return $form;
2322 2675 }
2323 2676
2677 + /**
2678 + * @param object $form
2679 + *
2680 + * @return bool
2681 + */
2324 2682 private static function is_viewable_draft_form( $form ) {
2325 2683 return $form->status === 'draft' && current_user_can( 'frm_edit_forms' ) && ! FrmAppHelper::is_preview_page();
2326 2684 }
2327 2685
2686 + /**
2687 + * @param object $form
2688 + * @param bool $title
2689 + * @param bool $description
2690 + * @param array $atts
2691 + *
2692 + * @return string
2693 + */
2328 2694 public static function get_form( $form, $title, $description, $atts = array() ) {
2329 2695 ob_start();
2330 2696
2331 2697 do_action( 'frm_before_get_form', $atts );
@@ -2332,10 +2698,9 @@
2332 2698
2333 2699 self::get_form_contents( $form, $title, $description, $atts );
2334 2700 self::enqueue_scripts( FrmForm::get_params( $form ) );
2335 2701
2336 - $contents = ob_get_contents();
2337 - ob_end_clean();
2702 + $contents = ob_get_clean();
2338 2703
2339 2704 self::maybe_minimize_form( $atts, $contents );
2340 2705
2341 2706 return $contents;
@@ -2340,12 +2705,25 @@
2340 2705
2341 2706 return $contents;
2342 2707 }
2343 2708
2709 + /**
2710 + * @param array $params
2711 + *
2712 + * @return void
2713 + */
2344 2714 public static function enqueue_scripts( $params ) {
2345 2715 do_action( 'frm_enqueue_form_scripts', $params );
2346 2716 }
2347 2717
2718 + /**
2719 + * @param object $form
2720 + * @param bool $title
2721 + * @param bool $description
2722 + * @param array $atts
2723 + *
2724 + * @return void
2725 + */
2348 2726 public static function get_form_contents( $form, $title, $description, $atts ) {
2349 2727 $params = FrmForm::get_params( $form );
2350 2728 $errors = self::get_saved_errors( $form, $params );
2351 2729 $fields = FrmFieldsHelper::get_form_fields( $form->id, $errors );
@@ -2352,9 +2730,10 @@
2352 2730 $reset = false;
2353 2731 $pass_args = compact( 'form', 'fields', 'errors', 'title', 'description', 'reset' );
2354 2732
2355 2733 $pass_args['action'] = $params['action'];
2356 - $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;
2357 2736
2358 2737 if ( ! $handle_process_here ) {
2359 2738 FrmFormState::set_initial_value( 'title', $title );
2360 2739 FrmFormState::set_initial_value( 'description', $description );
@@ -2359,16 +2738,15 @@
2359 2738 FrmFormState::set_initial_value( 'title', $title );
2360 2739 FrmFormState::set_initial_value( 'description', $description );
2361 2740
2362 2741 do_action( 'frm_display_form_action', $params, $fields, $form, $title, $description );
2742 +
2363 2743 if ( apply_filters( 'frm_continue_to_new', true, $form->id, $params['action'] ) ) {
2364 2744 self::show_form_after_submit( $pass_args );
2365 2745 }
2366 - } elseif ( ! empty( $errors ) ) {
2746 + } elseif ( $errors ) {
2367 2747 self::show_form_after_submit( $pass_args );
2368 -
2369 2748 } else {
2370 -
2371 2749 do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description );
2372 2750
2373 2751 if ( apply_filters( 'frm_continue_to_create', true, $form->id ) ) {
2374 2752 $entry_id = self::just_created_entry( $form->id );
@@ -2391,13 +2769,19 @@
2391 2769 /**
2392 2770 * If the form was processed earlier (init), get the generated errors
2393 2771 *
2394 2772 * @since 2.05
2773 + *
2774 + * @param object $form
2775 + * @param array $params
2776 + *
2777 + * @return array
2395 2778 */
2396 2779 private static function get_saved_errors( $form, $params ) {
2397 2780 global $frm_vars;
2398 2781
2399 - 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 ] ) ) {
2400 2784 $errors = $frm_vars['created_entries'][ $form->id ]['errors'];
2401 2785 } else {
2402 2786 $errors = array();
2403 2787 }
@@ -2414,13 +2798,16 @@
2414 2798 }
2415 2799
2416 2800 /**
2417 2801 * @since 2.2.7
2802 + *
2803 + * @param int|string $form_id
2804 + *
2805 + * @return int
2418 2806 */
2419 2807 public static function just_created_entry( $form_id ) {
2420 2808 global $frm_vars;
2421 -
2422 - 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
2423 2810 }
2424 2811
2425 2812 /**
2426 2813 * Gets confirmation method.
@@ -2433,8 +2820,9 @@
2433 2820 *
2434 2821 * @type object $form Form object.
2435 2822 * @type int $entry_id Entry ID.
2436 2823 * }
2824 + *
2437 2825 * @return array|string
2438 2826 */
2439 2827 private static function get_confirmation_method( $atts ) {
2440 2828 $action = FrmOnSubmitHelper::current_event( $atts );
@@ -2442,8 +2830,9 @@
2442 2830 $method = ! empty( $atts['form']->options[ $opt ] ) ? $atts['form']->options[ $opt ] : 'message';
2443 2831
2444 2832 if ( ! empty( $atts['entry_id'] ) ) {
2445 2833 $met_actions = self::get_met_on_submit_actions( $atts, $action );
2834 +
2446 2835 if ( $met_actions ) {
2447 2836 $method = $met_actions;
2448 2837 }
2449 2838 }
@@ -2450,14 +2839,21 @@
2450 2839
2451 2840 $method = apply_filters( 'frm_success_filter', $method, $atts['form'], $action );
2452 2841
2453 2842 if ( $method !== 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
2454 - $method = 'message';
2843 + return 'message';
2455 2844 }
2456 2845
2457 2846 return $method;
2458 2847 }
2459 2848
2849 + /**
2850 + * @param object $form
2851 + * @param array $params
2852 + * @param array $args
2853 + *
2854 + * @return void
2855 + */
2460 2856 public static function maybe_trigger_redirect( $form, $params, $args ) {
2461 2857 if ( ! isset( $params['id'] ) ) {
2462 2858 global $frm_vars;
2463 2859 $params['id'] = $frm_vars['created_entries'][ $form->id ]['entry_id'];
@@ -2484,14 +2880,12 @@
2484 2880 * @param array $params See {@see FrmFormsController::maybe_trigger_redirect()}.
2485 2881 * @param array $args See {@see FrmFormsController::maybe_trigger_redirect()}.
2486 2882 */
2487 2883 public static function maybe_trigger_redirect_with_action( $conf_method, $form, $params, $args ) {
2488 - if ( is_array( $conf_method ) && 1 === count( $conf_method ) ) {
2489 - if ( 'redirect' === FrmOnSubmitHelper::get_action_type( $conf_method[0] ) && empty( $conf_method[0]->post_content['redirect_delay'] ) ) {
2490 - $event = FrmOnSubmitHelper::current_event( $params );
2491 - FrmOnSubmitHelper::populate_on_submit_data( $form->options, $conf_method[0], $event );
2492 - $conf_method = 'redirect';
2493 - }
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';
2494 2888 }
2495 2889
2496 2890 if ( 'redirect' === $conf_method ) {
2497 2891 self::trigger_redirect( $form, $params, $args );
@@ -2497,8 +2891,15 @@
2497 2891 self::trigger_redirect( $form, $params, $args );
2498 2892 }
2499 2893 }
2500 2894
2895 + /**
2896 + * @param object $form
2897 + * @param array $params
2898 + * @param array $args
2899 + *
2900 + * @return void
2901 + */
2501 2902 public static function trigger_redirect( $form, $params, $args ) {
2502 2903 $success_args = array(
2503 2904 'action' => $params['action'],
2504 2905 'conf_method' => 'redirect',
@@ -2557,8 +2958,9 @@
2557 2958 * @since 6.0
2558 2959 *
2559 2960 * @param array $args See {@see FrmFormsController::run_success_action()}.
2560 2961 * @param string $event Form event. Default is `create`.
2962 + *
2561 2963 * @return array Array of actions that meet the conditional logics.
2562 2964 */
2563 2965 public static function get_met_on_submit_actions( $args, $event = 'create' ) {
2564 2966 if ( ! FrmOnSubmitHelper::form_has_migrated( $args['form'] ) ) {
@@ -2585,13 +2987,11 @@
2585 2987 }
2586 2988
2587 2989 $action_type = FrmOnSubmitHelper::get_action_type( $action );
2588 2990
2589 - if ( 'redirect' === $action_type ) {
2590 - if ( $has_redirect ) {
2591 - // Do not process because we run the first redirect action only.
2592 - continue;
2593 - }
2991 + if ( 'redirect' === $action_type && $has_redirect ) {
2992 + // Do not process because we run the first redirect action only.
2993 + continue;
2594 2994 }
2595 2995
2596 2996 if ( ! self::is_valid_on_submit_action( $action, $args, $event ) ) {
2597 2997 continue;
@@ -2616,10 +3016,10 @@
2616 3016 * @param array $args See {@see FrmFormsController::run_success_action()}. `$args['event']` is also added.
2617 3017 */
2618 3018 $met_actions = apply_filters( 'frm_get_met_on_submit_actions', $met_actions, $args );
2619 3019
2620 - if ( empty( $met_actions ) ) {
2621 - $met_actions = array( FrmOnSubmitHelper::get_fallback_action( $event ) );
3020 + if ( ! $met_actions ) {
3021 + return array( FrmOnSubmitHelper::get_fallback_action( $event ) );
2622 3022 }
2623 3023
2624 3024 return $met_actions;
2625 3025 }
@@ -2631,8 +3031,9 @@
2631 3031 *
2632 3032 * @param object $action Form action object.
2633 3033 * @param array $args See {@see FrmFormsController::run_success_action()}.
2634 3034 * @param string $event Form event. Default is `create`.
3035 + *
2635 3036 * @return bool
2636 3037 */
2637 3038 private static function is_valid_on_submit_action( $action, $args, $event = 'create' ) {
2638 3039 $action_type = FrmOnSubmitHelper::get_action_type( $action );
@@ -2654,8 +3055,9 @@
2654 3055 return false;
2655 3056 }
2656 3057
2657 3058 $page = get_post( $action->post_content['success_page_id'] );
3059 +
2658 3060 if ( ! $page || 'trash' === $page->post_status ) {
2659 3061 return false;
2660 3062 }
2661 3063 }
@@ -2677,8 +3079,9 @@
2677 3079 'entry_id' => $args['entry_id'],
2678 3080 'action' => FrmOnSubmitHelper::current_event( $args ),
2679 3081 )
2680 3082 );
3083 +
2681 3084 if ( ! is_array( $args['conf_method'] ) ) {
2682 3085 self::run_success_action( $args );
2683 3086 return;
2684 3087 }
@@ -2705,8 +3108,9 @@
2705 3108 * @param array $args See {@see FrmFormsController::run_success_action()}.
2706 3109 */
2707 3110 public static function run_multi_on_submit_actions( $args ) {
2708 3111 $redirect_action = null;
3112 +
2709 3113 foreach ( $args['conf_method'] as $action ) {
2710 3114 if ( 'redirect' === FrmOnSubmitHelper::get_action_type( $action ) ) {
2711 3115 // We catch the redirect action to run it last.
2712 3116 $redirect_action = $action;
@@ -2717,13 +3121,15 @@
2717 3121
2718 3122 unset( $action );
2719 3123 }
2720 3124
2721 - if ( $redirect_action ) {
2722 - // Show script to delay the redirection.
2723 - $args['force_delay_redirect'] = true;
2724 - self::run_single_on_submit_action( $args, $redirect_action );
3125 + if ( ! $redirect_action ) {
3126 + return;
2725 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 );
2726 3132 }
2727 3133
2728 3134 /**
2729 3135 * Runs single On Submit action.
@@ -2744,8 +3150,9 @@
2744 3150 * @since 6.0
2745 3151 *
2746 3152 * @param array $args See {@see FrmFormsController::run_success_action()}.
2747 3153 * @param object $action On Submit action object.
3154 + *
2748 3155 * @return array
2749 3156 */
2750 3157 private static function get_run_success_action_args( $args, $action ) {
2751 3158 $new_args = $args;
@@ -2751,10 +3158,9 @@
2751 3158 $new_args = $args;
2752 3159
2753 3160 FrmOnSubmitHelper::populate_on_submit_data( $new_args['form']->options, $action, $args['action'] );
2754 3161
2755 - $opt = 'update' === $args['action'] ? 'edit_' : 'success_';
2756 -
3162 + $opt = 'update' === $args['action'] ? 'edit_' : 'success_';
2757 3163 $new_args['conf_method'] = $new_args['form']->options[ $opt . 'action' ];
2758 3164
2759 3165 /**
2760 3166 * Filters the run success action args.
@@ -2769,12 +3175,18 @@
2769 3175 }
2770 3176
2771 3177 /**
2772 3178 * @since 3.0
3179 + *
3180 + * @param array $args
3181 + *
3182 + * @return void
2773 3183 */
2774 3184 private static function load_page_after_submit( $args ) {
2775 3185 global $post;
2776 3186 $opt = $args['success_opt'];
3187 +
3188 + // phpcs:ignore Universal.Operators.StrictComparisons
2777 3189 if ( ! $post || $args['form']->options[ $opt . '_page_id' ] != $post->ID ) {
2778 3190 $page = get_post( $args['form']->options[ $opt . '_page_id' ] );
2779 3191 $old_post = $post;
2780 3192 $post = $page;
@@ -2798,8 +3210,9 @@
2798 3210 }
2799 3211
2800 3212 /**
2801 3213 * @since 3.0
3214 + *
2802 3215 * @param array $args See {@see FrmFormsController::run_success_action()}.
2803 3216 */
2804 3217 private static function redirect_after_submit( $args ) {
2805 3218 add_filter( 'frm_use_wpautop', '__return_false' );
@@ -2813,11 +3226,10 @@
2813 3226 FrmEntriesController::delete_entry_before_redirect( $success_url, $args['form'], $args );
2814 3227
2815 3228 add_filter( 'frm_redirect_url', 'FrmEntriesController::prepare_redirect_url' );
2816 3229 $success_url = apply_filters( 'frm_redirect_url', $success_url, $args['form'], $args );
3230 + $doing_ajax = FrmAppHelper::doing_ajax();
2817 3231
2818 - $doing_ajax = FrmAppHelper::doing_ajax();
2819 -
2820 3232 if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) {
2821 3233 // Is AJAX submit and there is just one Redirect action runs.
2822 3234 echo json_encode( self::get_ajax_redirect_response_data( $args + compact( 'success_url' ) ) );
2823 3235 wp_die();
@@ -2866,8 +3278,9 @@
2866 3278 *
2867 3279 * @since 6.3.1
2868 3280 *
2869 3281 * @param array $args See {@see FrmFormsController::run_success_action()}.
3282 + *
2870 3283 * @return array
2871 3284 */
2872 3285 private static function get_ajax_redirect_response_data( $args ) {
2873 3286 $response_data = array(
@@ -2890,8 +3303,9 @@
2890 3303 $args['message'] = FrmOnSubmitHelper::get_default_new_tab_msg();
2891 3304
2892 3305 $args['form']->options['success_msg'] = $args['message'];
2893 3306 $args['form']->options['edit_msg'] = $args['message'];
3307 +
2894 3308 if ( ! isset( $args['fields'] ) ) {
2895 3309 $args['fields'] = FrmField::get_all_for_form( $args['form']->id );
2896 3310 }
2897 3311
@@ -2943,13 +3357,15 @@
2943 3357 add_filter( 'frm_use_wpautop', '__return_true' );
2944 3358
2945 3359 echo FrmAppHelper::maybe_kses( $redirect_msg ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2946 3360 echo '<script>';
3361 +
2947 3362 if ( empty( $args['doing_ajax'] ) ) {
2948 3363 // Not AJAX submit, delay JS until window.load.
2949 3364 echo 'window.onload=function(){';
2950 3365 }
2951 3366 echo 'setTimeout(function(){' . $redirect_js . '}, ' . intval( $delay_time ) . ');'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3367 +
2952 3368 if ( empty( $args['doing_ajax'] ) ) {
2953 3369 echo '};';
2954 3370 }
2955 3371 echo '</script>';
@@ -2962,13 +3378,16 @@
2962 3378 * @param string $success_msg
2963 3379 * @param array $args
2964 3380 */
2965 3381 private static function get_redirect_message( $success_url, $success_msg, $args ) {
2966 - $success_msg = apply_filters( 'frm_content', $success_msg, $args['form'], $args['entry_id'] );
2967 - $success_msg = do_shortcode( FrmAppHelper::use_wpautop( $success_msg ) );
2968 - $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
2969 3387 self::get_redirect_fallback_message( $success_url, $args ) .
2970 3388 '</div></div>';
3389 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
2971 3390
2972 3391 $redirect_args = array(
2973 3392 'entry_id' => $args['entry_id'],
2974 3393 'form_id' => $args['form']->id,
@@ -2984,12 +3403,14 @@
2984 3403 * @since 6.3.1
2985 3404 *
2986 3405 * @param string $success_url Redirect URL.
2987 3406 * @param array $args Contains `form` object.
3407 + *
2988 3408 * @return string
2989 3409 */
2990 3410 private static function get_redirect_fallback_message( $success_url, $args ) {
2991 3411 $target = '';
3412 +
2992 3413 if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2993 3414 $target = ' target="_blank"';
2994 3415 }
2995 3416
@@ -3004,8 +3425,12 @@
3004 3425 /**
3005 3426 * Prepare to show the success message and empty form after submit
3006 3427 *
3007 3428 * @since 2.05
3429 + *
3430 + * @param array $atts
3431 + *
3432 + * @return void
3008 3433 */
3009 3434 public static function show_message_after_save( $atts ) {
3010 3435 $atts['message'] = self::prepare_submit_message( $atts['form'], $atts['entry_id'], $atts );
3011 3436
@@ -3011,8 +3436,9 @@
3011 3436
3012 3437 if ( ! isset( $atts['form']->options['show_form'] ) || $atts['form']->options['show_form'] ) {
3013 3438 if ( isset( $atts['action'] ) && 'update' === $atts['action'] && is_callable( array( 'FrmProEntriesController', 'show_front_end_form_with_entry' ) ) ) {
3014 3439 $entry = FrmEntry::getOne( $atts['entry_id'] );
3440 +
3015 3441 if ( $entry ) {
3016 3442 // This is copied from the Pro plugin.
3017 3443 $atts['conf_message'] = FrmProEntriesController::confirmation( 'message', $atts['form'], $atts['form']->options, $entry->id, $atts );
3018 3444 $atts['show_form'] = FrmProEntriesController::is_form_displayed_after_edit( $atts['form'] );
@@ -3029,8 +3455,12 @@
3029 3455 /**
3030 3456 * Show an empty form
3031 3457 *
3032 3458 * @since 2.05
3459 + *
3460 + * @param array $args
3461 + *
3462 + * @return void
3033 3463 */
3034 3464 private static function show_form_after_submit( $args ) {
3035 3465 self::fill_atts_for_form_display( $args );
3036 3466
@@ -3049,12 +3479,11 @@
3049 3479 }
3050 3480 unset( $args );
3051 3481
3052 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;
3053 3485
3054 - $frm_settings = FrmAppHelper::get_settings();
3055 - $submit = $form->options['submit_value'] ?? $frm_settings->submit_value;
3056 -
3057 3486 global $frm_vars;
3058 3487 self::maybe_load_css( $form, $values['custom_style'], $frm_vars['load_css'] );
3059 3488
3060 3489 $message_placement = self::message_placement( $form, $message );
@@ -3062,25 +3491,36 @@
3062 3491 include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php';
3063 3492 }
3064 3493
3065 3494 /**
3495 + * Gets message placement.
3496 + *
3066 3497 * @since 4.05.02
3067 - * @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'.
3068 3504 */
3069 - private static function message_placement( $form, $message ) {
3505 + public static function message_placement( $form, $message ) {
3070 3506 $place = 'before';
3071 3507
3072 3508 if ( $message && isset( $form->options['form_class'] ) ) {
3073 - if ( strpos( $form->options['form_class'], 'frm_below_success' ) !== false ) {
3509 + if ( str_contains( $form->options['form_class'], 'frm_below_success' ) ) {
3074 3510 $place = 'after';
3075 - } elseif ( strpos( $form->options['form_class'], 'frm_inline_success' ) !== false ) {
3511 + } elseif ( str_contains( $form->options['form_class'], 'frm_inline_success' ) ) {
3076 3512 $place = 'submit';
3077 3513 }
3078 3514 }
3079 3515
3080 3516 /**
3517 + * Filter the message placement.
3518 + *
3081 3519 * @since 4.05.02
3082 - * @return string - 'before' or 'after'
3520 + *
3521 + * @param string $place Accepts 'before', 'after', or 'submit'.
3522 + * @param array $args Args.
3083 3523 */
3084 3524 return apply_filters( 'frm_message_placement', $place, compact( 'form', 'message' ) );
3085 3525 }
3086 3526
@@ -3087,8 +3527,12 @@
3087 3527 /**
3088 3528 * Get all the values needed on the new.php entry page
3089 3529 *
3090 3530 * @since 2.05
3531 + *
3532 + * @param array $args
3533 + *
3534 + * @return void
3091 3535 */
3092 3536 private static function fill_atts_for_form_display( &$args ) {
3093 3537 if ( ! isset( $args['title'] ) && isset( $args['show_title'] ) ) {
3094 3538 $args['title'] = $args['show_title'];
@@ -3113,8 +3557,12 @@
3113 3557 /**
3114 3558 * Show the success message without the form
3115 3559 *
3116 3560 * @since 2.05
3561 + *
3562 + * @param array $atts
3563 + *
3564 + * @return void
3117 3565 */
3118 3566 private static function show_lone_success_message( $atts ) {
3119 3567 global $frm_vars;
3120 3568 $values = FrmEntriesHelper::setup_new_vars( $atts['fields'], $atts['form'], true );
@@ -3120,13 +3568,12 @@
3120 3568 $values = FrmEntriesHelper::setup_new_vars( $atts['fields'], $atts['form'], true );
3121 3569 self::maybe_load_css( $atts['form'], $values['custom_style'], $frm_vars['load_css'] );
3122 3570
3123 3571 $include_extra_container = 'frm_forms' . FrmFormsHelper::get_form_style_class( $values );
3572 + $errors = array();
3573 + $form = $atts['form'];
3574 + $message = $atts['message'];
3124 3575
3125 - $errors = array();
3126 - $form = $atts['form'];
3127 - $message = $atts['message'];
3128 -
3129 3576 include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php';
3130 3577 }
3131 3578
3132 3579 /**
@@ -3134,11 +3581,12 @@
3134 3581 *
3135 3582 * @since 2.05
3136 3583 * @since 6.0.x Added the third parameter.
3137 3584 *
3138 - * @param object $form Form object.
3139 - * @param int $entry_id Entry ID.
3140 - * @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 + *
3141 3589 * @return string
3142 3590 */
3143 3591 private static function prepare_submit_message( $form, $entry_id, $args = array() ) {
3144 3592 $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) );
@@ -3163,9 +3611,9 @@
3163 3611 public static function front_head() {
3164 3612 $version = FrmAppHelper::plugin_version();
3165 3613 $suffix = FrmAppHelper::js_suffix();
3166 3614
3167 - if ( ! empty( $suffix ) && self::has_combo_js_file() ) {
3615 + if ( $suffix && self::has_combo_js_file() ) {
3168 3616 wp_register_script( 'formidable', FrmAppHelper::plugin_url() . '/js/frm.min.js', array( 'jquery' ), $version, true );
3169 3617 } else {
3170 3618 wp_register_script( 'formidable', FrmAppHelper::plugin_url() . "/js/formidable{$suffix}.js", array( 'jquery' ), $version, true );
3171 3619 }
@@ -3172,9 +3620,9 @@
3172 3620
3173 3621 add_filter( 'script_loader_tag', 'FrmFormsController::defer_script_loading', 10, 2 );
3174 3622
3175 3623 if ( FrmAppHelper::is_admin() ) {
3176 - // don't load this in back-end
3624 + // Don't load this in back-end
3177 3625 return;
3178 3626 }
3179 3627
3180 3628 FrmAppHelper::localize_script( 'front' );
@@ -3187,8 +3635,15 @@
3187 3635 public static function has_combo_js_file() {
3188 3636 return is_readable( FrmAppHelper::plugin_path() . '/js/frm.min.js' );
3189 3637 }
3190 3638
3639 + /**
3640 + * @param object $form
3641 + * @param int|string $this_load
3642 + * @param bool $global_load
3643 + *
3644 + * @return void
3645 + */
3191 3646 public static function maybe_load_css( $form, $this_load, $global_load ) {
3192 3647 $load_css = FrmForm::is_form_loaded( $form, $this_load, $global_load );
3193 3648
3194 3649 if ( ! $load_css ) {
@@ -3218,8 +3673,9 @@
3218 3673 return;
3219 3674 }
3220 3675
3221 3676 global $wp_styles;
3677 +
3222 3678 if ( is_array( $wp_styles->queue ) && in_array( 'formidable', $wp_styles->queue, true ) ) {
3223 3679 wp_print_styles( 'formidable' );
3224 3680 }
3225 3681 }
@@ -3234,34 +3690,57 @@
3234 3690 private static function should_load_late() {
3235 3691 return ! function_exists( 'aioseo' );
3236 3692 }
3237 3693
3694 + /**
3695 + * @param string $tag
3696 + * @param string $handle
3697 + *
3698 + * @return string
3699 + */
3238 3700 public static function defer_script_loading( $tag, $handle ) {
3239 - if ( 'captcha-api' == $handle && ! strpos( $tag, 'defer' ) ) {
3240 - $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 );
3241 3703 }
3242 3704
3243 3705 return $tag;
3244 3706 }
3245 3707
3708 + /**
3709 + * @param string $location
3710 + *
3711 + * @return void
3712 + */
3246 3713 public static function footer_js( $location = 'footer' ) {
3247 3714 global $frm_vars;
3248 3715
3249 3716 FrmStylesController::enqueue_css();
3250 3717
3251 - if ( ! FrmAppHelper::is_admin() && $location !== 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
3252 - // load formidable js
3253 - wp_enqueue_script( 'formidable' );
3718 + if ( FrmAppHelper::is_admin() || $location === 'header' || empty( $frm_vars['forms_loaded'] ) ) {
3719 + return;
3720 + }
3254 3721
3255 - 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();
3256 3730 }
3257 3731 }
3258 3732
3259 3733 /**
3260 3734 * @since 2.0.8
3735 + *
3736 + * @param array $atts
3737 + * @param string $content
3738 + *
3739 + * @return void
3261 3740 */
3262 3741 private static function maybe_minimize_form( $atts, &$content ) {
3263 - // check if minimizing is turned on
3742 + // Check if minimizing is turned on
3264 3743 if ( self::is_minification_on( $atts ) ) {
3265 3744 $content = str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', $content );
3266 3745 }
3267 3746 }
@@ -3267,8 +3746,11 @@
3267 3746 }
3268 3747
3269 3748 /**
3270 3749 * @since 2.0.8
3750 + *
3751 + * @param array $atts
3752 + *
3271 3753 * @return bool
3272 3754 */
3273 3755 private static function is_minification_on( $atts ) {
3274 3756 return ! empty( $atts['minimize'] );
@@ -3280,11 +3762,13 @@
3280 3762 * @return void
3281 3763 */
3282 3764 public static function landing_page_preview_option() {
3283 3765 $dir = apply_filters( 'frm_landing_page_preview_option', false );
3766 +
3284 3767 if ( false === $dir || ! file_exists( $dir . 'landing-page-preview-option.php' ) ) {
3285 3768 $dir = self::get_form_views_path();
3286 3769 }
3770 +
3287 3771 include $dir . 'landing-page-preview-option.php';
3288 3772 }
3289 3773
3290 3774 /**
@@ -3310,13 +3794,15 @@
3310 3794
3311 3795 check_ajax_referer( 'frm_ajax', 'nonce' );
3312 3796
3313 3797 $type = FrmAppHelper::get_post_param( 'type', '', 'sanitize_text_field' );
3798 +
3314 3799 if ( ! $type || ! in_array( $type, array( 'form', 'view' ), true ) ) {
3315 3800 die( 0 );
3316 3801 }
3317 3802
3318 3803 $object_id = FrmAppHelper::get_post_param( 'object_id', '', 'absint' );
3804 +
3319 3805 if ( ! $object_id ) {
3320 3806 die( 0 );
3321 3807 }
3322 3808
@@ -3328,13 +3814,15 @@
3328 3814 $postarr['post_content'] = apply_filters( 'frm_create_page_with_' . $type . '_shortcode_content', '', $object_id );
3329 3815 }
3330 3816
3331 3817 $name = FrmAppHelper::get_post_param( 'name', '', 'sanitize_text_field' );
3818 +
3332 3819 if ( $name ) {
3333 3820 $postarr['post_title'] = $name;
3334 3821 }
3335 3822
3336 3823 $success = wp_insert_post( $postarr );
3824 +
3337 3825 if ( ! is_numeric( $success ) || ! $success ) {
3338 3826 die( 0 );
3339 3827 }
3340 3828
@@ -3348,8 +3836,9 @@
3348 3836 /**
3349 3837 * @since 5.3
3350 3838 *
3351 3839 * @param int $form_id
3840 + *
3352 3841 * @return string
3353 3842 */
3354 3843 private static function get_page_shortcode_content_for_form( $form_id ) {
3355 3844 $shortcode = '[formidable id="' . $form_id . '"]';
@@ -3369,9 +3858,9 @@
3369 3858 }
3370 3859
3371 3860 check_ajax_referer( 'frm_ajax', 'nonce' );
3372 3861
3373 - $html = FrmAppHelper::clip(
3862 + $html = FrmAppHelper::clip(
3374 3863 function () {
3375 3864 FrmAppHelper::maybe_autocomplete_pages_options(
3376 3865 array(
3377 3866 'field_name' => 'frm_page_dropdown',
@@ -3380,19 +3869,53 @@
3380 3869 )
3381 3870 );
3382 3871 }
3383 3872 );
3384 - $post_type_object = get_post_type_object( 'page' );
3385 3873 wp_send_json(
3386 3874 array(
3387 3875 'html' => $html,
3388 - '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 ) ),
3389 3877 )
3390 3878 );
3391 3879 }
3392 3880
3393 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 + /**
3394 3913 * @deprecated 4.0
3914 + *
3915 + * @param array $values
3916 + *
3917 + * @return void
3395 3918 */
3396 3919 public static function create( $values = array() ) {
3397 3920 _deprecated_function( __METHOD__, '4.0', 'FrmFormsController::update' );
3398 3921 self::update( $values );
@@ -3398,16 +3921,14 @@
3398 3921 self::update( $values );
3399 3922 }
3400 3923
3401 3924 /**
3402 - * Education for premium features.
3925 + * @deprecated 6.33
3403 3926 *
3404 - * @since 4.05
3405 - * @deprecated 6.16.3
3927 + * @param array $values
3406 3928 *
3407 3929 * @return void
3408 3930 */
3409 - public static function add_form_style_tab_options() {
3410 - _deprecated_function( __METHOD__, '6.16.3' );
3411 - 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' );
3412 3933 }
3413 3934 }