PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.12.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.12.1
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 +646 -386 6.36.12.1 View file →
@@ -4,8 +4,28 @@
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 current 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 +
18 + /**
19 + * The HTML for the Formdiable TinyMCE button (That triggers a popup to insert shortcodes)
20 + * is stored here and re-used as an optimization.
21 + *
22 + * @since 6.11
23 + *
24 + * @var string|null
25 + */
26 + private static $formidable_tinymce_button;
27 +
8 28 public static function menu() {
9 29 $menu_label = __( 'Forms', 'formidable' );
10 30 if ( ! FrmAppHelper::pro_is_installed() ) {
11 31 $menu_label .= ' (Lite)';
@@ -44,9 +64,9 @@
44 64 */
45 65 public static function logic_tip() {
46 66 $images_url = FrmAppHelper::plugin_url() . '/images/';
47 67 $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' ) . '"/>';
68 + $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 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">';
50 70 esc_html_e( 'Conditional Logic', 'formidable' );
51 71 FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown6_icon', array( 'aria-hidden' => 'true' ) );
52 72 echo '</a>';
@@ -86,9 +106,9 @@
86 106 * Create the default email action
87 107 *
88 108 * @since 2.02.11
89 109 *
90 - * @param object|int $form
110 + * @param int|object $form
91 111 */
92 112 private static function create_default_email_action( $form ) {
93 113 FrmForm::maybe_get_form( $form );
94 114 $create_email = apply_filters( 'frm_create_default_email_action', true, $form );
@@ -103,9 +123,9 @@
103 123 * Create the default On submit action
104 124 *
105 125 * @since 6.0.0
106 126 *
107 - * @param object|int $form Form object or ID.
127 + * @param int|object $form Form object or ID.
108 128 */
109 129 private static function create_default_on_submit_action( $form ) {
110 130 FrmForm::maybe_get_form( $form );
111 131
@@ -124,16 +144,53 @@
124 144 $action_control->create( $form->id );
125 145 }
126 146 }
127 147
148 + /**
149 + * Creates submit button field.
150 + *
151 + * @since 6.9
152 + *
153 + * @param int|object $form Form ID or object.
154 + */
155 + private static function create_submit_button_field( $form ) {
156 + FrmForm::maybe_get_form( $form );
157 +
158 + if ( FrmSubmitHelper::get_submit_field( $form->id ) ) {
159 + // Do not create submit button field if it exists.
160 + return;
161 + }
162 +
163 + FrmField::create(
164 + array(
165 + 'type' => FrmSubmitHelper::FIELD_TYPE,
166 + 'name' => __( 'Submit', 'formidable' ),
167 + 'field_order' => 9999,
168 + 'form_id' => $form->id,
169 + 'field_options' => FrmFieldsHelper::get_default_field_options( FrmSubmitHelper::FIELD_TYPE ),
170 + 'description' => '',
171 + 'default_value' => '',
172 + 'options' => array(),
173 + )
174 + );
175 + }
176 +
177 + /**
178 + * @return void
179 + */
128 180 public static function edit( $values = false ) {
129 181 FrmAppHelper::permission_check( 'frm_edit_forms' );
130 182
131 183 $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
132 184
133 - return self::get_edit_vars( $id );
185 + self::get_edit_vars( $id );
134 186 }
135 187
188 + /**
189 + * @param mixed $id
190 + * @param string $message
191 + * @return void
192 + */
136 193 public static function settings( $id = false, $message = '' ) {
137 194 FrmAppHelper::permission_check( 'frm_edit_forms' );
138 195
139 196 if ( ! $id || ! is_numeric( $id ) ) {
@@ -141,21 +198,34 @@
141 198 }
142 199
143 200 FrmOnSubmitHelper::maybe_migrate_submit_settings_to_action( $id );
144 201
145 - return self::get_settings_vars( $id, array(), $message );
202 + self::get_settings_vars( $id, array(), $message );
146 203 }
147 204
148 205 public static function update_settings() {
149 206 FrmAppHelper::permission_check( 'frm_edit_forms' );
207 + $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
150 208
209 + if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) {
210 + $frm_settings = FrmAppHelper::get_settings();
211 + $error_args = array(
212 + 'title' => __( 'Verification failed', 'formidable' ),
213 + 'body' => $frm_settings->admin_permission,
214 + 'cancel_text' => __( 'Cancel', 'formidable' ),
215 + );
216 + FrmAppController::show_error_modal( $error_args );
217 + return;
218 + }
219 +
151 220 $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
152 221
153 - $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
222 + $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
154 223 $warnings = FrmFormsHelper::check_for_warnings( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
155 224
156 225 if ( count( $errors ) > 0 ) {
157 - return self::get_settings_vars( $id, $errors, compact( 'warnings' ) );
226 + self::get_settings_vars( $id, $errors, compact( 'warnings' ) );
227 + return;
158 228 }
159 229
160 230 do_action( 'frm_before_update_form_settings', $id );
161 231
@@ -169,9 +239,9 @@
169 239 }
170 240
171 241 $message = __( 'Settings Successfully Updated', 'formidable' );
172 242
173 - return self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) );
243 + self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) );
174 244 }
175 245
176 246 /**
177 247 * @param int $form_id
@@ -181,8 +251,11 @@
181 251 $form = FrmForm::getOne( $form_id );
182 252 return ! empty( $form->options['antispam'] );
183 253 }
184 254
255 + /**
256 + * @return void
257 + */
185 258 public static function update( $values = array() ) {
186 259 if ( empty( $values ) ) {
187 260 $values = $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing
188 261 }
@@ -200,65 +273,74 @@
200 273
201 274 $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
202 275
203 276 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' );
277 + self::get_edit_vars( $id, $errors );
278 + return;
279 + }
208 280
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 - }
281 + self::maybe_remove_draft_option_from_fields( $id );
217 282
218 - if ( defined( 'DOING_AJAX' ) ) {
219 - wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
220 - }
283 + FrmForm::update( $id, $values );
284 + $message = __( 'Form was successfully updated.', 'formidable' );
221 285
222 - return self::get_edit_vars( $id, array(), $message );
286 + if ( self::is_too_long( $values ) ) {
287 + $message .= '<br/> ' . sprintf(
288 + /* translators: %1$s: Start link HTML, %2$s: end link HTML */
289 + __( 'However, your form is very long and may be %1$sreaching server limits%2$s.', 'formidable' ),
290 + '<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">',
291 + '</a>'
292 + );
223 293 }
294 +
295 + if ( defined( 'DOING_AJAX' ) ) {
296 + wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
297 + }
298 +
299 + self::get_edit_vars( $id, array(), $message );
224 300 }
225 301
226 302 /**
303 + * Remove the draft flag from any new fields from this current session.
304 + *
305 + * @since 6.8
306 + *
307 + * @param int $form_id
308 + * @return void
309 + */
310 + private static function maybe_remove_draft_option_from_fields( $form_id ) {
311 + $draft_field_ids_csv = FrmAppHelper::get_post_param( 'draft_fields', '', 'sanitize_text_field' );
312 + if ( ! $draft_field_ids_csv ) {
313 + // If the draft_fields input is empty there are no new fields in the session.
314 + return;
315 + }
316 +
317 + $draft_field_ids = array_filter( explode( ',', $draft_field_ids_csv ), 'is_numeric' );
318 + if ( ! $draft_field_ids ) {
319 + // Exit early if the draft fields input is invalid. It should be a CSV of integer values.
320 + return;
321 + }
322 +
323 + $draft_field_rows = FrmFieldsHelper::get_draft_field_results( $form_id, $draft_field_ids );
324 + foreach ( $draft_field_rows as $row ) {
325 + $row->field_options['draft'] = 0;
326 + FrmField::update( $row->id, array( 'field_options' => $row->field_options ) );
327 + }
328 + }
329 +
330 + /**
227 331 * Check if the value at the end of the form was included.
228 332 * If it's missing, it means other values at the end of the form
229 333 * were likely not saved either.
230 334 *
231 335 * @since 3.06.01
336 + *
337 + * @return bool
232 338 */
233 339 private static function is_too_long( $values ) {
234 - return ( ! isset( $values['frm_end'] ) ) || empty( $values['frm_end'] );
340 + return empty( $values['frm_end'] );
235 341 }
236 342
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 343 public static function duplicate() {
262 344 FrmAppHelper::permission_check( 'frm_edit_forms' );
263 345 $nonce = FrmAppHelper::simple_get( '_wpnonce' );
264 346
@@ -272,10 +354,11 @@
272 354 $url = admin_url( 'admin.php?page=formidable' );
273 355 $message = 'form_duplicate_error';
274 356
275 357 if ( $form ) {
276 - $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) );
277 - $message = 'form_duplicated';
358 + $new_template = FrmAppHelper::simple_get( 'new_template' ) ? '&new_template=true' : '';
359 + $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) . $new_template );
360 + $message = 'form_duplicated';
278 361 }
279 362
280 363 $url .= '&message=' . $message;
281 364
@@ -283,24 +366,28 @@
283 366 exit();
284 367 }
285 368
286 369 /**
287 - * @return string
370 + * @return string|null
288 371 */
289 372 public static function page_preview() {
290 373 $params = FrmForm::list_page_params();
291 374 if ( ! $params['form'] ) {
292 - return;
375 + return null;
293 376 }
294 377
295 378 $form = FrmForm::getOne( $params['form'] );
296 - if ( $form ) {
297 - return self::show_form( $form->id, '', 'auto', 'auto' );
379 + if ( ! $form ) {
380 + return null;
298 381 }
382 +
383 + return self::show_form( $form->id, '', 'auto', 'auto' );
299 384 }
300 385
301 386 /**
302 387 * @since 3.0
388 + *
389 + * @return void
303 390 */
304 391 public static function show_page_preview() {
305 392 echo self::page_preview(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
306 393 }
@@ -350,8 +437,13 @@
350 437 return;
351 438 }
352 439
353 440 $random_page = reset( $random_page );
441 + if ( ! is_a( $random_page, 'WP_Post' ) ) {
442 + // The return type can also be int.
443 + return;
444 + }
445 +
354 446 query_posts(
355 447 array(
356 448 'post_type' => 'page',
357 449 'page_id' => $random_page->ID,
@@ -367,9 +459,9 @@
367 459 * Set the WP $post global object. Used for in-theme preview when defining a page.
368 460 *
369 461 * @since 5.5.2
370 462 *
371 - * @param WP_Post $post
463 + * @param WP_Post $page The page object.
372 464 * @return void
373 465 */
374 466 private static function set_post_global( $page ) {
375 467 global $post;
@@ -377,8 +469,10 @@
377 469 }
378 470
379 471 /**
380 472 * @since 3.0
473 + *
474 + * @return void
381 475 */
382 476 private static function load_theme_preview() {
383 477 add_filter( 'wp_title', 'FrmFormsController::preview_title', 9999 );
384 478 add_filter( 'the_title', 'FrmFormsController::preview_page_title', 9999 );
@@ -387,20 +481,39 @@
387 481 add_filter( 'is_active_sidebar', '__return_false' );
388 482 FrmStylesController::enqueue_css( 'enqueue', true );
389 483
390 484 if ( false === get_template_part( 'page' ) ) {
485 + if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) {
486 + add_filter( 'body_class', 'FrmFormsController::preview_block_theme_body_classnames' );
487 + }
391 488 self::fallback_when_page_template_part_is_not_supported_by_theme();
392 489 }
393 490 }
394 491
395 492 /**
493 + * Add padding to the body for block themes.
494 + *
495 + * @since 6.5.2
496 + *
497 + * @param array $classes The body classes list.
498 + * @return array
499 + */
500 + public static function preview_block_theme_body_classnames( $classes ) {
501 + $classes[] = 'has-global-padding';
502 + return $classes;
503 + }
504 +
505 + /**
396 506 * Not every theme supports get_template_part( 'page' ).
397 507 * When this is not supported, false is returned, and we can handle a fallback.
508 + *
509 + * @return void
398 510 */
399 511 private static function fallback_when_page_template_part_is_not_supported_by_theme() {
400 512 if ( have_posts() ) {
401 513 the_post();
402 - get_header( '' );
514 + self::get_template( 'header' );
515 +
403 516 // add some generic class names to the container to add some natural padding to the content.
404 517 // .entry-content catches the WordPress TwentyTwenty theme.
405 518 // .container catches Customizr content.
406 519 echo '<div class="container entry-content">';
@@ -405,13 +518,54 @@
405 518 // .container catches Customizr content.
406 519 echo '<div class="container entry-content">';
407 520 the_content();
408 521 echo '</div>';
409 - get_footer();
522 +
523 + self::get_template( 'footer' );
410 524 }
411 525 }
412 526
413 527 /**
528 + * Calls core function to get a template part if it doesn't cause deprecation warnings. Otherwise skips the deprecation function call
529 + * and renders required html fragments calling required functions.
530 + *
531 + * @since 6.7.1
532 + * @param string $template
533 + * @return void
534 + */
535 + private static function get_template( $template ) {
536 + if ( self::should_try_getting_template( $template ) ) {
537 + call_user_func( 'get_' . $template );
538 + return;
539 + }
540 +
541 + if ( 'header' === $template ) {
542 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/header.php';
543 + return;
544 + }
545 +
546 + if ( 'footer' === $template ) {
547 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/footer.php';
548 + }
549 + }
550 +
551 + /**
552 + * Returns true if calling a template function doesn't trigger deprecation warnings.
553 + *
554 + * @since 6.7.1
555 + * @param string $template
556 + * @return bool
557 + */
558 + private static function should_try_getting_template( $template ) {
559 + $stylesheet_path = get_stylesheet_directory();
560 + $template_path = get_template_directory();
561 + $is_child_theme = $stylesheet_path !== $template_path;
562 + $template_name = $template . '.php';
563 +
564 + return file_exists( $stylesheet_path . '/' . $template_name ) || $is_child_theme && file_exists( $template_path . '/' . $template_name );
565 + }
566 +
567 + /**
414 568 * Set the page title for the theme preview page
415 569 *
416 570 * @since 3.0
417 571 */
@@ -423,11 +577,14 @@
423 577 return $title;
424 578 }
425 579
426 580 /**
427 - * Set the page title for the theme preview page
581 + * Set the page title for the theme preview page.
428 582 *
429 583 * @since 3.0
584 + *
585 + * @param string $title
586 + * @return string
430 587 */
431 588 public static function preview_title( $title ) {
432 589 return __( 'Form Preview', 'formidable' );
433 590 }
@@ -432,15 +589,20 @@
432 589 return __( 'Form Preview', 'formidable' );
433 590 }
434 591
435 592 /**
436 - * Set the page content for the theme preview page
593 + * Set the page content for the theme preview page.
437 594 *
438 595 * @since 3.0
596 + *
597 + * @param string $content
598 + * @return string
439 599 */
440 600 public static function preview_content( $content ) {
441 601 if ( in_the_loop() ) {
442 - $content = self::show_page_preview();
602 + self::show_page_preview();
603 + // Clear the content for the page we're using.
604 + $content = '';
443 605 }
444 606
445 607 return $content;
446 608 }
@@ -450,8 +612,11 @@
450 612 */
451 613 private static function load_direct_preview() {
452 614 header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
453 615
616 + // print_emoji_styles is deprecated.
617 + remove_action( 'wp_print_styles', 'print_emoji_styles' );
618 +
454 619 $key = FrmAppHelper::simple_get( 'form', 'sanitize_title' );
455 620 if ( $key == '' ) {
456 621 $key = FrmAppHelper::get_post_param( 'form', '', 'sanitize_title' );
457 622 }
@@ -460,11 +625,38 @@
460 625 if ( empty( $form ) ) {
461 626 $form = FrmForm::getAll( array(), '', 1 );
462 627 }
463 628
464 - require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php' );
629 + self::fix_deprecated_null_param_warning();
630 +
631 + require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php';
465 632 }
466 633
634 + /**
635 + * Some themes have a null $src value.
636 + * This function adds a filter to ensure that $src is not null.
637 + * WP will call str_starts_with with the null value triggering a deprecated message otherwise.
638 + *
639 + * @since 6.10
640 + *
641 + * @return void
642 + */
643 + private static function fix_deprecated_null_param_warning() {
644 + add_filter(
645 + 'script_loader_src',
646 + /**
647 + * @param string|null $src
648 + * @return string
649 + */
650 + function ( $src ) {
651 + if ( is_null( $src ) ) {
652 + $src = '';
653 + }
654 + return $src;
655 + }
656 + );
657 + }
658 +
467 659 public static function untrash() {
468 660 self::change_form_status( 'untrash' );
469 661 }
470 662
@@ -527,14 +719,14 @@
527 719 FrmAppHelper::permission_check( $available_status[ $status ]['permission'] );
528 720
529 721 $params = FrmForm::list_page_params();
530 722
531 - //check nonce url
723 + // Check nonce url.
532 724 check_admin_referer( $status . '_form_' . $params['id'] );
533 725
534 726 $count = 0;
535 727 if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) {
536 - $count ++;
728 + ++$count;
537 729 }
538 730
539 731 $form_type = FrmAppHelper::get_simple_request(
540 732 array(
@@ -546,9 +738,9 @@
546 738 /* translators: %1$s: Number of forms */
547 739 $available_status['untrash']['message'] = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
548 740
549 741 /* 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>' );
742 + $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 743
552 744 $message = $available_status[ $status ]['message'];
553 745
554 746 self::display_forms_list( $params, $message );
@@ -553,8 +745,12 @@
553 745
554 746 self::display_forms_list( $params, $message );
555 747 }
556 748
749 + /**
750 + * @param array $ids
751 + * @return string
752 + */
557 753 public static function bulk_trash( $ids ) {
558 754 FrmAppHelper::permission_check( 'frm_delete_forms' );
559 755
560 756 $count = 0;
@@ -559,9 +755,9 @@
559 755
560 756 $count = 0;
561 757 foreach ( $ids as $id ) {
562 758 if ( FrmForm::trash( $id ) ) {
563 - $count ++;
759 + ++$count;
564 760 }
565 761 }
566 762
567 763 $current_page = FrmAppHelper::get_simple_request(
@@ -590,9 +786,9 @@
590 786 check_admin_referer( 'destroy_form_' . $params['id'] );
591 787
592 788 $count = 0;
593 789 if ( FrmForm::destroy( $params['id'] ) ) {
594 - $count ++;
790 + ++$count;
595 791 }
596 792
597 793 /* translators: %1$s: Number of forms */
598 794 $message = sprintf( _n( '%1$s Form Permanently Deleted', '%1$s Forms Permanently Deleted', $count, 'formidable' ), $count );
@@ -599,8 +795,12 @@
599 795
600 796 self::display_forms_list( $params, $message );
601 797 }
602 798
799 + /**
800 + * @param array $ids
801 + * @return string
802 + */
603 803 public static function bulk_destroy( $ids ) {
604 804 FrmAppHelper::permission_check( 'frm_delete_forms' );
605 805
606 806 $count = 0;
@@ -606,19 +806,24 @@
606 806 $count = 0;
607 807 foreach ( $ids as $id ) {
608 808 $d = FrmForm::destroy( $id );
609 809 if ( $d ) {
610 - $count ++;
810 + ++$count;
611 811 }
612 812 }
613 813
614 - /* translators: %1$s: Number of forms */
615 - $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
814 + if ( $count ) {
815 + /* translators: %1$s: Number of forms */
816 + return sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
817 + }
616 818
617 - return $message;
819 + return '';
618 820 }
619 821
620 - private static function delete_all() {
822 + /**
823 + * @since 6.7.1 Function went from private to public.
824 + */
825 + public static function delete_all() {
621 826 // Check nonce url.
622 827 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' );
623 828 if ( $permission_error !== false ) {
624 829 self::display_forms_list( array(), '', array( $permission_error ) );
@@ -625,14 +830,15 @@
625 830
626 831 return;
627 832 }
628 833
629 - $count = FrmForm::scheduled_delete( time() );
834 + $count = FrmForm::scheduled_delete( time() );
835 + $url = remove_query_arg( array( 'delete_all' ) );
630 836
631 - /* translators: %1$s: Number of forms */
632 - $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
837 + $url .= '&message=forms_permanently_deleted&forms_deleted=' . $count;
633 838
634 - self::display_forms_list( array(), $message );
839 + wp_safe_redirect( $url );
840 + die();
635 841 }
636 842
637 843 /**
638 844 * Create a new form from the modal.
@@ -645,9 +851,9 @@
645 851
646 852 $new_values = self::get_modal_values();
647 853 $new_values['form_key'] = $new_values['name'];
648 854 $new_values['options'] = array(
649 - 'antispam' => 1,
855 + 'antispam' => 1,
650 856 'on_submit_migrated' => 1,
651 857 );
652 858
653 859 /**
@@ -666,13 +872,14 @@
666 872 * @param int $form_id
667 873 */
668 874 do_action( 'frm_build_new_form', $form_id );
669 875
876 + self::create_submit_button_field( $form_id );
670 877 self::create_default_on_submit_action( $form_id );
671 878 self::create_default_email_action( $form_id );
672 879
673 880 $response = array(
674 - 'redirect' => FrmForm::get_edit_link( $form_id ),
881 + 'redirect' => FrmForm::get_edit_link( $form_id ) . '&new_template=true',
675 882 );
676 883
677 884 echo wp_json_encode( $response );
678 885 wp_die();
@@ -678,46 +885,15 @@
678 885 wp_die();
679 886 }
680 887
681 888 /**
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 889 * Before creating a new form, get the name and description from the modal.
716 890 *
717 891 * @since 4.0
892 + *
893 + * @return array<string,string>
718 894 */
719 - private static function get_modal_values() {
895 + public static function get_modal_values() {
720 896 $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' );
721 897 $desc = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' );
722 898
723 899 return array(
@@ -730,17 +906,24 @@
730 906 * Inserts Formidable button
731 907 * Hook exists since 2.5.0
732 908 *
733 909 * @since 2.0.15
910 + *
911 + * @return void
734 912 */
735 913 public static function insert_form_button() {
736 914 if ( current_user_can( 'frm_view_forms' ) ) {
737 - FrmAppHelper::load_admin_wide_js();
738 - $menu_name = FrmAppHelper::get_menu_name();
739 - $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() );
740 - echo '<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' ) . '">' .
741 - FrmAppHelper::kses( $icon, 'all' ) . // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
742 - ' ' . esc_html( $menu_name ) . '</a>';
915 + // Store the result in memory and re-use it when this function is called multiple times.
916 + // This helps speed up the form builder when there are a lot of HTML fields, where this
917 + // button is inserted once per HTML field.
918 + // In a form with 66 HTML fields, this saves 0.5 seconds on page load time, tested locally.
919 + if ( ! isset( self::$formidable_tinymce_button ) ) {
920 + FrmAppHelper::load_admin_wide_js();
921 + $menu_name = FrmAppHelper::get_menu_name();
922 + $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() );
923 + 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>';
924 + }
925 + echo self::$formidable_tinymce_button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
743 926 }
744 927 }
745 928
746 929 /**
@@ -828,9 +1011,9 @@
828 1011 $form_id = $opts['form_id'];
829 1012 unset( $opts['form_id'] );
830 1013 }
831 1014
832 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php' );
1015 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php';
833 1016
834 1017 echo '</div>';
835 1018
836 1019 wp_die();
@@ -879,14 +1062,14 @@
879 1062 * @return array<string,string>
880 1063 */
881 1064 public static function get_columns( $columns ) {
882 1065 $columns['cb'] = '<input type="checkbox" />';
883 - $columns['name'] = __( 'Form Title', 'formidable' );
884 - $columns['entries'] = __( 'Entries', 'formidable' );
1066 + $columns['name'] = esc_html__( 'Form Title', 'formidable' );
1067 + $columns['entries'] = esc_html__( 'Entries', 'formidable' );
885 1068 $columns['id'] = 'ID';
886 - $columns['form_key'] = __( 'Key', 'formidable' );
887 - $columns['shortcode'] = __( 'Actions', 'formidable' );
888 - $columns['created_at'] = __( 'Date', 'formidable' );
1069 + $columns['form_key'] = esc_html__( 'Key', 'formidable' );
1070 + $columns['shortcode'] = esc_html__( 'Actions', 'formidable' );
1071 + $columns['created_at'] = esc_html__( 'Date', 'formidable' );
889 1072
890 1073 add_screen_option(
891 1074 'per_page',
892 1075 array(
@@ -898,8 +1081,11 @@
898 1081
899 1082 return $columns;
900 1083 }
901 1084
1085 + /**
1086 + * @return array<string,string>
1087 + */
902 1088 public static function get_sortable_columns() {
903 1089 return array(
904 1090 'id' => 'id',
905 1091 'name' => 'name',
@@ -933,9 +1119,9 @@
933 1119 return $hidden_columns;
934 1120 }
935 1121
936 1122 public static function save_per_page( $save, $option, $value ) {
937 - if ( $option == 'formidable_page_formidable_per_page' ) {
1123 + if ( $option === 'formidable_page_formidable_per_page' ) {
938 1124 $save = (int) $value;
939 1125 }
940 1126
941 1127 return $save;
@@ -941,146 +1127,49 @@
941 1127 return $save;
942 1128 }
943 1129
944 1130 /**
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 - *
1131 + * @param int|string $id
1132 + * @param array $errors
1133 + * @param string $message
1134 + * @param bool $create_link
955 1135 * @return void
956 1136 */
957 - public static function before_list_templates() {
958 - global $frm_templates;
959 - global $frm_expired;
960 - global $frm_license_type;
1137 + private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
1138 + global $frm_vars;
961 1139
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 - }
1140 + $form = FrmForm::getOne( $id );
1141 + $error_args = array(
1142 + 'title' => __( 'You can\'t edit the form', 'formidable' ),
1143 + 'body' => __( 'You are trying to edit a form that does not exist', 'formidable' ),
1144 + 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
1145 + 'continue_url' => add_query_arg(
1146 + array(
1147 + 'page' => 'formidable',
1148 + )
1149 + ),
1019 1150 );
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 - }
1151 + if ( ! $form ) {
1152 + FrmAppController::show_error_modal( $error_args );
1153 + return;
1046 1154 }
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 1155
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,
1156 + if ( 'trash' === $form->status ) {
1157 + $error_args['body'] = __( 'The form you\'re trying to edit is in trash. You must restore it first before you can make changes', 'formidable' );
1158 + $error_args['continue_url'] = add_query_arg(
1159 + array(
1160 + 'page' => 'formidable',
1161 + '_wpnonce' => wp_create_nonce( 'untrash_form_' . $id ),
1162 + 'form_type' => 'trash',
1163 + 'frm_action' => 'untrash',
1164 + 'id' => $id,
1165 + )
1069 1166 );
1070 - array_unshift( $templates, $template );
1071 - unset( $template );
1167 + $error_args['continue_text'] = __( 'Restore form', 'formidable' );
1168 + FrmAppController::show_error_modal( $error_args );
1169 + return;
1072 1170 }
1073 - }
1074 1171
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 1172 if ( $form->parent_form_id ) {
1084 1173 /* translators: %1$s: Start link HTML, %2$s: End link HTML */
1085 1174 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 1175 }
@@ -1091,8 +1180,9 @@
1091 1180
1092 1181 // Automatically add end section fields if they don't exist (2.0 migration).
1093 1182 $reset_fields = false;
1094 1183 FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields );
1184 + FrmSubmitHelper::maybe_create_submit_field( $form, $fields, $reset_fields );
1095 1185
1096 1186 if ( $reset_fields ) {
1097 1187 $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' );
1098 1188 }
@@ -1119,17 +1209,21 @@
1119 1209
1120 1210 self::maybe_update_form_builder_message( $message );
1121 1211
1122 1212 $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
1123 - $has_fields = isset( $values['fields'] ) && ! empty( $values['fields'] );
1213 + $has_fields = ! empty( $values['fields'] ) && ! FrmSubmitHelper::only_contains_submit_field( $values['fields'] );
1124 1214
1125 1215 if ( defined( 'DOING_AJAX' ) ) {
1126 1216 wp_die();
1127 - } else {
1128 - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' );
1129 1217 }
1218 +
1219 + require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php';
1130 1220 }
1131 1221
1222 + /**
1223 + * @param array $fields
1224 + * @return array
1225 + */
1132 1226 public static function update_form_builder_fields( $fields, $form ) {
1133 1227 foreach ( $fields as $field ) {
1134 1228 $field->do_not_include_icons = true;
1135 1229 }
@@ -1141,13 +1235,21 @@
1141 1235 $message = __( 'Form was Successfully Copied', 'formidable' );
1142 1236 }
1143 1237 }
1144 1238
1239 + /**
1240 + * @param int|string $id
1241 + * @param array $errors
1242 + * @param array|string $args
1243 + * @return void
1244 + */
1145 1245 public static function get_settings_vars( $id, $errors = array(), $args = array() ) {
1146 1246 FrmAppHelper::permission_check( 'frm_edit_forms' );
1147 1247
1148 1248 global $frm_vars;
1149 1249
1250 + self::maybe_print_media_templates();
1251 +
1150 1252 if ( ! is_array( $args ) ) {
1151 1253 // For reverse compatibility.
1152 1254 $args = array(
1153 1255 'message' => $args,
@@ -1180,17 +1282,38 @@
1180 1282
1181 1283 $sections = self::get_settings_tabs( $values );
1182 1284 $current = FrmAppHelper::simple_get( 't', 'sanitize_title', 'advanced_settings' );
1183 1285
1184 - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php' );
1286 + require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php';
1185 1287 }
1186 1288
1187 1289 /**
1290 + * 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.
1291 + *
1292 + * @since 6.10
1293 + *
1294 + * @return void
1295 + */
1296 + private static function maybe_print_media_templates() {
1297 + if ( FrmAppHelper::pro_is_included() ) {
1298 + // This issue does not exist when Pro is active so exit early.
1299 + return;
1300 + }
1301 +
1302 + add_action(
1303 + 'wp_enqueue_editor',
1304 + function () {
1305 + wp_print_media_templates();
1306 + }
1307 + );
1308 + }
1309 +
1310 + /**
1188 1311 * @since 4.0
1189 1312 */
1190 1313 public static function form_publish_button( $atts ) {
1191 1314 $values = $atts['values'];
1192 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php' );
1315 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php';
1193 1316 }
1194 1317
1195 1318 /**
1196 1319 * Get a list of all the settings tabs for the form settings page.
@@ -1215,9 +1338,9 @@
1215 1338 'icon' => 'frm_icon_font frm_mail_bulk_icon',
1216 1339 ),
1217 1340 'permissions' => array(
1218 1341 'name' => __( 'Form Permissions', 'formidable' ),
1219 - 'icon' => 'frm_icon_font frm_lock_icon',
1342 + 'icon' => 'frm_icon_font frm_lock_closed_icon',
1220 1343 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1221 1344 'data' => array(
1222 1345 'medium' => 'permissions',
1223 1346 'upgrade' => __( 'Form Permissions', 'formidable' ),
@@ -1224,9 +1347,9 @@
1224 1347 'message' => __( 'Allow editing, protect forms and files, limit entries, and save drafts. Upgrade to get form and entry permissions.', 'formidable' ),
1225 1348 'screenshot' => 'permissions.png',
1226 1349 ),
1227 1350 ),
1228 - 'scheduling' => array(
1351 + 'scheduling' => array(
1229 1352 'name' => __( 'Form Scheduling', 'formidable' ),
1230 1353 'icon' => 'frm_icon_font frm_calendar_icon',
1231 1354 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1232 1355 'data' => array(
@@ -1259,8 +1382,21 @@
1259 1382 'screenshot' => 'chat.png',
1260 1383 )
1261 1384 ),
1262 1385 ),
1386 + 'abandonment' => array(
1387 + 'name' => __( 'Form Abandonment', 'formidable' ),
1388 + 'icon' => 'frm_icon_font frm_abandoned_icon',
1389 + 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1390 + 'data' => FrmAppHelper::get_upgrade_data_params(
1391 + 'abandonment',
1392 + array(
1393 + 'upgrade' => __( 'Form abandonment settings', 'formidable' ),
1394 + 'message' => __( 'Unlock the power of data capture to boost lead generation and master the art of form optimization.', 'formidable' ),
1395 + 'screenshot' => 'abandonment.png',
1396 + )
1397 + ),
1398 + ),
1263 1399 'html' => array(
1264 1400 'name' => __( 'Customize HTML', 'formidable' ),
1265 1401 'class' => __CLASS__,
1266 1402 'function' => 'html_settings',
@@ -1267,9 +1403,9 @@
1267 1403 'icon' => 'frm_icon_font frm_code_icon',
1268 1404 ),
1269 1405 );
1270 1406
1271 - foreach ( array( 'landing', 'chat' ) as $feature ) {
1407 + foreach ( array( 'landing', 'chat', 'abandonment' ) as $feature ) {
1272 1408 if ( ! FrmAppHelper::show_new_feature( $feature ) ) {
1273 1409 unset( $sections[ $feature ] );
1274 1410 }
1275 1411 }
@@ -1275,13 +1411,8 @@
1275 1411 }
1276 1412
1277 1413 $sections = apply_filters( 'frm_add_form_settings_section', $sections, $values );
1278 1414
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 1415 foreach ( $sections as $key => $section ) {
1285 1416 $defaults = array(
1286 1417 'html_class' => '',
1287 1418 'name' => ucfirst( $key ),
@@ -1303,9 +1434,9 @@
1303 1434 $section['id'] = $section['anchor'];
1304 1435 }
1305 1436
1306 1437 $sections[ $key ] = $section;
1307 - }
1438 + }//end foreach
1308 1439
1309 1440 return $sections;
1310 1441 }
1311 1442
@@ -1312,8 +1443,9 @@
1312 1443 /**
1313 1444 * @since 4.0
1314 1445 *
1315 1446 * @param array $values
1447 + * @return void
1316 1448 */
1317 1449 public static function advanced_settings( $values ) {
1318 1450 $first_h3 = 'frm_first_h3';
1319 1451
@@ -1321,8 +1453,9 @@
1321 1453 }
1322 1454
1323 1455 /**
1324 1456 * @param array $values
1457 + * @return void
1325 1458 */
1326 1459 public static function render_spam_settings( $values ) {
1327 1460 if ( function_exists( 'akismet_http_post' ) ) {
1328 1461 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/akismet.php';
@@ -1334,16 +1467,12 @@
1334 1467 /**
1335 1468 * @since 4.0
1336 1469 *
1337 1470 * @param array $values
1471 + * @return void
1338 1472 */
1339 1473 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' );
1474 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php';
1346 1475 }
1347 1476
1348 1477 /**
1349 1478 * @since 4.0
@@ -1348,11 +1477,12 @@
1348 1477 /**
1349 1478 * @since 4.0
1350 1479 *
1351 1480 * @param array $values
1481 + * @return void
1352 1482 */
1353 1483 public static function html_settings( $values ) {
1354 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php' );
1484 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php';
1355 1485 }
1356 1486
1357 1487 /**
1358 1488 * Replace old Submit Button href with new href to avoid errors in Chrome
@@ -1358,9 +1488,10 @@
1358 1488 * Replace old Submit Button href with new href to avoid errors in Chrome
1359 1489 *
1360 1490 * @since 2.03.08
1361 1491 *
1362 - * @param array|boolean $values
1492 + * @param array|bool $values
1493 + * @return void
1363 1494 */
1364 1495 private static function clean_submit_html( &$values ) {
1365 1496 if ( is_array( $values ) && isset( $values['submit_html'] ) ) {
1366 1497 $values['submit_html'] = str_replace( 'javascript:void(0)', '#', $values['submit_html'] );
@@ -1381,8 +1512,13 @@
1381 1512
1382 1513 return $classes;
1383 1514 }
1384 1515
1516 + /**
1517 + * @param int|string $form_id
1518 + * @param string $class
1519 + * @return void
1520 + */
1385 1521 public static function mb_tags_box( $form_id, $class = '' ) {
1386 1522 $fields = FrmField::get_all_for_form( $form_id, '', 'include' );
1387 1523
1388 1524 /**
@@ -1395,9 +1531,9 @@
1395 1531 */
1396 1532 $fields = apply_filters( 'frm_fields_in_tags_box', $fields, compact( 'form_id' ) );
1397 1533 $linked_forms = array();
1398 1534 $col = 'one';
1399 - $settings_tab = FrmAppHelper::is_admin_page( 'formidable' ) ? true : false;
1535 + $settings_tab = FrmAppHelper::is_admin_page( 'formidable' );
1400 1536
1401 1537 $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() );
1402 1538 $entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
1403 1539
@@ -1402,9 +1538,9 @@
1402 1538 $entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
1403 1539
1404 1540 $advanced_helpers = self::advanced_helpers( compact( 'fields', 'form_id' ) );
1405 1541
1406 - include( FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php' );
1542 + include FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php';
1407 1543 }
1408 1544
1409 1545 /**
1410 1546 * @since 3.04.01
@@ -1417,9 +1553,9 @@
1417 1553 ),
1418 1554 );
1419 1555
1420 1556 $user_fields = self::user_shortcodes();
1421 - if ( ! empty( $user_fields ) ) {
1557 + if ( $user_fields ) {
1422 1558 $user_helpers = array();
1423 1559 foreach ( $user_fields as $uk => $uf ) {
1424 1560 $user_helpers[ '|user_id| show="' . $uk . '"' ] = $uf;
1425 1561 unset( $uk, $uf );
@@ -1425,9 +1561,9 @@
1425 1561 unset( $uk, $uf );
1426 1562 }
1427 1563
1428 1564 $advanced_helpers['user_id'] = array(
1429 - 'codes' => $user_helpers,
1565 + 'codes' => $user_helpers,
1430 1566 );
1431 1567 }
1432 1568
1433 1569 /**
@@ -1568,11 +1704,11 @@
1568 1704 check_ajax_referer( 'frm_ajax', 'nonce' );
1569 1705
1570 1706 echo FrmEntriesController::show_entry_shortcode( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1571 1707 array(
1572 - 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ),
1708 + 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1573 1709 'default_email' => true,
1574 - 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ),
1710 + 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1575 1711 )
1576 1712 );
1577 1713 wp_die();
1578 1714 }
@@ -1578,10 +1714,10 @@
1578 1714 }
1579 1715
1580 1716 /**
1581 1717 * @param string $content
1582 - * @param stdClass|string|int $form
1583 - * @param stdClass|string|int|false $entry
1718 + * @param int|stdClass|string $form
1719 + * @param false|int|stdClass|string $entry
1584 1720 * @return string
1585 1721 */
1586 1722 public static function filter_content( $content, $form, $entry = false ) {
1587 1723 $content = self::replace_form_name_shortcodes( $content, $form );
@@ -1594,8 +1730,16 @@
1594 1730 if ( is_object( $form ) ) {
1595 1731 $form = $form->id;
1596 1732 }
1597 1733
1734 + /*
1735 + * Repeater actions adds `parent_entry` to `$entry` store the parent entry data. If `parent_entry` is not empty,
1736 + * use the parent form ID instead of repeater form ID to fix the parent form field shortcodes doesn't work.
1737 + */
1738 + if ( ! empty( $entry->parent_entry ) ) {
1739 + $form = $entry->parent_entry->form_id;
1740 + }
1741 +
1598 1742 $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form );
1599 1743 $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
1600 1744
1601 1745 return $content;
@@ -1605,13 +1749,17 @@
1605 1749 * Replace any [form_name] shortcodes in a string.
1606 1750 *
1607 1751 * @since 5.5
1608 1752 *
1609 - * @param string $string
1610 - * @param stdClass|string|int $form
1611 - * @return string
1753 + * @param array|string $string
1754 + * @param int|stdClass|string $form
1755 + * @return array|string
1612 1756 */
1613 1757 public static function replace_form_name_shortcodes( $string, $form ) {
1758 + if ( ! is_string( $string ) ) {
1759 + return $string;
1760 + }
1761 +
1614 1762 if ( false === strpos( $string, '[form_name]' ) ) {
1615 1763 return $string;
1616 1764 }
1617 1765
@@ -1623,9 +1771,9 @@
1623 1771 return str_replace( '[form_name]', $form_name, $string );
1624 1772 }
1625 1773
1626 1774 /**
1627 - * @param stdClass|string|int|false $entry
1775 + * @param false|int|stdClass|string $entry
1628 1776 * @return void
1629 1777 */
1630 1778 private static function get_entry_by_param( &$entry ) {
1631 1779 if ( ! $entry || ! is_object( $entry ) ) {
@@ -1640,8 +1788,12 @@
1640 1788 public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
1641 1789 return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes );
1642 1790 }
1643 1791
1792 + /**
1793 + * @param array $errors
1794 + * @return array
1795 + */
1644 1796 public static function process_bulk_form_actions( $errors ) {
1645 1797 if ( ! $_REQUEST ) {
1646 1798 return $errors;
1647 1799 }
@@ -1685,9 +1837,9 @@
1685 1837 case 'untrash':
1686 1838 $message = self::bulk_untrash( $ids );
1687 1839 }
1688 1840
1689 - if ( isset( $message ) && ! empty( $message ) ) {
1841 + if ( ! empty( $message ) ) {
1690 1842 $errors['message'] = $message;
1691 1843 }
1692 1844
1693 1845 return $errors;
@@ -1707,9 +1859,9 @@
1707 1859 $json_vars = json_decode( $json_vars, true );
1708 1860 if ( empty( $json_vars ) ) {
1709 1861 // json decoding failed so we should return an error message.
1710 1862 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
1711 - if ( 'edit' == $action ) {
1863 + if ( 'edit' === $action ) {
1712 1864 $action = 'update';
1713 1865 }
1714 1866
1715 1867 add_filter( 'frm_validate_form', 'FrmFormsController::json_error' );
@@ -1725,16 +1877,14 @@
1725 1877 if ( isset( $_REQUEST['delete_all'] ) ) {
1726 1878 // Override the action for this page.
1727 1879 $action = 'delete_all';
1728 1880 }
1729 - }
1881 + }//end if
1730 1882
1731 1883 add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
1732 1884 FrmAppHelper::trigger_hook_load( 'form' );
1733 1885
1734 1886 switch ( $action ) {
1735 - case 'new':
1736 - return self::new_form( $vars );
1737 1887 case 'create':
1738 1888 case 'edit':
1739 1889 case 'update':
1740 1890 case 'trash':
@@ -1739,16 +1889,17 @@
1739 1889 case 'update':
1740 1890 case 'trash':
1741 1891 case 'untrash':
1742 1892 case 'destroy':
1743 - case 'delete_all':
1744 1893 case 'settings':
1745 1894 case 'update_settings':
1746 1895 return self::$action( $vars );
1747 1896 case 'lite-reports':
1748 - return self::no_reports( $vars );
1897 + self::no_reports( $vars );
1898 + return;
1749 1899 case 'views':
1750 - return self::no_views( $vars );
1900 + self::no_views( $vars );
1901 + return;
1751 1902 default:
1752 1903 do_action( 'frm_form_action_' . $action );
1753 1904 if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) {
1754 1905 return;
@@ -1771,14 +1922,47 @@
1771 1922 self::display_forms_list( array(), '', array( __( 'There was a problem duplicating the form', 'formidable' ) ) );
1772 1923 return;
1773 1924 }
1774 1925
1926 + if ( 'forms_permanently_deleted' === $message ) {
1927 + $count = FrmAppHelper::get_param( 'forms_deleted', 0, 'get', 'absint' );
1928 + /* translators: %1$s: Number of forms */
1929 + $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
1930 + self::display_forms_list( array(), $message, '' );
1931 + return;
1932 + }
1933 +
1775 1934 self::display_forms_list();
1776 1935
1777 1936 return;
1778 - }
1937 + }//end switch
1779 1938 }
1780 1939
1940 + /**
1941 + * Rename a form.
1942 + *
1943 + * Handles the AJAX request for renaming a form.
1944 + *
1945 + * @since 6.7
1946 + *
1947 + * @return void
1948 + */
1949 + public static function rename_form() {
1950 + // Check permission and nonce
1951 + FrmAppHelper::permission_check( 'frm_edit_forms' );
1952 + check_ajax_referer( 'frm_ajax', 'nonce' );
1953 +
1954 + // Get posted data
1955 + $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
1956 + $name = FrmAppHelper::get_post_param( 'form_name', '', 'sanitize_text_field' );
1957 +
1958 + // Update the form name and form key.
1959 + $form_key = FrmAppHelper::get_unique_key( sanitize_title( $name ), 'frm_forms', 'form_key' );
1960 + FrmForm::update( $form_id, compact( 'name', 'form_key' ) );
1961 +
1962 + wp_send_json_success( compact( 'form_key' ) );
1963 + }
1964 +
1781 1965 public static function json_error( $errors ) {
1782 1966 $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
1783 1967
1784 1968 return $errors;
@@ -1787,11 +1971,12 @@
1787 1971 /**
1788 1972 * Education for premium features.
1789 1973 *
1790 1974 * @since 4.05
1975 + * @return void
1791 1976 */
1792 1977 public static function add_form_style_tab_options() {
1793 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php' );
1978 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php';
1794 1979 }
1795 1980
1796 1981 /**
1797 1982 * Add education about views.
@@ -1796,8 +1981,10 @@
1796 1981 /**
1797 1982 * Add education about views.
1798 1983 *
1799 1984 * @since 4.07
1985 + *
1986 + * @return void
1800 1987 */
1801 1988 public static function no_views( $values = array() ) {
1802 1989 FrmAppHelper::include_svg();
1803 1990 $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
@@ -1809,8 +1996,10 @@
1809 1996 /**
1810 1997 * Add education about reports.
1811 1998 *
1812 1999 * @since 4.07
2000 + *
2001 + * @return void
1813 2002 */
1814 2003 public static function no_reports( $values = array() ) {
1815 2004 $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
1816 2005 $form = $id ? FrmForm::getOne( $id ) : false;
@@ -1817,9 +2006,11 @@
1817 2006
1818 2007 include FrmAppHelper::plugin_path() . '/classes/views/shared/reports-info.php';
1819 2008 }
1820 2009
1821 - /* FRONT-END FORMS */
2010 + /**
2011 + * FRONT-END FORMS.
2012 + */
1822 2013 public static function admin_bar_css() {
1823 2014 if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
1824 2015 return;
1825 2016 }
@@ -1908,10 +2099,10 @@
1908 2099 * @return string
1909 2100 */
1910 2101 public static function get_form_shortcode( $atts ) {
1911 2102 global $frm_vars;
1912 - if ( isset( $frm_vars['skip_shortcode'] ) && $frm_vars['skip_shortcode'] ) {
1913 - $sc = '[formidable';
2103 + if ( ! empty( $frm_vars['skip_shortcode'] ) ) {
2104 + $sc = '[formidable';
1914 2105 $sc .= FrmAppHelper::array_to_html_params( $atts );
1915 2106 return $sc . ']';
1916 2107 }
1917 2108
@@ -1936,11 +2127,11 @@
1936 2127
1937 2128 /**
1938 2129 * @since 5.2.01
1939 2130 *
1940 - * @param string|int|false $id
1941 - * @param string|false $key
1942 - * @return stdClass|false
2131 + * @param false|int|string $id
2132 + * @param false|string $key
2133 + * @return false|stdClass
1943 2134 */
1944 2135 private static function maybe_get_form_by_id_or_key( $id, $key ) {
1945 2136 if ( ! $id ) {
1946 2137 $id = $key;
@@ -1948,12 +2139,12 @@
1948 2139 return self::maybe_get_form_to_show( $id );
1949 2140 }
1950 2141
1951 2142 /**
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.
2143 + * @param false|int|string $id
2144 + * @param false|string $key
2145 + * @param bool|int|string $title may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
2146 + * @param bool|int|string $description may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
1956 2147 * @param array $atts
1957 2148 * @return string
1958 2149 */
1959 2150 public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) {
@@ -2001,15 +2192,16 @@
2001 2192 return $form;
2002 2193 }
2003 2194
2004 2195 /**
2005 - * @param string|int|false $id
2006 - * @return stdClass|false
2196 + * @param false|int|string $id
2197 + * @return false|stdClass
2007 2198 */
2008 2199 private static function maybe_get_form_to_show( $id ) {
2009 2200 $form = false;
2010 2201
2011 - if ( ! empty( $id ) ) { // form id or key is set
2202 + if ( ! empty( $id ) ) {
2203 + // Form id or key is set.
2012 2204 $form = FrmForm::getOne( $id );
2013 2205 if ( ! $form || $form->parent_form_id || $form->status === 'trash' ) {
2014 2206 $form = false;
2015 2207 }
@@ -2067,11 +2259,11 @@
2067 2259
2068 2260 do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description );
2069 2261
2070 2262 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;
2263 + $entry_id = self::just_created_entry( $form->id );
2264 + $pass_args['entry_id'] = $entry_id;
2265 + $pass_args['reset'] = true;
2074 2266
2075 2267 self::run_on_submit_actions( $pass_args );
2076 2268
2077 2269 do_action(
@@ -2081,9 +2273,9 @@
2081 2273 'form' => $form,
2082 2274 )
2083 2275 );
2084 2276 }
2085 - }
2277 + }//end if
2086 2278 }
2087 2279
2088 2280 /**
2089 2281 * If the form was processed earlier (init), get the generated errors
@@ -2115,9 +2307,9 @@
2115 2307 */
2116 2308 public static function just_created_entry( $form_id ) {
2117 2309 global $frm_vars;
2118 2310
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;
2311 + 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 2312 }
2121 2313
2122 2314 /**
2123 2315 * Gets confirmation method.
@@ -2130,14 +2322,14 @@
2130 2322 *
2131 2323 * @type object $form Form object.
2132 2324 * @type int $entry_id Entry ID.
2133 2325 * }
2134 - * @return string|array
2326 + * @return array|string
2135 2327 */
2136 2328 private static function get_confirmation_method( $atts ) {
2137 2329 $action = FrmOnSubmitHelper::current_event( $atts );
2138 2330 $opt = 'update' === $action ? 'edit_action' : 'success_action';
2139 - $method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message';
2331 + $method = ! empty( $atts['form']->options[ $opt ] ) ? $atts['form']->options[ $opt ] : 'message';
2140 2332
2141 2333 if ( ! empty( $atts['entry_id'] ) ) {
2142 2334 $met_actions = self::get_met_on_submit_actions( $atts, $action );
2143 2335 if ( $met_actions ) {
@@ -2146,9 +2338,9 @@
2146 2338 }
2147 2339
2148 2340 $method = apply_filters( 'frm_success_filter', $method, $atts['form'], $action );
2149 2341
2150 - if ( $method != 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
2342 + if ( $method !== 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
2151 2343 $method = 'message';
2152 2344 }
2153 2345
2154 2346 return $method;
@@ -2233,9 +2425,9 @@
2233 2425 unset( $extra_args['form'] );
2234 2426
2235 2427 do_action( 'frm_success_action', $args['conf_method'], $args['form'], $args['form']->options, $args['entry_id'], $extra_args );
2236 2428
2237 - $opt = ( ! isset( $args['action'] ) || $args['action'] === 'create' ) ? 'success' : 'edit';
2429 + $opt = ! isset( $args['action'] ) || $args['action'] === 'create' ? 'success' : 'edit';
2238 2430
2239 2431 $args['success_opt'] = $opt;
2240 2432 $args['ajax'] = ! empty( $frm_vars['ajax'] );
2241 2433
@@ -2261,11 +2453,16 @@
2261 2453 if ( ! FrmOnSubmitHelper::form_has_migrated( $args['form'] ) ) {
2262 2454 return array();
2263 2455 }
2264 2456
2265 - $entry = FrmEntry::getOne( $args['entry_id'], true );
2266 - $actions = FrmOnSubmitHelper::get_actions( $args['form']->id );
2267 - $met_actions = array();
2457 + // If a redirect action has already opened the URL in a new tab, we show the default message in the current tab.
2458 + if ( ! empty( self::$redirected_in_new_tab[ $args['form']->id ] ) ) {
2459 + return array( FrmOnSubmitHelper::get_fallback_action_after_open_in_new_tab( $event ) );
2460 + }
2461 +
2462 + $entry = FrmEntry::getOne( $args['entry_id'], true );
2463 + $actions = FrmOnSubmitHelper::get_actions( $args['form']->id );
2464 + $met_actions = array();
2268 2465 $has_redirect = false;
2269 2466
2270 2467 foreach ( $actions as $action ) {
2271 2468 if ( ! in_array( $event, $action->post_content['event'], true ) ) {
@@ -2278,9 +2475,10 @@
2278 2475
2279 2476 $action_type = FrmOnSubmitHelper::get_action_type( $action );
2280 2477
2281 2478 if ( 'redirect' === $action_type ) {
2282 - if ( $has_redirect ) { // Do not process because we run the first redirect action only.
2479 + if ( $has_redirect ) {
2480 + // Do not process because we run the first redirect action only.
2283 2481 continue;
2284 2482 }
2285 2483 }
2286 2484
@@ -2293,9 +2491,9 @@
2293 2491 }
2294 2492
2295 2493 $met_actions[] = $action;
2296 2494 unset( $action );
2297 - }
2495 + }//end foreach
2298 2496
2299 2497 $args['event'] = $event;
2300 2498
2301 2499 /**
@@ -2484,9 +2682,9 @@
2484 2682 add_filter( 'the_content', 'FrmFormsController::preview_content', 9999 );
2485 2683 }
2486 2684
2487 2685 $post = $old_post;
2488 - }
2686 + }//end if
2489 2687 }
2490 2688
2491 2689 /**
2492 2690 * @since 3.0
@@ -2507,16 +2705,25 @@
2507 2705 $success_url = apply_filters( 'frm_redirect_url', $success_url, $args['form'], $args );
2508 2706
2509 2707 $doing_ajax = FrmAppHelper::doing_ajax();
2510 2708
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 ) );
2709 + if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) {
2710 + // Is AJAX submit and there is just one Redirect action runs.
2711 + echo json_encode( self::get_ajax_redirect_response_data( $args + compact( 'success_url' ) ) );
2513 2712 wp_die();
2514 2713 }
2515 2714
2516 - if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) ) { // Not AJAX submit, no headers sent, and there is just one Redirect action runs.
2715 + if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) ) {
2716 + // Not AJAX submit, no headers sent, and there is just one Redirect action runs.
2717 + if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2718 + self::print_open_in_new_tab_js_with_fallback_handler( $success_url, $args );
2719 + self::$redirected_in_new_tab[ $args['form']->id ] = 1;
2720 + return;
2721 + }
2722 +
2517 2723 wp_redirect( esc_url_raw( $success_url ) );
2518 - die(); // do not use wp_die or redirect fails
2724 + // Do not use wp_die or redirect fails.
2725 + die();
2519 2726 }
2520 2727
2521 2728 // Redirect with a delay.
2522 2729 self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) );
@@ -2522,8 +2729,63 @@
2522 2729 self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) );
2523 2730 }
2524 2731
2525 2732 /**
2733 + * Prints open in new tab js with fallback handler.
2734 + *
2735 + * @since 6.3.1
2736 + *
2737 + * @param string $success_url Success URL.
2738 + * @param array $args See {@see FrmFormsController::redirect_after_submit()}.
2739 + */
2740 + private static function print_open_in_new_tab_js_with_fallback_handler( $success_url, $args ) {
2741 + echo '<script>var newTab = window.open("' . esc_url_raw( $success_url ) . '", "_blank");';
2742 + echo 'if ( ! newTab ) {';
2743 +
2744 + $data = array(
2745 + 'formId' => intval( $args['form']->id ),
2746 + 'message' => self::get_redirect_fallback_message( $success_url, $args ),
2747 + );
2748 + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2749 + echo 'frmShowNewTabFallback = ' . FrmAppHelper::maybe_json_encode( $data ) . ';';
2750 + echo '}</script>';
2751 + }
2752 +
2753 + /**
2754 + * Gets response data for redirect action when AJAX submitting.
2755 + *
2756 + * @since 6.3.1
2757 + *
2758 + * @param array $args See {@see FrmFormsController::run_success_action()}.
2759 + * @return array
2760 + */
2761 + private static function get_ajax_redirect_response_data( $args ) {
2762 + $response_data = array( 'redirect' => $args['success_url'] );
2763 +
2764 + if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2765 + $response_data['openInNewTab'] = 1;
2766 +
2767 + $args['message'] = FrmOnSubmitHelper::get_default_new_tab_msg();
2768 +
2769 + $args['form']->options['success_msg'] = $args['message'];
2770 + $args['form']->options['edit_msg'] = $args['message'];
2771 + if ( ! isset( $args['fields'] ) ) {
2772 + $args['fields'] = FrmField::get_all_for_form( $args['form']->id );
2773 + }
2774 +
2775 + $args['message'] = self::prepare_submit_message( $args['form'], $args['entry_id'], $args );
2776 +
2777 + ob_start();
2778 + self::show_lone_success_message( $args );
2779 + $response_data['content'] = ob_get_clean();
2780 +
2781 + $response_data['fallbackMsg'] = self::get_redirect_fallback_message( $args['success_url'], $args );
2782 + }
2783 +
2784 + return $response_data;
2785 + }
2786 +
2787 + /**
2526 2788 * Redirects after submitting using JS. This is used when showing message before redirecting.
2527 2789 *
2528 2790 * @since 6.0
2529 2791 *
@@ -2531,8 +2793,9 @@
2531 2793 */
2532 2794 private static function redirect_after_submit_using_js( $args ) {
2533 2795 $success_msg = FrmOnSubmitHelper::get_default_redirect_msg();
2534 2796 $redirect_msg = self::get_redirect_message( $args['success_url'], $success_msg, $args );
2797 + $success_url = esc_url_raw( $args['success_url'] );
2535 2798
2536 2799 /**
2537 2800 * Filters the delay time before redirecting when On Submit Redirect action is delayed.
2538 2801 *
@@ -2537,20 +2800,27 @@
2537 2800 * Filters the delay time before redirecting when On Submit Redirect action is delayed.
2538 2801 *
2539 2802 * @since 6.0
2540 2803 *
2541 - * @param int $delay_time Delay time in miliseconds.
2804 + * @param int $delay_time Delay time in milliseconds.
2542 2805 */
2543 2806 $delay_time = apply_filters( 'frm_redirect_delay_time', 8000 );
2544 2807
2808 + if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2809 + $redirect_js = 'window.open("' . $success_url . '", "_blank")';
2810 + } else {
2811 + $redirect_js = 'window.location="' . $success_url . '";';
2812 + }
2813 +
2545 2814 add_filter( 'frm_use_wpautop', '__return_true' );
2546 2815
2547 2816 echo FrmAppHelper::maybe_kses( $redirect_msg ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2548 2817 echo '<script>';
2549 - if ( empty( $args['doing_ajax'] ) ) { // Not AJAX submit, delay JS until window.load.
2818 + if ( empty( $args['doing_ajax'] ) ) {
2819 + // Not AJAX submit, delay JS until window.load.
2550 2820 echo 'window.onload=function(){';
2551 2821 }
2552 - echo 'setTimeout(function(){window.location="' . esc_url_raw( $args['success_url'] ) . '";}, ' . intval( $delay_time ) . ');';
2822 + echo 'setTimeout(function(){' . $redirect_js . '}, ' . intval( $delay_time ) . ');'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2553 2823 if ( empty( $args['doing_ajax'] ) ) {
2554 2824 echo '};';
2555 2825 }
2556 2826 echo '</script>';
@@ -2560,14 +2830,13 @@
2560 2830 * @since 3.0
2561 2831 *
2562 2832 * @param string $success_url
2563 2833 * @param string $success_msg
2564 - * @param array $args
2834 + * @param array $args
2565 2835 */
2566 2836 private static function get_redirect_message( $success_url, $success_msg, $args ) {
2567 2837 $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>' ) .
2838 + self::get_redirect_fallback_message( $success_url, $args ) .
2570 2839 '</div></div>';
2571 2840
2572 2841 $redirect_args = array(
2573 2842 'entry_id' => $args['entry_id'],
@@ -2578,8 +2847,31 @@
2578 2847 return apply_filters( 'frm_redirect_msg', $redirect_msg, $redirect_args );
2579 2848 }
2580 2849
2581 2850 /**
2851 + * Gets fallback message when redirecting failed.
2852 + *
2853 + * @since 6.3.1
2854 + *
2855 + * @param string $success_url Redirect URL.
2856 + * @param array $args Contains `form` object.
2857 + * @return string
2858 + */
2859 + private static function get_redirect_fallback_message( $success_url, $args ) {
2860 + $target = '';
2861 + if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2862 + $target = ' target="_blank"';
2863 + }
2864 +
2865 + return sprintf(
2866 + /* translators: %1$s: Start link HTML, %2$s: End link HTML */
2867 + __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ),
2868 + '<a href="' . esc_url( $success_url ) . '"' . $target . '>',
2869 + '</a>'
2870 + );
2871 + }
2872 +
2873 + /**
2582 2874 * Prepare to show the success message and empty form after submit
2583 2875 *
2584 2876 * @since 2.05
2585 2877 */
@@ -2598,9 +2890,9 @@
2598 2890 } else {
2599 2891 self::show_form_after_submit( $atts );
2600 2892 }
2601 2893 } else {
2602 - self::show_lone_success_messsage( $atts );
2894 + self::show_lone_success_message( $atts );
2603 2895 }
2604 2896 }
2605 2897
2606 2898 /**
@@ -2639,11 +2931,10 @@
2639 2931 include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php';
2640 2932 }
2641 2933
2642 2934 /**
2935 + * @since 4.05.02
2643 2936 * @return string - 'before', 'after', or 'submit'
2644 - *
2645 - * @since 4.05.02
2646 2937 */
2647 2938 private static function message_placement( $form, $message ) {
2648 2939 $place = 'before';
2649 2940
@@ -2655,11 +2946,10 @@
2655 2946 }
2656 2947 }
2657 2948
2658 2949 /**
2950 + * @since 4.05.02
2659 2951 * @return string - 'before' or 'after'
2660 - *
2661 - * @since 4.05.02
2662 2952 */
2663 2953 return apply_filters( 'frm_message_placement', $place, compact( 'form', 'message' ) );
2664 2954 }
2665 2955
@@ -2693,9 +2983,9 @@
2693 2983 * Show the success message without the form
2694 2984 *
2695 2985 * @since 2.05
2696 2986 */
2697 - private static function show_lone_success_messsage( $atts ) {
2987 + private static function show_lone_success_message( $atts ) {
2698 2988 global $frm_vars;
2699 2989 $values = FrmEntriesHelper::setup_new_vars( $atts['fields'], $atts['form'], true );
2700 2990 self::maybe_load_css( $atts['form'], $values['custom_style'], $frm_vars['load_css'] );
2701 2991
@@ -2704,9 +2994,9 @@
2704 2994 $errors = array();
2705 2995 $form = $atts['form'];
2706 2996 $message = $atts['message'];
2707 2997
2708 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php' );
2998 + include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php';
2709 2999 }
2710 3000
2711 3001 /**
2712 3002 * Prepare the success message before it's shown
@@ -2826,9 +3116,9 @@
2826 3116 global $frm_vars;
2827 3117
2828 3118 FrmStylesController::enqueue_css();
2829 3119
2830 - if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
3120 + if ( ! FrmAppHelper::is_admin() && $location !== 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
2831 3121 // load formidable js
2832 3122 wp_enqueue_script( 'formidable' );
2833 3123 }
2834 3124 }
@@ -2844,12 +3134,12 @@
2844 3134 }
2845 3135
2846 3136 /**
2847 3137 * @since 2.0.8
2848 - * @return boolean
3138 + * @return bool
2849 3139 */
2850 3140 private static function is_minification_on( $atts ) {
2851 - return isset( $atts['minimize'] ) && ! empty( $atts['minimize'] );
3141 + return ! empty( $atts['minimize'] );
2852 3142 }
2853 3143
2854 3144 /**
2855 3145 * @since 5.0.16
@@ -2877,9 +3167,9 @@
2877 3167 * Create a page with an embedded formidable Gutenberg block.
2878 3168 *
2879 3169 * @since 5.2
2880 3170 *
2881 - * @return never
3171 + * @return void
2882 3172 */
2883 3173 public static function create_page_with_shortcode() {
2884 3174 if ( ! current_user_can( 'publish_posts' ) ) {
2885 3175 die( 0 );
@@ -2924,10 +3214,9 @@
2924 3214
2925 3215 /**
2926 3216 * @since 5.3
2927 3217 *
2928 - * @param string $content
2929 - * @param int $form_id
3218 + * @param int $form_id
2930 3219 * @return string
2931 3220 */
2932 3221 private static function get_page_shortcode_content_for_form( $form_id ) {
2933 3222 $shortcode = '[formidable id="' . $form_id . '"]';
@@ -2938,9 +3227,9 @@
2938 3227
2939 3228 /**
2940 3229 * Get page dropdown for AJAX request for embedding form in an existing page.
2941 3230 *
2942 - * @return never
3231 + * @return void
2943 3232 */
2944 3233 public static function get_page_dropdown() {
2945 3234 if ( ! current_user_can( 'publish_posts' ) ) {
2946 3235 die( 0 );
@@ -2948,9 +3237,9 @@
2948 3237
2949 3238 check_ajax_referer( 'frm_ajax', 'nonce' );
2950 3239
2951 3240 $html = FrmAppHelper::clip(
2952 - function() {
3241 + function () {
2953 3242 FrmAppHelper::maybe_autocomplete_pages_options(
2954 3243 array(
2955 3244 'field_name' => 'frm_page_dropdown',
2956 3245 'page_id' => '',
@@ -2970,15 +3259,8 @@
2970 3259
2971 3260 /**
2972 3261 * @deprecated 4.0
2973 3262 */
2974 - public static function new_form( $values = array() ) {
2975 - FrmDeprecated::new_form( $values );
2976 - }
2977 -
2978 - /**
2979 - * @deprecated 4.0
2980 - */
2981 3263 public static function create( $values = array() ) {
2982 3264 _deprecated_function( __METHOD__, '4.0', 'FrmFormsController::update' );
2983 3265 self::update( $values );
2984 3266 }
@@ -2983,35 +3265,13 @@
2983 3265 self::update( $values );
2984 3266 }
2985 3267
2986 3268 /**
2987 - * @deprecated 3.0
2988 - * @codeCoverageIgnore
3269 + * @deprecated 6.7
3270 + *
3271 + * @return bool
2989 3272 */
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' );
3273 + public static function expired() {
3274 + _deprecated_function( __METHOD__, '6.7' );
3275 + return FrmAddonsController::is_license_expired();
3016 3276 }
3017 3277 }