PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.20
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.20
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 +642 -418 6.5.36.20 View file →
@@ -6,9 +6,9 @@
6 6 class FrmFormsController {
7 7
8 8 /**
9 9 * Track the form that opened the redirect URL in a new tab. This is used to check if we should show the default
10 - * message in the currect tab.
10 + * message in the current tab.
11 11 *
12 12 * @since 6.2
13 13 *
14 14 * @var array Keys are form IDs and values are 1.
@@ -14,8 +14,18 @@
14 14 * @var array Keys are form IDs and values are 1.
15 15 */
16 16 private static $redirected_in_new_tab = array();
17 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 +
18 28 public static function menu() {
19 29 $menu_label = __( 'Forms', 'formidable' );
20 30 if ( ! FrmAppHelper::pro_is_installed() ) {
21 31 $menu_label .= ' (Lite)';
@@ -54,9 +64,9 @@
54 64 */
55 65 public static function logic_tip() {
56 66 $images_url = FrmAppHelper::plugin_url() . '/images/';
57 67 $data_message = __( 'Only show the fields you need and create branching forms. Upgrade to get conditional logic and question branching.', 'formidable' );
58 - $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' ) . '"/>';
59 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">';
60 70 esc_html_e( 'Conditional Logic', 'formidable' );
61 71 FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown6_icon', array( 'aria-hidden' => 'true' ) );
62 72 echo '</a>';
@@ -96,15 +106,23 @@
96 106 * Create the default email action
97 107 *
98 108 * @since 2.02.11
99 109 *
100 - * @param object|int $form
110 + * @param int|object $form
111 + * @return void
101 112 */
102 113 private static function create_default_email_action( $form ) {
103 114 FrmForm::maybe_get_form( $form );
115 + if ( ! is_object( $form ) ) {
116 + return;
117 + }
118 +
104 119 $create_email = apply_filters( 'frm_create_default_email_action', true, $form );
105 120
106 121 if ( $create_email ) {
122 + /**
123 + * @var FrmFormAction
124 + */
107 125 $action_control = FrmFormActionsController::get_form_actions( 'email' );
108 126 $action_control->create( $form->id );
109 127 }
110 128 }
@@ -113,12 +131,16 @@
113 131 * Create the default On submit action
114 132 *
115 133 * @since 6.0.0
116 134 *
117 - * @param object|int $form Form object or ID.
135 + * @param int|object $form Form object or ID.
136 + * @return void
118 137 */
119 138 private static function create_default_on_submit_action( $form ) {
120 139 FrmForm::maybe_get_form( $form );
140 + if ( ! is_object( $form ) ) {
141 + return;
142 + }
121 143
122 144 /**
123 145 * Enable or disable the default On Submit action.
124 146 *
@@ -129,21 +151,65 @@
129 151 */
130 152 $create = apply_filters( 'frm_create_default_on_submit_action', true, $form );
131 153
132 154 if ( $create ) {
155 + /**
156 + * @var FrmFormAction
157 + */
133 158 $action_control = FrmFormActionsController::get_form_actions( FrmOnSubmitAction::$slug );
134 159 $action_control->create( $form->id );
135 160 }
136 161 }
137 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 + */
138 199 public static function edit( $values = false ) {
139 200 FrmAppHelper::permission_check( 'frm_edit_forms' );
140 201
141 202 $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
142 203
143 - return self::get_edit_vars( $id );
204 + self::get_edit_vars( $id );
144 205 }
145 206
207 + /**
208 + * @param mixed $id
209 + * @param string $message
210 + * @return void
211 + */
146 212 public static function settings( $id = false, $message = '' ) {
147 213 FrmAppHelper::permission_check( 'frm_edit_forms' );
148 214
149 215 if ( ! $id || ! is_numeric( $id ) ) {
@@ -151,21 +217,34 @@
151 217 }
152 218
153 219 FrmOnSubmitHelper::maybe_migrate_submit_settings_to_action( $id );
154 220
155 - return self::get_settings_vars( $id, array(), $message );
221 + self::get_settings_vars( $id, array(), $message );
156 222 }
157 223
158 224 public static function update_settings() {
159 225 FrmAppHelper::permission_check( 'frm_edit_forms' );
226 + $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
160 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 +
161 239 $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
162 240
163 - $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
241 + $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
164 242 $warnings = FrmFormsHelper::check_for_warnings( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
165 243
166 244 if ( count( $errors ) > 0 ) {
167 - return self::get_settings_vars( $id, $errors, compact( 'warnings' ) );
245 + self::get_settings_vars( $id, $errors, compact( 'warnings' ) );
246 + return;
168 247 }
169 248
170 249 do_action( 'frm_before_update_form_settings', $id );
171 250
@@ -179,9 +258,9 @@
179 258 }
180 259
181 260 $message = __( 'Settings Successfully Updated', 'formidable' );
182 261
183 - return self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) );
262 + self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) );
184 263 }
185 264
186 265 /**
187 266 * @param int $form_id
@@ -191,8 +270,11 @@
191 270 $form = FrmForm::getOne( $form_id );
192 271 return ! empty( $form->options['antispam'] );
193 272 }
194 273
274 + /**
275 + * @return void
276 + */
195 277 public static function update( $values = array() ) {
196 278 if ( empty( $values ) ) {
197 279 $values = $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing
198 280 }
@@ -210,65 +292,74 @@
210 292
211 293 $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
212 294
213 295 if ( count( $errors ) > 0 ) {
214 - return self::get_edit_vars( $id, $errors );
215 - } else {
216 - FrmForm::update( $id, $values );
217 - $message = __( 'Form was successfully updated.', 'formidable' );
296 + self::get_edit_vars( $id, $errors );
297 + return;
298 + }
218 299
219 - if ( self::is_too_long( $values ) ) {
220 - $message .= '<br/> ' . sprintf(
221 - /* translators: %1$s: Start link HTML, %2$s: end link HTML */
222 - __( 'However, your form is very long and may be %1$sreaching server limits%2$s.', 'formidable' ),
223 - '<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">',
224 - '</a>'
225 - );
226 - }
300 + self::maybe_remove_draft_option_from_fields( $id );
227 301
228 - if ( defined( 'DOING_AJAX' ) ) {
229 - wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
230 - }
302 + FrmForm::update( $id, $values );
303 + $message = __( 'Form was successfully updated.', 'formidable' );
231 304
232 - 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 + );
233 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 );
234 319 }
235 320
236 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 + /**
237 350 * Check if the value at the end of the form was included.
238 351 * If it's missing, it means other values at the end of the form
239 352 * were likely not saved either.
240 353 *
241 354 * @since 3.06.01
355 + *
356 + * @return bool
242 357 */
243 358 private static function is_too_long( $values ) {
244 - return ( ! isset( $values['frm_end'] ) ) || empty( $values['frm_end'] );
359 + return empty( $values['frm_end'] );
245 360 }
246 361
247 - /**
248 - * Redirect to the url for creating from a template
249 - * Also delete the current form
250 - *
251 - * @since 2.0
252 - * @deprecated 3.06
253 - */
254 - public static function _create_from_template() {
255 - _deprecated_function( __FUNCTION__, '3.06' );
256 -
257 - FrmAppHelper::permission_check( 'frm_edit_forms' );
258 - check_ajax_referer( 'frm_ajax', 'nonce' );
259 -
260 - $current_form = FrmAppHelper::get_param( 'this_form', '', 'get', 'absint' );
261 - $template_id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
262 -
263 - if ( $current_form ) {
264 - FrmForm::destroy( $current_form );
265 - }
266 -
267 - echo esc_url_raw( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template_id ) ) );
268 - wp_die();
269 - }
270 -
271 362 public static function duplicate() {
272 363 FrmAppHelper::permission_check( 'frm_edit_forms' );
273 364 $nonce = FrmAppHelper::simple_get( '_wpnonce' );
274 365
@@ -282,10 +373,11 @@
282 373 $url = admin_url( 'admin.php?page=formidable' );
283 374 $message = 'form_duplicate_error';
284 375
285 376 if ( $form ) {
286 - $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) );
287 - $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';
288 380 }
289 381
290 382 $url .= '&message=' . $message;
291 383
@@ -293,27 +385,42 @@
293 385 exit();
294 386 }
295 387
296 388 /**
297 - * @return string
389 + * @return string|null
298 390 */
299 391 public static function page_preview() {
300 392 $params = FrmForm::list_page_params();
301 - if ( ! $params['form'] ) {
302 - return;
393 + if ( ! $params['form'] || is_numeric( $params['form'] ) ) {
394 + return null;
303 395 }
304 396
397 + self::maybe_block_preview( $params['form'] );
398 +
305 399 $form = FrmForm::getOne( $params['form'] );
306 - if ( $form ) {
307 - return self::show_form( $form->id, '', 'auto', 'auto' );
400 + if ( ! $form ) {
401 + return null;
308 402 }
403 +
404 + return self::show_form( $form->id, '', 'auto', 'auto' );
309 405 }
310 406
311 407 /**
312 408 * @since 3.0
409 + *
410 + * @return void
313 411 */
314 412 public static function show_page_preview() {
315 - echo self::page_preview(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
413 + $preview = self::page_preview();
414 + if ( is_null( $preview ) ) {
415 + wp_die(
416 + '<h1>' . esc_html__( 'Form key is invalid', 'formidable' ) . '</h1>',
417 + '<p>' . esc_html__( 'Form key is invalid', 'formidable' ) . '</p>',
418 + 404
419 + );
420 + }
421 +
422 + echo $preview; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
316 423 }
317 424
318 425 /**
319 426 * @return void
@@ -324,8 +431,11 @@
324 431
325 432 global $frm_vars;
326 433 $frm_vars['preview'] = true;
327 434
435 + // print_emoji_styles is deprecated.
436 + remove_action( 'wp_print_styles', 'print_emoji_styles' );
437 +
328 438 $include_theme = FrmAppHelper::get_param( 'theme', '', 'get', 'absint' );
329 439 if ( $include_theme ) {
330 440 self::set_preview_query();
331 441 self::load_theme_preview();
@@ -360,8 +470,13 @@
360 470 return;
361 471 }
362 472
363 473 $random_page = reset( $random_page );
474 + if ( ! is_a( $random_page, 'WP_Post' ) ) {
475 + // The return type can also be int.
476 + return;
477 + }
478 +
364 479 query_posts(
365 480 array(
366 481 'post_type' => 'page',
367 482 'page_id' => $random_page->ID,
@@ -377,9 +492,9 @@
377 492 * Set the WP $post global object. Used for in-theme preview when defining a page.
378 493 *
379 494 * @since 5.5.2
380 495 *
381 - * @param WP_Post $post
496 + * @param WP_Post $page The page object.
382 497 * @return void
383 498 */
384 499 private static function set_post_global( $page ) {
385 500 global $post;
@@ -387,8 +502,10 @@
387 502 }
388 503
389 504 /**
390 505 * @since 3.0
506 + *
507 + * @return void
391 508 */
392 509 private static function load_theme_preview() {
393 510 add_filter( 'wp_title', 'FrmFormsController::preview_title', 9999 );
394 511 add_filter( 'the_title', 'FrmFormsController::preview_page_title', 9999 );
@@ -420,13 +537,16 @@
420 537
421 538 /**
422 539 * Not every theme supports get_template_part( 'page' ).
423 540 * When this is not supported, false is returned, and we can handle a fallback.
541 + *
542 + * @return void
424 543 */
425 544 private static function fallback_when_page_template_part_is_not_supported_by_theme() {
426 545 if ( have_posts() ) {
427 546 the_post();
428 - get_header( '' );
547 + self::get_template( 'header' );
548 +
429 549 // add some generic class names to the container to add some natural padding to the content.
430 550 // .entry-content catches the WordPress TwentyTwenty theme.
431 551 // .container catches Customizr content.
432 552 echo '<div class="container entry-content">';
@@ -431,13 +551,54 @@
431 551 // .container catches Customizr content.
432 552 echo '<div class="container entry-content">';
433 553 the_content();
434 554 echo '</div>';
435 - get_footer();
555 +
556 + self::get_template( 'footer' );
436 557 }
437 558 }
438 559
439 560 /**
561 + * Calls core function to get a template part if it doesn't cause deprecation warnings. Otherwise skips the deprecation function call
562 + * and renders required html fragments calling required functions.
563 + *
564 + * @since 6.7.1
565 + * @param string $template
566 + * @return void
567 + */
568 + private static function get_template( $template ) {
569 + if ( self::should_try_getting_template( $template ) ) {
570 + call_user_func( 'get_' . $template );
571 + return;
572 + }
573 +
574 + if ( 'header' === $template ) {
575 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/header.php';
576 + return;
577 + }
578 +
579 + if ( 'footer' === $template ) {
580 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/footer.php';
581 + }
582 + }
583 +
584 + /**
585 + * Returns true if calling a template function doesn't trigger deprecation warnings.
586 + *
587 + * @since 6.7.1
588 + * @param string $template
589 + * @return bool
590 + */
591 + private static function should_try_getting_template( $template ) {
592 + $stylesheet_path = get_stylesheet_directory();
593 + $template_path = get_template_directory();
594 + $is_child_theme = $stylesheet_path !== $template_path;
595 + $template_name = $template . '.php';
596 +
597 + return file_exists( $stylesheet_path . '/' . $template_name ) || $is_child_theme && file_exists( $template_path . '/' . $template_name );
598 + }
599 +
600 + /**
440 601 * Set the page title for the theme preview page
441 602 *
442 603 * @since 3.0
443 604 */
@@ -449,11 +610,14 @@
449 610 return $title;
450 611 }
451 612
452 613 /**
453 - * Set the page title for the theme preview page
614 + * Set the page title for the theme preview page.
454 615 *
455 616 * @since 3.0
617 + *
618 + * @param string $title
619 + * @return string
456 620 */
457 621 public static function preview_title( $title ) {
458 622 return __( 'Form Preview', 'formidable' );
459 623 }
@@ -458,15 +622,20 @@
458 622 return __( 'Form Preview', 'formidable' );
459 623 }
460 624
461 625 /**
462 - * Set the page content for the theme preview page
626 + * Set the page content for the theme preview page.
463 627 *
464 628 * @since 3.0
629 + *
630 + * @param string $content
631 + * @return string
465 632 */
466 633 public static function preview_content( $content ) {
467 634 if ( in_the_loop() ) {
468 - $content = self::show_page_preview();
635 + self::show_page_preview();
636 + // Clear the content for the page we're using.
637 + $content = '';
469 638 }
470 639
471 640 return $content;
472 641 }
@@ -474,23 +643,88 @@
474 643 /**
475 644 * @since 3.0
476 645 */
477 646 private static function load_direct_preview() {
478 - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
479 -
480 647 $key = FrmAppHelper::simple_get( 'form', 'sanitize_title' );
481 648 if ( $key == '' ) {
482 649 $key = FrmAppHelper::get_post_param( 'form', '', 'sanitize_title' );
483 650 }
484 651
652 + if ( ! $key ) {
653 + $error = __( 'Form key is missing', 'formidable' );
654 + wp_die(
655 + '<h1>' . esc_html( $error ) . '</h1>',
656 + '<p>' . esc_html( $error ) . '</p>',
657 + 404
658 + );
659 + }
660 +
661 + self::maybe_block_preview( $key );
662 +
485 663 $form = FrmForm::getAll( array( 'form_key' => $key ), '', 1 );
486 - if ( empty( $form ) ) {
487 - $form = FrmForm::getAll( array(), '', 1 );
664 + if ( ! $form ) {
665 + $error = __( 'Form does not exist', 'formidable' );
666 + wp_die(
667 + '<h1>' . esc_html( $error ) . '</h1>',
668 + '<p>' . esc_html( $error ) . '</p>',
669 + 404
670 + );
488 671 }
489 672
490 - require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php' );
673 + header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
674 +
675 + self::fix_deprecated_null_param_warning();
676 +
677 + require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php';
491 678 }
492 679
680 + /**
681 + * Block the form preview for the contact form by default if the user cannot view forms.
682 + * This is to prevent the contact form being exploited.
683 + * Since this form is added by default and every site uses the same key, it is too easy
684 + * to guess this form.
685 + *
686 + * @since 6.20
687 + *
688 + * @param string $form_key Form key.
689 + * @return void
690 + */
691 + public static function maybe_block_preview( $form_key ) {
692 + if ( FrmFormsHelper::should_block_preview( $form_key ) ) {
693 + $error = __( 'You do not have permission to view this form', 'formidable' );
694 + wp_die(
695 + '<h1>' . esc_html( $error ) . '</h1>',
696 + '<p>' . esc_html( $error ) . '</p>',
697 + 403
698 + );
699 + }
700 + }
701 +
702 + /**
703 + * Some themes have a null $src value.
704 + * This function adds a filter to ensure that $src is not null.
705 + * WP will call str_starts_with with the null value triggering a deprecated message otherwise.
706 + *
707 + * @since 6.10
708 + *
709 + * @return void
710 + */
711 + private static function fix_deprecated_null_param_warning() {
712 + add_filter(
713 + 'script_loader_src',
714 + /**
715 + * @param string|null $src
716 + * @return string
717 + */
718 + function ( $src ) {
719 + if ( is_null( $src ) ) {
720 + $src = '';
721 + }
722 + return $src;
723 + }
724 + );
725 + }
726 +
493 727 public static function untrash() {
494 728 self::change_form_status( 'untrash' );
495 729 }
496 730
@@ -553,14 +787,14 @@
553 787 FrmAppHelper::permission_check( $available_status[ $status ]['permission'] );
554 788
555 789 $params = FrmForm::list_page_params();
556 790
557 - //check nonce url
791 + // Check nonce url.
558 792 check_admin_referer( $status . '_form_' . $params['id'] );
559 793
560 794 $count = 0;
561 795 if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) {
562 - $count ++;
796 + ++$count;
563 797 }
564 798
565 799 $form_type = FrmAppHelper::get_simple_request(
566 800 array(
@@ -572,9 +806,9 @@
572 806 /* translators: %1$s: Number of forms */
573 807 $available_status['untrash']['message'] = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
574 808
575 809 /* translators: %1$s: Number of forms, %2$s: Start link HTML, %3$s: End link HTML */
576 - $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>' );
810 + $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>' );
577 811
578 812 $message = $available_status[ $status ]['message'];
579 813
580 814 self::display_forms_list( $params, $message );
@@ -579,8 +813,12 @@
579 813
580 814 self::display_forms_list( $params, $message );
581 815 }
582 816
817 + /**
818 + * @param array $ids
819 + * @return string
820 + */
583 821 public static function bulk_trash( $ids ) {
584 822 FrmAppHelper::permission_check( 'frm_delete_forms' );
585 823
586 824 $count = 0;
@@ -585,12 +823,16 @@
585 823
586 824 $count = 0;
587 825 foreach ( $ids as $id ) {
588 826 if ( FrmForm::trash( $id ) ) {
589 - $count ++;
827 + ++$count;
590 828 }
591 829 }
592 830
831 + if ( ! $count ) {
832 + return '';
833 + }
834 +
593 835 $current_page = FrmAppHelper::get_simple_request(
594 836 array(
595 837 'param' => 'form_type',
596 838 'type' => 'request',
@@ -616,9 +858,9 @@
616 858 check_admin_referer( 'destroy_form_' . $params['id'] );
617 859
618 860 $count = 0;
619 861 if ( FrmForm::destroy( $params['id'] ) ) {
620 - $count ++;
862 + ++$count;
621 863 }
622 864
623 865 /* translators: %1$s: Number of forms */
624 866 $message = sprintf( _n( '%1$s Form Permanently Deleted', '%1$s Forms Permanently Deleted', $count, 'formidable' ), $count );
@@ -625,8 +867,12 @@
625 867
626 868 self::display_forms_list( $params, $message );
627 869 }
628 870
871 + /**
872 + * @param array $ids
873 + * @return string
874 + */
629 875 public static function bulk_destroy( $ids ) {
630 876 FrmAppHelper::permission_check( 'frm_delete_forms' );
631 877
632 878 $count = 0;
@@ -632,19 +878,24 @@
632 878 $count = 0;
633 879 foreach ( $ids as $id ) {
634 880 $d = FrmForm::destroy( $id );
635 881 if ( $d ) {
636 - $count ++;
882 + ++$count;
637 883 }
638 884 }
639 885
640 - /* translators: %1$s: Number of forms */
641 - $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
886 + if ( $count ) {
887 + /* translators: %1$s: Number of forms */
888 + return sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
889 + }
642 890
643 - return $message;
891 + return '';
644 892 }
645 893
646 - private static function delete_all() {
894 + /**
895 + * @since 6.7.1 Function went from private to public.
896 + */
897 + public static function delete_all() {
647 898 // Check nonce url.
648 899 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' );
649 900 if ( $permission_error !== false ) {
650 901 self::display_forms_list( array(), '', array( $permission_error ) );
@@ -651,14 +902,15 @@
651 902
652 903 return;
653 904 }
654 905
655 - $count = FrmForm::scheduled_delete( time() );
906 + $count = FrmForm::scheduled_delete( time() );
907 + $url = remove_query_arg( array( 'delete_all' ) );
656 908
657 - /* translators: %1$s: Number of forms */
658 - $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
909 + $url .= '&message=forms_permanently_deleted&forms_deleted=' . $count;
659 910
660 - self::display_forms_list( array(), $message );
911 + wp_safe_redirect( $url );
912 + die();
661 913 }
662 914
663 915 /**
664 916 * Create a new form from the modal.
@@ -671,9 +923,9 @@
671 923
672 924 $new_values = self::get_modal_values();
673 925 $new_values['form_key'] = $new_values['name'];
674 926 $new_values['options'] = array(
675 - 'antispam' => 1,
927 + 'antispam' => 1,
676 928 'on_submit_migrated' => 1,
677 929 );
678 930
679 931 /**
@@ -692,13 +944,14 @@
692 944 * @param int $form_id
693 945 */
694 946 do_action( 'frm_build_new_form', $form_id );
695 947
948 + self::create_submit_button_field( $form_id );
696 949 self::create_default_on_submit_action( $form_id );
697 950 self::create_default_email_action( $form_id );
698 951
699 952 $response = array(
700 - 'redirect' => FrmForm::get_edit_link( $form_id ),
953 + 'redirect' => FrmForm::get_edit_link( $form_id ) . '&new_template=true',
701 954 );
702 955
703 956 echo wp_json_encode( $response );
704 957 wp_die();
@@ -704,46 +957,15 @@
704 957 wp_die();
705 958 }
706 959
707 960 /**
708 - * Create a custom template from a form
709 - *
710 - * @since 3.06
711 - */
712 - public static function build_template() {
713 - global $wpdb;
714 -
715 - FrmAppHelper::permission_check( 'frm_edit_forms' );
716 - check_ajax_referer( 'frm_ajax', 'nonce' );
717 -
718 - $form_id = FrmAppHelper::get_param( 'xml', '', 'post', 'absint' );
719 - $new_form_id = FrmForm::duplicate( $form_id, 1, true );
720 - if ( ! $new_form_id ) {
721 - $response = array(
722 - 'message' => __( 'There was an error creating a template.', 'formidable' ),
723 - );
724 - } else {
725 - $new_values = self::get_modal_values();
726 - $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $new_form_id ) );
727 - if ( $query_results ) {
728 - FrmForm::clear_form_cache();
729 - }
730 -
731 - $response = array(
732 - 'redirect' => admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . $new_form_id ) . '&_wpnonce=' . wp_create_nonce(),
733 - );
734 - }
735 -
736 - echo wp_json_encode( $response );
737 - wp_die();
738 - }
739 -
740 - /**
741 961 * Before creating a new form, get the name and description from the modal.
742 962 *
743 963 * @since 4.0
964 + *
965 + * @return array<string,string>
744 966 */
745 - private static function get_modal_values() {
967 + public static function get_modal_values() {
746 968 $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' );
747 969 $desc = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' );
748 970
749 971 return array(
@@ -756,17 +978,24 @@
756 978 * Inserts Formidable button
757 979 * Hook exists since 2.5.0
758 980 *
759 981 * @since 2.0.15
982 + *
983 + * @return void
760 984 */
761 985 public static function insert_form_button() {
762 986 if ( current_user_can( 'frm_view_forms' ) ) {
763 - FrmAppHelper::load_admin_wide_js();
764 - $menu_name = FrmAppHelper::get_menu_name();
765 - $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() );
766 - 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' ) . '">' .
767 - FrmAppHelper::kses( $icon, 'all' ) . // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
768 - ' ' . esc_html( $menu_name ) . '</a>';
987 + // Store the result in memory and re-use it when this function is called multiple times.
988 + // This helps speed up the form builder when there are a lot of HTML fields, where this
989 + // button is inserted once per HTML field.
990 + // In a form with 66 HTML fields, this saves 0.5 seconds on page load time, tested locally.
991 + if ( ! isset( self::$formidable_tinymce_button ) ) {
992 + FrmAppHelper::load_admin_wide_js();
993 + $menu_name = FrmAppHelper::get_menu_name();
994 + $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() );
995 + 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>';
996 + }
997 + echo self::$formidable_tinymce_button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
769 998 }
770 999 }
771 1000
772 1001 /**
@@ -854,9 +1083,9 @@
854 1083 $form_id = $opts['form_id'];
855 1084 unset( $opts['form_id'] );
856 1085 }
857 1086
858 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php' );
1087 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php';
859 1088
860 1089 echo '</div>';
861 1090
862 1091 wp_die();
@@ -896,8 +1125,14 @@
896 1125 wp_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) );
897 1126 die();
898 1127 }
899 1128
1129 + $inbox = new FrmInbox();
1130 + $error = $inbox->check_for_error();
1131 + if ( $error ) {
1132 + $show_messages = array( $error['subject'] . '. ' . $error['message'] );
1133 + }
1134 +
900 1135 require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/list.php';
901 1136 }
902 1137
903 1138 /**
@@ -924,8 +1159,11 @@
924 1159
925 1160 return $columns;
926 1161 }
927 1162
1163 + /**
1164 + * @return array<string,string>
1165 + */
928 1166 public static function get_sortable_columns() {
929 1167 return array(
930 1168 'id' => 'id',
931 1169 'name' => 'name',
@@ -959,9 +1197,9 @@
959 1197 return $hidden_columns;
960 1198 }
961 1199
962 1200 public static function save_per_page( $save, $option, $value ) {
963 - if ( $option == 'formidable_page_formidable_per_page' ) {
1201 + if ( $option === 'formidable_page_formidable_per_page' ) {
964 1202 $save = (int) $value;
965 1203 }
966 1204
967 1205 return $save;
@@ -967,146 +1205,49 @@
967 1205 return $save;
968 1206 }
969 1207
970 1208 /**
971 - * @return bool
972 - */
973 - public static function expired() {
974 - global $frm_expired;
975 - return $frm_expired;
976 - }
977 -
978 - /**
979 - * Get data from api before rendering it so that we can flag the modal as expired
980 - *
1209 + * @param int|string $id
1210 + * @param array $errors
1211 + * @param string $message
1212 + * @param bool $create_link
981 1213 * @return void
982 1214 */
983 - public static function before_list_templates() {
984 - global $frm_templates;
985 - global $frm_expired;
986 - global $frm_license_type;
1215 + private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
1216 + global $frm_vars;
987 1217
988 - $api = new FrmFormTemplateApi();
989 - $frm_templates = $api->get_api_info();
990 - $expired = false;
991 - $license_type = '';
992 - if ( isset( $frm_templates['error'] ) ) {
993 - $error = $frm_templates['error']['message'];
994 - $error = str_replace( 'utm_medium=addons', 'utm_medium=form-templates', $error );
995 - $expired = 'expired' === $frm_templates['error']['code'];
996 - $license_type = isset( $frm_templates['error']['type'] ) ? $frm_templates['error']['type'] : '';
997 - unset( $frm_templates['error'] );
998 - }
999 -
1000 - $frm_expired = $expired;
1001 - $frm_license_type = $license_type;
1002 - }
1003 -
1004 - /**
1005 - * @return void
1006 - */
1007 - public static function list_templates() {
1008 - global $frm_templates;
1009 - global $frm_license_type;
1010 -
1011 - $templates = $frm_templates;
1012 - $custom_templates = array();
1013 - $templates_by_category = array();
1014 -
1015 - self::add_user_templates( $custom_templates );
1016 -
1017 - foreach ( $templates as $template ) {
1018 - if ( ! isset( $template['categories'] ) ) {
1019 - continue;
1020 - }
1021 -
1022 - foreach ( $template['categories'] as $category ) {
1023 - if ( ! isset( $templates_by_category[ $category ] ) ) {
1024 - $templates_by_category[ $category ] = array();
1025 - }
1026 -
1027 - $templates_by_category[ $category ][] = $template;
1028 - }
1029 - }
1030 - unset( $template );
1031 -
1032 - // Subcategories that are included elsewhere.
1033 - $redundant_cats = array( 'PayPal', 'Stripe', 'Twilio' );
1034 -
1035 - $categories = array_keys( $templates_by_category );
1036 - $categories = array_diff( $categories, FrmFormsHelper::ignore_template_categories() );
1037 - $categories = array_diff( $categories, $redundant_cats );
1038 - sort( $categories );
1039 -
1040 - array_walk(
1041 - $custom_templates,
1042 - function( &$template ) {
1043 - $template['custom'] = true;
1044 - }
1218 + $form = FrmForm::getOne( $id );
1219 + $error_args = array(
1220 + 'title' => __( 'You can\'t edit the form', 'formidable' ),
1221 + 'body' => __( 'You are trying to edit a form that does not exist', 'formidable' ),
1222 + 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
1223 + 'continue_url' => add_query_arg(
1224 + array(
1225 + 'page' => 'formidable',
1226 + )
1227 + ),
1045 1228 );
1046 -
1047 - $my_templates_translation = __( 'My Templates', 'formidable' );
1048 - $categories = array_merge( array( $my_templates_translation ), $categories );
1049 - $pricing = FrmAppHelper::admin_upgrade_link( 'form-templates' );
1050 - $license_type = $frm_license_type;
1051 - $args = compact( 'pricing', 'license_type' );
1052 - $where = apply_filters( 'frm_forms_dropdown', array(), '' );
1053 - $forms = FrmForm::get_published_forms( $where );
1054 - $view_path = FrmAppHelper::plugin_path() . '/classes/views/frm-forms/';
1055 -
1056 - $templates_by_category[ $my_templates_translation ] = $custom_templates;
1057 -
1058 - unset( $pricing, $license_type, $where );
1059 - wp_enqueue_script( 'accordion' ); // register accordion for template groups
1060 - require $view_path . 'list-templates.php';
1061 - }
1062 -
1063 - /**
1064 - * @since 4.03.01
1065 - */
1066 - private static function get_template_categories( $templates ) {
1067 - $categories = array();
1068 - foreach ( $templates as $template ) {
1069 - if ( isset( $template['categories'] ) ) {
1070 - $categories = array_merge( $categories, $template['categories'] );
1071 - }
1229 + if ( ! $form ) {
1230 + FrmAppController::show_error_modal( $error_args );
1231 + return;
1072 1232 }
1073 - $exclude_cats = FrmFormsHelper::ignore_template_categories();
1074 - $categories = array_unique( $categories );
1075 - $categories = array_diff( $categories, $exclude_cats );
1076 - sort( $categories );
1077 - return $categories;
1078 - }
1079 1233
1080 - private static function add_user_templates( &$templates ) {
1081 - $user_templates = array(
1082 - 'is_template' => 1,
1083 - 'default_template' => 0,
1084 - );
1085 - $user_templates = FrmForm::getAll( $user_templates, 'name' );
1086 - foreach ( $user_templates as $template ) {
1087 - $template = array(
1088 - 'id' => $template->id,
1089 - 'name' => $template->name,
1090 - 'key' => $template->form_key,
1091 - 'description' => $template->description,
1092 - 'url' => wp_nonce_url( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template->id ) ) ),
1093 - 'released' => $template->created_at,
1094 - 'installed' => 1,
1234 + if ( 'trash' === $form->status ) {
1235 + $error_args['body'] = __( 'The form you\'re trying to edit is in trash. You must restore it first before you can make changes', 'formidable' );
1236 + $error_args['continue_url'] = add_query_arg(
1237 + array(
1238 + 'page' => 'formidable',
1239 + '_wpnonce' => wp_create_nonce( 'untrash_form_' . $id ),
1240 + 'form_type' => 'trash',
1241 + 'frm_action' => 'untrash',
1242 + 'id' => $id,
1243 + )
1095 1244 );
1096 - array_unshift( $templates, $template );
1097 - unset( $template );
1245 + $error_args['continue_text'] = __( 'Restore form', 'formidable' );
1246 + FrmAppController::show_error_modal( $error_args );
1247 + return;
1098 1248 }
1099 - }
1100 1249
1101 - private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
1102 - global $frm_vars;
1103 -
1104 - $form = FrmForm::getOne( $id );
1105 - if ( ! $form ) {
1106 - wp_die( esc_html__( 'You are trying to edit a form that does not exist.', 'formidable' ) );
1107 - }
1108 -
1109 1250 if ( $form->parent_form_id ) {
1110 1251 /* translators: %1$s: Start link HTML, %2$s: End link HTML */
1111 1252 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>' ) );
1112 1253 }
@@ -1117,8 +1258,9 @@
1117 1258
1118 1259 // Automatically add end section fields if they don't exist (2.0 migration).
1119 1260 $reset_fields = false;
1120 1261 FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields );
1262 + FrmSubmitHelper::maybe_create_submit_field( $form, $fields, $reset_fields );
1121 1263
1122 1264 if ( $reset_fields ) {
1123 1265 $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' );
1124 1266 }
@@ -1144,18 +1286,21 @@
1144 1286 }
1145 1287
1146 1288 self::maybe_update_form_builder_message( $message );
1147 1289
1148 - $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
1149 - $has_fields = isset( $values['fields'] ) && ! empty( $values['fields'] );
1290 + $has_fields = ! empty( $values['fields'] ) && ! FrmSubmitHelper::only_contains_submit_field( $values['fields'] );
1150 1291
1151 1292 if ( defined( 'DOING_AJAX' ) ) {
1152 1293 wp_die();
1153 - } else {
1154 - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' );
1155 1294 }
1295 +
1296 + require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php';
1156 1297 }
1157 1298
1299 + /**
1300 + * @param array $fields
1301 + * @return array
1302 + */
1158 1303 public static function update_form_builder_fields( $fields, $form ) {
1159 1304 foreach ( $fields as $field ) {
1160 1305 $field->do_not_include_icons = true;
1161 1306 }
@@ -1167,13 +1312,21 @@
1167 1312 $message = __( 'Form was Successfully Copied', 'formidable' );
1168 1313 }
1169 1314 }
1170 1315
1316 + /**
1317 + * @param int|string $id
1318 + * @param array $errors
1319 + * @param array|string $args
1320 + * @return void
1321 + */
1171 1322 public static function get_settings_vars( $id, $errors = array(), $args = array() ) {
1172 1323 FrmAppHelper::permission_check( 'frm_edit_forms' );
1173 1324
1174 1325 global $frm_vars;
1175 1326
1327 + self::maybe_print_media_templates();
1328 +
1176 1329 if ( ! is_array( $args ) ) {
1177 1330 // For reverse compatibility.
1178 1331 $args = array(
1179 1332 'message' => $args,
@@ -1206,17 +1359,38 @@
1206 1359
1207 1360 $sections = self::get_settings_tabs( $values );
1208 1361 $current = FrmAppHelper::simple_get( 't', 'sanitize_title', 'advanced_settings' );
1209 1362
1210 - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php' );
1363 + require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php';
1211 1364 }
1212 1365
1213 1366 /**
1367 + * 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.
1368 + *
1369 + * @since 6.10
1370 + *
1371 + * @return void
1372 + */
1373 + private static function maybe_print_media_templates() {
1374 + if ( FrmAppHelper::pro_is_included() ) {
1375 + // This issue does not exist when Pro is active so exit early.
1376 + return;
1377 + }
1378 +
1379 + add_action(
1380 + 'wp_enqueue_editor',
1381 + function () {
1382 + wp_print_media_templates();
1383 + }
1384 + );
1385 + }
1386 +
1387 + /**
1214 1388 * @since 4.0
1215 1389 */
1216 1390 public static function form_publish_button( $atts ) {
1217 1391 $values = $atts['values'];
1218 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php' );
1392 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php';
1219 1393 }
1220 1394
1221 1395 /**
1222 1396 * Get a list of all the settings tabs for the form settings page.
@@ -1241,9 +1415,9 @@
1241 1415 'icon' => 'frm_icon_font frm_mail_bulk_icon',
1242 1416 ),
1243 1417 'permissions' => array(
1244 1418 'name' => __( 'Form Permissions', 'formidable' ),
1245 - 'icon' => 'frm_icon_font frm_lock_icon',
1419 + 'icon' => 'frm_icon_font frm_lock_closed_icon',
1246 1420 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1247 1421 'data' => array(
1248 1422 'medium' => 'permissions',
1249 1423 'upgrade' => __( 'Form Permissions', 'formidable' ),
@@ -1250,9 +1424,9 @@
1250 1424 'message' => __( 'Allow editing, protect forms and files, limit entries, and save drafts. Upgrade to get form and entry permissions.', 'formidable' ),
1251 1425 'screenshot' => 'permissions.png',
1252 1426 ),
1253 1427 ),
1254 - 'scheduling' => array(
1428 + 'scheduling' => array(
1255 1429 'name' => __( 'Form Scheduling', 'formidable' ),
1256 1430 'icon' => 'frm_icon_font frm_calendar_icon',
1257 1431 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1258 1432 'data' => array(
@@ -1285,9 +1459,9 @@
1285 1459 'screenshot' => 'chat.png',
1286 1460 )
1287 1461 ),
1288 1462 ),
1289 - 'abandonment' => array(
1463 + 'abandonment' => array(
1290 1464 'name' => __( 'Form Abandonment', 'formidable' ),
1291 1465 'icon' => 'frm_icon_font frm_abandoned_icon',
1292 1466 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1293 1467 'data' => FrmAppHelper::get_upgrade_data_params(
@@ -1306,8 +1480,12 @@
1306 1480 'icon' => 'frm_icon_font frm_code_icon',
1307 1481 ),
1308 1482 );
1309 1483
1484 + if ( ! has_action( 'frm_add_form_style_tab_options' ) && ! has_action( 'frm_add_form_button_options' ) ) {
1485 + unset( $sections['buttons'] );
1486 + }
1487 +
1310 1488 foreach ( array( 'landing', 'chat', 'abandonment' ) as $feature ) {
1311 1489 if ( ! FrmAppHelper::show_new_feature( $feature ) ) {
1312 1490 unset( $sections[ $feature ] );
1313 1491 }
@@ -1314,13 +1492,8 @@
1314 1492 }
1315 1493
1316 1494 $sections = apply_filters( 'frm_add_form_settings_section', $sections, $values );
1317 1495
1318 - if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) {
1319 - // Prevent settings from showing in 2 spots.
1320 - unset( $sections['permissions'], $sections['scheduling'] );
1321 - }
1322 -
1323 1496 foreach ( $sections as $key => $section ) {
1324 1497 $defaults = array(
1325 1498 'html_class' => '',
1326 1499 'name' => ucfirst( $key ),
@@ -1342,9 +1515,9 @@
1342 1515 $section['id'] = $section['anchor'];
1343 1516 }
1344 1517
1345 1518 $sections[ $key ] = $section;
1346 - }
1519 + }//end foreach
1347 1520
1348 1521 return $sections;
1349 1522 }
1350 1523
@@ -1351,8 +1524,9 @@
1351 1524 /**
1352 1525 * @since 4.0
1353 1526 *
1354 1527 * @param array $values
1528 + * @return void
1355 1529 */
1356 1530 public static function advanced_settings( $values ) {
1357 1531 $first_h3 = 'frm_first_h3';
1358 1532
@@ -1360,8 +1534,9 @@
1360 1534 }
1361 1535
1362 1536 /**
1363 1537 * @param array $values
1538 + * @return void
1364 1539 */
1365 1540 public static function render_spam_settings( $values ) {
1366 1541 if ( function_exists( 'akismet_http_post' ) ) {
1367 1542 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/akismet.php';
@@ -1373,16 +1548,12 @@
1373 1548 /**
1374 1549 * @since 4.0
1375 1550 *
1376 1551 * @param array $values
1552 + * @return void
1377 1553 */
1378 1554 public static function buttons_settings( $values ) {
1379 - $styles = apply_filters( 'frm_get_style_opts', array() );
1380 -
1381 - $frm_settings = FrmAppHelper::get_settings();
1382 - $no_global_style = $frm_settings->load_style === 'none';
1383 -
1384 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php' );
1555 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php';
1385 1556 }
1386 1557
1387 1558 /**
1388 1559 * @since 4.0
@@ -1387,11 +1558,12 @@
1387 1558 /**
1388 1559 * @since 4.0
1389 1560 *
1390 1561 * @param array $values
1562 + * @return void
1391 1563 */
1392 1564 public static function html_settings( $values ) {
1393 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php' );
1565 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php';
1394 1566 }
1395 1567
1396 1568 /**
1397 1569 * Replace old Submit Button href with new href to avoid errors in Chrome
@@ -1397,9 +1569,10 @@
1397 1569 * Replace old Submit Button href with new href to avoid errors in Chrome
1398 1570 *
1399 1571 * @since 2.03.08
1400 1572 *
1401 - * @param array|boolean $values
1573 + * @param array|bool $values
1574 + * @return void
1402 1575 */
1403 1576 private static function clean_submit_html( &$values ) {
1404 1577 if ( is_array( $values ) && isset( $values['submit_html'] ) ) {
1405 1578 $values['submit_html'] = str_replace( 'javascript:void(0)', '#', $values['submit_html'] );
@@ -1420,8 +1593,13 @@
1420 1593
1421 1594 return $classes;
1422 1595 }
1423 1596
1597 + /**
1598 + * @param int|string $form_id
1599 + * @param string $class
1600 + * @return void
1601 + */
1424 1602 public static function mb_tags_box( $form_id, $class = '' ) {
1425 1603 $fields = FrmField::get_all_for_form( $form_id, '', 'include' );
1426 1604
1427 1605 /**
@@ -1434,9 +1612,9 @@
1434 1612 */
1435 1613 $fields = apply_filters( 'frm_fields_in_tags_box', $fields, compact( 'form_id' ) );
1436 1614 $linked_forms = array();
1437 1615 $col = 'one';
1438 - $settings_tab = FrmAppHelper::is_admin_page( 'formidable' ) ? true : false;
1616 + $settings_tab = FrmAppHelper::is_admin_page( 'formidable' );
1439 1617
1440 1618 $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() );
1441 1619 $entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
1442 1620
@@ -1441,9 +1619,9 @@
1441 1619 $entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
1442 1620
1443 1621 $advanced_helpers = self::advanced_helpers( compact( 'fields', 'form_id' ) );
1444 1622
1445 - include( FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php' );
1623 + include FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php';
1446 1624 }
1447 1625
1448 1626 /**
1449 1627 * @since 3.04.01
@@ -1456,9 +1634,9 @@
1456 1634 ),
1457 1635 );
1458 1636
1459 1637 $user_fields = self::user_shortcodes();
1460 - if ( ! empty( $user_fields ) ) {
1638 + if ( $user_fields ) {
1461 1639 $user_helpers = array();
1462 1640 foreach ( $user_fields as $uk => $uf ) {
1463 1641 $user_helpers[ '|user_id| show="' . $uk . '"' ] = $uf;
1464 1642 unset( $uk, $uf );
@@ -1464,9 +1642,9 @@
1464 1642 unset( $uk, $uf );
1465 1643 }
1466 1644
1467 1645 $advanced_helpers['user_id'] = array(
1468 - 'codes' => $user_helpers,
1646 + 'codes' => $user_helpers,
1469 1647 );
1470 1648 }
1471 1649
1472 1650 /**
@@ -1543,21 +1721,16 @@
1543 1721 'updated-at' => __( 'Entry updated', 'formidable' ),
1544 1722 '' => '',
1545 1723 'siteurl' => __( 'Site URL', 'formidable' ),
1546 1724 'sitename' => __( 'Site Name', 'formidable' ),
1725 + 'form_name' => __( 'Form Name', 'formidable' ),
1547 1726 );
1548 1727
1728 + $entry_shortcodes = array_merge( FrmShortcodeHelper::get_contextual_shortcode_values(), $entry_shortcodes );
1549 1729 if ( ! FrmAppHelper::pro_is_installed() ) {
1550 1730 unset( $entry_shortcodes['post_id'] );
1551 1731 }
1552 1732
1553 - if ( $settings_tab ) {
1554 - $entry_shortcodes['default-message'] = __( 'Default Msg', 'formidable' );
1555 - $entry_shortcodes['default-html'] = __( 'Default HTML', 'formidable' );
1556 - $entry_shortcodes['default-plain'] = __( 'Default Plain', 'formidable' );
1557 - $entry_shortcodes['form_name'] = __( 'Form Name', 'formidable' );
1558 - }
1559 -
1560 1733 /**
1561 1734 * Use this hook to add or remove buttons in the helpers section
1562 1735 * in the customization panel
1563 1736 *
@@ -1583,9 +1756,9 @@
1583 1756 echo ' frm_js_validate ';
1584 1757 self::add_js_validate_form_to_global_vars( $form );
1585 1758 }
1586 1759
1587 - if ( ! FrmFormsHelper::should_use_pro_for_ajax_submit() && FrmForm::is_ajax_on( $form ) ) {
1760 + if ( FrmForm::is_ajax_on( $form ) ) {
1588 1761 echo ' frm_ajax_submit ';
1589 1762 }
1590 1763 }
1591 1764
@@ -1607,11 +1780,11 @@
1607 1780 check_ajax_referer( 'frm_ajax', 'nonce' );
1608 1781
1609 1782 echo FrmEntriesController::show_entry_shortcode( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1610 1783 array(
1611 - 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ),
1784 + 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1612 1785 'default_email' => true,
1613 - 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ),
1786 + 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1614 1787 )
1615 1788 );
1616 1789 wp_die();
1617 1790 }
@@ -1617,10 +1790,10 @@
1617 1790 }
1618 1791
1619 1792 /**
1620 1793 * @param string $content
1621 - * @param stdClass|string|int $form
1622 - * @param stdClass|string|int|false $entry
1794 + * @param int|stdClass|string $form
1795 + * @param false|int|stdClass|string $entry
1623 1796 * @return string
1624 1797 */
1625 1798 public static function filter_content( $content, $form, $entry = false ) {
1626 1799 $content = self::replace_form_name_shortcodes( $content, $form );
@@ -1633,8 +1806,16 @@
1633 1806 if ( is_object( $form ) ) {
1634 1807 $form = $form->id;
1635 1808 }
1636 1809
1810 + /*
1811 + * Repeater actions adds `parent_entry` to `$entry` store the parent entry data. If `parent_entry` is not empty,
1812 + * use the parent form ID instead of repeater form ID to fix the parent form field shortcodes doesn't work.
1813 + */
1814 + if ( ! empty( $entry->parent_entry ) ) {
1815 + $form = $entry->parent_entry->form_id;
1816 + }
1817 +
1637 1818 $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form );
1638 1819 $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
1639 1820
1640 1821 return $content;
@@ -1644,11 +1825,11 @@
1644 1825 * Replace any [form_name] shortcodes in a string.
1645 1826 *
1646 1827 * @since 5.5
1647 1828 *
1648 - * @param string|array $string
1649 - * @param stdClass|string|int $form
1650 - * @return string|array
1829 + * @param array|string $string
1830 + * @param int|stdClass|string $form
1831 + * @return array|string
1651 1832 */
1652 1833 public static function replace_form_name_shortcodes( $string, $form ) {
1653 1834 if ( ! is_string( $string ) ) {
1654 1835 return $string;
@@ -1666,9 +1847,9 @@
1666 1847 return str_replace( '[form_name]', $form_name, $string );
1667 1848 }
1668 1849
1669 1850 /**
1670 - * @param stdClass|string|int|false $entry
1851 + * @param false|int|stdClass|string $entry
1671 1852 * @return void
1672 1853 */
1673 1854 private static function get_entry_by_param( &$entry ) {
1674 1855 if ( ! $entry || ! is_object( $entry ) ) {
@@ -1683,8 +1864,12 @@
1683 1864 public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
1684 1865 return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes );
1685 1866 }
1686 1867
1868 + /**
1869 + * @param array $errors
1870 + * @return array
1871 + */
1687 1872 public static function process_bulk_form_actions( $errors ) {
1688 1873 if ( ! $_REQUEST ) {
1689 1874 return $errors;
1690 1875 }
@@ -1728,9 +1913,9 @@
1728 1913 case 'untrash':
1729 1914 $message = self::bulk_untrash( $ids );
1730 1915 }
1731 1916
1732 - if ( isset( $message ) && ! empty( $message ) ) {
1917 + if ( ! empty( $message ) ) {
1733 1918 $errors['message'] = $message;
1734 1919 }
1735 1920
1736 1921 return $errors;
@@ -1735,13 +1920,26 @@
1735 1920
1736 1921 return $errors;
1737 1922 }
1738 1923
1924 + /**
1925 + * Includes html that shows a message when the device is too small to use Formidable Forms admin pages.
1926 + *
1927 + * @since 6.20
1928 + * @return void
1929 + */
1930 + public static function include_device_too_small_message() {
1931 + if ( ! FrmAppHelper::is_formidable_admin() ) {
1932 + return;
1933 + }
1934 +
1935 + include FrmAppHelper::plugin_path() . '/classes/views/shared/small-device-message.php';
1936 + }
1937 +
1739 1938 public static function route() {
1740 1939 $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
1741 1940 $vars = array();
1742 1941 FrmAppHelper::include_svg();
1743 -
1744 1942 if ( isset( $_POST['frm_compact_fields'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
1745 1943 FrmAppHelper::permission_check( 'frm_edit_forms' );
1746 1944
1747 1945 // Javascript needs to be allowed in some field settings.
@@ -1750,9 +1948,9 @@
1750 1948 $json_vars = json_decode( $json_vars, true );
1751 1949 if ( empty( $json_vars ) ) {
1752 1950 // json decoding failed so we should return an error message.
1753 1951 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
1754 - if ( 'edit' == $action ) {
1952 + if ( 'edit' === $action ) {
1755 1953 $action = 'update';
1756 1954 }
1757 1955
1758 1956 add_filter( 'frm_validate_form', 'FrmFormsController::json_error' );
@@ -1768,16 +1966,14 @@
1768 1966 if ( isset( $_REQUEST['delete_all'] ) ) {
1769 1967 // Override the action for this page.
1770 1968 $action = 'delete_all';
1771 1969 }
1772 - }
1970 + }//end if
1773 1971
1774 1972 add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
1775 1973 FrmAppHelper::trigger_hook_load( 'form' );
1776 1974
1777 1975 switch ( $action ) {
1778 - case 'new':
1779 - return self::new_form( $vars );
1780 1976 case 'create':
1781 1977 case 'edit':
1782 1978 case 'update':
1783 1979 case 'trash':
@@ -1782,16 +1978,17 @@
1782 1978 case 'update':
1783 1979 case 'trash':
1784 1980 case 'untrash':
1785 1981 case 'destroy':
1786 - case 'delete_all':
1787 1982 case 'settings':
1788 1983 case 'update_settings':
1789 1984 return self::$action( $vars );
1790 1985 case 'lite-reports':
1791 - return self::no_reports( $vars );
1986 + self::no_reports( $vars );
1987 + return;
1792 1988 case 'views':
1793 - return self::no_views( $vars );
1989 + self::no_views( $vars );
1990 + return;
1794 1991 default:
1795 1992 do_action( 'frm_form_action_' . $action );
1796 1993 if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) {
1797 1994 return;
@@ -1814,14 +2011,47 @@
1814 2011 self::display_forms_list( array(), '', array( __( 'There was a problem duplicating the form', 'formidable' ) ) );
1815 2012 return;
1816 2013 }
1817 2014
2015 + if ( 'forms_permanently_deleted' === $message ) {
2016 + $count = FrmAppHelper::get_param( 'forms_deleted', 0, 'get', 'absint' );
2017 + /* translators: %1$s: Number of forms */
2018 + $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
2019 + self::display_forms_list( array(), $message, '' );
2020 + return;
2021 + }
2022 +
1818 2023 self::display_forms_list();
1819 2024
1820 2025 return;
1821 - }
2026 + }//end switch
1822 2027 }
1823 2028
2029 + /**
2030 + * Rename a form.
2031 + *
2032 + * Handles the AJAX request for renaming a form.
2033 + *
2034 + * @since 6.7
2035 + *
2036 + * @return void
2037 + */
2038 + public static function rename_form() {
2039 + // Check permission and nonce
2040 + FrmAppHelper::permission_check( 'frm_edit_forms' );
2041 + check_ajax_referer( 'frm_ajax', 'nonce' );
2042 +
2043 + // Get posted data
2044 + $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
2045 + $name = FrmAppHelper::get_post_param( 'form_name', '', 'sanitize_text_field' );
2046 +
2047 + // Update the form name and form key.
2048 + $form_key = FrmAppHelper::get_unique_key( sanitize_title( $name ), 'frm_forms', 'form_key' );
2049 + FrmForm::update( $form_id, compact( 'name', 'form_key' ) );
2050 +
2051 + wp_send_json_success( compact( 'form_key' ) );
2052 + }
2053 +
1824 2054 public static function json_error( $errors ) {
1825 2055 $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
1826 2056
1827 2057 return $errors;
@@ -1827,20 +2057,13 @@
1827 2057 return $errors;
1828 2058 }
1829 2059
1830 2060 /**
1831 - * Education for premium features.
1832 - *
1833 - * @since 4.05
1834 - */
1835 - public static function add_form_style_tab_options() {
1836 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php' );
1837 - }
1838 -
1839 - /**
1840 2061 * Add education about views.
1841 2062 *
1842 2063 * @since 4.07
2064 + *
2065 + * @return void
1843 2066 */
1844 2067 public static function no_views( $values = array() ) {
1845 2068 FrmAppHelper::include_svg();
1846 2069 $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
@@ -1852,8 +2075,10 @@
1852 2075 /**
1853 2076 * Add education about reports.
1854 2077 *
1855 2078 * @since 4.07
2079 + *
2080 + * @return void
1856 2081 */
1857 2082 public static function no_reports( $values = array() ) {
1858 2083 $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
1859 2084 $form = $id ? FrmForm::getOne( $id ) : false;
@@ -1860,9 +2085,11 @@
1860 2085
1861 2086 include FrmAppHelper::plugin_path() . '/classes/views/shared/reports-info.php';
1862 2087 }
1863 2088
1864 - /* FRONT-END FORMS */
2089 + /**
2090 + * FRONT-END FORMS.
2091 + */
1865 2092 public static function admin_bar_css() {
1866 2093 if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
1867 2094 return;
1868 2095 }
@@ -1936,9 +2163,9 @@
1936 2163 $wp_admin_bar->add_node(
1937 2164 array(
1938 2165 'parent' => 'frm-forms',
1939 2166 'id' => 'edit_form_' . $form_id,
1940 - 'title' => empty( $name ) ? __( '(no title)', 'formidable' ) : $name,
2167 + 'title' => empty( $name ) ? FrmFormsHelper::get_no_title_text() : $name,
1941 2168 'href' => FrmForm::get_edit_link( $form_id ),
1942 2169 )
1943 2170 );
1944 2171 }
@@ -1951,10 +2178,10 @@
1951 2178 * @return string
1952 2179 */
1953 2180 public static function get_form_shortcode( $atts ) {
1954 2181 global $frm_vars;
1955 - if ( isset( $frm_vars['skip_shortcode'] ) && $frm_vars['skip_shortcode'] ) {
1956 - $sc = '[formidable';
2182 + if ( ! empty( $frm_vars['skip_shortcode'] ) ) {
2183 + $sc = '[formidable';
1957 2184 $sc .= FrmAppHelper::array_to_html_params( $atts );
1958 2185 return $sc . ']';
1959 2186 }
1960 2187
@@ -1979,11 +2206,11 @@
1979 2206
1980 2207 /**
1981 2208 * @since 5.2.01
1982 2209 *
1983 - * @param string|int|false $id
1984 - * @param string|false $key
1985 - * @return stdClass|false
2210 + * @param false|int|string $id
2211 + * @param false|string $key
2212 + * @return false|stdClass
1986 2213 */
1987 2214 private static function maybe_get_form_by_id_or_key( $id, $key ) {
1988 2215 if ( ! $id ) {
1989 2216 $id = $key;
@@ -1991,12 +2218,12 @@
1991 2218 return self::maybe_get_form_to_show( $id );
1992 2219 }
1993 2220
1994 2221 /**
1995 - * @param string|int|false $id
1996 - * @param string|false $key
1997 - * @param string|int|bool $title may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
1998 - * @param string|int|bool $description may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
2222 + * @param false|int|string $id
2223 + * @param false|string $key
2224 + * @param bool|int|string $title may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
2225 + * @param bool|int|string $description may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
1999 2226 * @param array $atts
2000 2227 * @return string
2001 2228 */
2002 2229 public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) {
@@ -2044,15 +2271,16 @@
2044 2271 return $form;
2045 2272 }
2046 2273
2047 2274 /**
2048 - * @param string|int|false $id
2049 - * @return stdClass|false
2275 + * @param false|int|string $id
2276 + * @return false|stdClass
2050 2277 */
2051 2278 private static function maybe_get_form_to_show( $id ) {
2052 2279 $form = false;
2053 2280
2054 - if ( ! empty( $id ) ) { // form id or key is set
2281 + if ( ! empty( $id ) ) {
2282 + // Form id or key is set.
2055 2283 $form = FrmForm::getOne( $id );
2056 2284 if ( ! $form || $form->parent_form_id || $form->status === 'trash' ) {
2057 2285 $form = false;
2058 2286 }
@@ -2110,11 +2338,11 @@
2110 2338
2111 2339 do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description );
2112 2340
2113 2341 if ( apply_filters( 'frm_continue_to_create', true, $form->id ) ) {
2114 - $entry_id = self::just_created_entry( $form->id );
2115 - $pass_args['entry_id'] = $entry_id;
2116 - $pass_args['reset'] = true;
2342 + $entry_id = self::just_created_entry( $form->id );
2343 + $pass_args['entry_id'] = $entry_id;
2344 + $pass_args['reset'] = true;
2117 2345
2118 2346 self::run_on_submit_actions( $pass_args );
2119 2347
2120 2348 do_action(
@@ -2124,9 +2352,9 @@
2124 2352 'form' => $form,
2125 2353 )
2126 2354 );
2127 2355 }
2128 - }
2356 + }//end if
2129 2357 }
2130 2358
2131 2359 /**
2132 2360 * If the form was processed earlier (init), get the generated errors
@@ -2158,9 +2386,9 @@
2158 2386 */
2159 2387 public static function just_created_entry( $form_id ) {
2160 2388 global $frm_vars;
2161 2389
2162 - 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;
2390 + 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;
2163 2391 }
2164 2392
2165 2393 /**
2166 2394 * Gets confirmation method.
@@ -2173,14 +2401,14 @@
2173 2401 *
2174 2402 * @type object $form Form object.
2175 2403 * @type int $entry_id Entry ID.
2176 2404 * }
2177 - * @return string|array
2405 + * @return array|string
2178 2406 */
2179 2407 private static function get_confirmation_method( $atts ) {
2180 2408 $action = FrmOnSubmitHelper::current_event( $atts );
2181 2409 $opt = 'update' === $action ? 'edit_action' : 'success_action';
2182 - $method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message';
2410 + $method = ! empty( $atts['form']->options[ $opt ] ) ? $atts['form']->options[ $opt ] : 'message';
2183 2411
2184 2412 if ( ! empty( $atts['entry_id'] ) ) {
2185 2413 $met_actions = self::get_met_on_submit_actions( $atts, $action );
2186 2414 if ( $met_actions ) {
@@ -2189,9 +2417,9 @@
2189 2417 }
2190 2418
2191 2419 $method = apply_filters( 'frm_success_filter', $method, $atts['form'], $action );
2192 2420
2193 - if ( $method != 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
2421 + if ( $method !== 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
2194 2422 $method = 'message';
2195 2423 }
2196 2424
2197 2425 return $method;
@@ -2225,9 +2453,9 @@
2225 2453 * @param array $args See {@see FrmFormsController::maybe_trigger_redirect()}.
2226 2454 */
2227 2455 public static function maybe_trigger_redirect_with_action( $conf_method, $form, $params, $args ) {
2228 2456 if ( is_array( $conf_method ) && 1 === count( $conf_method ) ) {
2229 - if ( 'redirect' === FrmOnSubmitHelper::get_action_type( $conf_method[0] ) ) {
2457 + if ( 'redirect' === FrmOnSubmitHelper::get_action_type( $conf_method[0] ) && empty( $conf_method[0]->post_content['redirect_delay'] ) ) {
2230 2458 $event = FrmOnSubmitHelper::current_event( $params );
2231 2459 FrmOnSubmitHelper::populate_on_submit_data( $form->options, $conf_method[0], $event );
2232 2460 $conf_method = 'redirect';
2233 2461 }
@@ -2276,9 +2504,9 @@
2276 2504 unset( $extra_args['form'] );
2277 2505
2278 2506 do_action( 'frm_success_action', $args['conf_method'], $args['form'], $args['form']->options, $args['entry_id'], $extra_args );
2279 2507
2280 - $opt = ( ! isset( $args['action'] ) || $args['action'] === 'create' ) ? 'success' : 'edit';
2508 + $opt = ! isset( $args['action'] ) || $args['action'] === 'create' ? 'success' : 'edit';
2281 2509
2282 2510 $args['success_opt'] = $opt;
2283 2511 $args['ajax'] = ! empty( $frm_vars['ajax'] );
2284 2512
@@ -2304,16 +2532,16 @@
2304 2532 if ( ! FrmOnSubmitHelper::form_has_migrated( $args['form'] ) ) {
2305 2533 return array();
2306 2534 }
2307 2535
2308 - // If a redirect action has already opened the URL in a new tab, we show the default message in the currect tab.
2536 + // If a redirect action has already opened the URL in a new tab, we show the default message in the current tab.
2309 2537 if ( ! empty( self::$redirected_in_new_tab[ $args['form']->id ] ) ) {
2310 2538 return array( FrmOnSubmitHelper::get_fallback_action_after_open_in_new_tab( $event ) );
2311 2539 }
2312 2540
2313 - $entry = FrmEntry::getOne( $args['entry_id'], true );
2314 - $actions = FrmOnSubmitHelper::get_actions( $args['form']->id );
2315 - $met_actions = array();
2541 + $entry = FrmEntry::getOne( $args['entry_id'], true );
2542 + $actions = FrmOnSubmitHelper::get_actions( $args['form']->id );
2543 + $met_actions = array();
2316 2544 $has_redirect = false;
2317 2545
2318 2546 foreach ( $actions as $action ) {
2319 2547 if ( ! in_array( $event, $action->post_content['event'], true ) ) {
@@ -2326,9 +2554,10 @@
2326 2554
2327 2555 $action_type = FrmOnSubmitHelper::get_action_type( $action );
2328 2556
2329 2557 if ( 'redirect' === $action_type ) {
2330 - if ( $has_redirect ) { // Do not process because we run the first redirect action only.
2558 + if ( $has_redirect ) {
2559 + // Do not process because we run the first redirect action only.
2331 2560 continue;
2332 2561 }
2333 2562 }
2334 2563
@@ -2341,9 +2570,9 @@
2341 2570 }
2342 2571
2343 2572 $met_actions[] = $action;
2344 2573 unset( $action );
2345 - }
2574 + }//end foreach
2346 2575
2347 2576 $args['event'] = $event;
2348 2577
2349 2578 /**
@@ -2532,9 +2761,9 @@
2532 2761 add_filter( 'the_content', 'FrmFormsController::preview_content', 9999 );
2533 2762 }
2534 2763
2535 2764 $post = $old_post;
2536 - }
2765 + }//end if
2537 2766 }
2538 2767
2539 2768 /**
2540 2769 * @since 3.0
@@ -2555,14 +2784,16 @@
2555 2784 $success_url = apply_filters( 'frm_redirect_url', $success_url, $args['form'], $args );
2556 2785
2557 2786 $doing_ajax = FrmAppHelper::doing_ajax();
2558 2787
2559 - if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) { // Is AJAX submit and there is just one Redirect action runs.
2788 + if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) {
2789 + // Is AJAX submit and there is just one Redirect action runs.
2560 2790 echo json_encode( self::get_ajax_redirect_response_data( $args + compact( 'success_url' ) ) );
2561 2791 wp_die();
2562 2792 }
2563 2793
2564 - if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) ) { // Not AJAX submit, no headers sent, and there is just one Redirect action runs.
2794 + if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) && empty( $args['form']->options['redirect_delay'] ) ) {
2795 + // Not AJAX submit, no headers sent, and there is just one Redirect action runs.
2565 2796 if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2566 2797 self::print_open_in_new_tab_js_with_fallback_handler( $success_url, $args );
2567 2798 self::$redirected_in_new_tab[ $args['form']->id ] = 1;
2568 2799 return;
@@ -2568,9 +2799,10 @@
2568 2799 return;
2569 2800 }
2570 2801
2571 2802 wp_redirect( esc_url_raw( $success_url ) );
2572 - die(); // do not use wp_die or redirect fails
2803 + // Do not use wp_die or redirect fails.
2804 + die();
2573 2805 }
2574 2806
2575 2807 // Redirect with a delay.
2576 2808 self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) );
@@ -2605,28 +2837,46 @@
2605 2837 * @param array $args See {@see FrmFormsController::run_success_action()}.
2606 2838 * @return array
2607 2839 */
2608 2840 private static function get_ajax_redirect_response_data( $args ) {
2609 - $response_data = array( 'redirect' => $args['success_url'] );
2841 + $response_data = array(
2842 + 'redirect' => $args['success_url'],
2843 + 'content' => '',
2844 + );
2845 + $unset_content = true;
2610 2846
2847 + if ( ! empty( $args['form']->options['redirect_delay'] ) ) {
2848 + $response_data['delay'] = $args['form']->options['redirect_delay_time'];
2849 + $response_data['content'] .= self::get_redirect_message( $args['success_url'], $args['form']->options['redirect_delay_msg'], $args );
2850 + $unset_content = false;
2851 + }
2852 +
2611 2853 if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2612 2854 $response_data['openInNewTab'] = 1;
2613 2855
2614 - $args['message'] = FrmOnSubmitHelper::get_default_new_tab_msg();
2856 + // Only show open in new tab text if there is no delay.
2857 + if ( empty( $response_data['content'] ) ) {
2858 + $args['message'] = FrmOnSubmitHelper::get_default_new_tab_msg();
2615 2859
2616 - $args['form']->options['success_msg'] = $args['message'];
2617 - $args['form']->options['edit_msg'] = $args['message'];
2618 - if ( ! isset( $args['fields'] ) ) {
2619 - $args['fields'] = FrmField::get_all_for_form( $args['form']->id );
2620 - }
2860 + $args['form']->options['success_msg'] = $args['message'];
2861 + $args['form']->options['edit_msg'] = $args['message'];
2862 + if ( ! isset( $args['fields'] ) ) {
2863 + $args['fields'] = FrmField::get_all_for_form( $args['form']->id );
2864 + }
2621 2865
2622 - $args['message'] = self::prepare_submit_message( $args['form'], $args['entry_id'], $args );
2866 + $args['message'] = self::prepare_submit_message( $args['form'], $args['entry_id'], $args );
2623 2867
2624 - ob_start();
2625 - self::show_lone_success_messsage( $args );
2626 - $response_data['content'] = ob_get_clean();
2868 + ob_start();
2869 + self::show_lone_success_message( $args );
2870 + $response_data['content'] .= ob_get_clean();
2871 + $unset_content = false;
2872 + }//end if
2627 2873
2628 2874 $response_data['fallbackMsg'] = self::get_redirect_fallback_message( $args['success_url'], $args );
2875 + }//end if
2876 +
2877 + if ( $unset_content && '' === $response_data['content'] ) {
2878 + unset( $response_data['content'] );
2629 2879 }
2630 2880
2631 2881 return $response_data;
2632 2882 }
@@ -2638,9 +2888,9 @@
2638 2888 *
2639 2889 * @param array $args See {@see FrmFormsController::run_success_action()}.
2640 2890 */
2641 2891 private static function redirect_after_submit_using_js( $args ) {
2642 - $success_msg = FrmOnSubmitHelper::get_default_redirect_msg();
2892 + $success_msg = $args['form']->options['redirect_delay_msg'];
2643 2893 $redirect_msg = self::get_redirect_message( $args['success_url'], $success_msg, $args );
2644 2894 $success_url = esc_url_raw( $args['success_url'] );
2645 2895
2646 2896 /**
@@ -2647,11 +2897,11 @@
2647 2897 * Filters the delay time before redirecting when On Submit Redirect action is delayed.
2648 2898 *
2649 2899 * @since 6.0
2650 2900 *
2651 - * @param int $delay_time Delay time in miliseconds.
2901 + * @param int $delay_time Delay time in milliseconds.
2652 2902 */
2653 - $delay_time = apply_filters( 'frm_redirect_delay_time', 8000 );
2903 + $delay_time = apply_filters( 'frm_redirect_delay_time', 1000 * $args['form']->options['redirect_delay_time'] );
2654 2904
2655 2905 if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2656 2906 $redirect_js = 'window.open("' . $success_url . '", "_blank")';
2657 2907 } else {
@@ -2661,9 +2911,10 @@
2661 2911 add_filter( 'frm_use_wpautop', '__return_true' );
2662 2912
2663 2913 echo FrmAppHelper::maybe_kses( $redirect_msg ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2664 2914 echo '<script>';
2665 - if ( empty( $args['doing_ajax'] ) ) { // Not AJAX submit, delay JS until window.load.
2915 + if ( empty( $args['doing_ajax'] ) ) {
2916 + // Not AJAX submit, delay JS until window.load.
2666 2917 echo 'window.onload=function(){';
2667 2918 }
2668 2919 echo 'setTimeout(function(){' . $redirect_js . '}, ' . intval( $delay_time ) . ');'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2669 2920 if ( empty( $args['doing_ajax'] ) ) {
@@ -2676,11 +2927,13 @@
2676 2927 * @since 3.0
2677 2928 *
2678 2929 * @param string $success_url
2679 2930 * @param string $success_msg
2680 - * @param array $args
2931 + * @param array $args
2681 2932 */
2682 2933 private static function get_redirect_message( $success_url, $success_msg, $args ) {
2934 + $success_msg = apply_filters( 'frm_content', $success_msg, $args['form'], $args['entry_id'] );
2935 + $success_msg = do_shortcode( FrmAppHelper::use_wpautop( $success_msg ) );
2683 2936 $redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg" role="status">' . $success_msg . '<br/>' .
2684 2937 self::get_redirect_fallback_message( $success_url, $args ) .
2685 2938 '</div></div>';
2686 2939
@@ -2736,9 +2989,9 @@
2736 2989 } else {
2737 2990 self::show_form_after_submit( $atts );
2738 2991 }
2739 2992 } else {
2740 - self::show_lone_success_messsage( $atts );
2993 + self::show_lone_success_message( $atts );
2741 2994 }
2742 2995 }
2743 2996
2744 2997 /**
@@ -2777,11 +3030,10 @@
2777 3030 include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php';
2778 3031 }
2779 3032
2780 3033 /**
3034 + * @since 4.05.02
2781 3035 * @return string - 'before', 'after', or 'submit'
2782 - *
2783 - * @since 4.05.02
2784 3036 */
2785 3037 private static function message_placement( $form, $message ) {
2786 3038 $place = 'before';
2787 3039
@@ -2793,11 +3045,10 @@
2793 3045 }
2794 3046 }
2795 3047
2796 3048 /**
3049 + * @since 4.05.02
2797 3050 * @return string - 'before' or 'after'
2798 - *
2799 - * @since 4.05.02
2800 3051 */
2801 3052 return apply_filters( 'frm_message_placement', $place, compact( 'form', 'message' ) );
2802 3053 }
2803 3054
@@ -2831,9 +3082,9 @@
2831 3082 * Show the success message without the form
2832 3083 *
2833 3084 * @since 2.05
2834 3085 */
2835 - private static function show_lone_success_messsage( $atts ) {
3086 + private static function show_lone_success_message( $atts ) {
2836 3087 global $frm_vars;
2837 3088 $values = FrmEntriesHelper::setup_new_vars( $atts['fields'], $atts['form'], true );
2838 3089 self::maybe_load_css( $atts['form'], $values['custom_style'], $frm_vars['load_css'] );
2839 3090
@@ -2842,9 +3093,9 @@
2842 3093 $errors = array();
2843 3094 $form = $atts['form'];
2844 3095 $message = $atts['message'];
2845 3096
2846 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php' );
3097 + include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php';
2847 3098 }
2848 3099
2849 3100 /**
2850 3101 * Prepare the success message before it's shown
@@ -2964,9 +3215,9 @@
2964 3215 global $frm_vars;
2965 3216
2966 3217 FrmStylesController::enqueue_css();
2967 3218
2968 - if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
3219 + if ( ! FrmAppHelper::is_admin() && $location !== 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
2969 3220 // load formidable js
2970 3221 wp_enqueue_script( 'formidable' );
2971 3222 }
2972 3223 }
@@ -2982,12 +3233,12 @@
2982 3233 }
2983 3234
2984 3235 /**
2985 3236 * @since 2.0.8
2986 - * @return boolean
3237 + * @return bool
2987 3238 */
2988 3239 private static function is_minification_on( $atts ) {
2989 - return isset( $atts['minimize'] ) && ! empty( $atts['minimize'] );
3240 + return ! empty( $atts['minimize'] );
2990 3241 }
2991 3242
2992 3243 /**
2993 3244 * @since 5.0.16
@@ -3015,9 +3266,9 @@
3015 3266 * Create a page with an embedded formidable Gutenberg block.
3016 3267 *
3017 3268 * @since 5.2
3018 3269 *
3019 - * @return never
3270 + * @return void
3020 3271 */
3021 3272 public static function create_page_with_shortcode() {
3022 3273 if ( ! current_user_can( 'publish_posts' ) ) {
3023 3274 die( 0 );
@@ -3062,10 +3313,9 @@
3062 3313
3063 3314 /**
3064 3315 * @since 5.3
3065 3316 *
3066 - * @param string $content
3067 - * @param int $form_id
3317 + * @param int $form_id
3068 3318 * @return string
3069 3319 */
3070 3320 private static function get_page_shortcode_content_for_form( $form_id ) {
3071 3321 $shortcode = '[formidable id="' . $form_id . '"]';
@@ -3076,9 +3326,9 @@
3076 3326
3077 3327 /**
3078 3328 * Get page dropdown for AJAX request for embedding form in an existing page.
3079 3329 *
3080 - * @return never
3330 + * @return void
3081 3331 */
3082 3332 public static function get_page_dropdown() {
3083 3333 if ( ! current_user_can( 'publish_posts' ) ) {
3084 3334 die( 0 );
@@ -3086,9 +3336,9 @@
3086 3336
3087 3337 check_ajax_referer( 'frm_ajax', 'nonce' );
3088 3338
3089 3339 $html = FrmAppHelper::clip(
3090 - function() {
3340 + function () {
3091 3341 FrmAppHelper::maybe_autocomplete_pages_options(
3092 3342 array(
3093 3343 'field_name' => 'frm_page_dropdown',
3094 3344 'page_id' => '',
@@ -3108,15 +3358,8 @@
3108 3358
3109 3359 /**
3110 3360 * @deprecated 4.0
3111 3361 */
3112 - public static function new_form( $values = array() ) {
3113 - FrmDeprecated::new_form( $values );
3114 - }
3115 -
3116 - /**
3117 - * @deprecated 4.0
3118 - */
3119 3362 public static function create( $values = array() ) {
3120 3363 _deprecated_function( __METHOD__, '4.0', 'FrmFormsController::update' );
3121 3364 self::update( $values );
3122 3365 }
@@ -3121,35 +3364,16 @@
3121 3364 self::update( $values );
3122 3365 }
3123 3366
3124 3367 /**
3125 - * @deprecated 3.0
3126 - * @codeCoverageIgnore
3368 + * Education for premium features.
3369 + *
3370 + * @since 4.05
3371 + * @deprecated 6.16.3
3372 + *
3373 + * @return void
3127 3374 */
3128 - public static function bulk_create_template( $ids ) {
3129 - return FrmDeprecated::bulk_create_template( $ids );
3130 - }
3131 -
3132 - /**
3133 - * @deprecated 3.0
3134 - * @codeCoverageIgnore
3135 - */
3136 - public static function edit_key() {
3137 - FrmDeprecated::edit_key();
3138 - }
3139 -
3140 - /**
3141 - * @deprecated 3.0
3142 - * @codeCoverageIgnore
3143 - */
3144 - public static function edit_description() {
3145 - FrmDeprecated::edit_description();
3146 - }
3147 -
3148 - /**
3149 - * @deprecated 4.08
3150 - * @since 3.06
3151 - */
3152 - public static function add_new() {
3153 - _deprecated_function( __FUNCTION__, '4.08' );
3375 + public static function add_form_style_tab_options() {
3376 + _deprecated_function( __METHOD__, '6.16.3' );
3377 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php';
3154 3378 }
3155 3379 }