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