PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.2
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 +463 -829 6.256.2 View file →
@@ -5,27 +5,16 @@
5 5
6 6 class FrmFormsController {
7 7
8 8 /**
9 - * Track the form that opened the redirect URL in a new tab. This is used to check if we should show the default
10 - * message in the current tab.
9 + * Track the form and action that ran frm_redirect_url filter. Each item in array is {form_id}_create or {form_id}_update.
11 10 *
12 11 * @since 6.2
13 12 *
14 - * @var array Keys are form IDs and values are 1.
13 + * @var array
15 14 */
16 - private static $redirected_in_new_tab = array();
15 + private static $ran_redirect_url_filter = array();
17 16
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 -
28 17 public static function menu() {
29 18 $menu_label = __( 'Forms', 'formidable' );
30 19 if ( ! FrmAppHelper::pro_is_installed() ) {
31 20 $menu_label .= ' (Lite)';
@@ -64,12 +53,12 @@
64 53 */
65 54 public static function logic_tip() {
66 55 $images_url = FrmAppHelper::plugin_url() . '/images/';
67 56 $data_message = __( 'Only show the fields you need and create branching forms. Upgrade to get conditional logic and question branching.', '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' ) . '"/>';
57 + $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' ) . '"/>';
69 58 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">';
70 59 esc_html_e( 'Conditional Logic', 'formidable' );
71 - FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown8_icon', array( 'aria-hidden' => 'true' ) );
60 + FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown6_icon', array( 'aria-hidden' => 'true' ) );
72 61 echo '</a>';
73 62 }
74 63
75 64 /**
@@ -106,23 +95,15 @@
106 95 * Create the default email action
107 96 *
108 97 * @since 2.02.11
109 98 *
110 - * @param int|object $form
111 - * @return void
99 + * @param object|int $form
112 100 */
113 101 private static function create_default_email_action( $form ) {
114 102 FrmForm::maybe_get_form( $form );
115 - if ( ! is_object( $form ) ) {
116 - return;
117 - }
118 -
119 103 $create_email = apply_filters( 'frm_create_default_email_action', true, $form );
120 104
121 105 if ( $create_email ) {
122 - /**
123 - * @var FrmFormAction
124 - */
125 106 $action_control = FrmFormActionsController::get_form_actions( 'email' );
126 107 $action_control->create( $form->id );
127 108 }
128 109 }
@@ -131,16 +112,12 @@
131 112 * Create the default On submit action
132 113 *
133 114 * @since 6.0.0
134 115 *
135 - * @param int|object $form Form object or ID.
136 - * @return void
116 + * @param object|int $form Form object or ID.
137 117 */
138 118 private static function create_default_on_submit_action( $form ) {
139 119 FrmForm::maybe_get_form( $form );
140 - if ( ! is_object( $form ) ) {
141 - return;
142 - }
143 120
144 121 /**
145 122 * Enable or disable the default On Submit action.
146 123 *
@@ -151,65 +128,21 @@
151 128 */
152 129 $create = apply_filters( 'frm_create_default_on_submit_action', true, $form );
153 130
154 131 if ( $create ) {
155 - /**
156 - * @var FrmFormAction
157 - */
158 132 $action_control = FrmFormActionsController::get_form_actions( FrmOnSubmitAction::$slug );
159 133 $action_control->create( $form->id );
160 134 }
161 135 }
162 136
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 - */
199 137 public static function edit( $values = false ) {
200 138 FrmAppHelper::permission_check( 'frm_edit_forms' );
201 139
202 140 $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
203 141
204 - self::get_edit_vars( $id );
142 + return self::get_edit_vars( $id );
205 143 }
206 144
207 - /**
208 - * @param mixed $id
209 - * @param string $message
210 - * @return void
211 - */
212 145 public static function settings( $id = false, $message = '' ) {
213 146 FrmAppHelper::permission_check( 'frm_edit_forms' );
214 147
215 148 if ( ! $id || ! is_numeric( $id ) ) {
@@ -217,34 +150,21 @@
217 150 }
218 151
219 152 FrmOnSubmitHelper::maybe_migrate_submit_settings_to_action( $id );
220 153
221 - self::get_settings_vars( $id, array(), $message );
154 + return self::get_settings_vars( $id, array(), $message );
222 155 }
223 156
224 157 public static function update_settings() {
225 158 FrmAppHelper::permission_check( 'frm_edit_forms' );
226 - $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
227 159
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 -
239 160 $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
240 161
241 - $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
162 + $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
242 163 $warnings = FrmFormsHelper::check_for_warnings( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
243 164
244 165 if ( count( $errors ) > 0 ) {
245 - self::get_settings_vars( $id, $errors, compact( 'warnings' ) );
246 - return;
166 + return self::get_settings_vars( $id, $errors, compact( 'warnings' ) );
247 167 }
248 168
249 169 do_action( 'frm_before_update_form_settings', $id );
250 170
@@ -258,9 +178,9 @@
258 178 }
259 179
260 180 $message = __( 'Settings Successfully Updated', 'formidable' );
261 181
262 - self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) );
182 + return self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) );
263 183 }
264 184
265 185 /**
266 186 * @param int $form_id
@@ -270,11 +190,8 @@
270 190 $form = FrmForm::getOne( $form_id );
271 191 return ! empty( $form->options['antispam'] );
272 192 }
273 193
274 - /**
275 - * @return void
276 - */
277 194 public static function update( $values = array() ) {
278 195 if ( empty( $values ) ) {
279 196 $values = $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing
280 197 }
@@ -292,72 +209,63 @@
292 209
293 210 $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
294 211
295 212 if ( count( $errors ) > 0 ) {
296 - self::get_edit_vars( $id, $errors );
297 - return;
298 - }
213 + return self::get_edit_vars( $id, $errors );
214 + } else {
215 + FrmForm::update( $id, $values );
216 + $message = __( 'Form was successfully updated.', 'formidable' );
299 217
300 - self::maybe_remove_draft_option_from_fields( $id );
218 + if ( self::is_too_long( $values ) ) {
219 + $message .= '<br/> ' . sprintf(
220 + /* translators: %1$s: Start link HTML, %2$s: end link HTML */
221 + __( 'However, your form is very long and may be %1$sreaching server limits%2$s.', 'formidable' ),
222 + '<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">',
223 + '</a>'
224 + );
225 + }
301 226
302 - FrmForm::update( $id, $values );
303 - $message = __( 'Form was successfully updated.', 'formidable' );
227 + if ( defined( 'DOING_AJAX' ) ) {
228 + wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
229 + }
304 230
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 - );
231 + return self::get_edit_vars( $id, array(), $message );
312 232 }
233 + }
313 234
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 );
235 + /**
236 + * Check if the value at the end of the form was included.
237 + * If it's missing, it means other values at the end of the form
238 + * were likely not saved either.
239 + *
240 + * @since 3.06.01
241 + */
242 + private static function is_too_long( $values ) {
243 + return ( ! isset( $values['frm_end'] ) ) || empty( $values['frm_end'] );
319 244 }
320 245
321 246 /**
322 - * Remove the draft flag from any new fields from this current session.
247 + * Redirect to the url for creating from a template
248 + * Also delete the current form
323 249 *
324 - * @since 6.8
325 - *
326 - * @param int $form_id
327 - * @return void
250 + * @since 2.0
251 + * @deprecated 3.06
328 252 */
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 - }
253 + public static function _create_from_template() {
254 + _deprecated_function( __FUNCTION__, '3.06' );
335 255
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 - }
256 + FrmAppHelper::permission_check( 'frm_edit_forms' );
257 + check_ajax_referer( 'frm_ajax', 'nonce' );
341 258
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 ) );
259 + $current_form = FrmAppHelper::get_param( 'this_form', '', 'get', 'absint' );
260 + $template_id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
261 +
262 + if ( $current_form ) {
263 + FrmForm::destroy( $current_form );
346 264 }
347 - }
348 265
349 - /**
350 - * Check if the value at the end of the form was included.
351 - * If it's missing, it means other values at the end of the form
352 - * were likely not saved either.
353 - *
354 - * @since 3.06.01
355 - *
356 - * @return bool
357 - */
358 - private static function is_too_long( $values ) {
359 - return empty( $values['frm_end'] );
266 + echo esc_url_raw( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template_id ) ) );
267 + wp_die();
360 268 }
361 269
362 270 public static function duplicate() {
363 271 FrmAppHelper::permission_check( 'frm_edit_forms' );
@@ -373,11 +281,10 @@
373 281 $url = admin_url( 'admin.php?page=formidable' );
374 282 $message = 'form_duplicate_error';
375 283
376 284 if ( $form ) {
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';
285 + $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) );
286 + $message = 'form_duplicated';
380 287 }
381 288
382 289 $url .= '&message=' . $message;
383 290
@@ -385,42 +292,27 @@
385 292 exit();
386 293 }
387 294
388 295 /**
389 - * @return string|null
296 + * @return string
390 297 */
391 298 public static function page_preview() {
392 299 $params = FrmForm::list_page_params();
393 - if ( ! $params['form'] || is_numeric( $params['form'] ) ) {
394 - return null;
300 + if ( ! $params['form'] ) {
301 + return;
395 302 }
396 303
397 - self::maybe_block_preview( $params['form'] );
398 -
399 304 $form = FrmForm::getOne( $params['form'] );
400 - if ( ! $form ) {
401 - return null;
305 + if ( $form ) {
306 + return self::show_form( $form->id, '', 'auto', 'auto' );
402 307 }
403 -
404 - return self::show_form( $form->id, '', 'auto', 'auto' );
405 308 }
406 309
407 310 /**
408 311 * @since 3.0
409 - *
410 - * @return void
411 312 */
412 313 public static function show_page_preview() {
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
314 + echo self::page_preview(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
423 315 }
424 316
425 317 /**
426 318 * @return void
@@ -431,17 +323,8 @@
431 323
432 324 global $frm_vars;
433 325 $frm_vars['preview'] = true;
434 326
435 - // print_emoji_styles is deprecated.
436 - remove_action( 'wp_print_styles', 'print_emoji_styles' );
437 -
438 - if ( FrmTestModeController::should_add_test_mode_container() ) {
439 - do_action( 'frm_test_mode_init' );
440 - add_action( 'wp_enqueue_scripts', 'FrmTestModeController::register_and_enqueue_required_scripts' );
441 - add_filter( 'frm_filter_final_form', 'FrmTestModeController::maybe_add_test_mode_container', 99 );
442 - }
443 -
444 327 $include_theme = FrmAppHelper::get_param( 'theme', '', 'get', 'absint' );
445 328 if ( $include_theme ) {
446 329 self::set_preview_query();
447 330 self::load_theme_preview();
@@ -476,13 +359,8 @@
476 359 return;
477 360 }
478 361
479 362 $random_page = reset( $random_page );
480 - if ( ! is_a( $random_page, 'WP_Post' ) ) {
481 - // The return type can also be int.
482 - return;
483 - }
484 -
485 363 query_posts(
486 364 array(
487 365 'post_type' => 'page',
488 366 'page_id' => $random_page->ID,
@@ -498,9 +376,9 @@
498 376 * Set the WP $post global object. Used for in-theme preview when defining a page.
499 377 *
500 378 * @since 5.5.2
501 379 *
502 - * @param WP_Post $page The page object.
380 + * @param WP_Post $post
503 381 * @return void
504 382 */
505 383 private static function set_post_global( $page ) {
506 384 global $post;
@@ -508,10 +386,8 @@
508 386 }
509 387
510 388 /**
511 389 * @since 3.0
512 - *
513 - * @return void
514 390 */
515 391 private static function load_theme_preview() {
516 392 add_filter( 'wp_title', 'FrmFormsController::preview_title', 9999 );
517 393 add_filter( 'the_title', 'FrmFormsController::preview_page_title', 9999 );
@@ -520,39 +396,20 @@
520 396 add_filter( 'is_active_sidebar', '__return_false' );
521 397 FrmStylesController::enqueue_css( 'enqueue', true );
522 398
523 399 if ( false === get_template_part( 'page' ) ) {
524 - if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) {
525 - add_filter( 'body_class', 'FrmFormsController::preview_block_theme_body_classnames' );
526 - }
527 400 self::fallback_when_page_template_part_is_not_supported_by_theme();
528 401 }
529 402 }
530 403
531 404 /**
532 - * Add padding to the body for block themes.
533 - *
534 - * @since 6.5.2
535 - *
536 - * @param array $classes The body classes list.
537 - * @return array
538 - */
539 - public static function preview_block_theme_body_classnames( $classes ) {
540 - $classes[] = 'has-global-padding';
541 - return $classes;
542 - }
543 -
544 - /**
545 405 * Not every theme supports get_template_part( 'page' ).
546 406 * When this is not supported, false is returned, and we can handle a fallback.
547 - *
548 - * @return void
549 407 */
550 408 private static function fallback_when_page_template_part_is_not_supported_by_theme() {
551 409 if ( have_posts() ) {
552 410 the_post();
553 - self::get_template( 'header' );
554 -
411 + get_header( '' );
555 412 // add some generic class names to the container to add some natural padding to the content.
556 413 // .entry-content catches the WordPress TwentyTwenty theme.
557 414 // .container catches Customizr content.
558 415 echo '<div class="container entry-content">';
@@ -557,58 +414,13 @@
557 414 // .container catches Customizr content.
558 415 echo '<div class="container entry-content">';
559 416 the_content();
560 417 echo '</div>';
561 -
562 - // Prevent extra unexpected forms in the footer.
563 - // For some reason this happens in the Twenty Twenty Five theme.
564 - add_filter( 'frm_filter_final_form', '__return_empty_string' );
565 -
566 - self::get_template( 'footer' );
418 + get_footer();
567 419 }
568 420 }
569 421
570 422 /**
571 - * Calls core function to get a template part if it doesn't cause deprecation warnings. Otherwise skips the deprecation function call
572 - * and renders required html fragments calling required functions.
573 - *
574 - * @since 6.7.1
575 - * @param string $template
576 - * @return void
577 - */
578 - private static function get_template( $template ) {
579 - if ( self::should_try_getting_template( $template ) ) {
580 - call_user_func( 'get_' . $template );
581 - return;
582 - }
583 -
584 - if ( 'header' === $template ) {
585 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/header.php';
586 - return;
587 - }
588 -
589 - if ( 'footer' === $template ) {
590 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/footer.php';
591 - }
592 - }
593 -
594 - /**
595 - * Returns true if calling a template function doesn't trigger deprecation warnings.
596 - *
597 - * @since 6.7.1
598 - * @param string $template
599 - * @return bool
600 - */
601 - private static function should_try_getting_template( $template ) {
602 - $stylesheet_path = get_stylesheet_directory();
603 - $template_path = get_template_directory();
604 - $is_child_theme = $stylesheet_path !== $template_path;
605 - $template_name = $template . '.php';
606 -
607 - return file_exists( $stylesheet_path . '/' . $template_name ) || $is_child_theme && file_exists( $template_path . '/' . $template_name );
608 - }
609 -
610 - /**
611 423 * Set the page title for the theme preview page
612 424 *
613 425 * @since 3.0
614 426 */
@@ -620,14 +432,11 @@
620 432 return $title;
621 433 }
622 434
623 435 /**
624 - * Set the page title for the theme preview page.
436 + * Set the page title for the theme preview page
625 437 *
626 438 * @since 3.0
627 - *
628 - * @param string $title
629 - * @return string
630 439 */
631 440 public static function preview_title( $title ) {
632 441 return __( 'Form Preview', 'formidable' );
633 442 }
@@ -632,20 +441,15 @@
632 441 return __( 'Form Preview', 'formidable' );
633 442 }
634 443
635 444 /**
636 - * Set the page content for the theme preview page.
445 + * Set the page content for the theme preview page
637 446 *
638 447 * @since 3.0
639 - *
640 - * @param string $content
641 - * @return string
642 448 */
643 449 public static function preview_content( $content ) {
644 450 if ( in_the_loop() ) {
645 - self::show_page_preview();
646 - // Clear the content for the page we're using.
647 - $content = '';
451 + $content = self::show_page_preview();
648 452 }
649 453
650 454 return $content;
651 455 }
@@ -653,88 +457,23 @@
653 457 /**
654 458 * @since 3.0
655 459 */
656 460 private static function load_direct_preview() {
461 + header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
462 +
657 463 $key = FrmAppHelper::simple_get( 'form', 'sanitize_title' );
658 464 if ( $key == '' ) {
659 465 $key = FrmAppHelper::get_post_param( 'form', '', 'sanitize_title' );
660 466 }
661 467
662 - if ( ! $key ) {
663 - $error = __( 'Form key is missing', 'formidable' );
664 - wp_die(
665 - '<h1>' . esc_html( $error ) . '</h1>',
666 - '<p>' . esc_html( $error ) . '</p>',
667 - 404
668 - );
669 - }
670 -
671 - self::maybe_block_preview( $key );
672 -
673 468 $form = FrmForm::getAll( array( 'form_key' => $key ), '', 1 );
674 - if ( ! $form ) {
675 - $error = __( 'Form does not exist', 'formidable' );
676 - wp_die(
677 - '<h1>' . esc_html( $error ) . '</h1>',
678 - '<p>' . esc_html( $error ) . '</p>',
679 - 404
680 - );
469 + if ( empty( $form ) ) {
470 + $form = FrmForm::getAll( array(), '', 1 );
681 471 }
682 472
683 - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
684 -
685 - self::fix_deprecated_null_param_warning();
686 -
687 - require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php';
473 + require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php' );
688 474 }
689 475
690 - /**
691 - * Block the form preview for the contact form by default if the user cannot view forms.
692 - * This is to prevent the contact form being exploited.
693 - * Since this form is added by default and every site uses the same key, it is too easy
694 - * to guess this form.
695 - *
696 - * @since 6.20
697 - *
698 - * @param string $form_key Form key.
699 - * @return void
700 - */
701 - public static function maybe_block_preview( $form_key ) {
702 - if ( FrmFormsHelper::should_block_preview( $form_key ) ) {
703 - $error = __( 'You do not have permission to view this form', 'formidable' );
704 - wp_die(
705 - '<h1>' . esc_html( $error ) . '</h1>',
706 - '<p>' . esc_html( $error ) . '</p>',
707 - 403
708 - );
709 - }
710 - }
711 -
712 - /**
713 - * Some themes have a null $src value.
714 - * This function adds a filter to ensure that $src is not null.
715 - * WP will call str_starts_with with the null value triggering a deprecated message otherwise.
716 - *
717 - * @since 6.10
718 - *
719 - * @return void
720 - */
721 - private static function fix_deprecated_null_param_warning() {
722 - add_filter(
723 - 'script_loader_src',
724 - /**
725 - * @param string|null $src
726 - * @return string
727 - */
728 - function ( $src ) {
729 - if ( is_null( $src ) ) {
730 - $src = '';
731 - }
732 - return $src;
733 - }
734 - );
735 - }
736 -
737 476 public static function untrash() {
738 477 self::change_form_status( 'untrash' );
739 478 }
740 479
@@ -797,14 +536,14 @@
797 536 FrmAppHelper::permission_check( $available_status[ $status ]['permission'] );
798 537
799 538 $params = FrmForm::list_page_params();
800 539
801 - // Check nonce url.
540 + //check nonce url
802 541 check_admin_referer( $status . '_form_' . $params['id'] );
803 542
804 543 $count = 0;
805 544 if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) {
806 - ++$count;
545 + $count ++;
807 546 }
808 547
809 548 $form_type = FrmAppHelper::get_simple_request(
810 549 array(
@@ -816,9 +555,9 @@
816 555 /* translators: %1$s: Number of forms */
817 556 $available_status['untrash']['message'] = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
818 557
819 558 /* translators: %1$s: Number of forms, %2$s: Start link HTML, %3$s: End link HTML */
820 - $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>' );
559 + $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>' );
821 560
822 561 $message = $available_status[ $status ]['message'];
823 562
824 563 self::display_forms_list( $params, $message );
@@ -823,12 +562,8 @@
823 562
824 563 self::display_forms_list( $params, $message );
825 564 }
826 565
827 - /**
828 - * @param array $ids
829 - * @return string
830 - */
831 566 public static function bulk_trash( $ids ) {
832 567 FrmAppHelper::permission_check( 'frm_delete_forms' );
833 568
834 569 $count = 0;
@@ -833,16 +568,12 @@
833 568
834 569 $count = 0;
835 570 foreach ( $ids as $id ) {
836 571 if ( FrmForm::trash( $id ) ) {
837 - ++$count;
572 + $count ++;
838 573 }
839 574 }
840 575
841 - if ( ! $count ) {
842 - return '';
843 - }
844 -
845 576 $current_page = FrmAppHelper::get_simple_request(
846 577 array(
847 578 'param' => 'form_type',
848 579 'type' => 'request',
@@ -868,9 +599,9 @@
868 599 check_admin_referer( 'destroy_form_' . $params['id'] );
869 600
870 601 $count = 0;
871 602 if ( FrmForm::destroy( $params['id'] ) ) {
872 - ++$count;
603 + $count ++;
873 604 }
874 605
875 606 /* translators: %1$s: Number of forms */
876 607 $message = sprintf( _n( '%1$s Form Permanently Deleted', '%1$s Forms Permanently Deleted', $count, 'formidable' ), $count );
@@ -877,12 +608,8 @@
877 608
878 609 self::display_forms_list( $params, $message );
879 610 }
880 611
881 - /**
882 - * @param array $ids
883 - * @return string
884 - */
885 612 public static function bulk_destroy( $ids ) {
886 613 FrmAppHelper::permission_check( 'frm_delete_forms' );
887 614
888 615 $count = 0;
@@ -888,24 +615,19 @@
888 615 $count = 0;
889 616 foreach ( $ids as $id ) {
890 617 $d = FrmForm::destroy( $id );
891 618 if ( $d ) {
892 - ++$count;
619 + $count ++;
893 620 }
894 621 }
895 622
896 - if ( $count ) {
897 - /* translators: %1$s: Number of forms */
898 - return sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
899 - }
623 + /* translators: %1$s: Number of forms */
624 + $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
900 625
901 - return '';
626 + return $message;
902 627 }
903 628
904 - /**
905 - * @since 6.7.1 Function went from private to public.
906 - */
907 - public static function delete_all() {
629 + private static function delete_all() {
908 630 // Check nonce url.
909 631 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' );
910 632 if ( $permission_error !== false ) {
911 633 self::display_forms_list( array(), '', array( $permission_error ) );
@@ -912,15 +634,14 @@
912 634
913 635 return;
914 636 }
915 637
916 - $count = FrmForm::scheduled_delete( time() );
917 - $url = remove_query_arg( array( 'delete_all' ) );
638 + $count = FrmForm::scheduled_delete( time() );
918 639
919 - $url .= '&message=forms_permanently_deleted&forms_deleted=' . $count;
640 + /* translators: %1$s: Number of forms */
641 + $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
920 642
921 - wp_safe_redirect( $url );
922 - die();
643 + self::display_forms_list( array(), $message );
923 644 }
924 645
925 646 /**
926 647 * Create a new form from the modal.
@@ -933,9 +654,9 @@
933 654
934 655 $new_values = self::get_modal_values();
935 656 $new_values['form_key'] = $new_values['name'];
936 657 $new_values['options'] = array(
937 - 'antispam' => 1,
658 + 'antispam' => 1,
938 659 'on_submit_migrated' => 1,
939 660 );
940 661
941 662 /**
@@ -954,14 +675,13 @@
954 675 * @param int $form_id
955 676 */
956 677 do_action( 'frm_build_new_form', $form_id );
957 678
958 - self::create_submit_button_field( $form_id );
959 679 self::create_default_on_submit_action( $form_id );
960 680 self::create_default_email_action( $form_id );
961 681
962 682 $response = array(
963 - 'redirect' => FrmForm::get_edit_link( $form_id ) . '&new_template=true',
683 + 'redirect' => FrmForm::get_edit_link( $form_id ),
964 684 );
965 685
966 686 echo wp_json_encode( $response );
967 687 wp_die();
@@ -967,15 +687,46 @@
967 687 wp_die();
968 688 }
969 689
970 690 /**
691 + * Create a custom template from a form
692 + *
693 + * @since 3.06
694 + */
695 + public static function build_template() {
696 + global $wpdb;
697 +
698 + FrmAppHelper::permission_check( 'frm_edit_forms' );
699 + check_ajax_referer( 'frm_ajax', 'nonce' );
700 +
701 + $form_id = FrmAppHelper::get_param( 'xml', '', 'post', 'absint' );
702 + $new_form_id = FrmForm::duplicate( $form_id, 1, true );
703 + if ( ! $new_form_id ) {
704 + $response = array(
705 + 'message' => __( 'There was an error creating a template.', 'formidable' ),
706 + );
707 + } else {
708 + $new_values = self::get_modal_values();
709 + $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $new_form_id ) );
710 + if ( $query_results ) {
711 + FrmForm::clear_form_cache();
712 + }
713 +
714 + $response = array(
715 + 'redirect' => admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . $new_form_id ) . '&_wpnonce=' . wp_create_nonce(),
716 + );
717 + }
718 +
719 + echo wp_json_encode( $response );
720 + wp_die();
721 + }
722 +
723 + /**
971 724 * Before creating a new form, get the name and description from the modal.
972 725 *
973 726 * @since 4.0
974 - *
975 - * @return array<string,string>
976 727 */
977 - public static function get_modal_values() {
728 + private static function get_modal_values() {
978 729 $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' );
979 730 $desc = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' );
980 731
981 732 return array(
@@ -988,24 +739,17 @@
988 739 * Inserts Formidable button
989 740 * Hook exists since 2.5.0
990 741 *
991 742 * @since 2.0.15
992 - *
993 - * @return void
994 743 */
995 744 public static function insert_form_button() {
996 745 if ( current_user_can( 'frm_view_forms' ) ) {
997 - // Store the result in memory and re-use it when this function is called multiple times.
998 - // This helps speed up the form builder when there are a lot of HTML fields, where this
999 - // button is inserted once per HTML field.
1000 - // In a form with 66 HTML fields, this saves 0.5 seconds on page load time, tested locally.
1001 - if ( ! isset( self::$formidable_tinymce_button ) ) {
1002 - FrmAppHelper::load_admin_wide_js();
1003 - $menu_name = FrmAppHelper::get_menu_name();
1004 - $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() );
1005 - 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>';
1006 - }
1007 - echo self::$formidable_tinymce_button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
746 + FrmAppHelper::load_admin_wide_js();
747 + $menu_name = FrmAppHelper::get_menu_name();
748 + $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() );
749 + 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' ) . '">' .
750 + FrmAppHelper::kses( $icon, 'all' ) . // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
751 + ' ' . esc_html( $menu_name ) . '</a>';
1008 752 }
1009 753 }
1010 754
1011 755 /**
@@ -1093,9 +837,9 @@
1093 837 $form_id = $opts['form_id'];
1094 838 unset( $opts['form_id'] );
1095 839 }
1096 840
1097 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php';
841 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php' );
1098 842
1099 843 echo '</div>';
1100 844
1101 845 wp_die();
@@ -1135,14 +879,8 @@
1135 879 wp_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) );
1136 880 die();
1137 881 }
1138 882
1139 - $inbox = new FrmInbox();
1140 - $error = $inbox->check_for_error();
1141 - if ( $error ) {
1142 - $show_messages = array( $error['subject'] . '. ' . $error['message'] );
1143 - }
1144 -
1145 883 require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/list.php';
1146 884 }
1147 885
1148 886 /**
@@ -1149,17 +887,15 @@
1149 887 * @param array<string,string> $columns
1150 888 * @return array<string,string>
1151 889 */
1152 890 public static function get_columns( $columns ) {
1153 - $columns['cb'] = '<input type="checkbox" />';
1154 - $columns['name'] = esc_html__( 'Form Title', 'formidable' );
1155 - $columns['entries'] = esc_html__( 'Entries', 'formidable' );
1156 - $columns['id'] = 'ID';
1157 - $columns['form_key'] = esc_html__( 'Key', 'formidable' );
1158 - if ( 'trash' !== FrmAppHelper::simple_get( 'form_type' ) ) {
1159 - $columns['shortcode'] = esc_html__( 'Actions', 'formidable' );
1160 - }
1161 - $columns['created_at'] = esc_html__( 'Date', 'formidable' );
891 + $columns['cb'] = '<input type="checkbox" />';
892 + $columns['name'] = __( 'Form Title', 'formidable' );
893 + $columns['entries'] = __( 'Entries', 'formidable' );
894 + $columns['id'] = 'ID';
895 + $columns['form_key'] = __( 'Key', 'formidable' );
896 + $columns['shortcode'] = __( 'Actions', 'formidable' );
897 + $columns['created_at'] = __( 'Date', 'formidable' );
1162 898
1163 899 add_screen_option(
1164 900 'per_page',
1165 901 array(
@@ -1171,11 +907,8 @@
1171 907
1172 908 return $columns;
1173 909 }
1174 910
1175 - /**
1176 - * @return array<string,string>
1177 - */
1178 911 public static function get_sortable_columns() {
1179 912 return array(
1180 913 'id' => 'id',
1181 914 'name' => 'name',
@@ -1209,9 +942,9 @@
1209 942 return $hidden_columns;
1210 943 }
1211 944
1212 945 public static function save_per_page( $save, $option, $value ) {
1213 - if ( $option === 'formidable_page_formidable_per_page' ) {
946 + if ( $option == 'formidable_page_formidable_per_page' ) {
1214 947 $save = (int) $value;
1215 948 }
1216 949
1217 950 return $save;
@@ -1217,49 +950,146 @@
1217 950 return $save;
1218 951 }
1219 952
1220 953 /**
1221 - * @param int|string $id
1222 - * @param array $errors
1223 - * @param string $message
1224 - * @param bool $create_link
954 + * @return bool
955 + */
956 + public static function expired() {
957 + global $frm_expired;
958 + return $frm_expired;
959 + }
960 +
961 + /**
962 + * Get data from api before rendering it so that we can flag the modal as expired
963 + *
1225 964 * @return void
1226 965 */
1227 - private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
1228 - global $frm_vars;
966 + public static function before_list_templates() {
967 + global $frm_templates;
968 + global $frm_expired;
969 + global $frm_license_type;
1229 970
1230 - $form = FrmForm::getOne( $id );
1231 - $error_args = array(
1232 - 'title' => __( 'You can\'t edit the form', 'formidable' ),
1233 - 'body' => __( 'You are trying to edit a form that does not exist', 'formidable' ),
1234 - 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
1235 - 'continue_url' => add_query_arg(
1236 - array(
1237 - 'page' => 'formidable',
1238 - )
1239 - ),
971 + $api = new FrmFormTemplateApi();
972 + $frm_templates = $api->get_api_info();
973 + $expired = false;
974 + $license_type = '';
975 + if ( isset( $frm_templates['error'] ) ) {
976 + $error = $frm_templates['error']['message'];
977 + $error = str_replace( 'utm_medium=addons', 'utm_medium=form-templates', $error );
978 + $expired = 'expired' === $frm_templates['error']['code'];
979 + $license_type = isset( $frm_templates['error']['type'] ) ? $frm_templates['error']['type'] : '';
980 + unset( $frm_templates['error'] );
981 + }
982 +
983 + $frm_expired = $expired;
984 + $frm_license_type = $license_type;
985 + }
986 +
987 + /**
988 + * @return void
989 + */
990 + public static function list_templates() {
991 + global $frm_templates;
992 + global $frm_license_type;
993 +
994 + $templates = $frm_templates;
995 + $custom_templates = array();
996 + $templates_by_category = array();
997 +
998 + self::add_user_templates( $custom_templates );
999 +
1000 + foreach ( $templates as $template ) {
1001 + if ( ! isset( $template['categories'] ) ) {
1002 + continue;
1003 + }
1004 +
1005 + foreach ( $template['categories'] as $category ) {
1006 + if ( ! isset( $templates_by_category[ $category ] ) ) {
1007 + $templates_by_category[ $category ] = array();
1008 + }
1009 +
1010 + $templates_by_category[ $category ][] = $template;
1011 + }
1012 + }
1013 + unset( $template );
1014 +
1015 + // Subcategories that are included elsewhere.
1016 + $redundant_cats = array( 'PayPal', 'Stripe', 'Twilio' );
1017 +
1018 + $categories = array_keys( $templates_by_category );
1019 + $categories = array_diff( $categories, FrmFormsHelper::ignore_template_categories() );
1020 + $categories = array_diff( $categories, $redundant_cats );
1021 + sort( $categories );
1022 +
1023 + array_walk(
1024 + $custom_templates,
1025 + function( &$template ) {
1026 + $template['custom'] = true;
1027 + }
1240 1028 );
1241 - if ( ! $form ) {
1242 - FrmAppController::show_error_modal( $error_args );
1243 - return;
1029 +
1030 + $my_templates_translation = __( 'My Templates', 'formidable' );
1031 + $categories = array_merge( array( $my_templates_translation ), $categories );
1032 + $pricing = FrmAppHelper::admin_upgrade_link( 'form-templates' );
1033 + $license_type = $frm_license_type;
1034 + $args = compact( 'pricing', 'license_type' );
1035 + $where = apply_filters( 'frm_forms_dropdown', array(), '' );
1036 + $forms = FrmForm::get_published_forms( $where );
1037 + $view_path = FrmAppHelper::plugin_path() . '/classes/views/frm-forms/';
1038 +
1039 + $templates_by_category[ $my_templates_translation ] = $custom_templates;
1040 +
1041 + unset( $pricing, $license_type, $where );
1042 + wp_enqueue_script( 'accordion' ); // register accordion for template groups
1043 + require $view_path . 'list-templates.php';
1044 + }
1045 +
1046 + /**
1047 + * @since 4.03.01
1048 + */
1049 + private static function get_template_categories( $templates ) {
1050 + $categories = array();
1051 + foreach ( $templates as $template ) {
1052 + if ( isset( $template['categories'] ) ) {
1053 + $categories = array_merge( $categories, $template['categories'] );
1054 + }
1244 1055 }
1056 + $exclude_cats = FrmFormsHelper::ignore_template_categories();
1057 + $categories = array_unique( $categories );
1058 + $categories = array_diff( $categories, $exclude_cats );
1059 + sort( $categories );
1060 + return $categories;
1061 + }
1245 1062
1246 - if ( 'trash' === $form->status ) {
1247 - $error_args['body'] = __( 'The form you\'re trying to edit is in trash. You must restore it first before you can make changes', 'formidable' );
1248 - $error_args['continue_url'] = add_query_arg(
1249 - array(
1250 - 'page' => 'formidable',
1251 - '_wpnonce' => wp_create_nonce( 'untrash_form_' . $id ),
1252 - 'form_type' => 'trash',
1253 - 'frm_action' => 'untrash',
1254 - 'id' => $id,
1255 - )
1063 + private static function add_user_templates( &$templates ) {
1064 + $user_templates = array(
1065 + 'is_template' => 1,
1066 + 'default_template' => 0,
1067 + );
1068 + $user_templates = FrmForm::getAll( $user_templates, 'name' );
1069 + foreach ( $user_templates as $template ) {
1070 + $template = array(
1071 + 'id' => $template->id,
1072 + 'name' => $template->name,
1073 + 'key' => $template->form_key,
1074 + 'description' => $template->description,
1075 + 'url' => wp_nonce_url( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template->id ) ) ),
1076 + 'released' => $template->created_at,
1077 + 'installed' => 1,
1256 1078 );
1257 - $error_args['continue_text'] = __( 'Restore form', 'formidable' );
1258 - FrmAppController::show_error_modal( $error_args );
1259 - return;
1079 + array_unshift( $templates, $template );
1080 + unset( $template );
1260 1081 }
1082 + }
1261 1083
1084 + private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
1085 + global $frm_vars;
1086 +
1087 + $form = FrmForm::getOne( $id );
1088 + if ( ! $form ) {
1089 + wp_die( esc_html__( 'You are trying to edit a form that does not exist.', 'formidable' ) );
1090 + }
1091 +
1262 1092 if ( $form->parent_form_id ) {
1263 1093 /* translators: %1$s: Start link HTML, %2$s: End link HTML */
1264 1094 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>' ) );
1265 1095 }
@@ -1270,9 +1100,8 @@
1270 1100
1271 1101 // Automatically add end section fields if they don't exist (2.0 migration).
1272 1102 $reset_fields = false;
1273 1103 FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields );
1274 - FrmSubmitHelper::maybe_create_submit_field( $form, $fields, $reset_fields );
1275 1104
1276 1105 if ( $reset_fields ) {
1277 1106 $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' );
1278 1107 }
@@ -1298,21 +1127,18 @@
1298 1127 }
1299 1128
1300 1129 self::maybe_update_form_builder_message( $message );
1301 1130
1302 - $has_fields = ! empty( $values['fields'] ) && ! FrmSubmitHelper::only_contains_submit_field( $values['fields'] );
1131 + $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
1132 + $has_fields = isset( $values['fields'] ) && ! empty( $values['fields'] );
1303 1133
1304 1134 if ( defined( 'DOING_AJAX' ) ) {
1305 1135 wp_die();
1136 + } else {
1137 + require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' );
1306 1138 }
1307 -
1308 - require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php';
1309 1139 }
1310 1140
1311 - /**
1312 - * @param array $fields
1313 - * @return array
1314 - */
1315 1141 public static function update_form_builder_fields( $fields, $form ) {
1316 1142 foreach ( $fields as $field ) {
1317 1143 $field->do_not_include_icons = true;
1318 1144 }
@@ -1324,21 +1150,13 @@
1324 1150 $message = __( 'Form was Successfully Copied', 'formidable' );
1325 1151 }
1326 1152 }
1327 1153
1328 - /**
1329 - * @param int|string $id
1330 - * @param array $errors
1331 - * @param array|string $args
1332 - * @return void
1333 - */
1334 1154 public static function get_settings_vars( $id, $errors = array(), $args = array() ) {
1335 1155 FrmAppHelper::permission_check( 'frm_edit_forms' );
1336 1156
1337 1157 global $frm_vars;
1338 1158
1339 - self::maybe_print_media_templates();
1340 -
1341 1159 if ( ! is_array( $args ) ) {
1342 1160 // For reverse compatibility.
1343 1161 $args = array(
1344 1162 'message' => $args,
@@ -1371,38 +1189,17 @@
1371 1189
1372 1190 $sections = self::get_settings_tabs( $values );
1373 1191 $current = FrmAppHelper::simple_get( 't', 'sanitize_title', 'advanced_settings' );
1374 1192
1375 - require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php';
1193 + require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php' );
1376 1194 }
1377 1195
1378 1196 /**
1379 - * 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.
1380 - *
1381 - * @since 6.10
1382 - *
1383 - * @return void
1384 - */
1385 - private static function maybe_print_media_templates() {
1386 - if ( FrmAppHelper::pro_is_included() ) {
1387 - // This issue does not exist when Pro is active so exit early.
1388 - return;
1389 - }
1390 -
1391 - add_action(
1392 - 'wp_enqueue_editor',
1393 - function () {
1394 - wp_print_media_templates();
1395 - }
1396 - );
1397 - }
1398 -
1399 - /**
1400 1197 * @since 4.0
1401 1198 */
1402 1199 public static function form_publish_button( $atts ) {
1403 1200 $values = $atts['values'];
1404 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php';
1201 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php' );
1405 1202 }
1406 1203
1407 1204 /**
1408 1205 * Get a list of all the settings tabs for the form settings page.
@@ -1416,9 +1213,9 @@
1416 1213 $sections = array(
1417 1214 'advanced' => array(
1418 1215 'name' => __( 'General', 'formidable' ),
1419 1216 'title' => __( 'General Form Settings', 'formidable' ),
1420 - 'function' => array( self::class, 'advanced_settings' ),
1217 + 'function' => array( __CLASS__, 'advanced_settings' ),
1421 1218 'icon' => 'frm_icon_font frm_settings_icon',
1422 1219 ),
1423 1220 'email' => array(
1424 1221 'name' => __( 'Actions & Notifications', 'formidable' ),
@@ -1427,9 +1224,9 @@
1427 1224 'icon' => 'frm_icon_font frm_mail_bulk_icon',
1428 1225 ),
1429 1226 'permissions' => array(
1430 1227 'name' => __( 'Form Permissions', 'formidable' ),
1431 - 'icon' => 'frm_icon_font frm_lock_closed_icon',
1228 + 'icon' => 'frm_icon_font frm_lock_icon',
1432 1229 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1433 1230 'data' => array(
1434 1231 'medium' => 'permissions',
1435 1232 'upgrade' => __( 'Form Permissions', 'formidable' ),
@@ -1436,9 +1233,9 @@
1436 1233 'message' => __( 'Allow editing, protect forms and files, limit entries, and save drafts. Upgrade to get form and entry permissions.', 'formidable' ),
1437 1234 'screenshot' => 'permissions.png',
1438 1235 ),
1439 1236 ),
1440 - 'scheduling' => array(
1237 + 'scheduling' => array(
1441 1238 'name' => __( 'Form Scheduling', 'formidable' ),
1442 1239 'icon' => 'frm_icon_font frm_calendar_icon',
1443 1240 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1444 1241 'data' => array(
@@ -1448,9 +1245,9 @@
1448 1245 ),
1449 1246 ),
1450 1247 'buttons' => array(
1451 1248 'name' => __( 'Buttons', 'formidable' ),
1452 - 'class' => self::class,
1249 + 'class' => __CLASS__,
1453 1250 'function' => 'buttons_settings',
1454 1251 'icon' => 'frm_icon_font frm_button_icon',
1455 1252 ),
1456 1253 'landing' => array(
@@ -1471,34 +1268,17 @@
1471 1268 'screenshot' => 'chat.png',
1472 1269 )
1473 1270 ),
1474 1271 ),
1475 - 'abandonment' => array(
1476 - 'name' => __( 'Form Abandonment', 'formidable' ),
1477 - 'icon' => 'frm_icon_font frm_abandoned_icon',
1478 - 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1479 - 'data' => FrmAppHelper::get_upgrade_data_params(
1480 - 'abandonment',
1481 - array(
1482 - 'upgrade' => __( 'Form abandonment settings', 'formidable' ),
1483 - 'message' => __( 'Unlock the power of data capture to boost lead generation and master the art of form optimization.', 'formidable' ),
1484 - 'screenshot' => 'abandonment.png',
1485 - )
1486 - ),
1487 - ),
1488 1272 'html' => array(
1489 1273 'name' => __( 'Customize HTML', 'formidable' ),
1490 - 'class' => self::class,
1274 + 'class' => __CLASS__,
1491 1275 'function' => 'html_settings',
1492 1276 'icon' => 'frm_icon_font frm_code_icon',
1493 1277 ),
1494 1278 );
1495 1279
1496 - if ( ! has_action( 'frm_add_form_style_tab_options' ) && ! has_action( 'frm_add_form_button_options' ) ) {
1497 - unset( $sections['buttons'] );
1498 - }
1499 -
1500 - foreach ( array( 'landing', 'chat', 'abandonment' ) as $feature ) {
1280 + foreach ( array( 'landing', 'chat' ) as $feature ) {
1501 1281 if ( ! FrmAppHelper::show_new_feature( $feature ) ) {
1502 1282 unset( $sections[ $feature ] );
1503 1283 }
1504 1284 }
@@ -1504,8 +1284,13 @@
1504 1284 }
1505 1285
1506 1286 $sections = apply_filters( 'frm_add_form_settings_section', $sections, $values );
1507 1287
1288 + if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) {
1289 + // Prevent settings from showing in 2 spots.
1290 + unset( $sections['permissions'], $sections['scheduling'] );
1291 + }
1292 +
1508 1293 foreach ( $sections as $key => $section ) {
1509 1294 $defaults = array(
1510 1295 'html_class' => '',
1511 1296 'name' => ucfirst( $key ),
@@ -1527,9 +1312,9 @@
1527 1312 $section['id'] = $section['anchor'];
1528 1313 }
1529 1314
1530 1315 $sections[ $key ] = $section;
1531 - }//end foreach
1316 + }
1532 1317
1533 1318 return $sections;
1534 1319 }
1535 1320
@@ -1536,9 +1321,8 @@
1536 1321 /**
1537 1322 * @since 4.0
1538 1323 *
1539 1324 * @param array $values
1540 - * @return void
1541 1325 */
1542 1326 public static function advanced_settings( $values ) {
1543 1327 $first_h3 = 'frm_first_h3';
1544 1328
@@ -1546,15 +1330,14 @@
1546 1330 }
1547 1331
1548 1332 /**
1549 1333 * @param array $values
1550 - * @return void
1551 1334 */
1552 1335 public static function render_spam_settings( $values ) {
1553 1336 if ( function_exists( 'akismet_http_post' ) ) {
1554 1337 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/akismet.php';
1555 1338 }
1556 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/stopforumspam.php';
1339 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/honeypot.php';
1557 1340 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/antispam.php';
1558 1341 }
1559 1342
1560 1343 /**
@@ -1560,12 +1343,16 @@
1560 1343 /**
1561 1344 * @since 4.0
1562 1345 *
1563 1346 * @param array $values
1564 - * @return void
1565 1347 */
1566 1348 public static function buttons_settings( $values ) {
1567 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php';
1349 + $styles = apply_filters( 'frm_get_style_opts', array() );
1350 +
1351 + $frm_settings = FrmAppHelper::get_settings();
1352 + $no_global_style = $frm_settings->load_style === 'none';
1353 +
1354 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php' );
1568 1355 }
1569 1356
1570 1357 /**
1571 1358 * @since 4.0
@@ -1570,12 +1357,11 @@
1570 1357 /**
1571 1358 * @since 4.0
1572 1359 *
1573 1360 * @param array $values
1574 - * @return void
1575 1361 */
1576 1362 public static function html_settings( $values ) {
1577 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php';
1363 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php' );
1578 1364 }
1579 1365
1580 1366 /**
1581 1367 * Replace old Submit Button href with new href to avoid errors in Chrome
@@ -1581,10 +1367,9 @@
1581 1367 * Replace old Submit Button href with new href to avoid errors in Chrome
1582 1368 *
1583 1369 * @since 2.03.08
1584 1370 *
1585 - * @param array|bool $values
1586 - * @return void
1371 + * @param array|boolean $values
1587 1372 */
1588 1373 private static function clean_submit_html( &$values ) {
1589 1374 if ( is_array( $values ) && isset( $values['submit_html'] ) ) {
1590 1375 $values['submit_html'] = str_replace( 'javascript:void(0)', '#', $values['submit_html'] );
@@ -1605,13 +1390,8 @@
1605 1390
1606 1391 return $classes;
1607 1392 }
1608 1393
1609 - /**
1610 - * @param int|string $form_id
1611 - * @param string $class
1612 - * @return void
1613 - */
1614 1394 public static function mb_tags_box( $form_id, $class = '' ) {
1615 1395 $fields = FrmField::get_all_for_form( $form_id, '', 'include' );
1616 1396
1617 1397 /**
@@ -1624,9 +1404,9 @@
1624 1404 */
1625 1405 $fields = apply_filters( 'frm_fields_in_tags_box', $fields, compact( 'form_id' ) );
1626 1406 $linked_forms = array();
1627 1407 $col = 'one';
1628 - $settings_tab = FrmAppHelper::is_admin_page( 'formidable' );
1408 + $settings_tab = FrmAppHelper::is_admin_page( 'formidable' ) ? true : false;
1629 1409
1630 1410 $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() );
1631 1411 $entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
1632 1412
@@ -1631,9 +1411,9 @@
1631 1411 $entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
1632 1412
1633 1413 $advanced_helpers = self::advanced_helpers( compact( 'fields', 'form_id' ) );
1634 1414
1635 - include FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php';
1415 + include( FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php' );
1636 1416 }
1637 1417
1638 1418 /**
1639 1419 * @since 3.04.01
@@ -1646,9 +1426,9 @@
1646 1426 ),
1647 1427 );
1648 1428
1649 1429 $user_fields = self::user_shortcodes();
1650 - if ( $user_fields ) {
1430 + if ( ! empty( $user_fields ) ) {
1651 1431 $user_helpers = array();
1652 1432 foreach ( $user_fields as $uk => $uf ) {
1653 1433 $user_helpers[ '|user_id| show="' . $uk . '"' ] = $uf;
1654 1434 unset( $uk, $uf );
@@ -1654,9 +1434,9 @@
1654 1434 unset( $uk, $uf );
1655 1435 }
1656 1436
1657 1437 $advanced_helpers['user_id'] = array(
1658 - 'codes' => $user_helpers,
1438 + 'codes' => $user_helpers,
1659 1439 );
1660 1440 }
1661 1441
1662 1442 /**
@@ -1733,16 +1513,21 @@
1733 1513 'updated-at' => __( 'Entry updated', 'formidable' ),
1734 1514 '' => '',
1735 1515 'siteurl' => __( 'Site URL', 'formidable' ),
1736 1516 'sitename' => __( 'Site Name', 'formidable' ),
1737 - 'form_name' => __( 'Form Name', 'formidable' ),
1738 1517 );
1739 1518
1740 - $entry_shortcodes = array_merge( FrmShortcodeHelper::get_contextual_shortcode_values(), $entry_shortcodes );
1741 1519 if ( ! FrmAppHelper::pro_is_installed() ) {
1742 1520 unset( $entry_shortcodes['post_id'] );
1743 1521 }
1744 1522
1523 + if ( $settings_tab ) {
1524 + $entry_shortcodes['default-message'] = __( 'Default Msg', 'formidable' );
1525 + $entry_shortcodes['default-html'] = __( 'Default HTML', 'formidable' );
1526 + $entry_shortcodes['default-plain'] = __( 'Default Plain', 'formidable' );
1527 + $entry_shortcodes['form_name'] = __( 'Form Name', 'formidable' );
1528 + }
1529 +
1745 1530 /**
1746 1531 * Use this hook to add or remove buttons in the helpers section
1747 1532 * in the customization panel
1748 1533 *
@@ -1768,9 +1553,9 @@
1768 1553 echo ' frm_js_validate ';
1769 1554 self::add_js_validate_form_to_global_vars( $form );
1770 1555 }
1771 1556
1772 - if ( FrmForm::is_ajax_on( $form ) ) {
1557 + if ( ! FrmFormsHelper::should_use_pro_for_ajax_submit() && FrmForm::is_ajax_on( $form ) ) {
1773 1558 echo ' frm_ajax_submit ';
1774 1559 }
1775 1560 }
1776 1561
@@ -1792,11 +1577,11 @@
1792 1577 check_ajax_referer( 'frm_ajax', 'nonce' );
1793 1578
1794 1579 echo FrmEntriesController::show_entry_shortcode( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1795 1580 array(
1796 - 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1581 + 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ),
1797 1582 'default_email' => true,
1798 - 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1583 + 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ),
1799 1584 )
1800 1585 );
1801 1586 wp_die();
1802 1587 }
@@ -1802,10 +1587,10 @@
1802 1587 }
1803 1588
1804 1589 /**
1805 1590 * @param string $content
1806 - * @param int|stdClass|string $form
1807 - * @param false|int|stdClass|string $entry
1591 + * @param stdClass|string|int $form
1592 + * @param stdClass|string|int|false $entry
1808 1593 * @return string
1809 1594 */
1810 1595 public static function filter_content( $content, $form, $entry = false ) {
1811 1596 $content = self::replace_form_name_shortcodes( $content, $form );
@@ -1818,16 +1603,8 @@
1818 1603 if ( is_object( $form ) ) {
1819 1604 $form = $form->id;
1820 1605 }
1821 1606
1822 - /*
1823 - * Repeater actions adds `parent_entry` to `$entry` store the parent entry data. If `parent_entry` is not empty,
1824 - * use the parent form ID instead of repeater form ID to fix the parent form field shortcodes doesn't work.
1825 - */
1826 - if ( ! empty( $entry->parent_entry ) ) {
1827 - $form = $entry->parent_entry->form_id;
1828 - }
1829 -
1830 1607 $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form );
1831 1608 $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
1832 1609
1833 1610 return $content;
@@ -1837,17 +1614,13 @@
1837 1614 * Replace any [form_name] shortcodes in a string.
1838 1615 *
1839 1616 * @since 5.5
1840 1617 *
1841 - * @param array|string $string
1842 - * @param int|stdClass|string $form
1843 - * @return array|string
1618 + * @param string $string
1619 + * @param stdClass|string|int $form
1620 + * @return string
1844 1621 */
1845 1622 public static function replace_form_name_shortcodes( $string, $form ) {
1846 - if ( ! is_string( $string ) ) {
1847 - return $string;
1848 - }
1849 -
1850 1623 if ( false === strpos( $string, '[form_name]' ) ) {
1851 1624 return $string;
1852 1625 }
1853 1626
@@ -1859,9 +1632,9 @@
1859 1632 return str_replace( '[form_name]', $form_name, $string );
1860 1633 }
1861 1634
1862 1635 /**
1863 - * @param false|int|stdClass|string $entry
1636 + * @param stdClass|string|int|false $entry
1864 1637 * @return void
1865 1638 */
1866 1639 private static function get_entry_by_param( &$entry ) {
1867 1640 if ( ! $entry || ! is_object( $entry ) ) {
@@ -1876,12 +1649,8 @@
1876 1649 public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
1877 1650 return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes );
1878 1651 }
1879 1652
1880 - /**
1881 - * @param array $errors
1882 - * @return array
1883 - */
1884 1653 public static function process_bulk_form_actions( $errors ) {
1885 1654 if ( ! $_REQUEST ) {
1886 1655 return $errors;
1887 1656 }
@@ -1925,9 +1694,9 @@
1925 1694 case 'untrash':
1926 1695 $message = self::bulk_untrash( $ids );
1927 1696 }
1928 1697
1929 - if ( ! empty( $message ) ) {
1698 + if ( isset( $message ) && ! empty( $message ) ) {
1930 1699 $errors['message'] = $message;
1931 1700 }
1932 1701
1933 1702 return $errors;
@@ -1932,26 +1701,13 @@
1932 1701
1933 1702 return $errors;
1934 1703 }
1935 1704
1936 - /**
1937 - * Includes html that shows a message when the device is too small to use Formidable Forms admin pages.
1938 - *
1939 - * @since 6.20
1940 - * @return void
1941 - */
1942 - public static function include_device_too_small_message() {
1943 - if ( ! FrmAppHelper::is_formidable_admin() ) {
1944 - return;
1945 - }
1946 -
1947 - include FrmAppHelper::plugin_path() . '/classes/views/shared/small-device-message.php';
1948 - }
1949 -
1950 1705 public static function route() {
1951 1706 $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
1952 1707 $vars = array();
1953 1708 FrmAppHelper::include_svg();
1709 +
1954 1710 if ( isset( $_POST['frm_compact_fields'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
1955 1711 FrmAppHelper::permission_check( 'frm_edit_forms' );
1956 1712
1957 1713 // Javascript needs to be allowed in some field settings.
@@ -1960,9 +1716,9 @@
1960 1716 $json_vars = json_decode( $json_vars, true );
1961 1717 if ( empty( $json_vars ) ) {
1962 1718 // json decoding failed so we should return an error message.
1963 1719 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
1964 - if ( 'edit' === $action ) {
1720 + if ( 'edit' == $action ) {
1965 1721 $action = 'update';
1966 1722 }
1967 1723
1968 1724 add_filter( 'frm_validate_form', 'FrmFormsController::json_error' );
@@ -1978,14 +1734,16 @@
1978 1734 if ( isset( $_REQUEST['delete_all'] ) ) {
1979 1735 // Override the action for this page.
1980 1736 $action = 'delete_all';
1981 1737 }
1982 - }//end if
1738 + }
1983 1739
1984 1740 add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
1985 1741 FrmAppHelper::trigger_hook_load( 'form' );
1986 1742
1987 1743 switch ( $action ) {
1744 + case 'new':
1745 + return self::new_form( $vars );
1988 1746 case 'create':
1989 1747 case 'edit':
1990 1748 case 'update':
1991 1749 case 'trash':
@@ -1990,17 +1748,16 @@
1990 1748 case 'update':
1991 1749 case 'trash':
1992 1750 case 'untrash':
1993 1751 case 'destroy':
1752 + case 'delete_all':
1994 1753 case 'settings':
1995 1754 case 'update_settings':
1996 1755 return self::$action( $vars );
1997 1756 case 'lite-reports':
1998 - self::no_reports( $vars );
1999 - return;
1757 + return self::no_reports( $vars );
2000 1758 case 'views':
2001 - self::no_views( $vars );
2002 - return;
1759 + return self::no_views( $vars );
2003 1760 default:
2004 1761 do_action( 'frm_form_action_' . $action );
2005 1762 if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) {
2006 1763 return;
@@ -2023,65 +1780,12 @@
2023 1780 self::display_forms_list( array(), '', array( __( 'There was a problem duplicating the form', 'formidable' ) ) );
2024 1781 return;
2025 1782 }
2026 1783
2027 - if ( 'forms_permanently_deleted' === $message ) {
2028 - $count = FrmAppHelper::get_param( 'forms_deleted', 0, 'get', 'absint' );
2029 - /* translators: %1$s: Number of forms */
2030 - $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
2031 - self::display_forms_list( array(), $message, '' );
2032 - return;
2033 - }
2034 -
2035 1784 self::display_forms_list();
2036 1785
2037 1786 return;
2038 - }//end switch
2039 - }
2040 -
2041 - /**
2042 - * Rename a form.
2043 - *
2044 - * Handles the AJAX request for renaming a form.
2045 - *
2046 - * @since 6.7
2047 - *
2048 - * @return void
2049 - */
2050 - public static function rename_form() {
2051 - // Check permission and nonce
2052 - FrmAppHelper::permission_check( 'frm_edit_forms' );
2053 - check_ajax_referer( 'frm_ajax', 'nonce' );
2054 -
2055 - // Get posted data
2056 - $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
2057 - $name = FrmAppHelper::get_post_param( 'form_name', '', 'sanitize_text_field' );
2058 -
2059 - $form = FrmForm::getOne( $form_id );
2060 - if ( ! $form ) {
2061 - wp_send_json_error( __( 'Form not found', 'formidable' ) );
2062 1787 }
2063 -
2064 - if ( $name === $form->name ) {
2065 - // Nothing to change so exit early.
2066 - wp_send_json_success();
2067 - }
2068 -
2069 - $to_update = array(
2070 - 'name' => $name,
2071 - );
2072 -
2073 - if ( '' !== $name ) {
2074 - // Only update form_key if name is not empty.
2075 - $form_key = FrmAppHelper::get_unique_key( sanitize_title( $name ), 'frm_forms', 'form_key' );
2076 - $to_update['form_key'] = $form_key;
2077 - } else {
2078 - $form_key = $form->form_key;
2079 - }
2080 -
2081 - FrmForm::update( $form_id, $to_update );
2082 -
2083 - wp_send_json_success( compact( 'form_key' ) );
2084 1788 }
2085 1789
2086 1790 public static function json_error( $errors ) {
2087 1791 $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
@@ -2089,13 +1793,20 @@
2089 1793 return $errors;
2090 1794 }
2091 1795
2092 1796 /**
1797 + * Education for premium features.
1798 + *
1799 + * @since 4.05
1800 + */
1801 + public static function add_form_style_tab_options() {
1802 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php' );
1803 + }
1804 +
1805 + /**
2093 1806 * Add education about views.
2094 1807 *
2095 1808 * @since 4.07
2096 - *
2097 - * @return void
2098 1809 */
2099 1810 public static function no_views( $values = array() ) {
2100 1811 FrmAppHelper::include_svg();
2101 1812 $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
@@ -2107,10 +1818,8 @@
2107 1818 /**
2108 1819 * Add education about reports.
2109 1820 *
2110 1821 * @since 4.07
2111 - *
2112 - * @return void
2113 1822 */
2114 1823 public static function no_reports( $values = array() ) {
2115 1824 $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
2116 1825 $form = $id ? FrmForm::getOne( $id ) : false;
@@ -2117,11 +1826,9 @@
2117 1826
2118 1827 include FrmAppHelper::plugin_path() . '/classes/views/shared/reports-info.php';
2119 1828 }
2120 1829
2121 - /**
2122 - * FRONT-END FORMS.
2123 - */
1830 + /* FRONT-END FORMS */
2124 1831 public static function admin_bar_css() {
2125 1832 if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
2126 1833 return;
2127 1834 }
@@ -2195,9 +1902,9 @@
2195 1902 $wp_admin_bar->add_node(
2196 1903 array(
2197 1904 'parent' => 'frm-forms',
2198 1905 'id' => 'edit_form_' . $form_id,
2199 - 'title' => empty( $name ) ? FrmFormsHelper::get_no_title_text() : $name,
1906 + 'title' => empty( $name ) ? __( '(no title)', 'formidable' ) : $name,
2200 1907 'href' => FrmForm::get_edit_link( $form_id ),
2201 1908 )
2202 1909 );
2203 1910 }
@@ -2210,10 +1917,10 @@
2210 1917 * @return string
2211 1918 */
2212 1919 public static function get_form_shortcode( $atts ) {
2213 1920 global $frm_vars;
2214 - if ( ! empty( $frm_vars['skip_shortcode'] ) ) {
2215 - $sc = '[formidable';
1921 + if ( isset( $frm_vars['skip_shortcode'] ) && $frm_vars['skip_shortcode'] ) {
1922 + $sc = '[formidable';
2216 1923 $sc .= FrmAppHelper::array_to_html_params( $atts );
2217 1924 return $sc . ']';
2218 1925 }
2219 1926
@@ -2238,11 +1945,11 @@
2238 1945
2239 1946 /**
2240 1947 * @since 5.2.01
2241 1948 *
2242 - * @param false|int|string $id
2243 - * @param false|string $key
2244 - * @return false|stdClass
1949 + * @param string|int|false $id
1950 + * @param string|false $key
1951 + * @return stdClass|false
2245 1952 */
2246 1953 private static function maybe_get_form_by_id_or_key( $id, $key ) {
2247 1954 if ( ! $id ) {
2248 1955 $id = $key;
@@ -2250,12 +1957,12 @@
2250 1957 return self::maybe_get_form_to_show( $id );
2251 1958 }
2252 1959
2253 1960 /**
2254 - * @param false|int|string $id
2255 - * @param false|string $key
2256 - * @param bool|int|string $title may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
2257 - * @param bool|int|string $description may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
1961 + * @param string|int|false $id
1962 + * @param string|false $key
1963 + * @param string|int|bool $title may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
1964 + * @param string|int|bool $description may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
2258 1965 * @param array $atts
2259 1966 * @return string
2260 1967 */
2261 1968 public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) {
@@ -2303,16 +2010,15 @@
2303 2010 return $form;
2304 2011 }
2305 2012
2306 2013 /**
2307 - * @param false|int|string $id
2308 - * @return false|stdClass
2014 + * @param string|int|false $id
2015 + * @return stdClass|false
2309 2016 */
2310 2017 private static function maybe_get_form_to_show( $id ) {
2311 2018 $form = false;
2312 2019
2313 - if ( ! empty( $id ) ) {
2314 - // Form id or key is set.
2020 + if ( ! empty( $id ) ) { // form id or key is set
2315 2021 $form = FrmForm::getOne( $id );
2316 2022 if ( ! $form || $form->parent_form_id || $form->status === 'trash' ) {
2317 2023 $form = false;
2318 2024 }
@@ -2370,11 +2076,11 @@
2370 2076
2371 2077 do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description );
2372 2078
2373 2079 if ( apply_filters( 'frm_continue_to_create', true, $form->id ) ) {
2374 - $entry_id = self::just_created_entry( $form->id );
2375 - $pass_args['entry_id'] = $entry_id;
2376 - $pass_args['reset'] = true;
2080 + $entry_id = self::just_created_entry( $form->id );
2081 + $pass_args['entry_id'] = $entry_id;
2082 + $pass_args['reset'] = true;
2377 2083
2378 2084 self::run_on_submit_actions( $pass_args );
2379 2085
2380 2086 do_action(
@@ -2384,9 +2090,9 @@
2384 2090 'form' => $form,
2385 2091 )
2386 2092 );
2387 2093 }
2388 - }//end if
2094 + }
2389 2095 }
2390 2096
2391 2097 /**
2392 2098 * If the form was processed earlier (init), get the generated errors
@@ -2418,9 +2124,9 @@
2418 2124 */
2419 2125 public static function just_created_entry( $form_id ) {
2420 2126 global $frm_vars;
2421 2127
2422 - 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;
2128 + 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;
2423 2129 }
2424 2130
2425 2131 /**
2426 2132 * Gets confirmation method.
@@ -2433,14 +2139,14 @@
2433 2139 *
2434 2140 * @type object $form Form object.
2435 2141 * @type int $entry_id Entry ID.
2436 2142 * }
2437 - * @return array|string
2143 + * @return string|array
2438 2144 */
2439 2145 private static function get_confirmation_method( $atts ) {
2440 2146 $action = FrmOnSubmitHelper::current_event( $atts );
2441 2147 $opt = 'update' === $action ? 'edit_action' : 'success_action';
2442 - $method = ! empty( $atts['form']->options[ $opt ] ) ? $atts['form']->options[ $opt ] : 'message';
2148 + $method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message';
2443 2149
2444 2150 if ( ! empty( $atts['entry_id'] ) ) {
2445 2151 $met_actions = self::get_met_on_submit_actions( $atts, $action );
2446 2152 if ( $met_actions ) {
@@ -2449,9 +2155,9 @@
2449 2155 }
2450 2156
2451 2157 $method = apply_filters( 'frm_success_filter', $method, $atts['form'], $action );
2452 2158
2453 - if ( $method !== 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
2159 + if ( $method != 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
2454 2160 $method = 'message';
2455 2161 }
2456 2162
2457 2163 return $method;
@@ -2485,9 +2191,9 @@
2485 2191 * @param array $args See {@see FrmFormsController::maybe_trigger_redirect()}.
2486 2192 */
2487 2193 public static function maybe_trigger_redirect_with_action( $conf_method, $form, $params, $args ) {
2488 2194 if ( is_array( $conf_method ) && 1 === count( $conf_method ) ) {
2489 - if ( 'redirect' === FrmOnSubmitHelper::get_action_type( $conf_method[0] ) && empty( $conf_method[0]->post_content['redirect_delay'] ) ) {
2195 + if ( 'redirect' === FrmOnSubmitHelper::get_action_type( $conf_method[0] ) ) {
2490 2196 $event = FrmOnSubmitHelper::current_event( $params );
2491 2197 FrmOnSubmitHelper::populate_on_submit_data( $form->options, $conf_method[0], $event );
2492 2198 $conf_method = 'redirect';
2493 2199 }
@@ -2536,9 +2242,9 @@
2536 2242 unset( $extra_args['form'] );
2537 2243
2538 2244 do_action( 'frm_success_action', $args['conf_method'], $args['form'], $args['form']->options, $args['entry_id'], $extra_args );
2539 2245
2540 - $opt = ! isset( $args['action'] ) || $args['action'] === 'create' ? 'success' : 'edit';
2246 + $opt = ( ! isset( $args['action'] ) || $args['action'] === 'create' ) ? 'success' : 'edit';
2541 2247
2542 2248 $args['success_opt'] = $opt;
2543 2249 $args['ajax'] = ! empty( $frm_vars['ajax'] );
2544 2250
@@ -2564,16 +2270,11 @@
2564 2270 if ( ! FrmOnSubmitHelper::form_has_migrated( $args['form'] ) ) {
2565 2271 return array();
2566 2272 }
2567 2273
2568 - // If a redirect action has already opened the URL in a new tab, we show the default message in the current tab.
2569 - if ( ! empty( self::$redirected_in_new_tab[ $args['form']->id ] ) ) {
2570 - return array( FrmOnSubmitHelper::get_fallback_action_after_open_in_new_tab( $event ) );
2571 - }
2572 -
2573 - $entry = FrmEntry::getOne( $args['entry_id'], true );
2574 - $actions = FrmOnSubmitHelper::get_actions( $args['form']->id );
2575 - $met_actions = array();
2274 + $entry = FrmEntry::getOne( $args['entry_id'], true );
2275 + $actions = FrmOnSubmitHelper::get_actions( $args['form']->id );
2276 + $met_actions = array();
2576 2277 $has_redirect = false;
2577 2278
2578 2279 foreach ( $actions as $action ) {
2579 2280 if ( ! in_array( $event, $action->post_content['event'], true ) ) {
@@ -2586,15 +2287,21 @@
2586 2287
2587 2288 $action_type = FrmOnSubmitHelper::get_action_type( $action );
2588 2289
2589 2290 if ( 'redirect' === $action_type ) {
2590 - if ( $has_redirect ) {
2591 - // Do not process because we run the first redirect action only.
2291 + if ( $has_redirect ) { // Do not process because we run the first redirect action only.
2592 2292 continue;
2593 2293 }
2294 +
2295 + // Run through frm_redirect_url filter. This is used for the valid action check.
2296 + $action->post_content['success_url'] = self::run_redirect_url_filter(
2297 + $action->post_content['success_url'],
2298 + $args['form'],
2299 + $args + array( 'action' => $event )
2300 + );
2594 2301 }
2595 2302
2596 - if ( ! self::is_valid_on_submit_action( $action, $args, $event ) ) {
2303 + if ( ! self::is_valid_on_submit_action( $action ) ) {
2597 2304 continue;
2598 2305 }
2599 2306
2600 2307 if ( 'redirect' === $action_type ) {
@@ -2602,9 +2309,9 @@
2602 2309 }
2603 2310
2604 2311 $met_actions[] = $action;
2605 2312 unset( $action );
2606 - }//end foreach
2313 + }
2607 2314
2608 2315 $args['event'] = $event;
2609 2316
2610 2317 /**
@@ -2624,30 +2331,45 @@
2624 2331 return $met_actions;
2625 2332 }
2626 2333
2627 2334 /**
2335 + * Runs frm_redirect_url filter and prepare the URL.
2336 + * This ensures that filter just fires once per form and action.
2337 + *
2338 + * @since 6.2
2339 + *
2340 + * @param string $url The URL.
2341 + * @param object $form Form object.
2342 + * @param array $args Args from {@see FrmFormsController::run_success_action()}. `$args['action']` is required.
2343 + */
2344 + private static function run_redirect_url_filter( $url, $form, $args ) {
2345 + if ( empty( $args['action'] ) || ! is_string( $args['action'] ) ) {
2346 + return $url;
2347 + }
2348 +
2349 + if ( in_array( $form->id . '_' . $args['action'], self::$ran_redirect_url_filter, true ) ) {
2350 + return $url;
2351 + }
2352 +
2353 + self::$ran_redirect_url_filter[] = $form->id . '_' . $args['action'];
2354 +
2355 + add_filter( 'frm_redirect_url', 'FrmEntriesController::prepare_redirect_url' );
2356 + return apply_filters( 'frm_redirect_url', $url, $form, $args );
2357 + }
2358 +
2359 + /**
2628 2360 * Checks if a Confirmation action has the valid data.
2629 2361 *
2630 2362 * @since 6.1.2
2631 2363 *
2632 2364 * @param object $action Form action object.
2633 - * @param array $args See {@see FrmFormsController::run_success_action()}.
2634 - * @param string $event Form event. Default is `create`.
2635 2365 * @return bool
2636 2366 */
2637 - private static function is_valid_on_submit_action( $action, $args, $event = 'create' ) {
2367 + private static function is_valid_on_submit_action( $action ) {
2638 2368 $action_type = FrmOnSubmitHelper::get_action_type( $action );
2639 2369
2640 - if ( 'redirect' === $action_type ) {
2641 - // Run through frm_redirect_url filter. This is used for the valid action check.
2642 - $action->post_content['success_url'] = apply_filters(
2643 - 'frm_redirect_url',
2644 - $action->post_content['success_url'],
2645 - $args['form'],
2646 - $args + array( 'action' => $event )
2647 - );
2648 -
2649 - return ! empty( $action->post_content['success_url'] );
2370 + if ( 'redirect' === $action_type && empty( $action->post_content['success_url'] ) ) {
2371 + return false;
2650 2372 }
2651 2373
2652 2374 if ( 'page' === $action_type ) {
2653 2375 if ( empty( $action->post_content['success_page_id'] ) ) {
@@ -2793,9 +2515,9 @@
2793 2515 add_filter( 'the_content', 'FrmFormsController::preview_content', 9999 );
2794 2516 }
2795 2517
2796 2518 $post = $old_post;
2797 - }//end if
2519 + }
2798 2520 }
2799 2521
2800 2522 /**
2801 2523 * @since 3.0
@@ -2811,30 +2533,20 @@
2811 2533
2812 2534 $args['id'] = $args['entry_id'];
2813 2535 FrmEntriesController::delete_entry_before_redirect( $success_url, $args['form'], $args );
2814 2536
2815 - add_filter( 'frm_redirect_url', 'FrmEntriesController::prepare_redirect_url' );
2816 - $success_url = apply_filters( 'frm_redirect_url', $success_url, $args['form'], $args );
2537 + $success_url = self::run_redirect_url_filter( $success_url, $args['form'], $args );
2817 2538
2818 2539 $doing_ajax = FrmAppHelper::doing_ajax();
2819 2540
2820 - if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) {
2821 - // Is AJAX submit and there is just one Redirect action runs.
2822 - echo json_encode( self::get_ajax_redirect_response_data( $args + compact( 'success_url' ) ) );
2541 + if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) { // Is AJAX submit and there is just one Redirect action runs.
2542 + echo json_encode( array( 'redirect' => $success_url ) );
2823 2543 wp_die();
2824 2544 }
2825 2545
2826 - if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) && empty( $args['form']->options['redirect_delay'] ) ) {
2827 - // Not AJAX submit, no headers sent, and there is just one Redirect action runs.
2828 - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2829 - self::print_open_in_new_tab_js_with_fallback_handler( $success_url, $args );
2830 - self::$redirected_in_new_tab[ $args['form']->id ] = 1;
2831 - return;
2832 - }
2833 -
2546 + if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) ) { // Not AJAX submit, no headers sent, and there is just one Redirect action runs.
2834 2547 wp_redirect( esc_url_raw( $success_url ) );
2835 - // Do not use wp_die or redirect fails.
2836 - die();
2548 + die(); // do not use wp_die or redirect fails
2837 2549 }
2838 2550
2839 2551 // Redirect with a delay.
2840 2552 self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) );
@@ -2840,81 +2552,8 @@
2840 2552 self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) );
2841 2553 }
2842 2554
2843 2555 /**
2844 - * Prints open in new tab js with fallback handler.
2845 - *
2846 - * @since 6.3.1
2847 - *
2848 - * @param string $success_url Success URL.
2849 - * @param array $args See {@see FrmFormsController::redirect_after_submit()}.
2850 - */
2851 - private static function print_open_in_new_tab_js_with_fallback_handler( $success_url, $args ) {
2852 - echo '<script>var newTab = window.open("' . esc_url_raw( $success_url ) . '", "_blank");';
2853 - echo 'if ( ! newTab ) {';
2854 -
2855 - $data = array(
2856 - 'formId' => intval( $args['form']->id ),
2857 - 'message' => self::get_redirect_fallback_message( $success_url, $args ),
2858 - );
2859 - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2860 - echo 'frmShowNewTabFallback = ' . FrmAppHelper::maybe_json_encode( $data ) . ';';
2861 - echo '}</script>';
2862 - }
2863 -
2864 - /**
2865 - * Gets response data for redirect action when AJAX submitting.
2866 - *
2867 - * @since 6.3.1
2868 - *
2869 - * @param array $args See {@see FrmFormsController::run_success_action()}.
2870 - * @return array
2871 - */
2872 - private static function get_ajax_redirect_response_data( $args ) {
2873 - $response_data = array(
2874 - 'redirect' => $args['success_url'],
2875 - 'content' => '',
2876 - );
2877 - $unset_content = true;
2878 -
2879 - if ( ! empty( $args['form']->options['redirect_delay'] ) ) {
2880 - $response_data['delay'] = $args['form']->options['redirect_delay_time'];
2881 - $response_data['content'] .= self::get_redirect_message( $args['success_url'], $args['form']->options['redirect_delay_msg'], $args );
2882 - $unset_content = false;
2883 - }
2884 -
2885 - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2886 - $response_data['openInNewTab'] = 1;
2887 -
2888 - // Only show open in new tab text if there is no delay.
2889 - if ( empty( $response_data['content'] ) ) {
2890 - $args['message'] = FrmOnSubmitHelper::get_default_new_tab_msg();
2891 -
2892 - $args['form']->options['success_msg'] = $args['message'];
2893 - $args['form']->options['edit_msg'] = $args['message'];
2894 - if ( ! isset( $args['fields'] ) ) {
2895 - $args['fields'] = FrmField::get_all_for_form( $args['form']->id );
2896 - }
2897 -
2898 - $args['message'] = self::prepare_submit_message( $args['form'], $args['entry_id'], $args );
2899 -
2900 - ob_start();
2901 - self::show_lone_success_message( $args );
2902 - $response_data['content'] .= ob_get_clean();
2903 - $unset_content = false;
2904 - }//end if
2905 -
2906 - $response_data['fallbackMsg'] = self::get_redirect_fallback_message( $args['success_url'], $args );
2907 - }//end if
2908 -
2909 - if ( $unset_content && '' === $response_data['content'] ) {
2910 - unset( $response_data['content'] );
2911 - }
2912 -
2913 - return $response_data;
2914 - }
2915 -
2916 - /**
2917 2556 * Redirects after submitting using JS. This is used when showing message before redirecting.
2918 2557 *
2919 2558 * @since 6.0
2920 2559 *
@@ -2920,11 +2559,10 @@
2920 2559 *
2921 2560 * @param array $args See {@see FrmFormsController::run_success_action()}.
2922 2561 */
2923 2562 private static function redirect_after_submit_using_js( $args ) {
2924 - $success_msg = $args['form']->options['redirect_delay_msg'];
2563 + $success_msg = FrmOnSubmitHelper::get_default_redirect_msg();
2925 2564 $redirect_msg = self::get_redirect_message( $args['success_url'], $success_msg, $args );
2926 - $success_url = esc_url_raw( $args['success_url'] );
2927 2565
2928 2566 /**
2929 2567 * Filters the delay time before redirecting when On Submit Redirect action is delayed.
2930 2568 *
@@ -2929,27 +2567,20 @@
2929 2567 * Filters the delay time before redirecting when On Submit Redirect action is delayed.
2930 2568 *
2931 2569 * @since 6.0
2932 2570 *
2933 - * @param int $delay_time Delay time in milliseconds.
2571 + * @param int $delay_time Delay time in miliseconds.
2934 2572 */
2935 - $delay_time = apply_filters( 'frm_redirect_delay_time', 1000 * $args['form']->options['redirect_delay_time'] );
2573 + $delay_time = apply_filters( 'frm_redirect_delay_time', 8000 );
2936 2574
2937 - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2938 - $redirect_js = 'window.open("' . $success_url . '", "_blank")';
2939 - } else {
2940 - $redirect_js = 'window.location="' . $success_url . '";';
2941 - }
2942 -
2943 2575 add_filter( 'frm_use_wpautop', '__return_true' );
2944 2576
2945 2577 echo FrmAppHelper::maybe_kses( $redirect_msg ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2946 2578 echo '<script>';
2947 - if ( empty( $args['doing_ajax'] ) ) {
2948 - // Not AJAX submit, delay JS until window.load.
2579 + if ( empty( $args['doing_ajax'] ) ) { // Not AJAX submit, delay JS until window.load.
2949 2580 echo 'window.onload=function(){';
2950 2581 }
2951 - echo 'setTimeout(function(){' . $redirect_js . '}, ' . intval( $delay_time ) . ');'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2582 + echo 'setTimeout(function(){window.location="' . esc_url_raw( $args['success_url'] ) . '";}, ' . intval( $delay_time ) . ');';
2952 2583 if ( empty( $args['doing_ajax'] ) ) {
2953 2584 echo '};';
2954 2585 }
2955 2586 echo '</script>';
@@ -2959,15 +2590,14 @@
2959 2590 * @since 3.0
2960 2591 *
2961 2592 * @param string $success_url
2962 2593 * @param string $success_msg
2963 - * @param array $args
2594 + * @param array $args
2964 2595 */
2965 2596 private static function get_redirect_message( $success_url, $success_msg, $args ) {
2966 - $success_msg = apply_filters( 'frm_content', $success_msg, $args['form'], $args['entry_id'] );
2967 - $success_msg = do_shortcode( FrmAppHelper::use_wpautop( $success_msg ) );
2968 2597 $redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg" role="status">' . $success_msg . '<br/>' .
2969 - self::get_redirect_fallback_message( $success_url, $args ) .
2598 + /* translators: %1$s: Start link HTML, %2$s: End link HTML */
2599 + sprintf( __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ), '<a href="' . esc_url( $success_url ) . '">', '</a>' ) .
2970 2600 '</div></div>';
2971 2601
2972 2602 $redirect_args = array(
2973 2603 'entry_id' => $args['entry_id'],
@@ -2978,31 +2608,8 @@
2978 2608 return apply_filters( 'frm_redirect_msg', $redirect_msg, $redirect_args );
2979 2609 }
2980 2610
2981 2611 /**
2982 - * Gets fallback message when redirecting failed.
2983 - *
2984 - * @since 6.3.1
2985 - *
2986 - * @param string $success_url Redirect URL.
2987 - * @param array $args Contains `form` object.
2988 - * @return string
2989 - */
2990 - private static function get_redirect_fallback_message( $success_url, $args ) {
2991 - $target = '';
2992 - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2993 - $target = ' target="_blank"';
2994 - }
2995 -
2996 - return sprintf(
2997 - /* translators: %1$s: Start link HTML, %2$s: End link HTML */
2998 - __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ),
2999 - '<a href="' . esc_url( $success_url ) . '"' . $target . '>',
3000 - '</a>'
3001 - );
3002 - }
3003 -
3004 - /**
3005 2612 * Prepare to show the success message and empty form after submit
3006 2613 *
3007 2614 * @since 2.05
3008 2615 */
@@ -3021,9 +2628,9 @@
3021 2628 } else {
3022 2629 self::show_form_after_submit( $atts );
3023 2630 }
3024 2631 } else {
3025 - self::show_lone_success_message( $atts );
2632 + self::show_lone_success_messsage( $atts );
3026 2633 }
3027 2634 }
3028 2635
3029 2636 /**
@@ -3051,9 +2658,9 @@
3051 2658
3052 2659 $include_form_tag = apply_filters( 'frm_include_form_tag', true, $form );
3053 2660
3054 2661 $frm_settings = FrmAppHelper::get_settings();
3055 - $submit = $form->options['submit_value'] ?? $frm_settings->submit_value;
2662 + $submit = isset( $form->options['submit_value'] ) ? $form->options['submit_value'] : $frm_settings->submit_value;
3056 2663
3057 2664 global $frm_vars;
3058 2665 self::maybe_load_css( $form, $values['custom_style'], $frm_vars['load_css'] );
3059 2666
@@ -3062,10 +2669,11 @@
3062 2669 include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php';
3063 2670 }
3064 2671
3065 2672 /**
2673 + * @return string - 'before', 'after', or 'submit'
2674 + *
3066 2675 * @since 4.05.02
3067 - * @return string - 'before', 'after', or 'submit'
3068 2676 */
3069 2677 private static function message_placement( $form, $message ) {
3070 2678 $place = 'before';
3071 2679
@@ -3077,10 +2685,11 @@
3077 2685 }
3078 2686 }
3079 2687
3080 2688 /**
2689 + * @return string - 'before' or 'after'
2690 + *
3081 2691 * @since 4.05.02
3082 - * @return string - 'before' or 'after'
3083 2692 */
3084 2693 return apply_filters( 'frm_message_placement', $place, compact( 'form', 'message' ) );
3085 2694 }
3086 2695
@@ -3114,9 +2723,9 @@
3114 2723 * Show the success message without the form
3115 2724 *
3116 2725 * @since 2.05
3117 2726 */
3118 - private static function show_lone_success_message( $atts ) {
2727 + private static function show_lone_success_messsage( $atts ) {
3119 2728 global $frm_vars;
3120 2729 $values = FrmEntriesHelper::setup_new_vars( $atts['fields'], $atts['form'], true );
3121 2730 self::maybe_load_css( $atts['form'], $values['custom_style'], $frm_vars['load_css'] );
3122 2731
@@ -3125,9 +2734,9 @@
3125 2734 $errors = array();
3126 2735 $form = $atts['form'];
3127 2736 $message = $atts['message'];
3128 2737
3129 - include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php';
2738 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php' );
3130 2739 }
3131 2740
3132 2741 /**
3133 2742 * Prepare the success message before it's shown
@@ -3141,12 +2750,12 @@
3141 2750 * @return string
3142 2751 */
3143 2752 private static function prepare_submit_message( $form, $entry_id, $args = array() ) {
3144 2753 $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) );
3145 - $opt = $args['success_opt'] ?? 'success';
2754 + $opt = isset( $args['success_opt'] ) ? $args['success_opt'] : 'success';
3146 2755
3147 2756 if ( $entry_id && is_numeric( $entry_id ) ) {
3148 - $message = $form->options[ $opt . '_msg' ] ?? $frm_settings->success_msg;
2757 + $message = isset( $form->options[ $opt . '_msg' ] ) ? $form->options[ $opt . '_msg' ] : $frm_settings->success_msg;
3149 2758 $class = 'frm_message';
3150 2759 } else {
3151 2760 $message = $frm_settings->failed_msg;
3152 2761 $class = FrmFormsHelper::form_error_class();
@@ -3247,13 +2856,11 @@
3247 2856 global $frm_vars;
3248 2857
3249 2858 FrmStylesController::enqueue_css();
3250 2859
3251 - if ( ! FrmAppHelper::is_admin() && $location !== 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
2860 + if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
3252 2861 // load formidable js
3253 2862 wp_enqueue_script( 'formidable' );
3254 -
3255 - FrmHoneypot::maybe_print_honeypot_js();
3256 2863 }
3257 2864 }
3258 2865
3259 2866 /**
@@ -3267,12 +2874,12 @@
3267 2874 }
3268 2875
3269 2876 /**
3270 2877 * @since 2.0.8
3271 - * @return bool
2878 + * @return boolean
3272 2879 */
3273 2880 private static function is_minification_on( $atts ) {
3274 - return ! empty( $atts['minimize'] );
2881 + return isset( $atts['minimize'] ) && ! empty( $atts['minimize'] );
3275 2882 }
3276 2883
3277 2884 /**
3278 2885 * @since 5.0.16
@@ -3300,9 +2907,9 @@
3300 2907 * Create a page with an embedded formidable Gutenberg block.
3301 2908 *
3302 2909 * @since 5.2
3303 2910 *
3304 - * @return void
2911 + * @return never
3305 2912 */
3306 2913 public static function create_page_with_shortcode() {
3307 2914 if ( ! current_user_can( 'publish_posts' ) ) {
3308 2915 die( 0 );
@@ -3347,9 +2954,10 @@
3347 2954
3348 2955 /**
3349 2956 * @since 5.3
3350 2957 *
3351 - * @param int $form_id
2958 + * @param string $content
2959 + * @param int $form_id
3352 2960 * @return string
3353 2961 */
3354 2962 private static function get_page_shortcode_content_for_form( $form_id ) {
3355 2963 $shortcode = '[formidable id="' . $form_id . '"]';
@@ -3360,9 +2968,9 @@
3360 2968
3361 2969 /**
3362 2970 * Get page dropdown for AJAX request for embedding form in an existing page.
3363 2971 *
3364 - * @return void
2972 + * @return never
3365 2973 */
3366 2974 public static function get_page_dropdown() {
3367 2975 if ( ! current_user_can( 'publish_posts' ) ) {
3368 2976 die( 0 );
@@ -3370,9 +2978,9 @@
3370 2978
3371 2979 check_ajax_referer( 'frm_ajax', 'nonce' );
3372 2980
3373 2981 $html = FrmAppHelper::clip(
3374 - function () {
2982 + function() {
3375 2983 FrmAppHelper::maybe_autocomplete_pages_options(
3376 2984 array(
3377 2985 'field_name' => 'frm_page_dropdown',
3378 2986 'page_id' => '',
@@ -3392,8 +3000,15 @@
3392 3000
3393 3001 /**
3394 3002 * @deprecated 4.0
3395 3003 */
3004 + public static function new_form( $values = array() ) {
3005 + FrmDeprecated::new_form( $values );
3006 + }
3007 +
3008 + /**
3009 + * @deprecated 4.0
3010 + */
3396 3011 public static function create( $values = array() ) {
3397 3012 _deprecated_function( __METHOD__, '4.0', 'FrmFormsController::update' );
3398 3013 self::update( $values );
3399 3014 }
@@ -3398,16 +3013,35 @@
3398 3013 self::update( $values );
3399 3014 }
3400 3015
3401 3016 /**
3402 - * Education for premium features.
3403 - *
3404 - * @since 4.05
3405 - * @deprecated 6.16.3
3406 - *
3407 - * @return void
3017 + * @deprecated 3.0
3018 + * @codeCoverageIgnore
3408 3019 */
3409 - public static function add_form_style_tab_options() {
3410 - _deprecated_function( __METHOD__, '6.16.3' );
3411 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php';
3020 + public static function bulk_create_template( $ids ) {
3021 + return FrmDeprecated::bulk_create_template( $ids );
3022 + }
3023 +
3024 + /**
3025 + * @deprecated 3.0
3026 + * @codeCoverageIgnore
3027 + */
3028 + public static function edit_key() {
3029 + FrmDeprecated::edit_key();
3030 + }
3031 +
3032 + /**
3033 + * @deprecated 3.0
3034 + * @codeCoverageIgnore
3035 + */
3036 + public static function edit_description() {
3037 + FrmDeprecated::edit_description();
3038 + }
3039 +
3040 + /**
3041 + * @deprecated 4.08
3042 + * @since 3.06
3043 + */
3044 + public static function add_new() {
3045 + _deprecated_function( __FUNCTION__, '4.08' );
3412 3046 }
3413 3047 }