PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.10
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.10
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 +606 -375 6.36.10 View file →
@@ -4,8 +4,18 @@
4 4 }
5 5
6 6 class FrmFormsController {
7 7
8 + /**
9 + * Track the form that opened the redirect URL in a new tab. This is used to check if we should show the default
10 + * message in the currect tab.
11 + *
12 + * @since 6.2
13 + *
14 + * @var array Keys are form IDs and values are 1.
15 + */
16 + private static $redirected_in_new_tab = array();
17 +
8 18 public static function menu() {
9 19 $menu_label = __( 'Forms', 'formidable' );
10 20 if ( ! FrmAppHelper::pro_is_installed() ) {
11 21 $menu_label .= ' (Lite)';
@@ -44,9 +54,9 @@
44 54 */
45 55 public static function logic_tip() {
46 56 $images_url = FrmAppHelper::plugin_url() . '/images/';
47 57 $data_message = __( 'Only show the fields you need and create branching forms. Upgrade to get conditional logic and question branching.', 'formidable' );
48 - $data_message .= ' <img src="' . esc_attr( $images_url ) . '/survey-logic.png" srcset="' . esc_attr( $images_url ) . 'survey-logic@2x.png 2x" alt="' . esc_attr__( 'Conditional Logic options', 'formidable' ) . '"/>';
58 + $data_message .= ' <img src="' . esc_url( $images_url ) . '/survey-logic.png" srcset="' . esc_url( $images_url ) . 'survey-logic@2x.png 2x" alt="' . esc_attr__( 'Conditional Logic options', 'formidable' ) . '"/>';
49 59 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">';
50 60 esc_html_e( 'Conditional Logic', 'formidable' );
51 61 FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown6_icon', array( 'aria-hidden' => 'true' ) );
52 62 echo '</a>';
@@ -86,9 +96,9 @@
86 96 * Create the default email action
87 97 *
88 98 * @since 2.02.11
89 99 *
90 - * @param object|int $form
100 + * @param int|object $form
91 101 */
92 102 private static function create_default_email_action( $form ) {
93 103 FrmForm::maybe_get_form( $form );
94 104 $create_email = apply_filters( 'frm_create_default_email_action', true, $form );
@@ -103,9 +113,9 @@
103 113 * Create the default On submit action
104 114 *
105 115 * @since 6.0.0
106 116 *
107 - * @param object|int $form Form object or ID.
117 + * @param int|object $form Form object or ID.
108 118 */
109 119 private static function create_default_on_submit_action( $form ) {
110 120 FrmForm::maybe_get_form( $form );
111 121
@@ -124,16 +134,53 @@
124 134 $action_control->create( $form->id );
125 135 }
126 136 }
127 137
138 + /**
139 + * Creates submit button field.
140 + *
141 + * @since 6.9
142 + *
143 + * @param int|object $form Form ID or object.
144 + */
145 + private static function create_submit_button_field( $form ) {
146 + FrmForm::maybe_get_form( $form );
147 +
148 + if ( FrmSubmitHelper::get_submit_field( $form->id ) ) {
149 + // Do not create submit button field if it exists.
150 + return;
151 + }
152 +
153 + FrmField::create(
154 + array(
155 + 'type' => FrmSubmitHelper::FIELD_TYPE,
156 + 'name' => __( 'Submit', 'formidable' ),
157 + 'field_order' => 9999,
158 + 'form_id' => $form->id,
159 + 'field_options' => FrmFieldsHelper::get_default_field_options( FrmSubmitHelper::FIELD_TYPE ),
160 + 'description' => '',
161 + 'default_value' => '',
162 + 'options' => array(),
163 + )
164 + );
165 + }
166 +
167 + /**
168 + * @return void
169 + */
128 170 public static function edit( $values = false ) {
129 171 FrmAppHelper::permission_check( 'frm_edit_forms' );
130 172
131 173 $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
132 174
133 - return self::get_edit_vars( $id );
175 + self::get_edit_vars( $id );
134 176 }
135 177
178 + /**
179 + * @param mixed $id
180 + * @param string $message
181 + * @return void
182 + */
136 183 public static function settings( $id = false, $message = '' ) {
137 184 FrmAppHelper::permission_check( 'frm_edit_forms' );
138 185
139 186 if ( ! $id || ! is_numeric( $id ) ) {
@@ -141,21 +188,34 @@
141 188 }
142 189
143 190 FrmOnSubmitHelper::maybe_migrate_submit_settings_to_action( $id );
144 191
145 - return self::get_settings_vars( $id, array(), $message );
192 + self::get_settings_vars( $id, array(), $message );
146 193 }
147 194
148 195 public static function update_settings() {
149 196 FrmAppHelper::permission_check( 'frm_edit_forms' );
197 + $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
150 198
199 + if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) {
200 + $frm_settings = FrmAppHelper::get_settings();
201 + $error_args = array(
202 + 'title' => __( 'Verification failed', 'formidable' ),
203 + 'body' => $frm_settings->admin_permission,
204 + 'cancel_text' => __( 'Cancel', 'formidable' ),
205 + );
206 + FrmAppController::show_error_modal( $error_args );
207 + return;
208 + }
209 +
151 210 $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
152 211
153 - $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
212 + $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
154 213 $warnings = FrmFormsHelper::check_for_warnings( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
155 214
156 215 if ( count( $errors ) > 0 ) {
157 - return self::get_settings_vars( $id, $errors, compact( 'warnings' ) );
216 + self::get_settings_vars( $id, $errors, compact( 'warnings' ) );
217 + return;
158 218 }
159 219
160 220 do_action( 'frm_before_update_form_settings', $id );
161 221
@@ -169,9 +229,9 @@
169 229 }
170 230
171 231 $message = __( 'Settings Successfully Updated', 'formidable' );
172 232
173 - return self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) );
233 + self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) );
174 234 }
175 235
176 236 /**
177 237 * @param int $form_id
@@ -181,8 +241,11 @@
181 241 $form = FrmForm::getOne( $form_id );
182 242 return ! empty( $form->options['antispam'] );
183 243 }
184 244
245 + /**
246 + * @return void
247 + */
185 248 public static function update( $values = array() ) {
186 249 if ( empty( $values ) ) {
187 250 $values = $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing
188 251 }
@@ -200,65 +263,74 @@
200 263
201 264 $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
202 265
203 266 if ( count( $errors ) > 0 ) {
204 - return self::get_edit_vars( $id, $errors );
205 - } else {
206 - FrmForm::update( $id, $values );
207 - $message = __( 'Form was successfully updated.', 'formidable' );
267 + self::get_edit_vars( $id, $errors );
268 + return;
269 + }
208 270
209 - if ( self::is_too_long( $values ) ) {
210 - $message .= '<br/> ' . sprintf(
211 - /* translators: %1$s: Start link HTML, %2$s: end link HTML */
212 - __( 'However, your form is very long and may be %1$sreaching server limits%2$s.', 'formidable' ),
213 - '<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">',
214 - '</a>'
215 - );
216 - }
271 + self::maybe_remove_draft_option_from_fields( $id );
217 272
218 - if ( defined( 'DOING_AJAX' ) ) {
219 - wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
220 - }
273 + FrmForm::update( $id, $values );
274 + $message = __( 'Form was successfully updated.', 'formidable' );
221 275
222 - return self::get_edit_vars( $id, array(), $message );
276 + if ( self::is_too_long( $values ) ) {
277 + $message .= '<br/> ' . sprintf(
278 + /* translators: %1$s: Start link HTML, %2$s: end link HTML */
279 + __( 'However, your form is very long and may be %1$sreaching server limits%2$s.', 'formidable' ),
280 + '<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">',
281 + '</a>'
282 + );
223 283 }
284 +
285 + if ( defined( 'DOING_AJAX' ) ) {
286 + wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
287 + }
288 +
289 + self::get_edit_vars( $id, array(), $message );
224 290 }
225 291
226 292 /**
293 + * Remove the draft flag from any new fields from this current session.
294 + *
295 + * @since 6.8
296 + *
297 + * @param int $form_id
298 + * @return void
299 + */
300 + private static function maybe_remove_draft_option_from_fields( $form_id ) {
301 + $draft_field_ids_csv = FrmAppHelper::get_post_param( 'draft_fields', '', 'sanitize_text_field' );
302 + if ( ! $draft_field_ids_csv ) {
303 + // If the draft_fields input is empty there are no new fields in the session.
304 + return;
305 + }
306 +
307 + $draft_field_ids = array_filter( explode( ',', $draft_field_ids_csv ), 'is_numeric' );
308 + if ( ! $draft_field_ids ) {
309 + // Exit early if the draft fields input is invalid. It should be a CSV of integer values.
310 + return;
311 + }
312 +
313 + $draft_field_rows = FrmFieldsHelper::get_draft_field_results( $form_id, $draft_field_ids );
314 + foreach ( $draft_field_rows as $row ) {
315 + $row->field_options['draft'] = 0;
316 + FrmField::update( $row->id, array( 'field_options' => $row->field_options ) );
317 + }
318 + }
319 +
320 + /**
227 321 * Check if the value at the end of the form was included.
228 322 * If it's missing, it means other values at the end of the form
229 323 * were likely not saved either.
230 324 *
231 325 * @since 3.06.01
326 + *
327 + * @return bool
232 328 */
233 329 private static function is_too_long( $values ) {
234 - return ( ! isset( $values['frm_end'] ) ) || empty( $values['frm_end'] );
330 + return empty( $values['frm_end'] );
235 331 }
236 332
237 - /**
238 - * Redirect to the url for creating from a template
239 - * Also delete the current form
240 - *
241 - * @since 2.0
242 - * @deprecated 3.06
243 - */
244 - public static function _create_from_template() {
245 - _deprecated_function( __FUNCTION__, '3.06' );
246 -
247 - FrmAppHelper::permission_check( 'frm_edit_forms' );
248 - check_ajax_referer( 'frm_ajax', 'nonce' );
249 -
250 - $current_form = FrmAppHelper::get_param( 'this_form', '', 'get', 'absint' );
251 - $template_id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
252 -
253 - if ( $current_form ) {
254 - FrmForm::destroy( $current_form );
255 - }
256 -
257 - echo esc_url_raw( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template_id ) ) );
258 - wp_die();
259 - }
260 -
261 333 public static function duplicate() {
262 334 FrmAppHelper::permission_check( 'frm_edit_forms' );
263 335 $nonce = FrmAppHelper::simple_get( '_wpnonce' );
264 336
@@ -272,10 +344,11 @@
272 344 $url = admin_url( 'admin.php?page=formidable' );
273 345 $message = 'form_duplicate_error';
274 346
275 347 if ( $form ) {
276 - $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) );
277 - $message = 'form_duplicated';
348 + $new_template = FrmAppHelper::simple_get( 'new_template' ) ? '&new_template=true' : '';
349 + $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) . $new_template );
350 + $message = 'form_duplicated';
278 351 }
279 352
280 353 $url .= '&message=' . $message;
281 354
@@ -283,24 +356,28 @@
283 356 exit();
284 357 }
285 358
286 359 /**
287 - * @return string
360 + * @return string|null
288 361 */
289 362 public static function page_preview() {
290 363 $params = FrmForm::list_page_params();
291 364 if ( ! $params['form'] ) {
292 - return;
365 + return null;
293 366 }
294 367
295 368 $form = FrmForm::getOne( $params['form'] );
296 - if ( $form ) {
297 - return self::show_form( $form->id, '', 'auto', 'auto' );
369 + if ( ! $form ) {
370 + return null;
298 371 }
372 +
373 + return self::show_form( $form->id, '', 'auto', 'auto' );
299 374 }
300 375
301 376 /**
302 377 * @since 3.0
378 + *
379 + * @return void
303 380 */
304 381 public static function show_page_preview() {
305 382 echo self::page_preview(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
306 383 }
@@ -350,8 +427,13 @@
350 427 return;
351 428 }
352 429
353 430 $random_page = reset( $random_page );
431 + if ( ! is_a( $random_page, 'WP_Post' ) ) {
432 + // The return type can also be int.
433 + return;
434 + }
435 +
354 436 query_posts(
355 437 array(
356 438 'post_type' => 'page',
357 439 'page_id' => $random_page->ID,
@@ -367,9 +449,9 @@
367 449 * Set the WP $post global object. Used for in-theme preview when defining a page.
368 450 *
369 451 * @since 5.5.2
370 452 *
371 - * @param WP_Post $post
453 + * @param WP_Post $page The page object.
372 454 * @return void
373 455 */
374 456 private static function set_post_global( $page ) {
375 457 global $post;
@@ -377,8 +459,10 @@
377 459 }
378 460
379 461 /**
380 462 * @since 3.0
463 + *
464 + * @return void
381 465 */
382 466 private static function load_theme_preview() {
383 467 add_filter( 'wp_title', 'FrmFormsController::preview_title', 9999 );
384 468 add_filter( 'the_title', 'FrmFormsController::preview_page_title', 9999 );
@@ -387,20 +471,39 @@
387 471 add_filter( 'is_active_sidebar', '__return_false' );
388 472 FrmStylesController::enqueue_css( 'enqueue', true );
389 473
390 474 if ( false === get_template_part( 'page' ) ) {
475 + if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) {
476 + add_filter( 'body_class', 'FrmFormsController::preview_block_theme_body_classnames' );
477 + }
391 478 self::fallback_when_page_template_part_is_not_supported_by_theme();
392 479 }
393 480 }
394 481
395 482 /**
483 + * Add padding to the body for block themes.
484 + *
485 + * @since 6.5.2
486 + *
487 + * @param array $classes The body classes list.
488 + * @return array
489 + */
490 + public static function preview_block_theme_body_classnames( $classes ) {
491 + $classes[] = 'has-global-padding';
492 + return $classes;
493 + }
494 +
495 + /**
396 496 * Not every theme supports get_template_part( 'page' ).
397 497 * When this is not supported, false is returned, and we can handle a fallback.
498 + *
499 + * @return void
398 500 */
399 501 private static function fallback_when_page_template_part_is_not_supported_by_theme() {
400 502 if ( have_posts() ) {
401 503 the_post();
402 - get_header( '' );
504 + self::get_template( 'header' );
505 +
403 506 // add some generic class names to the container to add some natural padding to the content.
404 507 // .entry-content catches the WordPress TwentyTwenty theme.
405 508 // .container catches Customizr content.
406 509 echo '<div class="container entry-content">';
@@ -405,13 +508,54 @@
405 508 // .container catches Customizr content.
406 509 echo '<div class="container entry-content">';
407 510 the_content();
408 511 echo '</div>';
409 - get_footer();
512 +
513 + self::get_template( 'footer' );
410 514 }
411 515 }
412 516
413 517 /**
518 + * Calls core function to get a template part if it doesn't cause deprecation warnings. Otherwise skips the deprecation function call
519 + * and renders required html fragements calling required functions.
520 + *
521 + * @since 6.7.1
522 + * @param string $template
523 + * @return void
524 + */
525 + private static function get_template( $template ) {
526 + if ( self::should_try_getting_template( $template ) ) {
527 + call_user_func( 'get_' . $template );
528 + return;
529 + }
530 +
531 + if ( 'header' === $template ) {
532 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/header.php';
533 + return;
534 + }
535 +
536 + if ( 'footer' === $template ) {
537 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/footer.php';
538 + }
539 + }
540 +
541 + /**
542 + * Returns true if calling a template function doesn't trigger deprecation warnings.
543 + *
544 + * @since 6.7.1
545 + * @param string $template
546 + * @return bool
547 + */
548 + private static function should_try_getting_template( $template ) {
549 + $stylesheet_path = get_stylesheet_directory();
550 + $template_path = get_template_directory();
551 + $is_child_theme = $stylesheet_path !== $template_path;
552 + $template_name = $template . '.php';
553 +
554 + return file_exists( $stylesheet_path . '/' . $template_name ) || $is_child_theme && file_exists( $template_path . '/' . $template_name );
555 + }
556 +
557 + /**
414 558 * Set the page title for the theme preview page
415 559 *
416 560 * @since 3.0
417 561 */
@@ -423,11 +567,14 @@
423 567 return $title;
424 568 }
425 569
426 570 /**
427 - * Set the page title for the theme preview page
571 + * Set the page title for the theme preview page.
428 572 *
429 573 * @since 3.0
574 + *
575 + * @param string $title
576 + * @return string
430 577 */
431 578 public static function preview_title( $title ) {
432 579 return __( 'Form Preview', 'formidable' );
433 580 }
@@ -432,15 +579,20 @@
432 579 return __( 'Form Preview', 'formidable' );
433 580 }
434 581
435 582 /**
436 - * Set the page content for the theme preview page
583 + * Set the page content for the theme preview page.
437 584 *
438 585 * @since 3.0
586 + *
587 + * @param string $content
588 + * @return string
439 589 */
440 590 public static function preview_content( $content ) {
441 591 if ( in_the_loop() ) {
442 - $content = self::show_page_preview();
592 + self::show_page_preview();
593 + // Clear the content for the page we're using.
594 + $content = '';
443 595 }
444 596
445 597 return $content;
446 598 }
@@ -450,8 +602,11 @@
450 602 */
451 603 private static function load_direct_preview() {
452 604 header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
453 605
606 + // print_emoji_styles is deprecated.
607 + remove_action( 'wp_print_styles', 'print_emoji_styles' );
608 +
454 609 $key = FrmAppHelper::simple_get( 'form', 'sanitize_title' );
455 610 if ( $key == '' ) {
456 611 $key = FrmAppHelper::get_post_param( 'form', '', 'sanitize_title' );
457 612 }
@@ -460,11 +615,38 @@
460 615 if ( empty( $form ) ) {
461 616 $form = FrmForm::getAll( array(), '', 1 );
462 617 }
463 618
464 - require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php' );
619 + self::fix_deprecated_null_param_warning();
620 +
621 + require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php';
465 622 }
466 623
624 + /**
625 + * Some themes have a null $src value.
626 + * This function adds a filter to ensure that $src is not null.
627 + * WP will call str_starts_with with the null value triggering a deprecated message otherwise.
628 + *
629 + * @since 6.10
630 + *
631 + * @return void
632 + */
633 + private static function fix_deprecated_null_param_warning() {
634 + add_filter(
635 + 'script_loader_src',
636 + /**
637 + * @param string|null $src
638 + * @return string
639 + */
640 + function ( $src ) {
641 + if ( is_null( $src ) ) {
642 + $src = '';
643 + }
644 + return $src;
645 + }
646 + );
647 + }
648 +
467 649 public static function untrash() {
468 650 self::change_form_status( 'untrash' );
469 651 }
470 652
@@ -527,14 +709,14 @@
527 709 FrmAppHelper::permission_check( $available_status[ $status ]['permission'] );
528 710
529 711 $params = FrmForm::list_page_params();
530 712
531 - //check nonce url
713 + // Check nonce url.
532 714 check_admin_referer( $status . '_form_' . $params['id'] );
533 715
534 716 $count = 0;
535 717 if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) {
536 - $count ++;
718 + ++$count;
537 719 }
538 720
539 721 $form_type = FrmAppHelper::get_simple_request(
540 722 array(
@@ -546,9 +728,9 @@
546 728 /* translators: %1$s: Number of forms */
547 729 $available_status['untrash']['message'] = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
548 730
549 731 /* translators: %1$s: Number of forms, %2$s: Start link HTML, %3$s: End link HTML */
550 - $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>' );
732 + $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>' );
551 733
552 734 $message = $available_status[ $status ]['message'];
553 735
554 736 self::display_forms_list( $params, $message );
@@ -553,8 +735,12 @@
553 735
554 736 self::display_forms_list( $params, $message );
555 737 }
556 738
739 + /**
740 + * @param array $ids
741 + * @return string
742 + */
557 743 public static function bulk_trash( $ids ) {
558 744 FrmAppHelper::permission_check( 'frm_delete_forms' );
559 745
560 746 $count = 0;
@@ -559,9 +745,9 @@
559 745
560 746 $count = 0;
561 747 foreach ( $ids as $id ) {
562 748 if ( FrmForm::trash( $id ) ) {
563 - $count ++;
749 + ++$count;
564 750 }
565 751 }
566 752
567 753 $current_page = FrmAppHelper::get_simple_request(
@@ -590,9 +776,9 @@
590 776 check_admin_referer( 'destroy_form_' . $params['id'] );
591 777
592 778 $count = 0;
593 779 if ( FrmForm::destroy( $params['id'] ) ) {
594 - $count ++;
780 + ++$count;
595 781 }
596 782
597 783 /* translators: %1$s: Number of forms */
598 784 $message = sprintf( _n( '%1$s Form Permanently Deleted', '%1$s Forms Permanently Deleted', $count, 'formidable' ), $count );
@@ -599,8 +785,12 @@
599 785
600 786 self::display_forms_list( $params, $message );
601 787 }
602 788
789 + /**
790 + * @param array $ids
791 + * @return string
792 + */
603 793 public static function bulk_destroy( $ids ) {
604 794 FrmAppHelper::permission_check( 'frm_delete_forms' );
605 795
606 796 $count = 0;
@@ -606,19 +796,24 @@
606 796 $count = 0;
607 797 foreach ( $ids as $id ) {
608 798 $d = FrmForm::destroy( $id );
609 799 if ( $d ) {
610 - $count ++;
800 + ++$count;
611 801 }
612 802 }
613 803
614 - /* translators: %1$s: Number of forms */
615 - $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
804 + if ( $count ) {
805 + /* translators: %1$s: Number of forms */
806 + return sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
807 + }
616 808
617 - return $message;
809 + return '';
618 810 }
619 811
620 - private static function delete_all() {
812 + /**
813 + * @since 6.7.1 Function went from private to public.
814 + */
815 + public static function delete_all() {
621 816 // Check nonce url.
622 817 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' );
623 818 if ( $permission_error !== false ) {
624 819 self::display_forms_list( array(), '', array( $permission_error ) );
@@ -625,14 +820,15 @@
625 820
626 821 return;
627 822 }
628 823
629 - $count = FrmForm::scheduled_delete( time() );
824 + $count = FrmForm::scheduled_delete( time() );
825 + $url = remove_query_arg( array( 'delete_all' ) );
630 826
631 - /* translators: %1$s: Number of forms */
632 - $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
827 + $url .= '&message=forms_permanently_deleted&forms_deleted=' . $count;
633 828
634 - self::display_forms_list( array(), $message );
829 + wp_safe_redirect( $url );
830 + die();
635 831 }
636 832
637 833 /**
638 834 * Create a new form from the modal.
@@ -645,9 +841,9 @@
645 841
646 842 $new_values = self::get_modal_values();
647 843 $new_values['form_key'] = $new_values['name'];
648 844 $new_values['options'] = array(
649 - 'antispam' => 1,
845 + 'antispam' => 1,
650 846 'on_submit_migrated' => 1,
651 847 );
652 848
653 849 /**
@@ -666,13 +862,14 @@
666 862 * @param int $form_id
667 863 */
668 864 do_action( 'frm_build_new_form', $form_id );
669 865
866 + self::create_submit_button_field( $form_id );
670 867 self::create_default_on_submit_action( $form_id );
671 868 self::create_default_email_action( $form_id );
672 869
673 870 $response = array(
674 - 'redirect' => FrmForm::get_edit_link( $form_id ),
871 + 'redirect' => FrmForm::get_edit_link( $form_id ) . '&new_template=true',
675 872 );
676 873
677 874 echo wp_json_encode( $response );
678 875 wp_die();
@@ -678,46 +875,15 @@
678 875 wp_die();
679 876 }
680 877
681 878 /**
682 - * Create a custom template from a form
683 - *
684 - * @since 3.06
685 - */
686 - public static function build_template() {
687 - global $wpdb;
688 -
689 - FrmAppHelper::permission_check( 'frm_edit_forms' );
690 - check_ajax_referer( 'frm_ajax', 'nonce' );
691 -
692 - $form_id = FrmAppHelper::get_param( 'xml', '', 'post', 'absint' );
693 - $new_form_id = FrmForm::duplicate( $form_id, 1, true );
694 - if ( ! $new_form_id ) {
695 - $response = array(
696 - 'message' => __( 'There was an error creating a template.', 'formidable' ),
697 - );
698 - } else {
699 - $new_values = self::get_modal_values();
700 - $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $new_form_id ) );
701 - if ( $query_results ) {
702 - FrmForm::clear_form_cache();
703 - }
704 -
705 - $response = array(
706 - 'redirect' => admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . $new_form_id ) . '&_wpnonce=' . wp_create_nonce(),
707 - );
708 - }
709 -
710 - echo wp_json_encode( $response );
711 - wp_die();
712 - }
713 -
714 - /**
715 879 * Before creating a new form, get the name and description from the modal.
716 880 *
717 881 * @since 4.0
882 + *
883 + * @return array<string,string>
718 884 */
719 - private static function get_modal_values() {
885 + public static function get_modal_values() {
720 886 $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' );
721 887 $desc = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' );
722 888
723 889 return array(
@@ -730,8 +896,10 @@
730 896 * Inserts Formidable button
731 897 * Hook exists since 2.5.0
732 898 *
733 899 * @since 2.0.15
900 + *
901 + * @return void
734 902 */
735 903 public static function insert_form_button() {
736 904 if ( current_user_can( 'frm_view_forms' ) ) {
737 905 FrmAppHelper::load_admin_wide_js();
@@ -828,9 +996,9 @@
828 996 $form_id = $opts['form_id'];
829 997 unset( $opts['form_id'] );
830 998 }
831 999
832 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php' );
1000 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php';
833 1001
834 1002 echo '</div>';
835 1003
836 1004 wp_die();
@@ -879,14 +1047,14 @@
879 1047 * @return array<string,string>
880 1048 */
881 1049 public static function get_columns( $columns ) {
882 1050 $columns['cb'] = '<input type="checkbox" />';
883 - $columns['name'] = __( 'Form Title', 'formidable' );
884 - $columns['entries'] = __( 'Entries', 'formidable' );
1051 + $columns['name'] = esc_html__( 'Form Title', 'formidable' );
1052 + $columns['entries'] = esc_html__( 'Entries', 'formidable' );
885 1053 $columns['id'] = 'ID';
886 - $columns['form_key'] = __( 'Key', 'formidable' );
887 - $columns['shortcode'] = __( 'Actions', 'formidable' );
888 - $columns['created_at'] = __( 'Date', 'formidable' );
1054 + $columns['form_key'] = esc_html__( 'Key', 'formidable' );
1055 + $columns['shortcode'] = esc_html__( 'Actions', 'formidable' );
1056 + $columns['created_at'] = esc_html__( 'Date', 'formidable' );
889 1057
890 1058 add_screen_option(
891 1059 'per_page',
892 1060 array(
@@ -898,8 +1066,11 @@
898 1066
899 1067 return $columns;
900 1068 }
901 1069
1070 + /**
1071 + * @return array<string,string>
1072 + */
902 1073 public static function get_sortable_columns() {
903 1074 return array(
904 1075 'id' => 'id',
905 1076 'name' => 'name',
@@ -933,9 +1104,9 @@
933 1104 return $hidden_columns;
934 1105 }
935 1106
936 1107 public static function save_per_page( $save, $option, $value ) {
937 - if ( $option == 'formidable_page_formidable_per_page' ) {
1108 + if ( $option === 'formidable_page_formidable_per_page' ) {
938 1109 $save = (int) $value;
939 1110 }
940 1111
941 1112 return $save;
@@ -941,146 +1112,49 @@
941 1112 return $save;
942 1113 }
943 1114
944 1115 /**
945 - * @return bool
946 - */
947 - public static function expired() {
948 - global $frm_expired;
949 - return $frm_expired;
950 - }
951 -
952 - /**
953 - * Get data from api before rendering it so that we can flag the modal as expired
954 - *
1116 + * @param int|string $id
1117 + * @param array $errors
1118 + * @param string $message
1119 + * @param bool $create_link
955 1120 * @return void
956 1121 */
957 - public static function before_list_templates() {
958 - global $frm_templates;
959 - global $frm_expired;
960 - global $frm_license_type;
1122 + private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
1123 + global $frm_vars;
961 1124
962 - $api = new FrmFormTemplateApi();
963 - $frm_templates = $api->get_api_info();
964 - $expired = false;
965 - $license_type = '';
966 - if ( isset( $frm_templates['error'] ) ) {
967 - $error = $frm_templates['error']['message'];
968 - $error = str_replace( 'utm_medium=addons', 'utm_medium=form-templates', $error );
969 - $expired = 'expired' === $frm_templates['error']['code'];
970 - $license_type = isset( $frm_templates['error']['type'] ) ? $frm_templates['error']['type'] : '';
971 - unset( $frm_templates['error'] );
972 - }
973 -
974 - $frm_expired = $expired;
975 - $frm_license_type = $license_type;
976 - }
977 -
978 - /**
979 - * @return void
980 - */
981 - public static function list_templates() {
982 - global $frm_templates;
983 - global $frm_license_type;
984 -
985 - $templates = $frm_templates;
986 - $custom_templates = array();
987 - $templates_by_category = array();
988 -
989 - self::add_user_templates( $custom_templates );
990 -
991 - foreach ( $templates as $template ) {
992 - if ( ! isset( $template['categories'] ) ) {
993 - continue;
994 - }
995 -
996 - foreach ( $template['categories'] as $category ) {
997 - if ( ! isset( $templates_by_category[ $category ] ) ) {
998 - $templates_by_category[ $category ] = array();
999 - }
1000 -
1001 - $templates_by_category[ $category ][] = $template;
1002 - }
1003 - }
1004 - unset( $template );
1005 -
1006 - // Subcategories that are included elsewhere.
1007 - $redundant_cats = array( 'PayPal', 'Stripe', 'Twilio' );
1008 -
1009 - $categories = array_keys( $templates_by_category );
1010 - $categories = array_diff( $categories, FrmFormsHelper::ignore_template_categories() );
1011 - $categories = array_diff( $categories, $redundant_cats );
1012 - sort( $categories );
1013 -
1014 - array_walk(
1015 - $custom_templates,
1016 - function( &$template ) {
1017 - $template['custom'] = true;
1018 - }
1125 + $form = FrmForm::getOne( $id );
1126 + $error_args = array(
1127 + 'title' => __( 'You can\'t edit the form', 'formidable' ),
1128 + 'body' => __( 'You are trying to edit a form that does not exist', 'formidable' ),
1129 + 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
1130 + 'continue_url' => add_query_arg(
1131 + array(
1132 + 'page' => 'formidable',
1133 + )
1134 + ),
1019 1135 );
1020 -
1021 - $my_templates_translation = __( 'My Templates', 'formidable' );
1022 - $categories = array_merge( array( $my_templates_translation ), $categories );
1023 - $pricing = FrmAppHelper::admin_upgrade_link( 'form-templates' );
1024 - $license_type = $frm_license_type;
1025 - $args = compact( 'pricing', 'license_type' );
1026 - $where = apply_filters( 'frm_forms_dropdown', array(), '' );
1027 - $forms = FrmForm::get_published_forms( $where );
1028 - $view_path = FrmAppHelper::plugin_path() . '/classes/views/frm-forms/';
1029 -
1030 - $templates_by_category[ $my_templates_translation ] = $custom_templates;
1031 -
1032 - unset( $pricing, $license_type, $where );
1033 - wp_enqueue_script( 'accordion' ); // register accordion for template groups
1034 - require $view_path . 'list-templates.php';
1035 - }
1036 -
1037 - /**
1038 - * @since 4.03.01
1039 - */
1040 - private static function get_template_categories( $templates ) {
1041 - $categories = array();
1042 - foreach ( $templates as $template ) {
1043 - if ( isset( $template['categories'] ) ) {
1044 - $categories = array_merge( $categories, $template['categories'] );
1045 - }
1136 + if ( ! $form ) {
1137 + FrmAppController::show_error_modal( $error_args );
1138 + return;
1046 1139 }
1047 - $exclude_cats = FrmFormsHelper::ignore_template_categories();
1048 - $categories = array_unique( $categories );
1049 - $categories = array_diff( $categories, $exclude_cats );
1050 - sort( $categories );
1051 - return $categories;
1052 - }
1053 1140
1054 - private static function add_user_templates( &$templates ) {
1055 - $user_templates = array(
1056 - 'is_template' => 1,
1057 - 'default_template' => 0,
1058 - );
1059 - $user_templates = FrmForm::getAll( $user_templates, 'name' );
1060 - foreach ( $user_templates as $template ) {
1061 - $template = array(
1062 - 'id' => $template->id,
1063 - 'name' => $template->name,
1064 - 'key' => $template->form_key,
1065 - 'description' => $template->description,
1066 - 'url' => wp_nonce_url( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template->id ) ) ),
1067 - 'released' => $template->created_at,
1068 - 'installed' => 1,
1141 + if ( 'trash' === $form->status ) {
1142 + $error_args['body'] = __( 'The form you\'re trying to edit is in trash. You must restore it first before you can make changes', 'formidable' );
1143 + $error_args['continue_url'] = add_query_arg(
1144 + array(
1145 + 'page' => 'formidable',
1146 + '_wpnonce' => wp_create_nonce( 'untrash_form_' . $id ),
1147 + 'form_type' => 'trash',
1148 + 'frm_action' => 'untrash',
1149 + 'id' => $id,
1150 + )
1069 1151 );
1070 - array_unshift( $templates, $template );
1071 - unset( $template );
1152 + $error_args['continue_text'] = __( 'Restore form', 'formidable' );
1153 + FrmAppController::show_error_modal( $error_args );
1154 + return;
1072 1155 }
1073 - }
1074 1156
1075 - private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
1076 - global $frm_vars;
1077 -
1078 - $form = FrmForm::getOne( $id );
1079 - if ( ! $form ) {
1080 - wp_die( esc_html__( 'You are trying to edit a form that does not exist.', 'formidable' ) );
1081 - }
1082 -
1083 1157 if ( $form->parent_form_id ) {
1084 1158 /* translators: %1$s: Start link HTML, %2$s: End link HTML */
1085 1159 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>' ) );
1086 1160 }
@@ -1091,8 +1165,9 @@
1091 1165
1092 1166 // Automatically add end section fields if they don't exist (2.0 migration).
1093 1167 $reset_fields = false;
1094 1168 FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields );
1169 + FrmSubmitHelper::maybe_create_submit_field( $form, $fields, $reset_fields );
1095 1170
1096 1171 if ( $reset_fields ) {
1097 1172 $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' );
1098 1173 }
@@ -1119,17 +1194,21 @@
1119 1194
1120 1195 self::maybe_update_form_builder_message( $message );
1121 1196
1122 1197 $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
1123 - $has_fields = isset( $values['fields'] ) && ! empty( $values['fields'] );
1198 + $has_fields = ! empty( $values['fields'] ) && ! FrmSubmitHelper::only_contains_submit_field( $values['fields'] );
1124 1199
1125 1200 if ( defined( 'DOING_AJAX' ) ) {
1126 1201 wp_die();
1127 - } else {
1128 - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' );
1129 1202 }
1203 +
1204 + require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php';
1130 1205 }
1131 1206
1207 + /**
1208 + * @param array $fields
1209 + * @return array
1210 + */
1132 1211 public static function update_form_builder_fields( $fields, $form ) {
1133 1212 foreach ( $fields as $field ) {
1134 1213 $field->do_not_include_icons = true;
1135 1214 }
@@ -1141,13 +1220,21 @@
1141 1220 $message = __( 'Form was Successfully Copied', 'formidable' );
1142 1221 }
1143 1222 }
1144 1223
1224 + /**
1225 + * @param int|string $id
1226 + * @param array $errors
1227 + * @param array|string $args
1228 + * @return void
1229 + */
1145 1230 public static function get_settings_vars( $id, $errors = array(), $args = array() ) {
1146 1231 FrmAppHelper::permission_check( 'frm_edit_forms' );
1147 1232
1148 1233 global $frm_vars;
1149 1234
1235 + self::maybe_print_media_templates();
1236 +
1150 1237 if ( ! is_array( $args ) ) {
1151 1238 // For reverse compatibility.
1152 1239 $args = array(
1153 1240 'message' => $args,
@@ -1180,17 +1267,38 @@
1180 1267
1181 1268 $sections = self::get_settings_tabs( $values );
1182 1269 $current = FrmAppHelper::simple_get( 't', 'sanitize_title', 'advanced_settings' );
1183 1270
1184 - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php' );
1271 + require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php';
1185 1272 }
1186 1273
1187 1274 /**
1275 + * Print WordPress media templates email actions does not trigger a "Uncaught Error: Template not found: #tmpl-media-selection" error when the media button is clicked.
1276 + *
1277 + * @since 6.10
1278 + *
1279 + * @return void
1280 + */
1281 + private static function maybe_print_media_templates() {
1282 + if ( FrmAppHelper::pro_is_included() ) {
1283 + // This issue does not exist when Pro is active so exit early.
1284 + return;
1285 + }
1286 +
1287 + add_action(
1288 + 'wp_enqueue_editor',
1289 + function () {
1290 + wp_print_media_templates();
1291 + }
1292 + );
1293 + }
1294 +
1295 + /**
1188 1296 * @since 4.0
1189 1297 */
1190 1298 public static function form_publish_button( $atts ) {
1191 1299 $values = $atts['values'];
1192 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php' );
1300 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php';
1193 1301 }
1194 1302
1195 1303 /**
1196 1304 * Get a list of all the settings tabs for the form settings page.
@@ -1215,9 +1323,9 @@
1215 1323 'icon' => 'frm_icon_font frm_mail_bulk_icon',
1216 1324 ),
1217 1325 'permissions' => array(
1218 1326 'name' => __( 'Form Permissions', 'formidable' ),
1219 - 'icon' => 'frm_icon_font frm_lock_icon',
1327 + 'icon' => 'frm_icon_font frm_lock_closed_icon',
1220 1328 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1221 1329 'data' => array(
1222 1330 'medium' => 'permissions',
1223 1331 'upgrade' => __( 'Form Permissions', 'formidable' ),
@@ -1224,9 +1332,9 @@
1224 1332 'message' => __( 'Allow editing, protect forms and files, limit entries, and save drafts. Upgrade to get form and entry permissions.', 'formidable' ),
1225 1333 'screenshot' => 'permissions.png',
1226 1334 ),
1227 1335 ),
1228 - 'scheduling' => array(
1336 + 'scheduling' => array(
1229 1337 'name' => __( 'Form Scheduling', 'formidable' ),
1230 1338 'icon' => 'frm_icon_font frm_calendar_icon',
1231 1339 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1232 1340 'data' => array(
@@ -1259,8 +1367,21 @@
1259 1367 'screenshot' => 'chat.png',
1260 1368 )
1261 1369 ),
1262 1370 ),
1371 + 'abandonment' => array(
1372 + 'name' => __( 'Form Abandonment', 'formidable' ),
1373 + 'icon' => 'frm_icon_font frm_abandoned_icon',
1374 + 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1375 + 'data' => FrmAppHelper::get_upgrade_data_params(
1376 + 'abandonment',
1377 + array(
1378 + 'upgrade' => __( 'Form abandonment settings', 'formidable' ),
1379 + 'message' => __( 'Unlock the power of data capture to boost lead generation and master the art of form optimization.', 'formidable' ),
1380 + 'screenshot' => 'abandonment.png',
1381 + )
1382 + ),
1383 + ),
1263 1384 'html' => array(
1264 1385 'name' => __( 'Customize HTML', 'formidable' ),
1265 1386 'class' => __CLASS__,
1266 1387 'function' => 'html_settings',
@@ -1267,9 +1388,9 @@
1267 1388 'icon' => 'frm_icon_font frm_code_icon',
1268 1389 ),
1269 1390 );
1270 1391
1271 - foreach ( array( 'landing', 'chat' ) as $feature ) {
1392 + foreach ( array( 'landing', 'chat', 'abandonment' ) as $feature ) {
1272 1393 if ( ! FrmAppHelper::show_new_feature( $feature ) ) {
1273 1394 unset( $sections[ $feature ] );
1274 1395 }
1275 1396 }
@@ -1275,13 +1396,8 @@
1275 1396 }
1276 1397
1277 1398 $sections = apply_filters( 'frm_add_form_settings_section', $sections, $values );
1278 1399
1279 - if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) {
1280 - // Prevent settings from showing in 2 spots.
1281 - unset( $sections['permissions'], $sections['scheduling'] );
1282 - }
1283 -
1284 1400 foreach ( $sections as $key => $section ) {
1285 1401 $defaults = array(
1286 1402 'html_class' => '',
1287 1403 'name' => ucfirst( $key ),
@@ -1303,9 +1419,9 @@
1303 1419 $section['id'] = $section['anchor'];
1304 1420 }
1305 1421
1306 1422 $sections[ $key ] = $section;
1307 - }
1423 + }//end foreach
1308 1424
1309 1425 return $sections;
1310 1426 }
1311 1427
@@ -1312,8 +1428,9 @@
1312 1428 /**
1313 1429 * @since 4.0
1314 1430 *
1315 1431 * @param array $values
1432 + * @return void
1316 1433 */
1317 1434 public static function advanced_settings( $values ) {
1318 1435 $first_h3 = 'frm_first_h3';
1319 1436
@@ -1321,8 +1438,9 @@
1321 1438 }
1322 1439
1323 1440 /**
1324 1441 * @param array $values
1442 + * @return void
1325 1443 */
1326 1444 public static function render_spam_settings( $values ) {
1327 1445 if ( function_exists( 'akismet_http_post' ) ) {
1328 1446 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/akismet.php';
@@ -1334,16 +1452,12 @@
1334 1452 /**
1335 1453 * @since 4.0
1336 1454 *
1337 1455 * @param array $values
1456 + * @return void
1338 1457 */
1339 1458 public static function buttons_settings( $values ) {
1340 - $styles = apply_filters( 'frm_get_style_opts', array() );
1341 -
1342 - $frm_settings = FrmAppHelper::get_settings();
1343 - $no_global_style = $frm_settings->load_style === 'none';
1344 -
1345 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php' );
1459 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php';
1346 1460 }
1347 1461
1348 1462 /**
1349 1463 * @since 4.0
@@ -1348,11 +1462,12 @@
1348 1462 /**
1349 1463 * @since 4.0
1350 1464 *
1351 1465 * @param array $values
1466 + * @return void
1352 1467 */
1353 1468 public static function html_settings( $values ) {
1354 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php' );
1469 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php';
1355 1470 }
1356 1471
1357 1472 /**
1358 1473 * Replace old Submit Button href with new href to avoid errors in Chrome
@@ -1358,9 +1473,10 @@
1358 1473 * Replace old Submit Button href with new href to avoid errors in Chrome
1359 1474 *
1360 1475 * @since 2.03.08
1361 1476 *
1362 - * @param array|boolean $values
1477 + * @param array|bool $values
1478 + * @return void
1363 1479 */
1364 1480 private static function clean_submit_html( &$values ) {
1365 1481 if ( is_array( $values ) && isset( $values['submit_html'] ) ) {
1366 1482 $values['submit_html'] = str_replace( 'javascript:void(0)', '#', $values['submit_html'] );
@@ -1381,8 +1497,13 @@
1381 1497
1382 1498 return $classes;
1383 1499 }
1384 1500
1501 + /**
1502 + * @param int|string $form_id
1503 + * @param string $class
1504 + * @return void
1505 + */
1385 1506 public static function mb_tags_box( $form_id, $class = '' ) {
1386 1507 $fields = FrmField::get_all_for_form( $form_id, '', 'include' );
1387 1508
1388 1509 /**
@@ -1395,9 +1516,9 @@
1395 1516 */
1396 1517 $fields = apply_filters( 'frm_fields_in_tags_box', $fields, compact( 'form_id' ) );
1397 1518 $linked_forms = array();
1398 1519 $col = 'one';
1399 - $settings_tab = FrmAppHelper::is_admin_page( 'formidable' ) ? true : false;
1520 + $settings_tab = FrmAppHelper::is_admin_page( 'formidable' );
1400 1521
1401 1522 $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() );
1402 1523 $entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
1403 1524
@@ -1402,9 +1523,9 @@
1402 1523 $entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
1403 1524
1404 1525 $advanced_helpers = self::advanced_helpers( compact( 'fields', 'form_id' ) );
1405 1526
1406 - include( FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php' );
1527 + include FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php';
1407 1528 }
1408 1529
1409 1530 /**
1410 1531 * @since 3.04.01
@@ -1417,9 +1538,9 @@
1417 1538 ),
1418 1539 );
1419 1540
1420 1541 $user_fields = self::user_shortcodes();
1421 - if ( ! empty( $user_fields ) ) {
1542 + if ( $user_fields ) {
1422 1543 $user_helpers = array();
1423 1544 foreach ( $user_fields as $uk => $uf ) {
1424 1545 $user_helpers[ '|user_id| show="' . $uk . '"' ] = $uf;
1425 1546 unset( $uk, $uf );
@@ -1425,9 +1546,9 @@
1425 1546 unset( $uk, $uf );
1426 1547 }
1427 1548
1428 1549 $advanced_helpers['user_id'] = array(
1429 - 'codes' => $user_helpers,
1550 + 'codes' => $user_helpers,
1430 1551 );
1431 1552 }
1432 1553
1433 1554 /**
@@ -1568,11 +1689,11 @@
1568 1689 check_ajax_referer( 'frm_ajax', 'nonce' );
1569 1690
1570 1691 echo FrmEntriesController::show_entry_shortcode( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1571 1692 array(
1572 - 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ),
1693 + 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1573 1694 'default_email' => true,
1574 - 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ),
1695 + 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1575 1696 )
1576 1697 );
1577 1698 wp_die();
1578 1699 }
@@ -1578,10 +1699,10 @@
1578 1699 }
1579 1700
1580 1701 /**
1581 1702 * @param string $content
1582 - * @param stdClass|string|int $form
1583 - * @param stdClass|string|int|false $entry
1703 + * @param int|stdClass|string $form
1704 + * @param false|int|stdClass|string $entry
1584 1705 * @return string
1585 1706 */
1586 1707 public static function filter_content( $content, $form, $entry = false ) {
1587 1708 $content = self::replace_form_name_shortcodes( $content, $form );
@@ -1605,13 +1726,17 @@
1605 1726 * Replace any [form_name] shortcodes in a string.
1606 1727 *
1607 1728 * @since 5.5
1608 1729 *
1609 - * @param string $string
1610 - * @param stdClass|string|int $form
1611 - * @return string
1730 + * @param array|string $string
1731 + * @param int|stdClass|string $form
1732 + * @return array|string
1612 1733 */
1613 1734 public static function replace_form_name_shortcodes( $string, $form ) {
1735 + if ( ! is_string( $string ) ) {
1736 + return $string;
1737 + }
1738 +
1614 1739 if ( false === strpos( $string, '[form_name]' ) ) {
1615 1740 return $string;
1616 1741 }
1617 1742
@@ -1623,9 +1748,9 @@
1623 1748 return str_replace( '[form_name]', $form_name, $string );
1624 1749 }
1625 1750
1626 1751 /**
1627 - * @param stdClass|string|int|false $entry
1752 + * @param false|int|stdClass|string $entry
1628 1753 * @return void
1629 1754 */
1630 1755 private static function get_entry_by_param( &$entry ) {
1631 1756 if ( ! $entry || ! is_object( $entry ) ) {
@@ -1640,8 +1765,12 @@
1640 1765 public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
1641 1766 return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes );
1642 1767 }
1643 1768
1769 + /**
1770 + * @param array $errors
1771 + * @return array
1772 + */
1644 1773 public static function process_bulk_form_actions( $errors ) {
1645 1774 if ( ! $_REQUEST ) {
1646 1775 return $errors;
1647 1776 }
@@ -1685,9 +1814,9 @@
1685 1814 case 'untrash':
1686 1815 $message = self::bulk_untrash( $ids );
1687 1816 }
1688 1817
1689 - if ( isset( $message ) && ! empty( $message ) ) {
1818 + if ( ! empty( $message ) ) {
1690 1819 $errors['message'] = $message;
1691 1820 }
1692 1821
1693 1822 return $errors;
@@ -1707,9 +1836,9 @@
1707 1836 $json_vars = json_decode( $json_vars, true );
1708 1837 if ( empty( $json_vars ) ) {
1709 1838 // json decoding failed so we should return an error message.
1710 1839 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
1711 - if ( 'edit' == $action ) {
1840 + if ( 'edit' === $action ) {
1712 1841 $action = 'update';
1713 1842 }
1714 1843
1715 1844 add_filter( 'frm_validate_form', 'FrmFormsController::json_error' );
@@ -1725,16 +1854,14 @@
1725 1854 if ( isset( $_REQUEST['delete_all'] ) ) {
1726 1855 // Override the action for this page.
1727 1856 $action = 'delete_all';
1728 1857 }
1729 - }
1858 + }//end if
1730 1859
1731 1860 add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
1732 1861 FrmAppHelper::trigger_hook_load( 'form' );
1733 1862
1734 1863 switch ( $action ) {
1735 - case 'new':
1736 - return self::new_form( $vars );
1737 1864 case 'create':
1738 1865 case 'edit':
1739 1866 case 'update':
1740 1867 case 'trash':
@@ -1739,9 +1866,8 @@
1739 1866 case 'update':
1740 1867 case 'trash':
1741 1868 case 'untrash':
1742 1869 case 'destroy':
1743 - case 'delete_all':
1744 1870 case 'settings':
1745 1871 case 'update_settings':
1746 1872 return self::$action( $vars );
1747 1873 case 'lite-reports':
@@ -1771,14 +1897,47 @@
1771 1897 self::display_forms_list( array(), '', array( __( 'There was a problem duplicating the form', 'formidable' ) ) );
1772 1898 return;
1773 1899 }
1774 1900
1901 + if ( 'forms_permanently_deleted' === $message ) {
1902 + $count = FrmAppHelper::get_param( 'forms_deleted', 0, 'get', 'absint' );
1903 + /* translators: %1$s: Number of forms */
1904 + $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
1905 + self::display_forms_list( array(), $message, '' );
1906 + return;
1907 + }
1908 +
1775 1909 self::display_forms_list();
1776 1910
1777 1911 return;
1778 - }
1912 + }//end switch
1779 1913 }
1780 1914
1915 + /**
1916 + * Rename a form.
1917 + *
1918 + * Handles the AJAX request for renaming a form.
1919 + *
1920 + * @since 6.7
1921 + *
1922 + * @return void
1923 + */
1924 + public static function rename_form() {
1925 + // Check permission and nonce
1926 + FrmAppHelper::permission_check( 'frm_edit_forms' );
1927 + check_ajax_referer( 'frm_ajax', 'nonce' );
1928 +
1929 + // Get posted data
1930 + $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
1931 + $name = FrmAppHelper::get_post_param( 'form_name', '', 'sanitize_text_field' );
1932 +
1933 + // Update the form name and form key.
1934 + $form_key = FrmAppHelper::get_unique_key( sanitize_title( $name ), 'frm_forms', 'form_key' );
1935 + FrmForm::update( $form_id, compact( 'name', 'form_key' ) );
1936 +
1937 + wp_send_json_success( compact( 'form_key' ) );
1938 + }
1939 +
1781 1940 public static function json_error( $errors ) {
1782 1941 $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
1783 1942
1784 1943 return $errors;
@@ -1787,11 +1946,12 @@
1787 1946 /**
1788 1947 * Education for premium features.
1789 1948 *
1790 1949 * @since 4.05
1950 + * @return void
1791 1951 */
1792 1952 public static function add_form_style_tab_options() {
1793 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php' );
1953 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php';
1794 1954 }
1795 1955
1796 1956 /**
1797 1957 * Add education about views.
@@ -1817,9 +1977,11 @@
1817 1977
1818 1978 include FrmAppHelper::plugin_path() . '/classes/views/shared/reports-info.php';
1819 1979 }
1820 1980
1821 - /* FRONT-END FORMS */
1981 + /**
1982 + * FRONT-END FORMS.
1983 + */
1822 1984 public static function admin_bar_css() {
1823 1985 if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
1824 1986 return;
1825 1987 }
@@ -1908,10 +2070,10 @@
1908 2070 * @return string
1909 2071 */
1910 2072 public static function get_form_shortcode( $atts ) {
1911 2073 global $frm_vars;
1912 - if ( isset( $frm_vars['skip_shortcode'] ) && $frm_vars['skip_shortcode'] ) {
1913 - $sc = '[formidable';
2074 + if ( ! empty( $frm_vars['skip_shortcode'] ) ) {
2075 + $sc = '[formidable';
1914 2076 $sc .= FrmAppHelper::array_to_html_params( $atts );
1915 2077 return $sc . ']';
1916 2078 }
1917 2079
@@ -1936,11 +2098,11 @@
1936 2098
1937 2099 /**
1938 2100 * @since 5.2.01
1939 2101 *
1940 - * @param string|int|false $id
1941 - * @param string|false $key
1942 - * @return stdClass|false
2102 + * @param false|int|string $id
2103 + * @param false|string $key
2104 + * @return false|stdClass
1943 2105 */
1944 2106 private static function maybe_get_form_by_id_or_key( $id, $key ) {
1945 2107 if ( ! $id ) {
1946 2108 $id = $key;
@@ -1948,12 +2110,12 @@
1948 2110 return self::maybe_get_form_to_show( $id );
1949 2111 }
1950 2112
1951 2113 /**
1952 - * @param string|int|false $id
1953 - * @param string|false $key
1954 - * @param string|int|bool $title may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
1955 - * @param string|int|bool $description may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
2114 + * @param false|int|string $id
2115 + * @param false|string $key
2116 + * @param bool|int|string $title may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
2117 + * @param bool|int|string $description may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
1956 2118 * @param array $atts
1957 2119 * @return string
1958 2120 */
1959 2121 public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) {
@@ -2001,15 +2163,16 @@
2001 2163 return $form;
2002 2164 }
2003 2165
2004 2166 /**
2005 - * @param string|int|false $id
2006 - * @return stdClass|false
2167 + * @param false|int|string $id
2168 + * @return false|stdClass
2007 2169 */
2008 2170 private static function maybe_get_form_to_show( $id ) {
2009 2171 $form = false;
2010 2172
2011 - if ( ! empty( $id ) ) { // form id or key is set
2173 + if ( ! empty( $id ) ) {
2174 + // Form id or key is set.
2012 2175 $form = FrmForm::getOne( $id );
2013 2176 if ( ! $form || $form->parent_form_id || $form->status === 'trash' ) {
2014 2177 $form = false;
2015 2178 }
@@ -2067,11 +2230,11 @@
2067 2230
2068 2231 do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description );
2069 2232
2070 2233 if ( apply_filters( 'frm_continue_to_create', true, $form->id ) ) {
2071 - $entry_id = self::just_created_entry( $form->id );
2072 - $pass_args['entry_id'] = $entry_id;
2073 - $pass_args['reset'] = true;
2234 + $entry_id = self::just_created_entry( $form->id );
2235 + $pass_args['entry_id'] = $entry_id;
2236 + $pass_args['reset'] = true;
2074 2237
2075 2238 self::run_on_submit_actions( $pass_args );
2076 2239
2077 2240 do_action(
@@ -2081,9 +2244,9 @@
2081 2244 'form' => $form,
2082 2245 )
2083 2246 );
2084 2247 }
2085 - }
2248 + }//end if
2086 2249 }
2087 2250
2088 2251 /**
2089 2252 * If the form was processed earlier (init), get the generated errors
@@ -2115,9 +2278,9 @@
2115 2278 */
2116 2279 public static function just_created_entry( $form_id ) {
2117 2280 global $frm_vars;
2118 2281
2119 - 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;
2282 + 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;
2120 2283 }
2121 2284
2122 2285 /**
2123 2286 * Gets confirmation method.
@@ -2130,14 +2293,14 @@
2130 2293 *
2131 2294 * @type object $form Form object.
2132 2295 * @type int $entry_id Entry ID.
2133 2296 * }
2134 - * @return string|array
2297 + * @return array|string
2135 2298 */
2136 2299 private static function get_confirmation_method( $atts ) {
2137 2300 $action = FrmOnSubmitHelper::current_event( $atts );
2138 2301 $opt = 'update' === $action ? 'edit_action' : 'success_action';
2139 - $method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message';
2302 + $method = ! empty( $atts['form']->options[ $opt ] ) ? $atts['form']->options[ $opt ] : 'message';
2140 2303
2141 2304 if ( ! empty( $atts['entry_id'] ) ) {
2142 2305 $met_actions = self::get_met_on_submit_actions( $atts, $action );
2143 2306 if ( $met_actions ) {
@@ -2146,9 +2309,9 @@
2146 2309 }
2147 2310
2148 2311 $method = apply_filters( 'frm_success_filter', $method, $atts['form'], $action );
2149 2312
2150 - if ( $method != 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
2313 + if ( $method !== 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
2151 2314 $method = 'message';
2152 2315 }
2153 2316
2154 2317 return $method;
@@ -2233,9 +2396,9 @@
2233 2396 unset( $extra_args['form'] );
2234 2397
2235 2398 do_action( 'frm_success_action', $args['conf_method'], $args['form'], $args['form']->options, $args['entry_id'], $extra_args );
2236 2399
2237 - $opt = ( ! isset( $args['action'] ) || $args['action'] === 'create' ) ? 'success' : 'edit';
2400 + $opt = ! isset( $args['action'] ) || $args['action'] === 'create' ? 'success' : 'edit';
2238 2401
2239 2402 $args['success_opt'] = $opt;
2240 2403 $args['ajax'] = ! empty( $frm_vars['ajax'] );
2241 2404
@@ -2261,11 +2424,16 @@
2261 2424 if ( ! FrmOnSubmitHelper::form_has_migrated( $args['form'] ) ) {
2262 2425 return array();
2263 2426 }
2264 2427
2265 - $entry = FrmEntry::getOne( $args['entry_id'], true );
2266 - $actions = FrmOnSubmitHelper::get_actions( $args['form']->id );
2267 - $met_actions = array();
2428 + // If a redirect action has already opened the URL in a new tab, we show the default message in the currect tab.
2429 + if ( ! empty( self::$redirected_in_new_tab[ $args['form']->id ] ) ) {
2430 + return array( FrmOnSubmitHelper::get_fallback_action_after_open_in_new_tab( $event ) );
2431 + }
2432 +
2433 + $entry = FrmEntry::getOne( $args['entry_id'], true );
2434 + $actions = FrmOnSubmitHelper::get_actions( $args['form']->id );
2435 + $met_actions = array();
2268 2436 $has_redirect = false;
2269 2437
2270 2438 foreach ( $actions as $action ) {
2271 2439 if ( ! in_array( $event, $action->post_content['event'], true ) ) {
@@ -2278,9 +2446,10 @@
2278 2446
2279 2447 $action_type = FrmOnSubmitHelper::get_action_type( $action );
2280 2448
2281 2449 if ( 'redirect' === $action_type ) {
2282 - if ( $has_redirect ) { // Do not process because we run the first redirect action only.
2450 + if ( $has_redirect ) {
2451 + // Do not process because we run the first redirect action only.
2283 2452 continue;
2284 2453 }
2285 2454 }
2286 2455
@@ -2293,9 +2462,9 @@
2293 2462 }
2294 2463
2295 2464 $met_actions[] = $action;
2296 2465 unset( $action );
2297 - }
2466 + }//end foreach
2298 2467
2299 2468 $args['event'] = $event;
2300 2469
2301 2470 /**
@@ -2484,9 +2653,9 @@
2484 2653 add_filter( 'the_content', 'FrmFormsController::preview_content', 9999 );
2485 2654 }
2486 2655
2487 2656 $post = $old_post;
2488 - }
2657 + }//end if
2489 2658 }
2490 2659
2491 2660 /**
2492 2661 * @since 3.0
@@ -2507,16 +2676,25 @@
2507 2676 $success_url = apply_filters( 'frm_redirect_url', $success_url, $args['form'], $args );
2508 2677
2509 2678 $doing_ajax = FrmAppHelper::doing_ajax();
2510 2679
2511 - if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) { // Is AJAX submit and there is just one Redirect action runs.
2512 - echo json_encode( array( 'redirect' => $success_url ) );
2680 + if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) {
2681 + // Is AJAX submit and there is just one Redirect action runs.
2682 + echo json_encode( self::get_ajax_redirect_response_data( $args + compact( 'success_url' ) ) );
2513 2683 wp_die();
2514 2684 }
2515 2685
2516 - if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) ) { // Not AJAX submit, no headers sent, and there is just one Redirect action runs.
2686 + if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) ) {
2687 + // Not AJAX submit, no headers sent, and there is just one Redirect action runs.
2688 + if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2689 + self::print_open_in_new_tab_js_with_fallback_handler( $success_url, $args );
2690 + self::$redirected_in_new_tab[ $args['form']->id ] = 1;
2691 + return;
2692 + }
2693 +
2517 2694 wp_redirect( esc_url_raw( $success_url ) );
2518 - die(); // do not use wp_die or redirect fails
2695 + // Do not use wp_die or redirect fails.
2696 + die();
2519 2697 }
2520 2698
2521 2699 // Redirect with a delay.
2522 2700 self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) );
@@ -2522,8 +2700,63 @@
2522 2700 self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) );
2523 2701 }
2524 2702
2525 2703 /**
2704 + * Prints open in new tab js with fallback handler.
2705 + *
2706 + * @since 6.3.1
2707 + *
2708 + * @param string $success_url Success URL.
2709 + * @param array $args See {@see FrmFormsController::redirect_after_submit()}.
2710 + */
2711 + private static function print_open_in_new_tab_js_with_fallback_handler( $success_url, $args ) {
2712 + echo '<script>var newTab = window.open("' . esc_url_raw( $success_url ) . '", "_blank");';
2713 + echo 'if ( ! newTab ) {';
2714 +
2715 + $data = array(
2716 + 'formId' => intval( $args['form']->id ),
2717 + 'message' => self::get_redirect_fallback_message( $success_url, $args ),
2718 + );
2719 + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2720 + echo 'frmShowNewTabFallback = ' . FrmAppHelper::maybe_json_encode( $data ) . ';';
2721 + echo '}</script>';
2722 + }
2723 +
2724 + /**
2725 + * Gets response data for redirect action when AJAX submitting.
2726 + *
2727 + * @since 6.3.1
2728 + *
2729 + * @param array $args See {@see FrmFormsController::run_success_action()}.
2730 + * @return array
2731 + */
2732 + private static function get_ajax_redirect_response_data( $args ) {
2733 + $response_data = array( 'redirect' => $args['success_url'] );
2734 +
2735 + if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2736 + $response_data['openInNewTab'] = 1;
2737 +
2738 + $args['message'] = FrmOnSubmitHelper::get_default_new_tab_msg();
2739 +
2740 + $args['form']->options['success_msg'] = $args['message'];
2741 + $args['form']->options['edit_msg'] = $args['message'];
2742 + if ( ! isset( $args['fields'] ) ) {
2743 + $args['fields'] = FrmField::get_all_for_form( $args['form']->id );
2744 + }
2745 +
2746 + $args['message'] = self::prepare_submit_message( $args['form'], $args['entry_id'], $args );
2747 +
2748 + ob_start();
2749 + self::show_lone_success_messsage( $args );
2750 + $response_data['content'] = ob_get_clean();
2751 +
2752 + $response_data['fallbackMsg'] = self::get_redirect_fallback_message( $args['success_url'], $args );
2753 + }
2754 +
2755 + return $response_data;
2756 + }
2757 +
2758 + /**
2526 2759 * Redirects after submitting using JS. This is used when showing message before redirecting.
2527 2760 *
2528 2761 * @since 6.0
2529 2762 *
@@ -2531,8 +2764,9 @@
2531 2764 */
2532 2765 private static function redirect_after_submit_using_js( $args ) {
2533 2766 $success_msg = FrmOnSubmitHelper::get_default_redirect_msg();
2534 2767 $redirect_msg = self::get_redirect_message( $args['success_url'], $success_msg, $args );
2768 + $success_url = esc_url_raw( $args['success_url'] );
2535 2769
2536 2770 /**
2537 2771 * Filters the delay time before redirecting when On Submit Redirect action is delayed.
2538 2772 *
@@ -2541,16 +2775,23 @@
2541 2775 * @param int $delay_time Delay time in miliseconds.
2542 2776 */
2543 2777 $delay_time = apply_filters( 'frm_redirect_delay_time', 8000 );
2544 2778
2779 + if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2780 + $redirect_js = 'window.open("' . $success_url . '", "_blank")';
2781 + } else {
2782 + $redirect_js = 'window.location="' . $success_url . '";';
2783 + }
2784 +
2545 2785 add_filter( 'frm_use_wpautop', '__return_true' );
2546 2786
2547 2787 echo FrmAppHelper::maybe_kses( $redirect_msg ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2548 2788 echo '<script>';
2549 - if ( empty( $args['doing_ajax'] ) ) { // Not AJAX submit, delay JS until window.load.
2789 + if ( empty( $args['doing_ajax'] ) ) {
2790 + // Not AJAX submit, delay JS until window.load.
2550 2791 echo 'window.onload=function(){';
2551 2792 }
2552 - echo 'setTimeout(function(){window.location="' . esc_url_raw( $args['success_url'] ) . '";}, ' . intval( $delay_time ) . ');';
2793 + echo 'setTimeout(function(){' . $redirect_js . '}, ' . intval( $delay_time ) . ');'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2553 2794 if ( empty( $args['doing_ajax'] ) ) {
2554 2795 echo '};';
2555 2796 }
2556 2797 echo '</script>';
@@ -2560,14 +2801,13 @@
2560 2801 * @since 3.0
2561 2802 *
2562 2803 * @param string $success_url
2563 2804 * @param string $success_msg
2564 - * @param array $args
2805 + * @param array $args
2565 2806 */
2566 2807 private static function get_redirect_message( $success_url, $success_msg, $args ) {
2567 2808 $redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg" role="status">' . $success_msg . '<br/>' .
2568 - /* translators: %1$s: Start link HTML, %2$s: End link HTML */
2569 - sprintf( __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ), '<a href="' . esc_url( $success_url ) . '">', '</a>' ) .
2809 + self::get_redirect_fallback_message( $success_url, $args ) .
2570 2810 '</div></div>';
2571 2811
2572 2812 $redirect_args = array(
2573 2813 'entry_id' => $args['entry_id'],
@@ -2578,8 +2818,31 @@
2578 2818 return apply_filters( 'frm_redirect_msg', $redirect_msg, $redirect_args );
2579 2819 }
2580 2820
2581 2821 /**
2822 + * Gets fallback message when redirecting failed.
2823 + *
2824 + * @since 6.3.1
2825 + *
2826 + * @param string $success_url Redirect URL.
2827 + * @param array $args Contains `form` object.
2828 + * @return string
2829 + */
2830 + private static function get_redirect_fallback_message( $success_url, $args ) {
2831 + $target = '';
2832 + if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2833 + $target = ' target="_blank"';
2834 + }
2835 +
2836 + return sprintf(
2837 + /* translators: %1$s: Start link HTML, %2$s: End link HTML */
2838 + __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ),
2839 + '<a href="' . esc_url( $success_url ) . '"' . $target . '>',
2840 + '</a>'
2841 + );
2842 + }
2843 +
2844 + /**
2582 2845 * Prepare to show the success message and empty form after submit
2583 2846 *
2584 2847 * @since 2.05
2585 2848 */
@@ -2639,11 +2902,10 @@
2639 2902 include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php';
2640 2903 }
2641 2904
2642 2905 /**
2906 + * @since 4.05.02
2643 2907 * @return string - 'before', 'after', or 'submit'
2644 - *
2645 - * @since 4.05.02
2646 2908 */
2647 2909 private static function message_placement( $form, $message ) {
2648 2910 $place = 'before';
2649 2911
@@ -2655,11 +2917,10 @@
2655 2917 }
2656 2918 }
2657 2919
2658 2920 /**
2921 + * @since 4.05.02
2659 2922 * @return string - 'before' or 'after'
2660 - *
2661 - * @since 4.05.02
2662 2923 */
2663 2924 return apply_filters( 'frm_message_placement', $place, compact( 'form', 'message' ) );
2664 2925 }
2665 2926
@@ -2704,9 +2965,9 @@
2704 2965 $errors = array();
2705 2966 $form = $atts['form'];
2706 2967 $message = $atts['message'];
2707 2968
2708 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php' );
2969 + include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php';
2709 2970 }
2710 2971
2711 2972 /**
2712 2973 * Prepare the success message before it's shown
@@ -2826,9 +3087,9 @@
2826 3087 global $frm_vars;
2827 3088
2828 3089 FrmStylesController::enqueue_css();
2829 3090
2830 - if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
3091 + if ( ! FrmAppHelper::is_admin() && $location !== 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
2831 3092 // load formidable js
2832 3093 wp_enqueue_script( 'formidable' );
2833 3094 }
2834 3095 }
@@ -2844,12 +3105,12 @@
2844 3105 }
2845 3106
2846 3107 /**
2847 3108 * @since 2.0.8
2848 - * @return boolean
3109 + * @return bool
2849 3110 */
2850 3111 private static function is_minification_on( $atts ) {
2851 - return isset( $atts['minimize'] ) && ! empty( $atts['minimize'] );
3112 + return ! empty( $atts['minimize'] );
2852 3113 }
2853 3114
2854 3115 /**
2855 3116 * @since 5.0.16
@@ -2877,9 +3138,9 @@
2877 3138 * Create a page with an embedded formidable Gutenberg block.
2878 3139 *
2879 3140 * @since 5.2
2880 3141 *
2881 - * @return never
3142 + * @return void
2882 3143 */
2883 3144 public static function create_page_with_shortcode() {
2884 3145 if ( ! current_user_can( 'publish_posts' ) ) {
2885 3146 die( 0 );
@@ -2924,10 +3185,9 @@
2924 3185
2925 3186 /**
2926 3187 * @since 5.3
2927 3188 *
2928 - * @param string $content
2929 - * @param int $form_id
3189 + * @param int $form_id
2930 3190 * @return string
2931 3191 */
2932 3192 private static function get_page_shortcode_content_for_form( $form_id ) {
2933 3193 $shortcode = '[formidable id="' . $form_id . '"]';
@@ -2938,9 +3198,9 @@
2938 3198
2939 3199 /**
2940 3200 * Get page dropdown for AJAX request for embedding form in an existing page.
2941 3201 *
2942 - * @return never
3202 + * @return void
2943 3203 */
2944 3204 public static function get_page_dropdown() {
2945 3205 if ( ! current_user_can( 'publish_posts' ) ) {
2946 3206 die( 0 );
@@ -2948,9 +3208,9 @@
2948 3208
2949 3209 check_ajax_referer( 'frm_ajax', 'nonce' );
2950 3210
2951 3211 $html = FrmAppHelper::clip(
2952 - function() {
3212 + function () {
2953 3213 FrmAppHelper::maybe_autocomplete_pages_options(
2954 3214 array(
2955 3215 'field_name' => 'frm_page_dropdown',
2956 3216 'page_id' => '',
@@ -2970,15 +3230,8 @@
2970 3230
2971 3231 /**
2972 3232 * @deprecated 4.0
2973 3233 */
2974 - public static function new_form( $values = array() ) {
2975 - FrmDeprecated::new_form( $values );
2976 - }
2977 -
2978 - /**
2979 - * @deprecated 4.0
2980 - */
2981 3234 public static function create( $values = array() ) {
2982 3235 _deprecated_function( __METHOD__, '4.0', 'FrmFormsController::update' );
2983 3236 self::update( $values );
2984 3237 }
@@ -2983,35 +3236,13 @@
2983 3236 self::update( $values );
2984 3237 }
2985 3238
2986 3239 /**
2987 - * @deprecated 3.0
2988 - * @codeCoverageIgnore
3240 + * @deprecated 6.7
3241 + *
3242 + * @return bool
2989 3243 */
2990 - public static function bulk_create_template( $ids ) {
2991 - return FrmDeprecated::bulk_create_template( $ids );
2992 - }
2993 -
2994 - /**
2995 - * @deprecated 3.0
2996 - * @codeCoverageIgnore
2997 - */
2998 - public static function edit_key() {
2999 - FrmDeprecated::edit_key();
3000 - }
3001 -
3002 - /**
3003 - * @deprecated 3.0
3004 - * @codeCoverageIgnore
3005 - */
3006 - public static function edit_description() {
3007 - FrmDeprecated::edit_description();
3008 - }
3009 -
3010 - /**
3011 - * @deprecated 4.08
3012 - * @since 3.06
3013 - */
3014 - public static function add_new() {
3015 - _deprecated_function( __FUNCTION__, '4.08' );
3244 + public static function expired() {
3245 + _deprecated_function( __METHOD__, '6.7' );
3246 + return FrmAddonsController::is_license_expired();
3016 3247 }
3017 3248 }