PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.13
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.13
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 +539 -388 6.3.26.13 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,9 +106,9 @@
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
101 111 */
102 112 private static function create_default_email_action( $form ) {
103 113 FrmForm::maybe_get_form( $form );
104 114 $create_email = apply_filters( 'frm_create_default_email_action', true, $form );
@@ -113,9 +123,9 @@
113 123 * Create the default On submit action
114 124 *
115 125 * @since 6.0.0
116 126 *
117 - * @param object|int $form Form object or ID.
127 + * @param int|object $form Form object or ID.
118 128 */
119 129 private static function create_default_on_submit_action( $form ) {
120 130 FrmForm::maybe_get_form( $form );
121 131
@@ -134,16 +144,53 @@
134 144 $action_control->create( $form->id );
135 145 }
136 146 }
137 147
148 + /**
149 + * Creates submit button field.
150 + *
151 + * @since 6.9
152 + *
153 + * @param int|object $form Form ID or object.
154 + */
155 + private static function create_submit_button_field( $form ) {
156 + FrmForm::maybe_get_form( $form );
157 +
158 + if ( FrmSubmitHelper::get_submit_field( $form->id ) ) {
159 + // Do not create submit button field if it exists.
160 + return;
161 + }
162 +
163 + FrmField::create(
164 + array(
165 + 'type' => FrmSubmitHelper::FIELD_TYPE,
166 + 'name' => __( 'Submit', 'formidable' ),
167 + 'field_order' => 9999,
168 + 'form_id' => $form->id,
169 + 'field_options' => FrmFieldsHelper::get_default_field_options( FrmSubmitHelper::FIELD_TYPE ),
170 + 'description' => '',
171 + 'default_value' => '',
172 + 'options' => array(),
173 + )
174 + );
175 + }
176 +
177 + /**
178 + * @return void
179 + */
138 180 public static function edit( $values = false ) {
139 181 FrmAppHelper::permission_check( 'frm_edit_forms' );
140 182
141 183 $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
142 184
143 - return self::get_edit_vars( $id );
185 + self::get_edit_vars( $id );
144 186 }
145 187
188 + /**
189 + * @param mixed $id
190 + * @param string $message
191 + * @return void
192 + */
146 193 public static function settings( $id = false, $message = '' ) {
147 194 FrmAppHelper::permission_check( 'frm_edit_forms' );
148 195
149 196 if ( ! $id || ! is_numeric( $id ) ) {
@@ -151,21 +198,34 @@
151 198 }
152 199
153 200 FrmOnSubmitHelper::maybe_migrate_submit_settings_to_action( $id );
154 201
155 - return self::get_settings_vars( $id, array(), $message );
202 + self::get_settings_vars( $id, array(), $message );
156 203 }
157 204
158 205 public static function update_settings() {
159 206 FrmAppHelper::permission_check( 'frm_edit_forms' );
207 + $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
160 208
209 + if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) {
210 + $frm_settings = FrmAppHelper::get_settings();
211 + $error_args = array(
212 + 'title' => __( 'Verification failed', 'formidable' ),
213 + 'body' => $frm_settings->admin_permission,
214 + 'cancel_text' => __( 'Cancel', 'formidable' ),
215 + );
216 + FrmAppController::show_error_modal( $error_args );
217 + return;
218 + }
219 +
161 220 $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
162 221
163 - $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
222 + $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
164 223 $warnings = FrmFormsHelper::check_for_warnings( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
165 224
166 225 if ( count( $errors ) > 0 ) {
167 - return self::get_settings_vars( $id, $errors, compact( 'warnings' ) );
226 + self::get_settings_vars( $id, $errors, compact( 'warnings' ) );
227 + return;
168 228 }
169 229
170 230 do_action( 'frm_before_update_form_settings', $id );
171 231
@@ -179,9 +239,9 @@
179 239 }
180 240
181 241 $message = __( 'Settings Successfully Updated', 'formidable' );
182 242
183 - return self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) );
243 + self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) );
184 244 }
185 245
186 246 /**
187 247 * @param int $form_id
@@ -191,8 +251,11 @@
191 251 $form = FrmForm::getOne( $form_id );
192 252 return ! empty( $form->options['antispam'] );
193 253 }
194 254
255 + /**
256 + * @return void
257 + */
195 258 public static function update( $values = array() ) {
196 259 if ( empty( $values ) ) {
197 260 $values = $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing
198 261 }
@@ -210,65 +273,74 @@
210 273
211 274 $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
212 275
213 276 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' );
277 + self::get_edit_vars( $id, $errors );
278 + return;
279 + }
218 280
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 - }
281 + self::maybe_remove_draft_option_from_fields( $id );
227 282
228 - if ( defined( 'DOING_AJAX' ) ) {
229 - wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
230 - }
283 + FrmForm::update( $id, $values );
284 + $message = __( 'Form was successfully updated.', 'formidable' );
231 285
232 - return self::get_edit_vars( $id, array(), $message );
286 + if ( self::is_too_long( $values ) ) {
287 + $message .= '<br/> ' . sprintf(
288 + /* translators: %1$s: Start link HTML, %2$s: end link HTML */
289 + __( 'However, your form is very long and may be %1$sreaching server limits%2$s.', 'formidable' ),
290 + '<a href="https://formidableforms.com/knowledgebase/i-have-a-long-form-why-did-the-options-at-the-end-of-the-form-stop-saving/?utm_source=WordPress&utm_medium=builder&utm_campaign=liteplugin" target="_blank" rel="noopener">',
291 + '</a>'
292 + );
233 293 }
294 +
295 + if ( defined( 'DOING_AJAX' ) ) {
296 + wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
297 + }
298 +
299 + self::get_edit_vars( $id, array(), $message );
234 300 }
235 301
236 302 /**
303 + * Remove the draft flag from any new fields from this current session.
304 + *
305 + * @since 6.8
306 + *
307 + * @param int $form_id
308 + * @return void
309 + */
310 + private static function maybe_remove_draft_option_from_fields( $form_id ) {
311 + $draft_field_ids_csv = FrmAppHelper::get_post_param( 'draft_fields', '', 'sanitize_text_field' );
312 + if ( ! $draft_field_ids_csv ) {
313 + // If the draft_fields input is empty there are no new fields in the session.
314 + return;
315 + }
316 +
317 + $draft_field_ids = array_filter( explode( ',', $draft_field_ids_csv ), 'is_numeric' );
318 + if ( ! $draft_field_ids ) {
319 + // Exit early if the draft fields input is invalid. It should be a CSV of integer values.
320 + return;
321 + }
322 +
323 + $draft_field_rows = FrmFieldsHelper::get_draft_field_results( $form_id, $draft_field_ids );
324 + foreach ( $draft_field_rows as $row ) {
325 + $row->field_options['draft'] = 0;
326 + FrmField::update( $row->id, array( 'field_options' => $row->field_options ) );
327 + }
328 + }
329 +
330 + /**
237 331 * Check if the value at the end of the form was included.
238 332 * If it's missing, it means other values at the end of the form
239 333 * were likely not saved either.
240 334 *
241 335 * @since 3.06.01
336 + *
337 + * @return bool
242 338 */
243 339 private static function is_too_long( $values ) {
244 - return ( ! isset( $values['frm_end'] ) ) || empty( $values['frm_end'] );
340 + return empty( $values['frm_end'] );
245 341 }
246 342
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 343 public static function duplicate() {
272 344 FrmAppHelper::permission_check( 'frm_edit_forms' );
273 345 $nonce = FrmAppHelper::simple_get( '_wpnonce' );
274 346
@@ -282,10 +354,11 @@
282 354 $url = admin_url( 'admin.php?page=formidable' );
283 355 $message = 'form_duplicate_error';
284 356
285 357 if ( $form ) {
286 - $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) );
287 - $message = 'form_duplicated';
358 + $new_template = FrmAppHelper::simple_get( 'new_template' ) ? '&new_template=true' : '';
359 + $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) . $new_template );
360 + $message = 'form_duplicated';
288 361 }
289 362
290 363 $url .= '&message=' . $message;
291 364
@@ -293,24 +366,28 @@
293 366 exit();
294 367 }
295 368
296 369 /**
297 - * @return string
370 + * @return string|null
298 371 */
299 372 public static function page_preview() {
300 373 $params = FrmForm::list_page_params();
301 374 if ( ! $params['form'] ) {
302 - return;
375 + return null;
303 376 }
304 377
305 378 $form = FrmForm::getOne( $params['form'] );
306 - if ( $form ) {
307 - return self::show_form( $form->id, '', 'auto', 'auto' );
379 + if ( ! $form ) {
380 + return null;
308 381 }
382 +
383 + return self::show_form( $form->id, '', 'auto', 'auto' );
309 384 }
310 385
311 386 /**
312 387 * @since 3.0
388 + *
389 + * @return void
313 390 */
314 391 public static function show_page_preview() {
315 392 echo self::page_preview(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
316 393 }
@@ -360,8 +437,13 @@
360 437 return;
361 438 }
362 439
363 440 $random_page = reset( $random_page );
441 + if ( ! is_a( $random_page, 'WP_Post' ) ) {
442 + // The return type can also be int.
443 + return;
444 + }
445 +
364 446 query_posts(
365 447 array(
366 448 'post_type' => 'page',
367 449 'page_id' => $random_page->ID,
@@ -377,9 +459,9 @@
377 459 * Set the WP $post global object. Used for in-theme preview when defining a page.
378 460 *
379 461 * @since 5.5.2
380 462 *
381 - * @param WP_Post $post
463 + * @param WP_Post $page The page object.
382 464 * @return void
383 465 */
384 466 private static function set_post_global( $page ) {
385 467 global $post;
@@ -387,8 +469,10 @@
387 469 }
388 470
389 471 /**
390 472 * @since 3.0
473 + *
474 + * @return void
391 475 */
392 476 private static function load_theme_preview() {
393 477 add_filter( 'wp_title', 'FrmFormsController::preview_title', 9999 );
394 478 add_filter( 'the_title', 'FrmFormsController::preview_page_title', 9999 );
@@ -397,20 +481,39 @@
397 481 add_filter( 'is_active_sidebar', '__return_false' );
398 482 FrmStylesController::enqueue_css( 'enqueue', true );
399 483
400 484 if ( false === get_template_part( 'page' ) ) {
485 + if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) {
486 + add_filter( 'body_class', 'FrmFormsController::preview_block_theme_body_classnames' );
487 + }
401 488 self::fallback_when_page_template_part_is_not_supported_by_theme();
402 489 }
403 490 }
404 491
405 492 /**
493 + * Add padding to the body for block themes.
494 + *
495 + * @since 6.5.2
496 + *
497 + * @param array $classes The body classes list.
498 + * @return array
499 + */
500 + public static function preview_block_theme_body_classnames( $classes ) {
501 + $classes[] = 'has-global-padding';
502 + return $classes;
503 + }
504 +
505 + /**
406 506 * Not every theme supports get_template_part( 'page' ).
407 507 * When this is not supported, false is returned, and we can handle a fallback.
508 + *
509 + * @return void
408 510 */
409 511 private static function fallback_when_page_template_part_is_not_supported_by_theme() {
410 512 if ( have_posts() ) {
411 513 the_post();
412 - get_header( '' );
514 + self::get_template( 'header' );
515 +
413 516 // add some generic class names to the container to add some natural padding to the content.
414 517 // .entry-content catches the WordPress TwentyTwenty theme.
415 518 // .container catches Customizr content.
416 519 echo '<div class="container entry-content">';
@@ -415,13 +518,54 @@
415 518 // .container catches Customizr content.
416 519 echo '<div class="container entry-content">';
417 520 the_content();
418 521 echo '</div>';
419 - get_footer();
522 +
523 + self::get_template( 'footer' );
420 524 }
421 525 }
422 526
423 527 /**
528 + * Calls core function to get a template part if it doesn't cause deprecation warnings. Otherwise skips the deprecation function call
529 + * and renders required html fragments calling required functions.
530 + *
531 + * @since 6.7.1
532 + * @param string $template
533 + * @return void
534 + */
535 + private static function get_template( $template ) {
536 + if ( self::should_try_getting_template( $template ) ) {
537 + call_user_func( 'get_' . $template );
538 + return;
539 + }
540 +
541 + if ( 'header' === $template ) {
542 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/header.php';
543 + return;
544 + }
545 +
546 + if ( 'footer' === $template ) {
547 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/footer.php';
548 + }
549 + }
550 +
551 + /**
552 + * Returns true if calling a template function doesn't trigger deprecation warnings.
553 + *
554 + * @since 6.7.1
555 + * @param string $template
556 + * @return bool
557 + */
558 + private static function should_try_getting_template( $template ) {
559 + $stylesheet_path = get_stylesheet_directory();
560 + $template_path = get_template_directory();
561 + $is_child_theme = $stylesheet_path !== $template_path;
562 + $template_name = $template . '.php';
563 +
564 + return file_exists( $stylesheet_path . '/' . $template_name ) || $is_child_theme && file_exists( $template_path . '/' . $template_name );
565 + }
566 +
567 + /**
424 568 * Set the page title for the theme preview page
425 569 *
426 570 * @since 3.0
427 571 */
@@ -433,11 +577,14 @@
433 577 return $title;
434 578 }
435 579
436 580 /**
437 - * Set the page title for the theme preview page
581 + * Set the page title for the theme preview page.
438 582 *
439 583 * @since 3.0
584 + *
585 + * @param string $title
586 + * @return string
440 587 */
441 588 public static function preview_title( $title ) {
442 589 return __( 'Form Preview', 'formidable' );
443 590 }
@@ -442,15 +589,20 @@
442 589 return __( 'Form Preview', 'formidable' );
443 590 }
444 591
445 592 /**
446 - * Set the page content for the theme preview page
593 + * Set the page content for the theme preview page.
447 594 *
448 595 * @since 3.0
596 + *
597 + * @param string $content
598 + * @return string
449 599 */
450 600 public static function preview_content( $content ) {
451 601 if ( in_the_loop() ) {
452 - $content = self::show_page_preview();
602 + self::show_page_preview();
603 + // Clear the content for the page we're using.
604 + $content = '';
453 605 }
454 606
455 607 return $content;
456 608 }
@@ -460,8 +612,11 @@
460 612 */
461 613 private static function load_direct_preview() {
462 614 header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
463 615
616 + // print_emoji_styles is deprecated.
617 + remove_action( 'wp_print_styles', 'print_emoji_styles' );
618 +
464 619 $key = FrmAppHelper::simple_get( 'form', 'sanitize_title' );
465 620 if ( $key == '' ) {
466 621 $key = FrmAppHelper::get_post_param( 'form', '', 'sanitize_title' );
467 622 }
@@ -470,11 +625,38 @@
470 625 if ( empty( $form ) ) {
471 626 $form = FrmForm::getAll( array(), '', 1 );
472 627 }
473 628
474 - require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php' );
629 + self::fix_deprecated_null_param_warning();
630 +
631 + require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php';
475 632 }
476 633
634 + /**
635 + * Some themes have a null $src value.
636 + * This function adds a filter to ensure that $src is not null.
637 + * WP will call str_starts_with with the null value triggering a deprecated message otherwise.
638 + *
639 + * @since 6.10
640 + *
641 + * @return void
642 + */
643 + private static function fix_deprecated_null_param_warning() {
644 + add_filter(
645 + 'script_loader_src',
646 + /**
647 + * @param string|null $src
648 + * @return string
649 + */
650 + function ( $src ) {
651 + if ( is_null( $src ) ) {
652 + $src = '';
653 + }
654 + return $src;
655 + }
656 + );
657 + }
658 +
477 659 public static function untrash() {
478 660 self::change_form_status( 'untrash' );
479 661 }
480 662
@@ -537,14 +719,14 @@
537 719 FrmAppHelper::permission_check( $available_status[ $status ]['permission'] );
538 720
539 721 $params = FrmForm::list_page_params();
540 722
541 - //check nonce url
723 + // Check nonce url.
542 724 check_admin_referer( $status . '_form_' . $params['id'] );
543 725
544 726 $count = 0;
545 727 if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) {
546 - $count ++;
728 + ++$count;
547 729 }
548 730
549 731 $form_type = FrmAppHelper::get_simple_request(
550 732 array(
@@ -556,9 +738,9 @@
556 738 /* translators: %1$s: Number of forms */
557 739 $available_status['untrash']['message'] = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
558 740
559 741 /* translators: %1$s: Number of forms, %2$s: Start link HTML, %3$s: End link HTML */
560 - $available_status['trash']['message'] = sprintf( _n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), $count, '<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=untrash&form_type=' . $form_type . '&id=' . $params['id'], 'untrash_form_' . $params['id'] ) ) . '">', '</a>' );
742 + $available_status['trash']['message'] = sprintf( _n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), $count, '<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=untrash&form_type=' . $form_type . '&id=' . $params['id'], 'untrash_form_' . $params['id'] ) ) . '">', '</a>' );
561 743
562 744 $message = $available_status[ $status ]['message'];
563 745
564 746 self::display_forms_list( $params, $message );
@@ -563,8 +745,12 @@
563 745
564 746 self::display_forms_list( $params, $message );
565 747 }
566 748
749 + /**
750 + * @param array $ids
751 + * @return string
752 + */
567 753 public static function bulk_trash( $ids ) {
568 754 FrmAppHelper::permission_check( 'frm_delete_forms' );
569 755
570 756 $count = 0;
@@ -569,9 +755,9 @@
569 755
570 756 $count = 0;
571 757 foreach ( $ids as $id ) {
572 758 if ( FrmForm::trash( $id ) ) {
573 - $count ++;
759 + ++$count;
574 760 }
575 761 }
576 762
577 763 $current_page = FrmAppHelper::get_simple_request(
@@ -600,9 +786,9 @@
600 786 check_admin_referer( 'destroy_form_' . $params['id'] );
601 787
602 788 $count = 0;
603 789 if ( FrmForm::destroy( $params['id'] ) ) {
604 - $count ++;
790 + ++$count;
605 791 }
606 792
607 793 /* translators: %1$s: Number of forms */
608 794 $message = sprintf( _n( '%1$s Form Permanently Deleted', '%1$s Forms Permanently Deleted', $count, 'formidable' ), $count );
@@ -609,8 +795,12 @@
609 795
610 796 self::display_forms_list( $params, $message );
611 797 }
612 798
799 + /**
800 + * @param array $ids
801 + * @return string
802 + */
613 803 public static function bulk_destroy( $ids ) {
614 804 FrmAppHelper::permission_check( 'frm_delete_forms' );
615 805
616 806 $count = 0;
@@ -616,19 +806,24 @@
616 806 $count = 0;
617 807 foreach ( $ids as $id ) {
618 808 $d = FrmForm::destroy( $id );
619 809 if ( $d ) {
620 - $count ++;
810 + ++$count;
621 811 }
622 812 }
623 813
624 - /* translators: %1$s: Number of forms */
625 - $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
814 + if ( $count ) {
815 + /* translators: %1$s: Number of forms */
816 + return sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
817 + }
626 818
627 - return $message;
819 + return '';
628 820 }
629 821
630 - private static function delete_all() {
822 + /**
823 + * @since 6.7.1 Function went from private to public.
824 + */
825 + public static function delete_all() {
631 826 // Check nonce url.
632 827 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' );
633 828 if ( $permission_error !== false ) {
634 829 self::display_forms_list( array(), '', array( $permission_error ) );
@@ -635,14 +830,15 @@
635 830
636 831 return;
637 832 }
638 833
639 - $count = FrmForm::scheduled_delete( time() );
834 + $count = FrmForm::scheduled_delete( time() );
835 + $url = remove_query_arg( array( 'delete_all' ) );
640 836
641 - /* translators: %1$s: Number of forms */
642 - $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
837 + $url .= '&message=forms_permanently_deleted&forms_deleted=' . $count;
643 838
644 - self::display_forms_list( array(), $message );
839 + wp_safe_redirect( $url );
840 + die();
645 841 }
646 842
647 843 /**
648 844 * Create a new form from the modal.
@@ -655,9 +851,9 @@
655 851
656 852 $new_values = self::get_modal_values();
657 853 $new_values['form_key'] = $new_values['name'];
658 854 $new_values['options'] = array(
659 - 'antispam' => 1,
855 + 'antispam' => 1,
660 856 'on_submit_migrated' => 1,
661 857 );
662 858
663 859 /**
@@ -676,13 +872,14 @@
676 872 * @param int $form_id
677 873 */
678 874 do_action( 'frm_build_new_form', $form_id );
679 875
876 + self::create_submit_button_field( $form_id );
680 877 self::create_default_on_submit_action( $form_id );
681 878 self::create_default_email_action( $form_id );
682 879
683 880 $response = array(
684 - 'redirect' => FrmForm::get_edit_link( $form_id ),
881 + 'redirect' => FrmForm::get_edit_link( $form_id ) . '&new_template=true',
685 882 );
686 883
687 884 echo wp_json_encode( $response );
688 885 wp_die();
@@ -688,46 +885,15 @@
688 885 wp_die();
689 886 }
690 887
691 888 /**
692 - * Create a custom template from a form
693 - *
694 - * @since 3.06
695 - */
696 - public static function build_template() {
697 - global $wpdb;
698 -
699 - FrmAppHelper::permission_check( 'frm_edit_forms' );
700 - check_ajax_referer( 'frm_ajax', 'nonce' );
701 -
702 - $form_id = FrmAppHelper::get_param( 'xml', '', 'post', 'absint' );
703 - $new_form_id = FrmForm::duplicate( $form_id, 1, true );
704 - if ( ! $new_form_id ) {
705 - $response = array(
706 - 'message' => __( 'There was an error creating a template.', 'formidable' ),
707 - );
708 - } else {
709 - $new_values = self::get_modal_values();
710 - $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $new_form_id ) );
711 - if ( $query_results ) {
712 - FrmForm::clear_form_cache();
713 - }
714 -
715 - $response = array(
716 - 'redirect' => admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . $new_form_id ) . '&_wpnonce=' . wp_create_nonce(),
717 - );
718 - }
719 -
720 - echo wp_json_encode( $response );
721 - wp_die();
722 - }
723 -
724 - /**
725 889 * Before creating a new form, get the name and description from the modal.
726 890 *
727 891 * @since 4.0
892 + *
893 + * @return array<string,string>
728 894 */
729 - private static function get_modal_values() {
895 + public static function get_modal_values() {
730 896 $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' );
731 897 $desc = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' );
732 898
733 899 return array(
@@ -740,17 +906,24 @@
740 906 * Inserts Formidable button
741 907 * Hook exists since 2.5.0
742 908 *
743 909 * @since 2.0.15
910 + *
911 + * @return void
744 912 */
745 913 public static function insert_form_button() {
746 914 if ( current_user_can( 'frm_view_forms' ) ) {
747 - FrmAppHelper::load_admin_wide_js();
748 - $menu_name = FrmAppHelper::get_menu_name();
749 - $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() );
750 - 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' ) . '">' .
751 - FrmAppHelper::kses( $icon, 'all' ) . // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
752 - ' ' . esc_html( $menu_name ) . '</a>';
915 + // Store the result in memory and re-use it when this function is called multiple times.
916 + // This helps speed up the form builder when there are a lot of HTML fields, where this
917 + // button is inserted once per HTML field.
918 + // In a form with 66 HTML fields, this saves 0.5 seconds on page load time, tested locally.
919 + if ( ! isset( self::$formidable_tinymce_button ) ) {
920 + FrmAppHelper::load_admin_wide_js();
921 + $menu_name = FrmAppHelper::get_menu_name();
922 + $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() );
923 + self::$formidable_tinymce_button = '<a href="#TB_inline?width=50&height=50&inlineId=frm_insert_form" class="thickbox button add_media frm_insert_form" title="' . esc_attr__( 'Add forms and content', 'formidable' ) . '">' . FrmAppHelper::kses( $icon, 'all' ) . ' ' . esc_html( $menu_name ) . '</a>';
924 + }
925 + echo self::$formidable_tinymce_button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
753 926 }
754 927 }
755 928
756 929 /**
@@ -838,9 +1011,9 @@
838 1011 $form_id = $opts['form_id'];
839 1012 unset( $opts['form_id'] );
840 1013 }
841 1014
842 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php' );
1015 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php';
843 1016
844 1017 echo '</div>';
845 1018
846 1019 wp_die();
@@ -889,14 +1062,14 @@
889 1062 * @return array<string,string>
890 1063 */
891 1064 public static function get_columns( $columns ) {
892 1065 $columns['cb'] = '<input type="checkbox" />';
893 - $columns['name'] = __( 'Form Title', 'formidable' );
894 - $columns['entries'] = __( 'Entries', 'formidable' );
1066 + $columns['name'] = esc_html__( 'Form Title', 'formidable' );
1067 + $columns['entries'] = esc_html__( 'Entries', 'formidable' );
895 1068 $columns['id'] = 'ID';
896 - $columns['form_key'] = __( 'Key', 'formidable' );
897 - $columns['shortcode'] = __( 'Actions', 'formidable' );
898 - $columns['created_at'] = __( 'Date', 'formidable' );
1069 + $columns['form_key'] = esc_html__( 'Key', 'formidable' );
1070 + $columns['shortcode'] = esc_html__( 'Actions', 'formidable' );
1071 + $columns['created_at'] = esc_html__( 'Date', 'formidable' );
899 1072
900 1073 add_screen_option(
901 1074 'per_page',
902 1075 array(
@@ -908,8 +1081,11 @@
908 1081
909 1082 return $columns;
910 1083 }
911 1084
1085 + /**
1086 + * @return array<string,string>
1087 + */
912 1088 public static function get_sortable_columns() {
913 1089 return array(
914 1090 'id' => 'id',
915 1091 'name' => 'name',
@@ -943,9 +1119,9 @@
943 1119 return $hidden_columns;
944 1120 }
945 1121
946 1122 public static function save_per_page( $save, $option, $value ) {
947 - if ( $option == 'formidable_page_formidable_per_page' ) {
1123 + if ( $option === 'formidable_page_formidable_per_page' ) {
948 1124 $save = (int) $value;
949 1125 }
950 1126
951 1127 return $save;
@@ -951,146 +1127,49 @@
951 1127 return $save;
952 1128 }
953 1129
954 1130 /**
955 - * @return bool
956 - */
957 - public static function expired() {
958 - global $frm_expired;
959 - return $frm_expired;
960 - }
961 -
962 - /**
963 - * Get data from api before rendering it so that we can flag the modal as expired
964 - *
1131 + * @param int|string $id
1132 + * @param array $errors
1133 + * @param string $message
1134 + * @param bool $create_link
965 1135 * @return void
966 1136 */
967 - public static function before_list_templates() {
968 - global $frm_templates;
969 - global $frm_expired;
970 - global $frm_license_type;
1137 + private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
1138 + global $frm_vars;
971 1139
972 - $api = new FrmFormTemplateApi();
973 - $frm_templates = $api->get_api_info();
974 - $expired = false;
975 - $license_type = '';
976 - if ( isset( $frm_templates['error'] ) ) {
977 - $error = $frm_templates['error']['message'];
978 - $error = str_replace( 'utm_medium=addons', 'utm_medium=form-templates', $error );
979 - $expired = 'expired' === $frm_templates['error']['code'];
980 - $license_type = isset( $frm_templates['error']['type'] ) ? $frm_templates['error']['type'] : '';
981 - unset( $frm_templates['error'] );
982 - }
983 -
984 - $frm_expired = $expired;
985 - $frm_license_type = $license_type;
986 - }
987 -
988 - /**
989 - * @return void
990 - */
991 - public static function list_templates() {
992 - global $frm_templates;
993 - global $frm_license_type;
994 -
995 - $templates = $frm_templates;
996 - $custom_templates = array();
997 - $templates_by_category = array();
998 -
999 - self::add_user_templates( $custom_templates );
1000 -
1001 - foreach ( $templates as $template ) {
1002 - if ( ! isset( $template['categories'] ) ) {
1003 - continue;
1004 - }
1005 -
1006 - foreach ( $template['categories'] as $category ) {
1007 - if ( ! isset( $templates_by_category[ $category ] ) ) {
1008 - $templates_by_category[ $category ] = array();
1009 - }
1010 -
1011 - $templates_by_category[ $category ][] = $template;
1012 - }
1013 - }
1014 - unset( $template );
1015 -
1016 - // Subcategories that are included elsewhere.
1017 - $redundant_cats = array( 'PayPal', 'Stripe', 'Twilio' );
1018 -
1019 - $categories = array_keys( $templates_by_category );
1020 - $categories = array_diff( $categories, FrmFormsHelper::ignore_template_categories() );
1021 - $categories = array_diff( $categories, $redundant_cats );
1022 - sort( $categories );
1023 -
1024 - array_walk(
1025 - $custom_templates,
1026 - function( &$template ) {
1027 - $template['custom'] = true;
1028 - }
1140 + $form = FrmForm::getOne( $id );
1141 + $error_args = array(
1142 + 'title' => __( 'You can\'t edit the form', 'formidable' ),
1143 + 'body' => __( 'You are trying to edit a form that does not exist', 'formidable' ),
1144 + 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
1145 + 'continue_url' => add_query_arg(
1146 + array(
1147 + 'page' => 'formidable',
1148 + )
1149 + ),
1029 1150 );
1030 -
1031 - $my_templates_translation = __( 'My Templates', 'formidable' );
1032 - $categories = array_merge( array( $my_templates_translation ), $categories );
1033 - $pricing = FrmAppHelper::admin_upgrade_link( 'form-templates' );
1034 - $license_type = $frm_license_type;
1035 - $args = compact( 'pricing', 'license_type' );
1036 - $where = apply_filters( 'frm_forms_dropdown', array(), '' );
1037 - $forms = FrmForm::get_published_forms( $where );
1038 - $view_path = FrmAppHelper::plugin_path() . '/classes/views/frm-forms/';
1039 -
1040 - $templates_by_category[ $my_templates_translation ] = $custom_templates;
1041 -
1042 - unset( $pricing, $license_type, $where );
1043 - wp_enqueue_script( 'accordion' ); // register accordion for template groups
1044 - require $view_path . 'list-templates.php';
1045 - }
1046 -
1047 - /**
1048 - * @since 4.03.01
1049 - */
1050 - private static function get_template_categories( $templates ) {
1051 - $categories = array();
1052 - foreach ( $templates as $template ) {
1053 - if ( isset( $template['categories'] ) ) {
1054 - $categories = array_merge( $categories, $template['categories'] );
1055 - }
1151 + if ( ! $form ) {
1152 + FrmAppController::show_error_modal( $error_args );
1153 + return;
1056 1154 }
1057 - $exclude_cats = FrmFormsHelper::ignore_template_categories();
1058 - $categories = array_unique( $categories );
1059 - $categories = array_diff( $categories, $exclude_cats );
1060 - sort( $categories );
1061 - return $categories;
1062 - }
1063 1155
1064 - private static function add_user_templates( &$templates ) {
1065 - $user_templates = array(
1066 - 'is_template' => 1,
1067 - 'default_template' => 0,
1068 - );
1069 - $user_templates = FrmForm::getAll( $user_templates, 'name' );
1070 - foreach ( $user_templates as $template ) {
1071 - $template = array(
1072 - 'id' => $template->id,
1073 - 'name' => $template->name,
1074 - 'key' => $template->form_key,
1075 - 'description' => $template->description,
1076 - 'url' => wp_nonce_url( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template->id ) ) ),
1077 - 'released' => $template->created_at,
1078 - 'installed' => 1,
1156 + if ( 'trash' === $form->status ) {
1157 + $error_args['body'] = __( 'The form you\'re trying to edit is in trash. You must restore it first before you can make changes', 'formidable' );
1158 + $error_args['continue_url'] = add_query_arg(
1159 + array(
1160 + 'page' => 'formidable',
1161 + '_wpnonce' => wp_create_nonce( 'untrash_form_' . $id ),
1162 + 'form_type' => 'trash',
1163 + 'frm_action' => 'untrash',
1164 + 'id' => $id,
1165 + )
1079 1166 );
1080 - array_unshift( $templates, $template );
1081 - unset( $template );
1167 + $error_args['continue_text'] = __( 'Restore form', 'formidable' );
1168 + FrmAppController::show_error_modal( $error_args );
1169 + return;
1082 1170 }
1083 - }
1084 1171
1085 - private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
1086 - global $frm_vars;
1087 -
1088 - $form = FrmForm::getOne( $id );
1089 - if ( ! $form ) {
1090 - wp_die( esc_html__( 'You are trying to edit a form that does not exist.', 'formidable' ) );
1091 - }
1092 -
1093 1172 if ( $form->parent_form_id ) {
1094 1173 /* translators: %1$s: Start link HTML, %2$s: End link HTML */
1095 1174 wp_die( sprintf( esc_html__( 'You are trying to edit a child form. Please edit from %1$shere%2$s', 'formidable' ), '<a href="' . esc_url( FrmForm::get_edit_link( $form->parent_form_id ) ) . '">', '</a>' ) );
1096 1175 }
@@ -1101,8 +1180,9 @@
1101 1180
1102 1181 // Automatically add end section fields if they don't exist (2.0 migration).
1103 1182 $reset_fields = false;
1104 1183 FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields );
1184 + FrmSubmitHelper::maybe_create_submit_field( $form, $fields, $reset_fields );
1105 1185
1106 1186 if ( $reset_fields ) {
1107 1187 $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' );
1108 1188 }
@@ -1129,17 +1209,21 @@
1129 1209
1130 1210 self::maybe_update_form_builder_message( $message );
1131 1211
1132 1212 $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
1133 - $has_fields = isset( $values['fields'] ) && ! empty( $values['fields'] );
1213 + $has_fields = ! empty( $values['fields'] ) && ! FrmSubmitHelper::only_contains_submit_field( $values['fields'] );
1134 1214
1135 1215 if ( defined( 'DOING_AJAX' ) ) {
1136 1216 wp_die();
1137 - } else {
1138 - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' );
1139 1217 }
1218 +
1219 + require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php';
1140 1220 }
1141 1221
1222 + /**
1223 + * @param array $fields
1224 + * @return array
1225 + */
1142 1226 public static function update_form_builder_fields( $fields, $form ) {
1143 1227 foreach ( $fields as $field ) {
1144 1228 $field->do_not_include_icons = true;
1145 1229 }
@@ -1151,13 +1235,21 @@
1151 1235 $message = __( 'Form was Successfully Copied', 'formidable' );
1152 1236 }
1153 1237 }
1154 1238
1239 + /**
1240 + * @param int|string $id
1241 + * @param array $errors
1242 + * @param array|string $args
1243 + * @return void
1244 + */
1155 1245 public static function get_settings_vars( $id, $errors = array(), $args = array() ) {
1156 1246 FrmAppHelper::permission_check( 'frm_edit_forms' );
1157 1247
1158 1248 global $frm_vars;
1159 1249
1250 + self::maybe_print_media_templates();
1251 +
1160 1252 if ( ! is_array( $args ) ) {
1161 1253 // For reverse compatibility.
1162 1254 $args = array(
1163 1255 'message' => $args,
@@ -1190,17 +1282,38 @@
1190 1282
1191 1283 $sections = self::get_settings_tabs( $values );
1192 1284 $current = FrmAppHelper::simple_get( 't', 'sanitize_title', 'advanced_settings' );
1193 1285
1194 - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php' );
1286 + require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php';
1195 1287 }
1196 1288
1197 1289 /**
1290 + * Print WordPress media templates email actions does not trigger a "Uncaught Error: Template not found: #tmpl-media-selection" error when the media button is clicked.
1291 + *
1292 + * @since 6.10
1293 + *
1294 + * @return void
1295 + */
1296 + private static function maybe_print_media_templates() {
1297 + if ( FrmAppHelper::pro_is_included() ) {
1298 + // This issue does not exist when Pro is active so exit early.
1299 + return;
1300 + }
1301 +
1302 + add_action(
1303 + 'wp_enqueue_editor',
1304 + function () {
1305 + wp_print_media_templates();
1306 + }
1307 + );
1308 + }
1309 +
1310 + /**
1198 1311 * @since 4.0
1199 1312 */
1200 1313 public static function form_publish_button( $atts ) {
1201 1314 $values = $atts['values'];
1202 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php' );
1315 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php';
1203 1316 }
1204 1317
1205 1318 /**
1206 1319 * Get a list of all the settings tabs for the form settings page.
@@ -1225,9 +1338,9 @@
1225 1338 'icon' => 'frm_icon_font frm_mail_bulk_icon',
1226 1339 ),
1227 1340 'permissions' => array(
1228 1341 'name' => __( 'Form Permissions', 'formidable' ),
1229 - 'icon' => 'frm_icon_font frm_lock_icon',
1342 + 'icon' => 'frm_icon_font frm_lock_closed_icon',
1230 1343 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1231 1344 'data' => array(
1232 1345 'medium' => 'permissions',
1233 1346 'upgrade' => __( 'Form Permissions', 'formidable' ),
@@ -1234,9 +1347,9 @@
1234 1347 'message' => __( 'Allow editing, protect forms and files, limit entries, and save drafts. Upgrade to get form and entry permissions.', 'formidable' ),
1235 1348 'screenshot' => 'permissions.png',
1236 1349 ),
1237 1350 ),
1238 - 'scheduling' => array(
1351 + 'scheduling' => array(
1239 1352 'name' => __( 'Form Scheduling', 'formidable' ),
1240 1353 'icon' => 'frm_icon_font frm_calendar_icon',
1241 1354 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1242 1355 'data' => array(
@@ -1269,8 +1382,21 @@
1269 1382 'screenshot' => 'chat.png',
1270 1383 )
1271 1384 ),
1272 1385 ),
1386 + 'abandonment' => array(
1387 + 'name' => __( 'Form Abandonment', 'formidable' ),
1388 + 'icon' => 'frm_icon_font frm_abandoned_icon',
1389 + 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1390 + 'data' => FrmAppHelper::get_upgrade_data_params(
1391 + 'abandonment',
1392 + array(
1393 + 'upgrade' => __( 'Form abandonment settings', 'formidable' ),
1394 + 'message' => __( 'Unlock the power of data capture to boost lead generation and master the art of form optimization.', 'formidable' ),
1395 + 'screenshot' => 'abandonment.png',
1396 + )
1397 + ),
1398 + ),
1273 1399 'html' => array(
1274 1400 'name' => __( 'Customize HTML', 'formidable' ),
1275 1401 'class' => __CLASS__,
1276 1402 'function' => 'html_settings',
@@ -1277,9 +1403,9 @@
1277 1403 'icon' => 'frm_icon_font frm_code_icon',
1278 1404 ),
1279 1405 );
1280 1406
1281 - foreach ( array( 'landing', 'chat' ) as $feature ) {
1407 + foreach ( array( 'landing', 'chat', 'abandonment' ) as $feature ) {
1282 1408 if ( ! FrmAppHelper::show_new_feature( $feature ) ) {
1283 1409 unset( $sections[ $feature ] );
1284 1410 }
1285 1411 }
@@ -1285,13 +1411,8 @@
1285 1411 }
1286 1412
1287 1413 $sections = apply_filters( 'frm_add_form_settings_section', $sections, $values );
1288 1414
1289 - if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) {
1290 - // Prevent settings from showing in 2 spots.
1291 - unset( $sections['permissions'], $sections['scheduling'] );
1292 - }
1293 -
1294 1415 foreach ( $sections as $key => $section ) {
1295 1416 $defaults = array(
1296 1417 'html_class' => '',
1297 1418 'name' => ucfirst( $key ),
@@ -1313,9 +1434,9 @@
1313 1434 $section['id'] = $section['anchor'];
1314 1435 }
1315 1436
1316 1437 $sections[ $key ] = $section;
1317 - }
1438 + }//end foreach
1318 1439
1319 1440 return $sections;
1320 1441 }
1321 1442
@@ -1322,8 +1443,9 @@
1322 1443 /**
1323 1444 * @since 4.0
1324 1445 *
1325 1446 * @param array $values
1447 + * @return void
1326 1448 */
1327 1449 public static function advanced_settings( $values ) {
1328 1450 $first_h3 = 'frm_first_h3';
1329 1451
@@ -1331,8 +1453,9 @@
1331 1453 }
1332 1454
1333 1455 /**
1334 1456 * @param array $values
1457 + * @return void
1335 1458 */
1336 1459 public static function render_spam_settings( $values ) {
1337 1460 if ( function_exists( 'akismet_http_post' ) ) {
1338 1461 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/akismet.php';
@@ -1344,16 +1467,12 @@
1344 1467 /**
1345 1468 * @since 4.0
1346 1469 *
1347 1470 * @param array $values
1471 + * @return void
1348 1472 */
1349 1473 public static function buttons_settings( $values ) {
1350 - $styles = apply_filters( 'frm_get_style_opts', array() );
1351 -
1352 - $frm_settings = FrmAppHelper::get_settings();
1353 - $no_global_style = $frm_settings->load_style === 'none';
1354 -
1355 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php' );
1474 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php';
1356 1475 }
1357 1476
1358 1477 /**
1359 1478 * @since 4.0
@@ -1358,11 +1477,12 @@
1358 1477 /**
1359 1478 * @since 4.0
1360 1479 *
1361 1480 * @param array $values
1481 + * @return void
1362 1482 */
1363 1483 public static function html_settings( $values ) {
1364 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php' );
1484 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php';
1365 1485 }
1366 1486
1367 1487 /**
1368 1488 * Replace old Submit Button href with new href to avoid errors in Chrome
@@ -1368,9 +1488,10 @@
1368 1488 * Replace old Submit Button href with new href to avoid errors in Chrome
1369 1489 *
1370 1490 * @since 2.03.08
1371 1491 *
1372 - * @param array|boolean $values
1492 + * @param array|bool $values
1493 + * @return void
1373 1494 */
1374 1495 private static function clean_submit_html( &$values ) {
1375 1496 if ( is_array( $values ) && isset( $values['submit_html'] ) ) {
1376 1497 $values['submit_html'] = str_replace( 'javascript:void(0)', '#', $values['submit_html'] );
@@ -1391,8 +1512,13 @@
1391 1512
1392 1513 return $classes;
1393 1514 }
1394 1515
1516 + /**
1517 + * @param int|string $form_id
1518 + * @param string $class
1519 + * @return void
1520 + */
1395 1521 public static function mb_tags_box( $form_id, $class = '' ) {
1396 1522 $fields = FrmField::get_all_for_form( $form_id, '', 'include' );
1397 1523
1398 1524 /**
@@ -1405,9 +1531,9 @@
1405 1531 */
1406 1532 $fields = apply_filters( 'frm_fields_in_tags_box', $fields, compact( 'form_id' ) );
1407 1533 $linked_forms = array();
1408 1534 $col = 'one';
1409 - $settings_tab = FrmAppHelper::is_admin_page( 'formidable' ) ? true : false;
1535 + $settings_tab = FrmAppHelper::is_admin_page( 'formidable' );
1410 1536
1411 1537 $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() );
1412 1538 $entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
1413 1539
@@ -1412,9 +1538,9 @@
1412 1538 $entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
1413 1539
1414 1540 $advanced_helpers = self::advanced_helpers( compact( 'fields', 'form_id' ) );
1415 1541
1416 - include( FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php' );
1542 + include FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php';
1417 1543 }
1418 1544
1419 1545 /**
1420 1546 * @since 3.04.01
@@ -1427,9 +1553,9 @@
1427 1553 ),
1428 1554 );
1429 1555
1430 1556 $user_fields = self::user_shortcodes();
1431 - if ( ! empty( $user_fields ) ) {
1557 + if ( $user_fields ) {
1432 1558 $user_helpers = array();
1433 1559 foreach ( $user_fields as $uk => $uf ) {
1434 1560 $user_helpers[ '|user_id| show="' . $uk . '"' ] = $uf;
1435 1561 unset( $uk, $uf );
@@ -1435,9 +1561,9 @@
1435 1561 unset( $uk, $uf );
1436 1562 }
1437 1563
1438 1564 $advanced_helpers['user_id'] = array(
1439 - 'codes' => $user_helpers,
1565 + 'codes' => $user_helpers,
1440 1566 );
1441 1567 }
1442 1568
1443 1569 /**
@@ -1578,11 +1704,11 @@
1578 1704 check_ajax_referer( 'frm_ajax', 'nonce' );
1579 1705
1580 1706 echo FrmEntriesController::show_entry_shortcode( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1581 1707 array(
1582 - 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ),
1708 + 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1583 1709 'default_email' => true,
1584 - 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ),
1710 + 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1585 1711 )
1586 1712 );
1587 1713 wp_die();
1588 1714 }
@@ -1588,10 +1714,10 @@
1588 1714 }
1589 1715
1590 1716 /**
1591 1717 * @param string $content
1592 - * @param stdClass|string|int $form
1593 - * @param stdClass|string|int|false $entry
1718 + * @param int|stdClass|string $form
1719 + * @param false|int|stdClass|string $entry
1594 1720 * @return string
1595 1721 */
1596 1722 public static function filter_content( $content, $form, $entry = false ) {
1597 1723 $content = self::replace_form_name_shortcodes( $content, $form );
@@ -1604,8 +1730,16 @@
1604 1730 if ( is_object( $form ) ) {
1605 1731 $form = $form->id;
1606 1732 }
1607 1733
1734 + /*
1735 + * Repeater actions adds `parent_entry` to `$entry` store the parent entry data. If `parent_entry` is not empty,
1736 + * use the parent form ID instead of repeater form ID to fix the parent form field shortcodes doesn't work.
1737 + */
1738 + if ( ! empty( $entry->parent_entry ) ) {
1739 + $form = $entry->parent_entry->form_id;
1740 + }
1741 +
1608 1742 $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form );
1609 1743 $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
1610 1744
1611 1745 return $content;
@@ -1615,11 +1749,11 @@
1615 1749 * Replace any [form_name] shortcodes in a string.
1616 1750 *
1617 1751 * @since 5.5
1618 1752 *
1619 - * @param string|array $string
1620 - * @param stdClass|string|int $form
1621 - * @return string|array
1753 + * @param array|string $string
1754 + * @param int|stdClass|string $form
1755 + * @return array|string
1622 1756 */
1623 1757 public static function replace_form_name_shortcodes( $string, $form ) {
1624 1758 if ( ! is_string( $string ) ) {
1625 1759 return $string;
@@ -1637,9 +1771,9 @@
1637 1771 return str_replace( '[form_name]', $form_name, $string );
1638 1772 }
1639 1773
1640 1774 /**
1641 - * @param stdClass|string|int|false $entry
1775 + * @param false|int|stdClass|string $entry
1642 1776 * @return void
1643 1777 */
1644 1778 private static function get_entry_by_param( &$entry ) {
1645 1779 if ( ! $entry || ! is_object( $entry ) ) {
@@ -1654,8 +1788,12 @@
1654 1788 public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
1655 1789 return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes );
1656 1790 }
1657 1791
1792 + /**
1793 + * @param array $errors
1794 + * @return array
1795 + */
1658 1796 public static function process_bulk_form_actions( $errors ) {
1659 1797 if ( ! $_REQUEST ) {
1660 1798 return $errors;
1661 1799 }
@@ -1699,9 +1837,9 @@
1699 1837 case 'untrash':
1700 1838 $message = self::bulk_untrash( $ids );
1701 1839 }
1702 1840
1703 - if ( isset( $message ) && ! empty( $message ) ) {
1841 + if ( ! empty( $message ) ) {
1704 1842 $errors['message'] = $message;
1705 1843 }
1706 1844
1707 1845 return $errors;
@@ -1721,9 +1859,9 @@
1721 1859 $json_vars = json_decode( $json_vars, true );
1722 1860 if ( empty( $json_vars ) ) {
1723 1861 // json decoding failed so we should return an error message.
1724 1862 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
1725 - if ( 'edit' == $action ) {
1863 + if ( 'edit' === $action ) {
1726 1864 $action = 'update';
1727 1865 }
1728 1866
1729 1867 add_filter( 'frm_validate_form', 'FrmFormsController::json_error' );
@@ -1739,16 +1877,14 @@
1739 1877 if ( isset( $_REQUEST['delete_all'] ) ) {
1740 1878 // Override the action for this page.
1741 1879 $action = 'delete_all';
1742 1880 }
1743 - }
1881 + }//end if
1744 1882
1745 1883 add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
1746 1884 FrmAppHelper::trigger_hook_load( 'form' );
1747 1885
1748 1886 switch ( $action ) {
1749 - case 'new':
1750 - return self::new_form( $vars );
1751 1887 case 'create':
1752 1888 case 'edit':
1753 1889 case 'update':
1754 1890 case 'trash':
@@ -1753,16 +1889,17 @@
1753 1889 case 'update':
1754 1890 case 'trash':
1755 1891 case 'untrash':
1756 1892 case 'destroy':
1757 - case 'delete_all':
1758 1893 case 'settings':
1759 1894 case 'update_settings':
1760 1895 return self::$action( $vars );
1761 1896 case 'lite-reports':
1762 - return self::no_reports( $vars );
1897 + self::no_reports( $vars );
1898 + return;
1763 1899 case 'views':
1764 - return self::no_views( $vars );
1900 + self::no_views( $vars );
1901 + return;
1765 1902 default:
1766 1903 do_action( 'frm_form_action_' . $action );
1767 1904 if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) {
1768 1905 return;
@@ -1785,14 +1922,47 @@
1785 1922 self::display_forms_list( array(), '', array( __( 'There was a problem duplicating the form', 'formidable' ) ) );
1786 1923 return;
1787 1924 }
1788 1925
1926 + if ( 'forms_permanently_deleted' === $message ) {
1927 + $count = FrmAppHelper::get_param( 'forms_deleted', 0, 'get', 'absint' );
1928 + /* translators: %1$s: Number of forms */
1929 + $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
1930 + self::display_forms_list( array(), $message, '' );
1931 + return;
1932 + }
1933 +
1789 1934 self::display_forms_list();
1790 1935
1791 1936 return;
1792 - }
1937 + }//end switch
1793 1938 }
1794 1939
1940 + /**
1941 + * Rename a form.
1942 + *
1943 + * Handles the AJAX request for renaming a form.
1944 + *
1945 + * @since 6.7
1946 + *
1947 + * @return void
1948 + */
1949 + public static function rename_form() {
1950 + // Check permission and nonce
1951 + FrmAppHelper::permission_check( 'frm_edit_forms' );
1952 + check_ajax_referer( 'frm_ajax', 'nonce' );
1953 +
1954 + // Get posted data
1955 + $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
1956 + $name = FrmAppHelper::get_post_param( 'form_name', '', 'sanitize_text_field' );
1957 +
1958 + // Update the form name and form key.
1959 + $form_key = FrmAppHelper::get_unique_key( sanitize_title( $name ), 'frm_forms', 'form_key' );
1960 + FrmForm::update( $form_id, compact( 'name', 'form_key' ) );
1961 +
1962 + wp_send_json_success( compact( 'form_key' ) );
1963 + }
1964 +
1795 1965 public static function json_error( $errors ) {
1796 1966 $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
1797 1967
1798 1968 return $errors;
@@ -1801,11 +1971,12 @@
1801 1971 /**
1802 1972 * Education for premium features.
1803 1973 *
1804 1974 * @since 4.05
1975 + * @return void
1805 1976 */
1806 1977 public static function add_form_style_tab_options() {
1807 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php' );
1978 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php';
1808 1979 }
1809 1980
1810 1981 /**
1811 1982 * Add education about views.
@@ -1810,8 +1981,10 @@
1810 1981 /**
1811 1982 * Add education about views.
1812 1983 *
1813 1984 * @since 4.07
1985 + *
1986 + * @return void
1814 1987 */
1815 1988 public static function no_views( $values = array() ) {
1816 1989 FrmAppHelper::include_svg();
1817 1990 $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
@@ -1823,8 +1996,10 @@
1823 1996 /**
1824 1997 * Add education about reports.
1825 1998 *
1826 1999 * @since 4.07
2000 + *
2001 + * @return void
1827 2002 */
1828 2003 public static function no_reports( $values = array() ) {
1829 2004 $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
1830 2005 $form = $id ? FrmForm::getOne( $id ) : false;
@@ -1831,9 +2006,11 @@
1831 2006
1832 2007 include FrmAppHelper::plugin_path() . '/classes/views/shared/reports-info.php';
1833 2008 }
1834 2009
1835 - /* FRONT-END FORMS */
2010 + /**
2011 + * FRONT-END FORMS.
2012 + */
1836 2013 public static function admin_bar_css() {
1837 2014 if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
1838 2015 return;
1839 2016 }
@@ -1922,10 +2099,10 @@
1922 2099 * @return string
1923 2100 */
1924 2101 public static function get_form_shortcode( $atts ) {
1925 2102 global $frm_vars;
1926 - if ( isset( $frm_vars['skip_shortcode'] ) && $frm_vars['skip_shortcode'] ) {
1927 - $sc = '[formidable';
2103 + if ( ! empty( $frm_vars['skip_shortcode'] ) ) {
2104 + $sc = '[formidable';
1928 2105 $sc .= FrmAppHelper::array_to_html_params( $atts );
1929 2106 return $sc . ']';
1930 2107 }
1931 2108
@@ -1950,11 +2127,11 @@
1950 2127
1951 2128 /**
1952 2129 * @since 5.2.01
1953 2130 *
1954 - * @param string|int|false $id
1955 - * @param string|false $key
1956 - * @return stdClass|false
2131 + * @param false|int|string $id
2132 + * @param false|string $key
2133 + * @return false|stdClass
1957 2134 */
1958 2135 private static function maybe_get_form_by_id_or_key( $id, $key ) {
1959 2136 if ( ! $id ) {
1960 2137 $id = $key;
@@ -1962,12 +2139,12 @@
1962 2139 return self::maybe_get_form_to_show( $id );
1963 2140 }
1964 2141
1965 2142 /**
1966 - * @param string|int|false $id
1967 - * @param string|false $key
1968 - * @param string|int|bool $title may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
1969 - * @param string|int|bool $description may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
2143 + * @param false|int|string $id
2144 + * @param false|string $key
2145 + * @param bool|int|string $title may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
2146 + * @param bool|int|string $description may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
1970 2147 * @param array $atts
1971 2148 * @return string
1972 2149 */
1973 2150 public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) {
@@ -2015,15 +2192,16 @@
2015 2192 return $form;
2016 2193 }
2017 2194
2018 2195 /**
2019 - * @param string|int|false $id
2020 - * @return stdClass|false
2196 + * @param false|int|string $id
2197 + * @return false|stdClass
2021 2198 */
2022 2199 private static function maybe_get_form_to_show( $id ) {
2023 2200 $form = false;
2024 2201
2025 - if ( ! empty( $id ) ) { // form id or key is set
2202 + if ( ! empty( $id ) ) {
2203 + // Form id or key is set.
2026 2204 $form = FrmForm::getOne( $id );
2027 2205 if ( ! $form || $form->parent_form_id || $form->status === 'trash' ) {
2028 2206 $form = false;
2029 2207 }
@@ -2081,11 +2259,11 @@
2081 2259
2082 2260 do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description );
2083 2261
2084 2262 if ( apply_filters( 'frm_continue_to_create', true, $form->id ) ) {
2085 - $entry_id = self::just_created_entry( $form->id );
2086 - $pass_args['entry_id'] = $entry_id;
2087 - $pass_args['reset'] = true;
2263 + $entry_id = self::just_created_entry( $form->id );
2264 + $pass_args['entry_id'] = $entry_id;
2265 + $pass_args['reset'] = true;
2088 2266
2089 2267 self::run_on_submit_actions( $pass_args );
2090 2268
2091 2269 do_action(
@@ -2095,9 +2273,9 @@
2095 2273 'form' => $form,
2096 2274 )
2097 2275 );
2098 2276 }
2099 - }
2277 + }//end if
2100 2278 }
2101 2279
2102 2280 /**
2103 2281 * If the form was processed earlier (init), get the generated errors
@@ -2129,9 +2307,9 @@
2129 2307 */
2130 2308 public static function just_created_entry( $form_id ) {
2131 2309 global $frm_vars;
2132 2310
2133 - return ( isset( $frm_vars['created_entries'] ) && isset( $frm_vars['created_entries'][ $form_id ] ) && isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) ? $frm_vars['created_entries'][ $form_id ]['entry_id'] : 0;
2311 + return isset( $frm_vars['created_entries'] ) && isset( $frm_vars['created_entries'][ $form_id ] ) && isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ? $frm_vars['created_entries'][ $form_id ]['entry_id'] : 0;
2134 2312 }
2135 2313
2136 2314 /**
2137 2315 * Gets confirmation method.
@@ -2144,14 +2322,14 @@
2144 2322 *
2145 2323 * @type object $form Form object.
2146 2324 * @type int $entry_id Entry ID.
2147 2325 * }
2148 - * @return string|array
2326 + * @return array|string
2149 2327 */
2150 2328 private static function get_confirmation_method( $atts ) {
2151 2329 $action = FrmOnSubmitHelper::current_event( $atts );
2152 2330 $opt = 'update' === $action ? 'edit_action' : 'success_action';
2153 - $method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message';
2331 + $method = ! empty( $atts['form']->options[ $opt ] ) ? $atts['form']->options[ $opt ] : 'message';
2154 2332
2155 2333 if ( ! empty( $atts['entry_id'] ) ) {
2156 2334 $met_actions = self::get_met_on_submit_actions( $atts, $action );
2157 2335 if ( $met_actions ) {
@@ -2160,9 +2338,9 @@
2160 2338 }
2161 2339
2162 2340 $method = apply_filters( 'frm_success_filter', $method, $atts['form'], $action );
2163 2341
2164 - if ( $method != 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
2342 + if ( $method !== 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
2165 2343 $method = 'message';
2166 2344 }
2167 2345
2168 2346 return $method;
@@ -2247,9 +2425,9 @@
2247 2425 unset( $extra_args['form'] );
2248 2426
2249 2427 do_action( 'frm_success_action', $args['conf_method'], $args['form'], $args['form']->options, $args['entry_id'], $extra_args );
2250 2428
2251 - $opt = ( ! isset( $args['action'] ) || $args['action'] === 'create' ) ? 'success' : 'edit';
2429 + $opt = ! isset( $args['action'] ) || $args['action'] === 'create' ? 'success' : 'edit';
2252 2430
2253 2431 $args['success_opt'] = $opt;
2254 2432 $args['ajax'] = ! empty( $frm_vars['ajax'] );
2255 2433
@@ -2275,16 +2453,16 @@
2275 2453 if ( ! FrmOnSubmitHelper::form_has_migrated( $args['form'] ) ) {
2276 2454 return array();
2277 2455 }
2278 2456
2279 - // If a redirect action has already opened the URL in a new tab, we show the default message in the currect tab.
2457 + // If a redirect action has already opened the URL in a new tab, we show the default message in the current tab.
2280 2458 if ( ! empty( self::$redirected_in_new_tab[ $args['form']->id ] ) ) {
2281 2459 return array( FrmOnSubmitHelper::get_fallback_action_after_open_in_new_tab( $event ) );
2282 2460 }
2283 2461
2284 - $entry = FrmEntry::getOne( $args['entry_id'], true );
2285 - $actions = FrmOnSubmitHelper::get_actions( $args['form']->id );
2286 - $met_actions = array();
2462 + $entry = FrmEntry::getOne( $args['entry_id'], true );
2463 + $actions = FrmOnSubmitHelper::get_actions( $args['form']->id );
2464 + $met_actions = array();
2287 2465 $has_redirect = false;
2288 2466
2289 2467 foreach ( $actions as $action ) {
2290 2468 if ( ! in_array( $event, $action->post_content['event'], true ) ) {
@@ -2297,9 +2475,10 @@
2297 2475
2298 2476 $action_type = FrmOnSubmitHelper::get_action_type( $action );
2299 2477
2300 2478 if ( 'redirect' === $action_type ) {
2301 - if ( $has_redirect ) { // Do not process because we run the first redirect action only.
2479 + if ( $has_redirect ) {
2480 + // Do not process because we run the first redirect action only.
2302 2481 continue;
2303 2482 }
2304 2483 }
2305 2484
@@ -2312,9 +2491,9 @@
2312 2491 }
2313 2492
2314 2493 $met_actions[] = $action;
2315 2494 unset( $action );
2316 - }
2495 + }//end foreach
2317 2496
2318 2497 $args['event'] = $event;
2319 2498
2320 2499 /**
@@ -2503,9 +2682,9 @@
2503 2682 add_filter( 'the_content', 'FrmFormsController::preview_content', 9999 );
2504 2683 }
2505 2684
2506 2685 $post = $old_post;
2507 - }
2686 + }//end if
2508 2687 }
2509 2688
2510 2689 /**
2511 2690 * @since 3.0
@@ -2526,14 +2705,16 @@
2526 2705 $success_url = apply_filters( 'frm_redirect_url', $success_url, $args['form'], $args );
2527 2706
2528 2707 $doing_ajax = FrmAppHelper::doing_ajax();
2529 2708
2530 - if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) { // Is AJAX submit and there is just one Redirect action runs.
2709 + if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) {
2710 + // Is AJAX submit and there is just one Redirect action runs.
2531 2711 echo json_encode( self::get_ajax_redirect_response_data( $args + compact( 'success_url' ) ) );
2532 2712 wp_die();
2533 2713 }
2534 2714
2535 - if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) ) { // Not AJAX submit, no headers sent, and there is just one Redirect action runs.
2715 + if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) ) {
2716 + // Not AJAX submit, no headers sent, and there is just one Redirect action runs.
2536 2717 if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2537 2718 self::print_open_in_new_tab_js_with_fallback_handler( $success_url, $args );
2538 2719 self::$redirected_in_new_tab[ $args['form']->id ] = 1;
2539 2720 return;
@@ -2539,9 +2720,10 @@
2539 2720 return;
2540 2721 }
2541 2722
2542 2723 wp_redirect( esc_url_raw( $success_url ) );
2543 - die(); // do not use wp_die or redirect fails
2724 + // Do not use wp_die or redirect fails.
2725 + die();
2544 2726 }
2545 2727
2546 2728 // Redirect with a delay.
2547 2729 self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) );
@@ -2549,9 +2731,9 @@
2549 2731
2550 2732 /**
2551 2733 * Prints open in new tab js with fallback handler.
2552 2734 *
2553 - * @since 6.x
2735 + * @since 6.3.1
2554 2736 *
2555 2737 * @param string $success_url Success URL.
2556 2738 * @param array $args See {@see FrmFormsController::redirect_after_submit()}.
2557 2739 */
@@ -2570,9 +2752,9 @@
2570 2752
2571 2753 /**
2572 2754 * Gets response data for redirect action when AJAX submitting.
2573 2755 *
2574 - * @since 6.x
2756 + * @since 6.3.1
2575 2757 *
2576 2758 * @param array $args See {@see FrmFormsController::run_success_action()}.
2577 2759 * @return array
2578 2760 */
@@ -2592,9 +2774,9 @@
2592 2774
2593 2775 $args['message'] = self::prepare_submit_message( $args['form'], $args['entry_id'], $args );
2594 2776
2595 2777 ob_start();
2596 - self::show_lone_success_messsage( $args );
2778 + self::show_lone_success_message( $args );
2597 2779 $response_data['content'] = ob_get_clean();
2598 2780
2599 2781 $response_data['fallbackMsg'] = self::get_redirect_fallback_message( $args['success_url'], $args );
2600 2782 }
@@ -2618,9 +2800,9 @@
2618 2800 * Filters the delay time before redirecting when On Submit Redirect action is delayed.
2619 2801 *
2620 2802 * @since 6.0
2621 2803 *
2622 - * @param int $delay_time Delay time in miliseconds.
2804 + * @param int $delay_time Delay time in milliseconds.
2623 2805 */
2624 2806 $delay_time = apply_filters( 'frm_redirect_delay_time', 8000 );
2625 2807
2626 2808 if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
@@ -2632,9 +2814,10 @@
2632 2814 add_filter( 'frm_use_wpautop', '__return_true' );
2633 2815
2634 2816 echo FrmAppHelper::maybe_kses( $redirect_msg ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2635 2817 echo '<script>';
2636 - if ( empty( $args['doing_ajax'] ) ) { // Not AJAX submit, delay JS until window.load.
2818 + if ( empty( $args['doing_ajax'] ) ) {
2819 + // Not AJAX submit, delay JS until window.load.
2637 2820 echo 'window.onload=function(){';
2638 2821 }
2639 2822 echo 'setTimeout(function(){' . $redirect_js . '}, ' . intval( $delay_time ) . ');'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2640 2823 if ( empty( $args['doing_ajax'] ) ) {
@@ -2647,9 +2830,9 @@
2647 2830 * @since 3.0
2648 2831 *
2649 2832 * @param string $success_url
2650 2833 * @param string $success_msg
2651 - * @param array $args
2834 + * @param array $args
2652 2835 */
2653 2836 private static function get_redirect_message( $success_url, $success_msg, $args ) {
2654 2837 $redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg" role="status">' . $success_msg . '<br/>' .
2655 2838 self::get_redirect_fallback_message( $success_url, $args ) .
@@ -2666,9 +2849,9 @@
2666 2849
2667 2850 /**
2668 2851 * Gets fallback message when redirecting failed.
2669 2852 *
2670 - * @since 6.x
2853 + * @since 6.3.1
2671 2854 *
2672 2855 * @param string $success_url Redirect URL.
2673 2856 * @param array $args Contains `form` object.
2674 2857 * @return string
@@ -2707,9 +2890,9 @@
2707 2890 } else {
2708 2891 self::show_form_after_submit( $atts );
2709 2892 }
2710 2893 } else {
2711 - self::show_lone_success_messsage( $atts );
2894 + self::show_lone_success_message( $atts );
2712 2895 }
2713 2896 }
2714 2897
2715 2898 /**
@@ -2748,11 +2931,10 @@
2748 2931 include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php';
2749 2932 }
2750 2933
2751 2934 /**
2935 + * @since 4.05.02
2752 2936 * @return string - 'before', 'after', or 'submit'
2753 - *
2754 - * @since 4.05.02
2755 2937 */
2756 2938 private static function message_placement( $form, $message ) {
2757 2939 $place = 'before';
2758 2940
@@ -2764,11 +2946,10 @@
2764 2946 }
2765 2947 }
2766 2948
2767 2949 /**
2950 + * @since 4.05.02
2768 2951 * @return string - 'before' or 'after'
2769 - *
2770 - * @since 4.05.02
2771 2952 */
2772 2953 return apply_filters( 'frm_message_placement', $place, compact( 'form', 'message' ) );
2773 2954 }
2774 2955
@@ -2802,9 +2983,9 @@
2802 2983 * Show the success message without the form
2803 2984 *
2804 2985 * @since 2.05
2805 2986 */
2806 - private static function show_lone_success_messsage( $atts ) {
2987 + private static function show_lone_success_message( $atts ) {
2807 2988 global $frm_vars;
2808 2989 $values = FrmEntriesHelper::setup_new_vars( $atts['fields'], $atts['form'], true );
2809 2990 self::maybe_load_css( $atts['form'], $values['custom_style'], $frm_vars['load_css'] );
2810 2991
@@ -2813,9 +2994,9 @@
2813 2994 $errors = array();
2814 2995 $form = $atts['form'];
2815 2996 $message = $atts['message'];
2816 2997
2817 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php' );
2998 + include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php';
2818 2999 }
2819 3000
2820 3001 /**
2821 3002 * Prepare the success message before it's shown
@@ -2935,9 +3116,9 @@
2935 3116 global $frm_vars;
2936 3117
2937 3118 FrmStylesController::enqueue_css();
2938 3119
2939 - if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
3120 + if ( ! FrmAppHelper::is_admin() && $location !== 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
2940 3121 // load formidable js
2941 3122 wp_enqueue_script( 'formidable' );
2942 3123 }
2943 3124 }
@@ -2953,12 +3134,12 @@
2953 3134 }
2954 3135
2955 3136 /**
2956 3137 * @since 2.0.8
2957 - * @return boolean
3138 + * @return bool
2958 3139 */
2959 3140 private static function is_minification_on( $atts ) {
2960 - return isset( $atts['minimize'] ) && ! empty( $atts['minimize'] );
3141 + return ! empty( $atts['minimize'] );
2961 3142 }
2962 3143
2963 3144 /**
2964 3145 * @since 5.0.16
@@ -2986,9 +3167,9 @@
2986 3167 * Create a page with an embedded formidable Gutenberg block.
2987 3168 *
2988 3169 * @since 5.2
2989 3170 *
2990 - * @return never
3171 + * @return void
2991 3172 */
2992 3173 public static function create_page_with_shortcode() {
2993 3174 if ( ! current_user_can( 'publish_posts' ) ) {
2994 3175 die( 0 );
@@ -3033,10 +3214,9 @@
3033 3214
3034 3215 /**
3035 3216 * @since 5.3
3036 3217 *
3037 - * @param string $content
3038 - * @param int $form_id
3218 + * @param int $form_id
3039 3219 * @return string
3040 3220 */
3041 3221 private static function get_page_shortcode_content_for_form( $form_id ) {
3042 3222 $shortcode = '[formidable id="' . $form_id . '"]';
@@ -3047,9 +3227,9 @@
3047 3227
3048 3228 /**
3049 3229 * Get page dropdown for AJAX request for embedding form in an existing page.
3050 3230 *
3051 - * @return never
3231 + * @return void
3052 3232 */
3053 3233 public static function get_page_dropdown() {
3054 3234 if ( ! current_user_can( 'publish_posts' ) ) {
3055 3235 die( 0 );
@@ -3057,9 +3237,9 @@
3057 3237
3058 3238 check_ajax_referer( 'frm_ajax', 'nonce' );
3059 3239
3060 3240 $html = FrmAppHelper::clip(
3061 - function() {
3241 + function () {
3062 3242 FrmAppHelper::maybe_autocomplete_pages_options(
3063 3243 array(
3064 3244 'field_name' => 'frm_page_dropdown',
3065 3245 'page_id' => '',
@@ -3079,15 +3259,8 @@
3079 3259
3080 3260 /**
3081 3261 * @deprecated 4.0
3082 3262 */
3083 - public static function new_form( $values = array() ) {
3084 - FrmDeprecated::new_form( $values );
3085 - }
3086 -
3087 - /**
3088 - * @deprecated 4.0
3089 - */
3090 3263 public static function create( $values = array() ) {
3091 3264 _deprecated_function( __METHOD__, '4.0', 'FrmFormsController::update' );
3092 3265 self::update( $values );
3093 3266 }
@@ -3092,35 +3265,13 @@
3092 3265 self::update( $values );
3093 3266 }
3094 3267
3095 3268 /**
3096 - * @deprecated 3.0
3097 - * @codeCoverageIgnore
3269 + * @deprecated 6.7
3270 + *
3271 + * @return bool
3098 3272 */
3099 - public static function bulk_create_template( $ids ) {
3100 - return FrmDeprecated::bulk_create_template( $ids );
3101 - }
3102 -
3103 - /**
3104 - * @deprecated 3.0
3105 - * @codeCoverageIgnore
3106 - */
3107 - public static function edit_key() {
3108 - FrmDeprecated::edit_key();
3109 - }
3110 -
3111 - /**
3112 - * @deprecated 3.0
3113 - * @codeCoverageIgnore
3114 - */
3115 - public static function edit_description() {
3116 - FrmDeprecated::edit_description();
3117 - }
3118 -
3119 - /**
3120 - * @deprecated 4.08
3121 - * @since 3.06
3122 - */
3123 - public static function add_new() {
3124 - _deprecated_function( __FUNCTION__, '4.08' );
3273 + public static function expired() {
3274 + _deprecated_function( __METHOD__, '6.7' );
3275 + return FrmAddonsController::is_license_expired();
3125 3276 }
3126 3277 }