PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.17
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.17
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 +700 -406 6.36.17 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,15 +106,23 @@
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
111 + * @return void
91 112 */
92 113 private static function create_default_email_action( $form ) {
93 114 FrmForm::maybe_get_form( $form );
115 + if ( ! is_object( $form ) ) {
116 + return;
117 + }
118 +
94 119 $create_email = apply_filters( 'frm_create_default_email_action', true, $form );
95 120
96 121 if ( $create_email ) {
122 + /**
123 + * @var FrmFormAction
124 + */
97 125 $action_control = FrmFormActionsController::get_form_actions( 'email' );
98 126 $action_control->create( $form->id );
99 127 }
100 128 }
@@ -103,12 +131,16 @@
103 131 * Create the default On submit action
104 132 *
105 133 * @since 6.0.0
106 134 *
107 - * @param object|int $form Form object or ID.
135 + * @param int|object $form Form object or ID.
136 + * @return void
108 137 */
109 138 private static function create_default_on_submit_action( $form ) {
110 139 FrmForm::maybe_get_form( $form );
140 + if ( ! is_object( $form ) ) {
141 + return;
142 + }
111 143
112 144 /**
113 145 * Enable or disable the default On Submit action.
114 146 *
@@ -119,21 +151,65 @@
119 151 */
120 152 $create = apply_filters( 'frm_create_default_on_submit_action', true, $form );
121 153
122 154 if ( $create ) {
155 + /**
156 + * @var FrmFormAction
157 + */
123 158 $action_control = FrmFormActionsController::get_form_actions( FrmOnSubmitAction::$slug );
124 159 $action_control->create( $form->id );
125 160 }
126 161 }
127 162
163 + /**
164 + * Creates submit button field.
165 + *
166 + * @since 6.9
167 + *
168 + * @param int|object $form Form ID or object.
169 + * @return void
170 + */
171 + private static function create_submit_button_field( $form ) {
172 + FrmForm::maybe_get_form( $form );
173 + if ( ! is_object( $form ) ) {
174 + return;
175 + }
176 +
177 + if ( FrmSubmitHelper::get_submit_field( $form->id ) ) {
178 + // Do not create submit button field if it exists.
179 + return;
180 + }
181 +
182 + FrmField::create(
183 + array(
184 + 'type' => FrmSubmitHelper::FIELD_TYPE,
185 + 'name' => __( 'Submit', 'formidable' ),
186 + 'field_order' => FrmSubmitHelper::DEFAULT_ORDER,
187 + 'form_id' => $form->id,
188 + 'field_options' => FrmFieldsHelper::get_default_field_options( FrmSubmitHelper::FIELD_TYPE ),
189 + 'description' => '',
190 + 'default_value' => '',
191 + 'options' => array(),
192 + )
193 + );
194 + }
195 +
196 + /**
197 + * @return void
198 + */
128 199 public static function edit( $values = false ) {
129 200 FrmAppHelper::permission_check( 'frm_edit_forms' );
130 201
131 202 $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
132 203
133 - return self::get_edit_vars( $id );
204 + self::get_edit_vars( $id );
134 205 }
135 206
207 + /**
208 + * @param mixed $id
209 + * @param string $message
210 + * @return void
211 + */
136 212 public static function settings( $id = false, $message = '' ) {
137 213 FrmAppHelper::permission_check( 'frm_edit_forms' );
138 214
139 215 if ( ! $id || ! is_numeric( $id ) ) {
@@ -141,21 +217,34 @@
141 217 }
142 218
143 219 FrmOnSubmitHelper::maybe_migrate_submit_settings_to_action( $id );
144 220
145 - return self::get_settings_vars( $id, array(), $message );
221 + self::get_settings_vars( $id, array(), $message );
146 222 }
147 223
148 224 public static function update_settings() {
149 225 FrmAppHelper::permission_check( 'frm_edit_forms' );
226 + $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
150 227
228 + if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) {
229 + $frm_settings = FrmAppHelper::get_settings();
230 + $error_args = array(
231 + 'title' => __( 'Verification failed', 'formidable' ),
232 + 'body' => $frm_settings->admin_permission,
233 + 'cancel_text' => __( 'Cancel', 'formidable' ),
234 + );
235 + FrmAppController::show_error_modal( $error_args );
236 + return;
237 + }
238 +
151 239 $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
152 240
153 - $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
241 + $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
154 242 $warnings = FrmFormsHelper::check_for_warnings( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
155 243
156 244 if ( count( $errors ) > 0 ) {
157 - return self::get_settings_vars( $id, $errors, compact( 'warnings' ) );
245 + self::get_settings_vars( $id, $errors, compact( 'warnings' ) );
246 + return;
158 247 }
159 248
160 249 do_action( 'frm_before_update_form_settings', $id );
161 250
@@ -169,9 +258,9 @@
169 258 }
170 259
171 260 $message = __( 'Settings Successfully Updated', 'formidable' );
172 261
173 - return self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) );
262 + self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) );
174 263 }
175 264
176 265 /**
177 266 * @param int $form_id
@@ -181,8 +270,11 @@
181 270 $form = FrmForm::getOne( $form_id );
182 271 return ! empty( $form->options['antispam'] );
183 272 }
184 273
274 + /**
275 + * @return void
276 + */
185 277 public static function update( $values = array() ) {
186 278 if ( empty( $values ) ) {
187 279 $values = $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing
188 280 }
@@ -200,65 +292,74 @@
200 292
201 293 $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
202 294
203 295 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' );
296 + self::get_edit_vars( $id, $errors );
297 + return;
298 + }
208 299
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 - }
300 + self::maybe_remove_draft_option_from_fields( $id );
217 301
218 - if ( defined( 'DOING_AJAX' ) ) {
219 - wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
220 - }
302 + FrmForm::update( $id, $values );
303 + $message = __( 'Form was successfully updated.', 'formidable' );
221 304
222 - return self::get_edit_vars( $id, array(), $message );
305 + if ( self::is_too_long( $values ) ) {
306 + $message .= '<br/> ' . sprintf(
307 + /* translators: %1$s: Start link HTML, %2$s: end link HTML */
308 + __( 'However, your form is very long and may be %1$sreaching server limits%2$s.', 'formidable' ),
309 + '<a href="https://formidableforms.com/knowledgebase/i-have-a-long-form-why-did-the-options-at-the-end-of-the-form-stop-saving/?utm_source=WordPress&utm_medium=builder&utm_campaign=liteplugin" target="_blank" rel="noopener">',
310 + '</a>'
311 + );
223 312 }
313 +
314 + if ( defined( 'DOING_AJAX' ) ) {
315 + wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
316 + }
317 +
318 + self::get_edit_vars( $id, array(), $message );
224 319 }
225 320
226 321 /**
322 + * Remove the draft flag from any new fields from this current session.
323 + *
324 + * @since 6.8
325 + *
326 + * @param int $form_id
327 + * @return void
328 + */
329 + private static function maybe_remove_draft_option_from_fields( $form_id ) {
330 + $draft_field_ids_csv = FrmAppHelper::get_post_param( 'draft_fields', '', 'sanitize_text_field' );
331 + if ( ! $draft_field_ids_csv ) {
332 + // If the draft_fields input is empty there are no new fields in the session.
333 + return;
334 + }
335 +
336 + $draft_field_ids = array_filter( explode( ',', $draft_field_ids_csv ), 'is_numeric' );
337 + if ( ! $draft_field_ids ) {
338 + // Exit early if the draft fields input is invalid. It should be a CSV of integer values.
339 + return;
340 + }
341 +
342 + $draft_field_rows = FrmFieldsHelper::get_draft_field_results( $form_id, $draft_field_ids );
343 + foreach ( $draft_field_rows as $row ) {
344 + $row->field_options['draft'] = 0;
345 + FrmField::update( $row->id, array( 'field_options' => $row->field_options ) );
346 + }
347 + }
348 +
349 + /**
227 350 * Check if the value at the end of the form was included.
228 351 * If it's missing, it means other values at the end of the form
229 352 * were likely not saved either.
230 353 *
231 354 * @since 3.06.01
355 + *
356 + * @return bool
232 357 */
233 358 private static function is_too_long( $values ) {
234 - return ( ! isset( $values['frm_end'] ) ) || empty( $values['frm_end'] );
359 + return empty( $values['frm_end'] );
235 360 }
236 361
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 362 public static function duplicate() {
262 363 FrmAppHelper::permission_check( 'frm_edit_forms' );
263 364 $nonce = FrmAppHelper::simple_get( '_wpnonce' );
264 365
@@ -272,10 +373,11 @@
272 373 $url = admin_url( 'admin.php?page=formidable' );
273 374 $message = 'form_duplicate_error';
274 375
275 376 if ( $form ) {
276 - $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) );
277 - $message = 'form_duplicated';
377 + $new_template = FrmAppHelper::simple_get( 'new_template' ) ? '&new_template=true' : '';
378 + $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) . $new_template );
379 + $message = 'form_duplicated';
278 380 }
279 381
280 382 $url .= '&message=' . $message;
281 383
@@ -283,24 +385,28 @@
283 385 exit();
284 386 }
285 387
286 388 /**
287 - * @return string
389 + * @return string|null
288 390 */
289 391 public static function page_preview() {
290 392 $params = FrmForm::list_page_params();
291 393 if ( ! $params['form'] ) {
292 - return;
394 + return null;
293 395 }
294 396
295 397 $form = FrmForm::getOne( $params['form'] );
296 - if ( $form ) {
297 - return self::show_form( $form->id, '', 'auto', 'auto' );
398 + if ( ! $form ) {
399 + return null;
298 400 }
401 +
402 + return self::show_form( $form->id, '', 'auto', 'auto' );
299 403 }
300 404
301 405 /**
302 406 * @since 3.0
407 + *
408 + * @return void
303 409 */
304 410 public static function show_page_preview() {
305 411 echo self::page_preview(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
306 412 }
@@ -350,8 +456,13 @@
350 456 return;
351 457 }
352 458
353 459 $random_page = reset( $random_page );
460 + if ( ! is_a( $random_page, 'WP_Post' ) ) {
461 + // The return type can also be int.
462 + return;
463 + }
464 +
354 465 query_posts(
355 466 array(
356 467 'post_type' => 'page',
357 468 'page_id' => $random_page->ID,
@@ -367,9 +478,9 @@
367 478 * Set the WP $post global object. Used for in-theme preview when defining a page.
368 479 *
369 480 * @since 5.5.2
370 481 *
371 - * @param WP_Post $post
482 + * @param WP_Post $page The page object.
372 483 * @return void
373 484 */
374 485 private static function set_post_global( $page ) {
375 486 global $post;
@@ -377,8 +488,10 @@
377 488 }
378 489
379 490 /**
380 491 * @since 3.0
492 + *
493 + * @return void
381 494 */
382 495 private static function load_theme_preview() {
383 496 add_filter( 'wp_title', 'FrmFormsController::preview_title', 9999 );
384 497 add_filter( 'the_title', 'FrmFormsController::preview_page_title', 9999 );
@@ -387,20 +500,39 @@
387 500 add_filter( 'is_active_sidebar', '__return_false' );
388 501 FrmStylesController::enqueue_css( 'enqueue', true );
389 502
390 503 if ( false === get_template_part( 'page' ) ) {
504 + if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) {
505 + add_filter( 'body_class', 'FrmFormsController::preview_block_theme_body_classnames' );
506 + }
391 507 self::fallback_when_page_template_part_is_not_supported_by_theme();
392 508 }
393 509 }
394 510
395 511 /**
512 + * Add padding to the body for block themes.
513 + *
514 + * @since 6.5.2
515 + *
516 + * @param array $classes The body classes list.
517 + * @return array
518 + */
519 + public static function preview_block_theme_body_classnames( $classes ) {
520 + $classes[] = 'has-global-padding';
521 + return $classes;
522 + }
523 +
524 + /**
396 525 * Not every theme supports get_template_part( 'page' ).
397 526 * When this is not supported, false is returned, and we can handle a fallback.
527 + *
528 + * @return void
398 529 */
399 530 private static function fallback_when_page_template_part_is_not_supported_by_theme() {
400 531 if ( have_posts() ) {
401 532 the_post();
402 - get_header( '' );
533 + self::get_template( 'header' );
534 +
403 535 // add some generic class names to the container to add some natural padding to the content.
404 536 // .entry-content catches the WordPress TwentyTwenty theme.
405 537 // .container catches Customizr content.
406 538 echo '<div class="container entry-content">';
@@ -405,13 +537,54 @@
405 537 // .container catches Customizr content.
406 538 echo '<div class="container entry-content">';
407 539 the_content();
408 540 echo '</div>';
409 - get_footer();
541 +
542 + self::get_template( 'footer' );
410 543 }
411 544 }
412 545
413 546 /**
547 + * Calls core function to get a template part if it doesn't cause deprecation warnings. Otherwise skips the deprecation function call
548 + * and renders required html fragments calling required functions.
549 + *
550 + * @since 6.7.1
551 + * @param string $template
552 + * @return void
553 + */
554 + private static function get_template( $template ) {
555 + if ( self::should_try_getting_template( $template ) ) {
556 + call_user_func( 'get_' . $template );
557 + return;
558 + }
559 +
560 + if ( 'header' === $template ) {
561 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/header.php';
562 + return;
563 + }
564 +
565 + if ( 'footer' === $template ) {
566 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/footer.php';
567 + }
568 + }
569 +
570 + /**
571 + * Returns true if calling a template function doesn't trigger deprecation warnings.
572 + *
573 + * @since 6.7.1
574 + * @param string $template
575 + * @return bool
576 + */
577 + private static function should_try_getting_template( $template ) {
578 + $stylesheet_path = get_stylesheet_directory();
579 + $template_path = get_template_directory();
580 + $is_child_theme = $stylesheet_path !== $template_path;
581 + $template_name = $template . '.php';
582 +
583 + return file_exists( $stylesheet_path . '/' . $template_name ) || $is_child_theme && file_exists( $template_path . '/' . $template_name );
584 + }
585 +
586 + /**
414 587 * Set the page title for the theme preview page
415 588 *
416 589 * @since 3.0
417 590 */
@@ -423,11 +596,14 @@
423 596 return $title;
424 597 }
425 598
426 599 /**
427 - * Set the page title for the theme preview page
600 + * Set the page title for the theme preview page.
428 601 *
429 602 * @since 3.0
603 + *
604 + * @param string $title
605 + * @return string
430 606 */
431 607 public static function preview_title( $title ) {
432 608 return __( 'Form Preview', 'formidable' );
433 609 }
@@ -432,15 +608,20 @@
432 608 return __( 'Form Preview', 'formidable' );
433 609 }
434 610
435 611 /**
436 - * Set the page content for the theme preview page
612 + * Set the page content for the theme preview page.
437 613 *
438 614 * @since 3.0
615 + *
616 + * @param string $content
617 + * @return string
439 618 */
440 619 public static function preview_content( $content ) {
441 620 if ( in_the_loop() ) {
442 - $content = self::show_page_preview();
621 + self::show_page_preview();
622 + // Clear the content for the page we're using.
623 + $content = '';
443 624 }
444 625
445 626 return $content;
446 627 }
@@ -450,8 +631,11 @@
450 631 */
451 632 private static function load_direct_preview() {
452 633 header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
453 634
635 + // print_emoji_styles is deprecated.
636 + remove_action( 'wp_print_styles', 'print_emoji_styles' );
637 +
454 638 $key = FrmAppHelper::simple_get( 'form', 'sanitize_title' );
455 639 if ( $key == '' ) {
456 640 $key = FrmAppHelper::get_post_param( 'form', '', 'sanitize_title' );
457 641 }
@@ -460,11 +644,38 @@
460 644 if ( empty( $form ) ) {
461 645 $form = FrmForm::getAll( array(), '', 1 );
462 646 }
463 647
464 - require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php' );
648 + self::fix_deprecated_null_param_warning();
649 +
650 + require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php';
465 651 }
466 652
653 + /**
654 + * Some themes have a null $src value.
655 + * This function adds a filter to ensure that $src is not null.
656 + * WP will call str_starts_with with the null value triggering a deprecated message otherwise.
657 + *
658 + * @since 6.10
659 + *
660 + * @return void
661 + */
662 + private static function fix_deprecated_null_param_warning() {
663 + add_filter(
664 + 'script_loader_src',
665 + /**
666 + * @param string|null $src
667 + * @return string
668 + */
669 + function ( $src ) {
670 + if ( is_null( $src ) ) {
671 + $src = '';
672 + }
673 + return $src;
674 + }
675 + );
676 + }
677 +
467 678 public static function untrash() {
468 679 self::change_form_status( 'untrash' );
469 680 }
470 681
@@ -527,14 +738,14 @@
527 738 FrmAppHelper::permission_check( $available_status[ $status ]['permission'] );
528 739
529 740 $params = FrmForm::list_page_params();
530 741
531 - //check nonce url
742 + // Check nonce url.
532 743 check_admin_referer( $status . '_form_' . $params['id'] );
533 744
534 745 $count = 0;
535 746 if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) {
536 - $count ++;
747 + ++$count;
537 748 }
538 749
539 750 $form_type = FrmAppHelper::get_simple_request(
540 751 array(
@@ -546,9 +757,9 @@
546 757 /* translators: %1$s: Number of forms */
547 758 $available_status['untrash']['message'] = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
548 759
549 760 /* 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>' );
761 + $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 762
552 763 $message = $available_status[ $status ]['message'];
553 764
554 765 self::display_forms_list( $params, $message );
@@ -553,8 +764,12 @@
553 764
554 765 self::display_forms_list( $params, $message );
555 766 }
556 767
768 + /**
769 + * @param array $ids
770 + * @return string
771 + */
557 772 public static function bulk_trash( $ids ) {
558 773 FrmAppHelper::permission_check( 'frm_delete_forms' );
559 774
560 775 $count = 0;
@@ -559,12 +774,16 @@
559 774
560 775 $count = 0;
561 776 foreach ( $ids as $id ) {
562 777 if ( FrmForm::trash( $id ) ) {
563 - $count ++;
778 + ++$count;
564 779 }
565 780 }
566 781
782 + if ( ! $count ) {
783 + return '';
784 + }
785 +
567 786 $current_page = FrmAppHelper::get_simple_request(
568 787 array(
569 788 'param' => 'form_type',
570 789 'type' => 'request',
@@ -590,9 +809,9 @@
590 809 check_admin_referer( 'destroy_form_' . $params['id'] );
591 810
592 811 $count = 0;
593 812 if ( FrmForm::destroy( $params['id'] ) ) {
594 - $count ++;
813 + ++$count;
595 814 }
596 815
597 816 /* translators: %1$s: Number of forms */
598 817 $message = sprintf( _n( '%1$s Form Permanently Deleted', '%1$s Forms Permanently Deleted', $count, 'formidable' ), $count );
@@ -599,8 +818,12 @@
599 818
600 819 self::display_forms_list( $params, $message );
601 820 }
602 821
822 + /**
823 + * @param array $ids
824 + * @return string
825 + */
603 826 public static function bulk_destroy( $ids ) {
604 827 FrmAppHelper::permission_check( 'frm_delete_forms' );
605 828
606 829 $count = 0;
@@ -606,19 +829,24 @@
606 829 $count = 0;
607 830 foreach ( $ids as $id ) {
608 831 $d = FrmForm::destroy( $id );
609 832 if ( $d ) {
610 - $count ++;
833 + ++$count;
611 834 }
612 835 }
613 836
614 - /* translators: %1$s: Number of forms */
615 - $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
837 + if ( $count ) {
838 + /* translators: %1$s: Number of forms */
839 + return sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
840 + }
616 841
617 - return $message;
842 + return '';
618 843 }
619 844
620 - private static function delete_all() {
845 + /**
846 + * @since 6.7.1 Function went from private to public.
847 + */
848 + public static function delete_all() {
621 849 // Check nonce url.
622 850 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' );
623 851 if ( $permission_error !== false ) {
624 852 self::display_forms_list( array(), '', array( $permission_error ) );
@@ -625,14 +853,15 @@
625 853
626 854 return;
627 855 }
628 856
629 - $count = FrmForm::scheduled_delete( time() );
857 + $count = FrmForm::scheduled_delete( time() );
858 + $url = remove_query_arg( array( 'delete_all' ) );
630 859
631 - /* translators: %1$s: Number of forms */
632 - $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
860 + $url .= '&message=forms_permanently_deleted&forms_deleted=' . $count;
633 861
634 - self::display_forms_list( array(), $message );
862 + wp_safe_redirect( $url );
863 + die();
635 864 }
636 865
637 866 /**
638 867 * Create a new form from the modal.
@@ -645,9 +874,9 @@
645 874
646 875 $new_values = self::get_modal_values();
647 876 $new_values['form_key'] = $new_values['name'];
648 877 $new_values['options'] = array(
649 - 'antispam' => 1,
878 + 'antispam' => 1,
650 879 'on_submit_migrated' => 1,
651 880 );
652 881
653 882 /**
@@ -666,13 +895,14 @@
666 895 * @param int $form_id
667 896 */
668 897 do_action( 'frm_build_new_form', $form_id );
669 898
899 + self::create_submit_button_field( $form_id );
670 900 self::create_default_on_submit_action( $form_id );
671 901 self::create_default_email_action( $form_id );
672 902
673 903 $response = array(
674 - 'redirect' => FrmForm::get_edit_link( $form_id ),
904 + 'redirect' => FrmForm::get_edit_link( $form_id ) . '&new_template=true',
675 905 );
676 906
677 907 echo wp_json_encode( $response );
678 908 wp_die();
@@ -678,46 +908,15 @@
678 908 wp_die();
679 909 }
680 910
681 911 /**
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 912 * Before creating a new form, get the name and description from the modal.
716 913 *
717 914 * @since 4.0
915 + *
916 + * @return array<string,string>
718 917 */
719 - private static function get_modal_values() {
918 + public static function get_modal_values() {
720 919 $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' );
721 920 $desc = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' );
722 921
723 922 return array(
@@ -730,17 +929,24 @@
730 929 * Inserts Formidable button
731 930 * Hook exists since 2.5.0
732 931 *
733 932 * @since 2.0.15
933 + *
934 + * @return void
734 935 */
735 936 public static function insert_form_button() {
736 937 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>';
938 + // Store the result in memory and re-use it when this function is called multiple times.
939 + // This helps speed up the form builder when there are a lot of HTML fields, where this
940 + // button is inserted once per HTML field.
941 + // In a form with 66 HTML fields, this saves 0.5 seconds on page load time, tested locally.
942 + if ( ! isset( self::$formidable_tinymce_button ) ) {
943 + FrmAppHelper::load_admin_wide_js();
944 + $menu_name = FrmAppHelper::get_menu_name();
945 + $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() );
946 + 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>';
947 + }
948 + echo self::$formidable_tinymce_button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
743 949 }
744 950 }
745 951
746 952 /**
@@ -828,9 +1034,9 @@
828 1034 $form_id = $opts['form_id'];
829 1035 unset( $opts['form_id'] );
830 1036 }
831 1037
832 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php' );
1038 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php';
833 1039
834 1040 echo '</div>';
835 1041
836 1042 wp_die();
@@ -879,14 +1085,14 @@
879 1085 * @return array<string,string>
880 1086 */
881 1087 public static function get_columns( $columns ) {
882 1088 $columns['cb'] = '<input type="checkbox" />';
883 - $columns['name'] = __( 'Form Title', 'formidable' );
884 - $columns['entries'] = __( 'Entries', 'formidable' );
1089 + $columns['name'] = esc_html__( 'Form Title', 'formidable' );
1090 + $columns['entries'] = esc_html__( 'Entries', 'formidable' );
885 1091 $columns['id'] = 'ID';
886 - $columns['form_key'] = __( 'Key', 'formidable' );
887 - $columns['shortcode'] = __( 'Actions', 'formidable' );
888 - $columns['created_at'] = __( 'Date', 'formidable' );
1092 + $columns['form_key'] = esc_html__( 'Key', 'formidable' );
1093 + $columns['shortcode'] = esc_html__( 'Actions', 'formidable' );
1094 + $columns['created_at'] = esc_html__( 'Date', 'formidable' );
889 1095
890 1096 add_screen_option(
891 1097 'per_page',
892 1098 array(
@@ -898,8 +1104,11 @@
898 1104
899 1105 return $columns;
900 1106 }
901 1107
1108 + /**
1109 + * @return array<string,string>
1110 + */
902 1111 public static function get_sortable_columns() {
903 1112 return array(
904 1113 'id' => 'id',
905 1114 'name' => 'name',
@@ -933,9 +1142,9 @@
933 1142 return $hidden_columns;
934 1143 }
935 1144
936 1145 public static function save_per_page( $save, $option, $value ) {
937 - if ( $option == 'formidable_page_formidable_per_page' ) {
1146 + if ( $option === 'formidable_page_formidable_per_page' ) {
938 1147 $save = (int) $value;
939 1148 }
940 1149
941 1150 return $save;
@@ -941,146 +1150,49 @@
941 1150 return $save;
942 1151 }
943 1152
944 1153 /**
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 - *
1154 + * @param int|string $id
1155 + * @param array $errors
1156 + * @param string $message
1157 + * @param bool $create_link
955 1158 * @return void
956 1159 */
957 - public static function before_list_templates() {
958 - global $frm_templates;
959 - global $frm_expired;
960 - global $frm_license_type;
1160 + private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
1161 + global $frm_vars;
961 1162
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 - }
1163 + $form = FrmForm::getOne( $id );
1164 + $error_args = array(
1165 + 'title' => __( 'You can\'t edit the form', 'formidable' ),
1166 + 'body' => __( 'You are trying to edit a form that does not exist', 'formidable' ),
1167 + 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
1168 + 'continue_url' => add_query_arg(
1169 + array(
1170 + 'page' => 'formidable',
1171 + )
1172 + ),
1019 1173 );
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 - }
1174 + if ( ! $form ) {
1175 + FrmAppController::show_error_modal( $error_args );
1176 + return;
1046 1177 }
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 1178
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,
1179 + if ( 'trash' === $form->status ) {
1180 + $error_args['body'] = __( 'The form you\'re trying to edit is in trash. You must restore it first before you can make changes', 'formidable' );
1181 + $error_args['continue_url'] = add_query_arg(
1182 + array(
1183 + 'page' => 'formidable',
1184 + '_wpnonce' => wp_create_nonce( 'untrash_form_' . $id ),
1185 + 'form_type' => 'trash',
1186 + 'frm_action' => 'untrash',
1187 + 'id' => $id,
1188 + )
1069 1189 );
1070 - array_unshift( $templates, $template );
1071 - unset( $template );
1190 + $error_args['continue_text'] = __( 'Restore form', 'formidable' );
1191 + FrmAppController::show_error_modal( $error_args );
1192 + return;
1072 1193 }
1073 - }
1074 1194
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 1195 if ( $form->parent_form_id ) {
1084 1196 /* translators: %1$s: Start link HTML, %2$s: End link HTML */
1085 1197 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 1198 }
@@ -1091,8 +1203,9 @@
1091 1203
1092 1204 // Automatically add end section fields if they don't exist (2.0 migration).
1093 1205 $reset_fields = false;
1094 1206 FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields );
1207 + FrmSubmitHelper::maybe_create_submit_field( $form, $fields, $reset_fields );
1095 1208
1096 1209 if ( $reset_fields ) {
1097 1210 $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' );
1098 1211 }
@@ -1118,18 +1231,21 @@
1118 1231 }
1119 1232
1120 1233 self::maybe_update_form_builder_message( $message );
1121 1234
1122 - $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
1123 - $has_fields = isset( $values['fields'] ) && ! empty( $values['fields'] );
1235 + $has_fields = ! empty( $values['fields'] ) && ! FrmSubmitHelper::only_contains_submit_field( $values['fields'] );
1124 1236
1125 1237 if ( defined( 'DOING_AJAX' ) ) {
1126 1238 wp_die();
1127 - } else {
1128 - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' );
1129 1239 }
1240 +
1241 + require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php';
1130 1242 }
1131 1243
1244 + /**
1245 + * @param array $fields
1246 + * @return array
1247 + */
1132 1248 public static function update_form_builder_fields( $fields, $form ) {
1133 1249 foreach ( $fields as $field ) {
1134 1250 $field->do_not_include_icons = true;
1135 1251 }
@@ -1141,13 +1257,21 @@
1141 1257 $message = __( 'Form was Successfully Copied', 'formidable' );
1142 1258 }
1143 1259 }
1144 1260
1261 + /**
1262 + * @param int|string $id
1263 + * @param array $errors
1264 + * @param array|string $args
1265 + * @return void
1266 + */
1145 1267 public static function get_settings_vars( $id, $errors = array(), $args = array() ) {
1146 1268 FrmAppHelper::permission_check( 'frm_edit_forms' );
1147 1269
1148 1270 global $frm_vars;
1149 1271
1272 + self::maybe_print_media_templates();
1273 +
1150 1274 if ( ! is_array( $args ) ) {
1151 1275 // For reverse compatibility.
1152 1276 $args = array(
1153 1277 'message' => $args,
@@ -1180,17 +1304,38 @@
1180 1304
1181 1305 $sections = self::get_settings_tabs( $values );
1182 1306 $current = FrmAppHelper::simple_get( 't', 'sanitize_title', 'advanced_settings' );
1183 1307
1184 - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php' );
1308 + require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php';
1185 1309 }
1186 1310
1187 1311 /**
1312 + * 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.
1313 + *
1314 + * @since 6.10
1315 + *
1316 + * @return void
1317 + */
1318 + private static function maybe_print_media_templates() {
1319 + if ( FrmAppHelper::pro_is_included() ) {
1320 + // This issue does not exist when Pro is active so exit early.
1321 + return;
1322 + }
1323 +
1324 + add_action(
1325 + 'wp_enqueue_editor',
1326 + function () {
1327 + wp_print_media_templates();
1328 + }
1329 + );
1330 + }
1331 +
1332 + /**
1188 1333 * @since 4.0
1189 1334 */
1190 1335 public static function form_publish_button( $atts ) {
1191 1336 $values = $atts['values'];
1192 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php' );
1337 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php';
1193 1338 }
1194 1339
1195 1340 /**
1196 1341 * Get a list of all the settings tabs for the form settings page.
@@ -1215,9 +1360,9 @@
1215 1360 'icon' => 'frm_icon_font frm_mail_bulk_icon',
1216 1361 ),
1217 1362 'permissions' => array(
1218 1363 'name' => __( 'Form Permissions', 'formidable' ),
1219 - 'icon' => 'frm_icon_font frm_lock_icon',
1364 + 'icon' => 'frm_icon_font frm_lock_closed_icon',
1220 1365 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1221 1366 'data' => array(
1222 1367 'medium' => 'permissions',
1223 1368 'upgrade' => __( 'Form Permissions', 'formidable' ),
@@ -1224,9 +1369,9 @@
1224 1369 'message' => __( 'Allow editing, protect forms and files, limit entries, and save drafts. Upgrade to get form and entry permissions.', 'formidable' ),
1225 1370 'screenshot' => 'permissions.png',
1226 1371 ),
1227 1372 ),
1228 - 'scheduling' => array(
1373 + 'scheduling' => array(
1229 1374 'name' => __( 'Form Scheduling', 'formidable' ),
1230 1375 'icon' => 'frm_icon_font frm_calendar_icon',
1231 1376 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1232 1377 'data' => array(
@@ -1259,8 +1404,21 @@
1259 1404 'screenshot' => 'chat.png',
1260 1405 )
1261 1406 ),
1262 1407 ),
1408 + 'abandonment' => array(
1409 + 'name' => __( 'Form Abandonment', 'formidable' ),
1410 + 'icon' => 'frm_icon_font frm_abandoned_icon',
1411 + 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1412 + 'data' => FrmAppHelper::get_upgrade_data_params(
1413 + 'abandonment',
1414 + array(
1415 + 'upgrade' => __( 'Form abandonment settings', 'formidable' ),
1416 + 'message' => __( 'Unlock the power of data capture to boost lead generation and master the art of form optimization.', 'formidable' ),
1417 + 'screenshot' => 'abandonment.png',
1418 + )
1419 + ),
1420 + ),
1263 1421 'html' => array(
1264 1422 'name' => __( 'Customize HTML', 'formidable' ),
1265 1423 'class' => __CLASS__,
1266 1424 'function' => 'html_settings',
@@ -1267,9 +1425,13 @@
1267 1425 'icon' => 'frm_icon_font frm_code_icon',
1268 1426 ),
1269 1427 );
1270 1428
1271 - foreach ( array( 'landing', 'chat' ) as $feature ) {
1429 + if ( ! has_action( 'frm_add_form_style_tab_options' ) && ! has_action( 'frm_add_form_button_options' ) ) {
1430 + unset( $sections['buttons'] );
1431 + }
1432 +
1433 + foreach ( array( 'landing', 'chat', 'abandonment' ) as $feature ) {
1272 1434 if ( ! FrmAppHelper::show_new_feature( $feature ) ) {
1273 1435 unset( $sections[ $feature ] );
1274 1436 }
1275 1437 }
@@ -1275,13 +1437,8 @@
1275 1437 }
1276 1438
1277 1439 $sections = apply_filters( 'frm_add_form_settings_section', $sections, $values );
1278 1440
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 1441 foreach ( $sections as $key => $section ) {
1285 1442 $defaults = array(
1286 1443 'html_class' => '',
1287 1444 'name' => ucfirst( $key ),
@@ -1303,9 +1460,9 @@
1303 1460 $section['id'] = $section['anchor'];
1304 1461 }
1305 1462
1306 1463 $sections[ $key ] = $section;
1307 - }
1464 + }//end foreach
1308 1465
1309 1466 return $sections;
1310 1467 }
1311 1468
@@ -1312,8 +1469,9 @@
1312 1469 /**
1313 1470 * @since 4.0
1314 1471 *
1315 1472 * @param array $values
1473 + * @return void
1316 1474 */
1317 1475 public static function advanced_settings( $values ) {
1318 1476 $first_h3 = 'frm_first_h3';
1319 1477
@@ -1321,8 +1479,9 @@
1321 1479 }
1322 1480
1323 1481 /**
1324 1482 * @param array $values
1483 + * @return void
1325 1484 */
1326 1485 public static function render_spam_settings( $values ) {
1327 1486 if ( function_exists( 'akismet_http_post' ) ) {
1328 1487 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/akismet.php';
@@ -1334,16 +1493,12 @@
1334 1493 /**
1335 1494 * @since 4.0
1336 1495 *
1337 1496 * @param array $values
1497 + * @return void
1338 1498 */
1339 1499 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' );
1500 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php';
1346 1501 }
1347 1502
1348 1503 /**
1349 1504 * @since 4.0
@@ -1348,11 +1503,12 @@
1348 1503 /**
1349 1504 * @since 4.0
1350 1505 *
1351 1506 * @param array $values
1507 + * @return void
1352 1508 */
1353 1509 public static function html_settings( $values ) {
1354 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php' );
1510 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php';
1355 1511 }
1356 1512
1357 1513 /**
1358 1514 * Replace old Submit Button href with new href to avoid errors in Chrome
@@ -1358,9 +1514,10 @@
1358 1514 * Replace old Submit Button href with new href to avoid errors in Chrome
1359 1515 *
1360 1516 * @since 2.03.08
1361 1517 *
1362 - * @param array|boolean $values
1518 + * @param array|bool $values
1519 + * @return void
1363 1520 */
1364 1521 private static function clean_submit_html( &$values ) {
1365 1522 if ( is_array( $values ) && isset( $values['submit_html'] ) ) {
1366 1523 $values['submit_html'] = str_replace( 'javascript:void(0)', '#', $values['submit_html'] );
@@ -1381,8 +1538,13 @@
1381 1538
1382 1539 return $classes;
1383 1540 }
1384 1541
1542 + /**
1543 + * @param int|string $form_id
1544 + * @param string $class
1545 + * @return void
1546 + */
1385 1547 public static function mb_tags_box( $form_id, $class = '' ) {
1386 1548 $fields = FrmField::get_all_for_form( $form_id, '', 'include' );
1387 1549
1388 1550 /**
@@ -1395,9 +1557,9 @@
1395 1557 */
1396 1558 $fields = apply_filters( 'frm_fields_in_tags_box', $fields, compact( 'form_id' ) );
1397 1559 $linked_forms = array();
1398 1560 $col = 'one';
1399 - $settings_tab = FrmAppHelper::is_admin_page( 'formidable' ) ? true : false;
1561 + $settings_tab = FrmAppHelper::is_admin_page( 'formidable' );
1400 1562
1401 1563 $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() );
1402 1564 $entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
1403 1565
@@ -1402,9 +1564,9 @@
1402 1564 $entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
1403 1565
1404 1566 $advanced_helpers = self::advanced_helpers( compact( 'fields', 'form_id' ) );
1405 1567
1406 - include( FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php' );
1568 + include FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php';
1407 1569 }
1408 1570
1409 1571 /**
1410 1572 * @since 3.04.01
@@ -1417,9 +1579,9 @@
1417 1579 ),
1418 1580 );
1419 1581
1420 1582 $user_fields = self::user_shortcodes();
1421 - if ( ! empty( $user_fields ) ) {
1583 + if ( $user_fields ) {
1422 1584 $user_helpers = array();
1423 1585 foreach ( $user_fields as $uk => $uf ) {
1424 1586 $user_helpers[ '|user_id| show="' . $uk . '"' ] = $uf;
1425 1587 unset( $uk, $uf );
@@ -1425,9 +1587,9 @@
1425 1587 unset( $uk, $uf );
1426 1588 }
1427 1589
1428 1590 $advanced_helpers['user_id'] = array(
1429 - 'codes' => $user_helpers,
1591 + 'codes' => $user_helpers,
1430 1592 );
1431 1593 }
1432 1594
1433 1595 /**
@@ -1504,21 +1666,16 @@
1504 1666 'updated-at' => __( 'Entry updated', 'formidable' ),
1505 1667 '' => '',
1506 1668 'siteurl' => __( 'Site URL', 'formidable' ),
1507 1669 'sitename' => __( 'Site Name', 'formidable' ),
1670 + 'form_name' => __( 'Form Name', 'formidable' ),
1508 1671 );
1509 1672
1673 + $entry_shortcodes = array_merge( FrmShortcodeHelper::get_contextual_shortcode_values(), $entry_shortcodes );
1510 1674 if ( ! FrmAppHelper::pro_is_installed() ) {
1511 1675 unset( $entry_shortcodes['post_id'] );
1512 1676 }
1513 1677
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 1678 /**
1522 1679 * Use this hook to add or remove buttons in the helpers section
1523 1680 * in the customization panel
1524 1681 *
@@ -1568,11 +1725,11 @@
1568 1725 check_ajax_referer( 'frm_ajax', 'nonce' );
1569 1726
1570 1727 echo FrmEntriesController::show_entry_shortcode( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1571 1728 array(
1572 - 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ),
1729 + 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1573 1730 'default_email' => true,
1574 - 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ),
1731 + 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1575 1732 )
1576 1733 );
1577 1734 wp_die();
1578 1735 }
@@ -1578,10 +1735,10 @@
1578 1735 }
1579 1736
1580 1737 /**
1581 1738 * @param string $content
1582 - * @param stdClass|string|int $form
1583 - * @param stdClass|string|int|false $entry
1739 + * @param int|stdClass|string $form
1740 + * @param false|int|stdClass|string $entry
1584 1741 * @return string
1585 1742 */
1586 1743 public static function filter_content( $content, $form, $entry = false ) {
1587 1744 $content = self::replace_form_name_shortcodes( $content, $form );
@@ -1594,8 +1751,16 @@
1594 1751 if ( is_object( $form ) ) {
1595 1752 $form = $form->id;
1596 1753 }
1597 1754
1755 + /*
1756 + * Repeater actions adds `parent_entry` to `$entry` store the parent entry data. If `parent_entry` is not empty,
1757 + * use the parent form ID instead of repeater form ID to fix the parent form field shortcodes doesn't work.
1758 + */
1759 + if ( ! empty( $entry->parent_entry ) ) {
1760 + $form = $entry->parent_entry->form_id;
1761 + }
1762 +
1598 1763 $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form );
1599 1764 $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
1600 1765
1601 1766 return $content;
@@ -1605,13 +1770,17 @@
1605 1770 * Replace any [form_name] shortcodes in a string.
1606 1771 *
1607 1772 * @since 5.5
1608 1773 *
1609 - * @param string $string
1610 - * @param stdClass|string|int $form
1611 - * @return string
1774 + * @param array|string $string
1775 + * @param int|stdClass|string $form
1776 + * @return array|string
1612 1777 */
1613 1778 public static function replace_form_name_shortcodes( $string, $form ) {
1779 + if ( ! is_string( $string ) ) {
1780 + return $string;
1781 + }
1782 +
1614 1783 if ( false === strpos( $string, '[form_name]' ) ) {
1615 1784 return $string;
1616 1785 }
1617 1786
@@ -1623,9 +1792,9 @@
1623 1792 return str_replace( '[form_name]', $form_name, $string );
1624 1793 }
1625 1794
1626 1795 /**
1627 - * @param stdClass|string|int|false $entry
1796 + * @param false|int|stdClass|string $entry
1628 1797 * @return void
1629 1798 */
1630 1799 private static function get_entry_by_param( &$entry ) {
1631 1800 if ( ! $entry || ! is_object( $entry ) ) {
@@ -1640,8 +1809,12 @@
1640 1809 public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
1641 1810 return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes );
1642 1811 }
1643 1812
1813 + /**
1814 + * @param array $errors
1815 + * @return array
1816 + */
1644 1817 public static function process_bulk_form_actions( $errors ) {
1645 1818 if ( ! $_REQUEST ) {
1646 1819 return $errors;
1647 1820 }
@@ -1685,9 +1858,9 @@
1685 1858 case 'untrash':
1686 1859 $message = self::bulk_untrash( $ids );
1687 1860 }
1688 1861
1689 - if ( isset( $message ) && ! empty( $message ) ) {
1862 + if ( ! empty( $message ) ) {
1690 1863 $errors['message'] = $message;
1691 1864 }
1692 1865
1693 1866 return $errors;
@@ -1707,9 +1880,9 @@
1707 1880 $json_vars = json_decode( $json_vars, true );
1708 1881 if ( empty( $json_vars ) ) {
1709 1882 // json decoding failed so we should return an error message.
1710 1883 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
1711 - if ( 'edit' == $action ) {
1884 + if ( 'edit' === $action ) {
1712 1885 $action = 'update';
1713 1886 }
1714 1887
1715 1888 add_filter( 'frm_validate_form', 'FrmFormsController::json_error' );
@@ -1725,16 +1898,14 @@
1725 1898 if ( isset( $_REQUEST['delete_all'] ) ) {
1726 1899 // Override the action for this page.
1727 1900 $action = 'delete_all';
1728 1901 }
1729 - }
1902 + }//end if
1730 1903
1731 1904 add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
1732 1905 FrmAppHelper::trigger_hook_load( 'form' );
1733 1906
1734 1907 switch ( $action ) {
1735 - case 'new':
1736 - return self::new_form( $vars );
1737 1908 case 'create':
1738 1909 case 'edit':
1739 1910 case 'update':
1740 1911 case 'trash':
@@ -1739,16 +1910,17 @@
1739 1910 case 'update':
1740 1911 case 'trash':
1741 1912 case 'untrash':
1742 1913 case 'destroy':
1743 - case 'delete_all':
1744 1914 case 'settings':
1745 1915 case 'update_settings':
1746 1916 return self::$action( $vars );
1747 1917 case 'lite-reports':
1748 - return self::no_reports( $vars );
1918 + self::no_reports( $vars );
1919 + return;
1749 1920 case 'views':
1750 - return self::no_views( $vars );
1921 + self::no_views( $vars );
1922 + return;
1751 1923 default:
1752 1924 do_action( 'frm_form_action_' . $action );
1753 1925 if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) {
1754 1926 return;
@@ -1771,14 +1943,47 @@
1771 1943 self::display_forms_list( array(), '', array( __( 'There was a problem duplicating the form', 'formidable' ) ) );
1772 1944 return;
1773 1945 }
1774 1946
1947 + if ( 'forms_permanently_deleted' === $message ) {
1948 + $count = FrmAppHelper::get_param( 'forms_deleted', 0, 'get', 'absint' );
1949 + /* translators: %1$s: Number of forms */
1950 + $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
1951 + self::display_forms_list( array(), $message, '' );
1952 + return;
1953 + }
1954 +
1775 1955 self::display_forms_list();
1776 1956
1777 1957 return;
1778 - }
1958 + }//end switch
1779 1959 }
1780 1960
1961 + /**
1962 + * Rename a form.
1963 + *
1964 + * Handles the AJAX request for renaming a form.
1965 + *
1966 + * @since 6.7
1967 + *
1968 + * @return void
1969 + */
1970 + public static function rename_form() {
1971 + // Check permission and nonce
1972 + FrmAppHelper::permission_check( 'frm_edit_forms' );
1973 + check_ajax_referer( 'frm_ajax', 'nonce' );
1974 +
1975 + // Get posted data
1976 + $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
1977 + $name = FrmAppHelper::get_post_param( 'form_name', '', 'sanitize_text_field' );
1978 +
1979 + // Update the form name and form key.
1980 + $form_key = FrmAppHelper::get_unique_key( sanitize_title( $name ), 'frm_forms', 'form_key' );
1981 + FrmForm::update( $form_id, compact( 'name', 'form_key' ) );
1982 +
1983 + wp_send_json_success( compact( 'form_key' ) );
1984 + }
1985 +
1781 1986 public static function json_error( $errors ) {
1782 1987 $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
1783 1988
1784 1989 return $errors;
@@ -1784,20 +1989,13 @@
1784 1989 return $errors;
1785 1990 }
1786 1991
1787 1992 /**
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 1993 * Add education about views.
1798 1994 *
1799 1995 * @since 4.07
1996 + *
1997 + * @return void
1800 1998 */
1801 1999 public static function no_views( $values = array() ) {
1802 2000 FrmAppHelper::include_svg();
1803 2001 $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
@@ -1809,8 +2007,10 @@
1809 2007 /**
1810 2008 * Add education about reports.
1811 2009 *
1812 2010 * @since 4.07
2011 + *
2012 + * @return void
1813 2013 */
1814 2014 public static function no_reports( $values = array() ) {
1815 2015 $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
1816 2016 $form = $id ? FrmForm::getOne( $id ) : false;
@@ -1817,9 +2017,11 @@
1817 2017
1818 2018 include FrmAppHelper::plugin_path() . '/classes/views/shared/reports-info.php';
1819 2019 }
1820 2020
1821 - /* FRONT-END FORMS */
2021 + /**
2022 + * FRONT-END FORMS.
2023 + */
1822 2024 public static function admin_bar_css() {
1823 2025 if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
1824 2026 return;
1825 2027 }
@@ -1893,9 +2095,9 @@
1893 2095 $wp_admin_bar->add_node(
1894 2096 array(
1895 2097 'parent' => 'frm-forms',
1896 2098 'id' => 'edit_form_' . $form_id,
1897 - 'title' => empty( $name ) ? __( '(no title)', 'formidable' ) : $name,
2099 + 'title' => empty( $name ) ? FrmFormsHelper::get_no_title_text() : $name,
1898 2100 'href' => FrmForm::get_edit_link( $form_id ),
1899 2101 )
1900 2102 );
1901 2103 }
@@ -1908,10 +2110,10 @@
1908 2110 * @return string
1909 2111 */
1910 2112 public static function get_form_shortcode( $atts ) {
1911 2113 global $frm_vars;
1912 - if ( isset( $frm_vars['skip_shortcode'] ) && $frm_vars['skip_shortcode'] ) {
1913 - $sc = '[formidable';
2114 + if ( ! empty( $frm_vars['skip_shortcode'] ) ) {
2115 + $sc = '[formidable';
1914 2116 $sc .= FrmAppHelper::array_to_html_params( $atts );
1915 2117 return $sc . ']';
1916 2118 }
1917 2119
@@ -1936,11 +2138,11 @@
1936 2138
1937 2139 /**
1938 2140 * @since 5.2.01
1939 2141 *
1940 - * @param string|int|false $id
1941 - * @param string|false $key
1942 - * @return stdClass|false
2142 + * @param false|int|string $id
2143 + * @param false|string $key
2144 + * @return false|stdClass
1943 2145 */
1944 2146 private static function maybe_get_form_by_id_or_key( $id, $key ) {
1945 2147 if ( ! $id ) {
1946 2148 $id = $key;
@@ -1948,12 +2150,12 @@
1948 2150 return self::maybe_get_form_to_show( $id );
1949 2151 }
1950 2152
1951 2153 /**
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.
2154 + * @param false|int|string $id
2155 + * @param false|string $key
2156 + * @param bool|int|string $title may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
2157 + * @param bool|int|string $description may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
1956 2158 * @param array $atts
1957 2159 * @return string
1958 2160 */
1959 2161 public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) {
@@ -2001,15 +2203,16 @@
2001 2203 return $form;
2002 2204 }
2003 2205
2004 2206 /**
2005 - * @param string|int|false $id
2006 - * @return stdClass|false
2207 + * @param false|int|string $id
2208 + * @return false|stdClass
2007 2209 */
2008 2210 private static function maybe_get_form_to_show( $id ) {
2009 2211 $form = false;
2010 2212
2011 - if ( ! empty( $id ) ) { // form id or key is set
2213 + if ( ! empty( $id ) ) {
2214 + // Form id or key is set.
2012 2215 $form = FrmForm::getOne( $id );
2013 2216 if ( ! $form || $form->parent_form_id || $form->status === 'trash' ) {
2014 2217 $form = false;
2015 2218 }
@@ -2067,11 +2270,11 @@
2067 2270
2068 2271 do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description );
2069 2272
2070 2273 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;
2274 + $entry_id = self::just_created_entry( $form->id );
2275 + $pass_args['entry_id'] = $entry_id;
2276 + $pass_args['reset'] = true;
2074 2277
2075 2278 self::run_on_submit_actions( $pass_args );
2076 2279
2077 2280 do_action(
@@ -2081,9 +2284,9 @@
2081 2284 'form' => $form,
2082 2285 )
2083 2286 );
2084 2287 }
2085 - }
2288 + }//end if
2086 2289 }
2087 2290
2088 2291 /**
2089 2292 * If the form was processed earlier (init), get the generated errors
@@ -2115,9 +2318,9 @@
2115 2318 */
2116 2319 public static function just_created_entry( $form_id ) {
2117 2320 global $frm_vars;
2118 2321
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;
2322 + 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 2323 }
2121 2324
2122 2325 /**
2123 2326 * Gets confirmation method.
@@ -2130,14 +2333,14 @@
2130 2333 *
2131 2334 * @type object $form Form object.
2132 2335 * @type int $entry_id Entry ID.
2133 2336 * }
2134 - * @return string|array
2337 + * @return array|string
2135 2338 */
2136 2339 private static function get_confirmation_method( $atts ) {
2137 2340 $action = FrmOnSubmitHelper::current_event( $atts );
2138 2341 $opt = 'update' === $action ? 'edit_action' : 'success_action';
2139 - $method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message';
2342 + $method = ! empty( $atts['form']->options[ $opt ] ) ? $atts['form']->options[ $opt ] : 'message';
2140 2343
2141 2344 if ( ! empty( $atts['entry_id'] ) ) {
2142 2345 $met_actions = self::get_met_on_submit_actions( $atts, $action );
2143 2346 if ( $met_actions ) {
@@ -2146,9 +2349,9 @@
2146 2349 }
2147 2350
2148 2351 $method = apply_filters( 'frm_success_filter', $method, $atts['form'], $action );
2149 2352
2150 - if ( $method != 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
2353 + if ( $method !== 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
2151 2354 $method = 'message';
2152 2355 }
2153 2356
2154 2357 return $method;
@@ -2182,9 +2385,9 @@
2182 2385 * @param array $args See {@see FrmFormsController::maybe_trigger_redirect()}.
2183 2386 */
2184 2387 public static function maybe_trigger_redirect_with_action( $conf_method, $form, $params, $args ) {
2185 2388 if ( is_array( $conf_method ) && 1 === count( $conf_method ) ) {
2186 - if ( 'redirect' === FrmOnSubmitHelper::get_action_type( $conf_method[0] ) ) {
2389 + if ( 'redirect' === FrmOnSubmitHelper::get_action_type( $conf_method[0] ) && empty( $conf_method[0]->post_content['redirect_delay'] ) ) {
2187 2390 $event = FrmOnSubmitHelper::current_event( $params );
2188 2391 FrmOnSubmitHelper::populate_on_submit_data( $form->options, $conf_method[0], $event );
2189 2392 $conf_method = 'redirect';
2190 2393 }
@@ -2233,9 +2436,9 @@
2233 2436 unset( $extra_args['form'] );
2234 2437
2235 2438 do_action( 'frm_success_action', $args['conf_method'], $args['form'], $args['form']->options, $args['entry_id'], $extra_args );
2236 2439
2237 - $opt = ( ! isset( $args['action'] ) || $args['action'] === 'create' ) ? 'success' : 'edit';
2440 + $opt = ! isset( $args['action'] ) || $args['action'] === 'create' ? 'success' : 'edit';
2238 2441
2239 2442 $args['success_opt'] = $opt;
2240 2443 $args['ajax'] = ! empty( $frm_vars['ajax'] );
2241 2444
@@ -2261,11 +2464,16 @@
2261 2464 if ( ! FrmOnSubmitHelper::form_has_migrated( $args['form'] ) ) {
2262 2465 return array();
2263 2466 }
2264 2467
2265 - $entry = FrmEntry::getOne( $args['entry_id'], true );
2266 - $actions = FrmOnSubmitHelper::get_actions( $args['form']->id );
2267 - $met_actions = array();
2468 + // If a redirect action has already opened the URL in a new tab, we show the default message in the current tab.
2469 + if ( ! empty( self::$redirected_in_new_tab[ $args['form']->id ] ) ) {
2470 + return array( FrmOnSubmitHelper::get_fallback_action_after_open_in_new_tab( $event ) );
2471 + }
2472 +
2473 + $entry = FrmEntry::getOne( $args['entry_id'], true );
2474 + $actions = FrmOnSubmitHelper::get_actions( $args['form']->id );
2475 + $met_actions = array();
2268 2476 $has_redirect = false;
2269 2477
2270 2478 foreach ( $actions as $action ) {
2271 2479 if ( ! in_array( $event, $action->post_content['event'], true ) ) {
@@ -2278,9 +2486,10 @@
2278 2486
2279 2487 $action_type = FrmOnSubmitHelper::get_action_type( $action );
2280 2488
2281 2489 if ( 'redirect' === $action_type ) {
2282 - if ( $has_redirect ) { // Do not process because we run the first redirect action only.
2490 + if ( $has_redirect ) {
2491 + // Do not process because we run the first redirect action only.
2283 2492 continue;
2284 2493 }
2285 2494 }
2286 2495
@@ -2293,9 +2502,9 @@
2293 2502 }
2294 2503
2295 2504 $met_actions[] = $action;
2296 2505 unset( $action );
2297 - }
2506 + }//end foreach
2298 2507
2299 2508 $args['event'] = $event;
2300 2509
2301 2510 /**
@@ -2484,9 +2693,9 @@
2484 2693 add_filter( 'the_content', 'FrmFormsController::preview_content', 9999 );
2485 2694 }
2486 2695
2487 2696 $post = $old_post;
2488 - }
2697 + }//end if
2489 2698 }
2490 2699
2491 2700 /**
2492 2701 * @since 3.0
@@ -2507,16 +2716,25 @@
2507 2716 $success_url = apply_filters( 'frm_redirect_url', $success_url, $args['form'], $args );
2508 2717
2509 2718 $doing_ajax = FrmAppHelper::doing_ajax();
2510 2719
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 ) );
2720 + if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) {
2721 + // Is AJAX submit and there is just one Redirect action runs.
2722 + echo json_encode( self::get_ajax_redirect_response_data( $args + compact( 'success_url' ) ) );
2513 2723 wp_die();
2514 2724 }
2515 2725
2516 - if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) ) { // Not AJAX submit, no headers sent, and there is just one Redirect action runs.
2726 + if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) && empty( $args['form']->options['redirect_delay'] ) ) {
2727 + // Not AJAX submit, no headers sent, and there is just one Redirect action runs.
2728 + if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2729 + self::print_open_in_new_tab_js_with_fallback_handler( $success_url, $args );
2730 + self::$redirected_in_new_tab[ $args['form']->id ] = 1;
2731 + return;
2732 + }
2733 +
2517 2734 wp_redirect( esc_url_raw( $success_url ) );
2518 - die(); // do not use wp_die or redirect fails
2735 + // Do not use wp_die or redirect fails.
2736 + die();
2519 2737 }
2520 2738
2521 2739 // Redirect with a delay.
2522 2740 self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) );
@@ -2522,8 +2740,81 @@
2522 2740 self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) );
2523 2741 }
2524 2742
2525 2743 /**
2744 + * Prints open in new tab js with fallback handler.
2745 + *
2746 + * @since 6.3.1
2747 + *
2748 + * @param string $success_url Success URL.
2749 + * @param array $args See {@see FrmFormsController::redirect_after_submit()}.
2750 + */
2751 + private static function print_open_in_new_tab_js_with_fallback_handler( $success_url, $args ) {
2752 + echo '<script>var newTab = window.open("' . esc_url_raw( $success_url ) . '", "_blank");';
2753 + echo 'if ( ! newTab ) {';
2754 +
2755 + $data = array(
2756 + 'formId' => intval( $args['form']->id ),
2757 + 'message' => self::get_redirect_fallback_message( $success_url, $args ),
2758 + );
2759 + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2760 + echo 'frmShowNewTabFallback = ' . FrmAppHelper::maybe_json_encode( $data ) . ';';
2761 + echo '}</script>';
2762 + }
2763 +
2764 + /**
2765 + * Gets response data for redirect action when AJAX submitting.
2766 + *
2767 + * @since 6.3.1
2768 + *
2769 + * @param array $args See {@see FrmFormsController::run_success_action()}.
2770 + * @return array
2771 + */
2772 + private static function get_ajax_redirect_response_data( $args ) {
2773 + $response_data = array(
2774 + 'redirect' => $args['success_url'],
2775 + 'content' => '',
2776 + );
2777 + $unset_content = true;
2778 +
2779 + if ( ! empty( $args['form']->options['redirect_delay'] ) ) {
2780 + $response_data['delay'] = $args['form']->options['redirect_delay_time'];
2781 + $response_data['content'] .= self::get_redirect_message( $args['success_url'], $args['form']->options['redirect_delay_msg'], $args );
2782 + $unset_content = false;
2783 + }
2784 +
2785 + if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2786 + $response_data['openInNewTab'] = 1;
2787 +
2788 + // Only show open in new tab text if there is no delay.
2789 + if ( empty( $response_data['content'] ) ) {
2790 + $args['message'] = FrmOnSubmitHelper::get_default_new_tab_msg();
2791 +
2792 + $args['form']->options['success_msg'] = $args['message'];
2793 + $args['form']->options['edit_msg'] = $args['message'];
2794 + if ( ! isset( $args['fields'] ) ) {
2795 + $args['fields'] = FrmField::get_all_for_form( $args['form']->id );
2796 + }
2797 +
2798 + $args['message'] = self::prepare_submit_message( $args['form'], $args['entry_id'], $args );
2799 +
2800 + ob_start();
2801 + self::show_lone_success_message( $args );
2802 + $response_data['content'] .= ob_get_clean();
2803 + $unset_content = false;
2804 + }//end if
2805 +
2806 + $response_data['fallbackMsg'] = self::get_redirect_fallback_message( $args['success_url'], $args );
2807 + }//end if
2808 +
2809 + if ( $unset_content && '' === $response_data['content'] ) {
2810 + unset( $response_data['content'] );
2811 + }
2812 +
2813 + return $response_data;
2814 + }
2815 +
2816 + /**
2526 2817 * Redirects after submitting using JS. This is used when showing message before redirecting.
2527 2818 *
2528 2819 * @since 6.0
2529 2820 *
@@ -2529,10 +2820,11 @@
2529 2820 *
2530 2821 * @param array $args See {@see FrmFormsController::run_success_action()}.
2531 2822 */
2532 2823 private static function redirect_after_submit_using_js( $args ) {
2533 - $success_msg = FrmOnSubmitHelper::get_default_redirect_msg();
2824 + $success_msg = $args['form']->options['redirect_delay_msg'];
2534 2825 $redirect_msg = self::get_redirect_message( $args['success_url'], $success_msg, $args );
2826 + $success_url = esc_url_raw( $args['success_url'] );
2535 2827
2536 2828 /**
2537 2829 * Filters the delay time before redirecting when On Submit Redirect action is delayed.
2538 2830 *
@@ -2537,20 +2829,27 @@
2537 2829 * Filters the delay time before redirecting when On Submit Redirect action is delayed.
2538 2830 *
2539 2831 * @since 6.0
2540 2832 *
2541 - * @param int $delay_time Delay time in miliseconds.
2833 + * @param int $delay_time Delay time in milliseconds.
2542 2834 */
2543 - $delay_time = apply_filters( 'frm_redirect_delay_time', 8000 );
2835 + $delay_time = apply_filters( 'frm_redirect_delay_time', 1000 * $args['form']->options['redirect_delay_time'] );
2544 2836
2837 + if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2838 + $redirect_js = 'window.open("' . $success_url . '", "_blank")';
2839 + } else {
2840 + $redirect_js = 'window.location="' . $success_url . '";';
2841 + }
2842 +
2545 2843 add_filter( 'frm_use_wpautop', '__return_true' );
2546 2844
2547 2845 echo FrmAppHelper::maybe_kses( $redirect_msg ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2548 2846 echo '<script>';
2549 - if ( empty( $args['doing_ajax'] ) ) { // Not AJAX submit, delay JS until window.load.
2847 + if ( empty( $args['doing_ajax'] ) ) {
2848 + // Not AJAX submit, delay JS until window.load.
2550 2849 echo 'window.onload=function(){';
2551 2850 }
2552 - echo 'setTimeout(function(){window.location="' . esc_url_raw( $args['success_url'] ) . '";}, ' . intval( $delay_time ) . ');';
2851 + echo 'setTimeout(function(){' . $redirect_js . '}, ' . intval( $delay_time ) . ');'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2553 2852 if ( empty( $args['doing_ajax'] ) ) {
2554 2853 echo '};';
2555 2854 }
2556 2855 echo '</script>';
@@ -2560,14 +2859,15 @@
2560 2859 * @since 3.0
2561 2860 *
2562 2861 * @param string $success_url
2563 2862 * @param string $success_msg
2564 - * @param array $args
2863 + * @param array $args
2565 2864 */
2566 2865 private static function get_redirect_message( $success_url, $success_msg, $args ) {
2866 + $success_msg = apply_filters( 'frm_content', $success_msg, $args['form'], $args['entry_id'] );
2867 + $success_msg = do_shortcode( FrmAppHelper::use_wpautop( $success_msg ) );
2567 2868 $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>' ) .
2869 + self::get_redirect_fallback_message( $success_url, $args ) .
2570 2870 '</div></div>';
2571 2871
2572 2872 $redirect_args = array(
2573 2873 'entry_id' => $args['entry_id'],
@@ -2578,8 +2878,31 @@
2578 2878 return apply_filters( 'frm_redirect_msg', $redirect_msg, $redirect_args );
2579 2879 }
2580 2880
2581 2881 /**
2882 + * Gets fallback message when redirecting failed.
2883 + *
2884 + * @since 6.3.1
2885 + *
2886 + * @param string $success_url Redirect URL.
2887 + * @param array $args Contains `form` object.
2888 + * @return string
2889 + */
2890 + private static function get_redirect_fallback_message( $success_url, $args ) {
2891 + $target = '';
2892 + if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2893 + $target = ' target="_blank"';
2894 + }
2895 +
2896 + return sprintf(
2897 + /* translators: %1$s: Start link HTML, %2$s: End link HTML */
2898 + __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ),
2899 + '<a href="' . esc_url( $success_url ) . '"' . $target . '>',
2900 + '</a>'
2901 + );
2902 + }
2903 +
2904 + /**
2582 2905 * Prepare to show the success message and empty form after submit
2583 2906 *
2584 2907 * @since 2.05
2585 2908 */
@@ -2598,9 +2921,9 @@
2598 2921 } else {
2599 2922 self::show_form_after_submit( $atts );
2600 2923 }
2601 2924 } else {
2602 - self::show_lone_success_messsage( $atts );
2925 + self::show_lone_success_message( $atts );
2603 2926 }
2604 2927 }
2605 2928
2606 2929 /**
@@ -2639,11 +2962,10 @@
2639 2962 include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php';
2640 2963 }
2641 2964
2642 2965 /**
2966 + * @since 4.05.02
2643 2967 * @return string - 'before', 'after', or 'submit'
2644 - *
2645 - * @since 4.05.02
2646 2968 */
2647 2969 private static function message_placement( $form, $message ) {
2648 2970 $place = 'before';
2649 2971
@@ -2655,11 +2977,10 @@
2655 2977 }
2656 2978 }
2657 2979
2658 2980 /**
2981 + * @since 4.05.02
2659 2982 * @return string - 'before' or 'after'
2660 - *
2661 - * @since 4.05.02
2662 2983 */
2663 2984 return apply_filters( 'frm_message_placement', $place, compact( 'form', 'message' ) );
2664 2985 }
2665 2986
@@ -2693,9 +3014,9 @@
2693 3014 * Show the success message without the form
2694 3015 *
2695 3016 * @since 2.05
2696 3017 */
2697 - private static function show_lone_success_messsage( $atts ) {
3018 + private static function show_lone_success_message( $atts ) {
2698 3019 global $frm_vars;
2699 3020 $values = FrmEntriesHelper::setup_new_vars( $atts['fields'], $atts['form'], true );
2700 3021 self::maybe_load_css( $atts['form'], $values['custom_style'], $frm_vars['load_css'] );
2701 3022
@@ -2704,9 +3025,9 @@
2704 3025 $errors = array();
2705 3026 $form = $atts['form'];
2706 3027 $message = $atts['message'];
2707 3028
2708 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php' );
3029 + include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php';
2709 3030 }
2710 3031
2711 3032 /**
2712 3033 * Prepare the success message before it's shown
@@ -2826,9 +3147,9 @@
2826 3147 global $frm_vars;
2827 3148
2828 3149 FrmStylesController::enqueue_css();
2829 3150
2830 - if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
3151 + if ( ! FrmAppHelper::is_admin() && $location !== 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
2831 3152 // load formidable js
2832 3153 wp_enqueue_script( 'formidable' );
2833 3154 }
2834 3155 }
@@ -2844,12 +3165,12 @@
2844 3165 }
2845 3166
2846 3167 /**
2847 3168 * @since 2.0.8
2848 - * @return boolean
3169 + * @return bool
2849 3170 */
2850 3171 private static function is_minification_on( $atts ) {
2851 - return isset( $atts['minimize'] ) && ! empty( $atts['minimize'] );
3172 + return ! empty( $atts['minimize'] );
2852 3173 }
2853 3174
2854 3175 /**
2855 3176 * @since 5.0.16
@@ -2877,9 +3198,9 @@
2877 3198 * Create a page with an embedded formidable Gutenberg block.
2878 3199 *
2879 3200 * @since 5.2
2880 3201 *
2881 - * @return never
3202 + * @return void
2882 3203 */
2883 3204 public static function create_page_with_shortcode() {
2884 3205 if ( ! current_user_can( 'publish_posts' ) ) {
2885 3206 die( 0 );
@@ -2924,10 +3245,9 @@
2924 3245
2925 3246 /**
2926 3247 * @since 5.3
2927 3248 *
2928 - * @param string $content
2929 - * @param int $form_id
3249 + * @param int $form_id
2930 3250 * @return string
2931 3251 */
2932 3252 private static function get_page_shortcode_content_for_form( $form_id ) {
2933 3253 $shortcode = '[formidable id="' . $form_id . '"]';
@@ -2938,9 +3258,9 @@
2938 3258
2939 3259 /**
2940 3260 * Get page dropdown for AJAX request for embedding form in an existing page.
2941 3261 *
2942 - * @return never
3262 + * @return void
2943 3263 */
2944 3264 public static function get_page_dropdown() {
2945 3265 if ( ! current_user_can( 'publish_posts' ) ) {
2946 3266 die( 0 );
@@ -2948,9 +3268,9 @@
2948 3268
2949 3269 check_ajax_referer( 'frm_ajax', 'nonce' );
2950 3270
2951 3271 $html = FrmAppHelper::clip(
2952 - function() {
3272 + function () {
2953 3273 FrmAppHelper::maybe_autocomplete_pages_options(
2954 3274 array(
2955 3275 'field_name' => 'frm_page_dropdown',
2956 3276 'page_id' => '',
@@ -2970,15 +3290,8 @@
2970 3290
2971 3291 /**
2972 3292 * @deprecated 4.0
2973 3293 */
2974 - public static function new_form( $values = array() ) {
2975 - FrmDeprecated::new_form( $values );
2976 - }
2977 -
2978 - /**
2979 - * @deprecated 4.0
2980 - */
2981 3294 public static function create( $values = array() ) {
2982 3295 _deprecated_function( __METHOD__, '4.0', 'FrmFormsController::update' );
2983 3296 self::update( $values );
2984 3297 }
@@ -2983,35 +3296,16 @@
2983 3296 self::update( $values );
2984 3297 }
2985 3298
2986 3299 /**
2987 - * @deprecated 3.0
2988 - * @codeCoverageIgnore
3300 + * Education for premium features.
3301 + *
3302 + * @since 4.05
3303 + * @deprecated 6.16.3
3304 + *
3305 + * @return void
2989 3306 */
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' );
3307 + public static function add_form_style_tab_options() {
3308 + _deprecated_function( __METHOD__, '6.16.3' );
3309 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php';
3016 3310 }
3017 3311 }