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 +459 -839 6.25.16.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,86 +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="' . esc_url( self::get_form_too_long_docs_url() ) . '" target="_blank" rel="noopener">',
310 - '</a>'
311 - );
231 + return self::get_edit_vars( $id, array(), $message );
312 232 }
313 -
314 - if ( defined( 'DOING_AJAX' ) ) {
315 - wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
316 - }
317 -
318 - self::get_edit_vars( $id, array(), $message );
319 233 }
320 234
321 235 /**
322 - * @since 6.25.1
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.
323 239 *
324 - * @return string
240 + * @since 3.06.01
325 241 */
326 - private static function get_form_too_long_docs_url() {
327 - $utm = array(
328 - 'campaign' => 'builder',
329 - 'content' => 'form-too-long',
330 - );
331 - return FrmAppHelper::admin_upgrade_link( $utm, 'knowledgebase/i-have-a-long-form-why-did-the-options-at-the-end-of-the-form-stop-saving/' );
242 + private static function is_too_long( $values ) {
243 + return ( ! isset( $values['frm_end'] ) ) || empty( $values['frm_end'] );
332 244 }
333 245
334 246 /**
335 - * 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
336 249 *
337 - * @since 6.8
338 - *
339 - * @param int $form_id
340 - * @return void
250 + * @since 2.0
251 + * @deprecated 3.06
341 252 */
342 - private static function maybe_remove_draft_option_from_fields( $form_id ) {
343 - $draft_field_ids_csv = FrmAppHelper::get_post_param( 'draft_fields', '', 'sanitize_text_field' );
344 - if ( ! $draft_field_ids_csv ) {
345 - // If the draft_fields input is empty there are no new fields in the session.
346 - return;
347 - }
253 + public static function _create_from_template() {
254 + _deprecated_function( __FUNCTION__, '3.06' );
348 255
349 - $draft_field_ids = array_filter( explode( ',', $draft_field_ids_csv ), 'is_numeric' );
350 - if ( ! $draft_field_ids ) {
351 - // Exit early if the draft fields input is invalid. It should be a CSV of integer values.
352 - return;
353 - }
256 + FrmAppHelper::permission_check( 'frm_edit_forms' );
257 + check_ajax_referer( 'frm_ajax', 'nonce' );
354 258
355 - $draft_field_rows = FrmFieldsHelper::get_draft_field_results( $form_id, $draft_field_ids );
356 - foreach ( $draft_field_rows as $row ) {
357 - $row->field_options['draft'] = 0;
358 - 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 );
359 264 }
360 - }
361 265
362 - /**
363 - * Check if the value at the end of the form was included.
364 - * If it's missing, it means other values at the end of the form
365 - * were likely not saved either.
366 - *
367 - * @since 3.06.01
368 - *
369 - * @param array $values
370 - * @return bool
371 - */
372 - private static function is_too_long( $values ) {
373 - 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();
374 268 }
375 269
376 270 public static function duplicate() {
377 271 FrmAppHelper::permission_check( 'frm_edit_forms' );
@@ -387,11 +281,10 @@
387 281 $url = admin_url( 'admin.php?page=formidable' );
388 282 $message = 'form_duplicate_error';
389 283
390 284 if ( $form ) {
391 - $new_template = FrmAppHelper::simple_get( 'new_template' ) ? '&new_template=true' : '';
392 - $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) . $new_template );
393 - $message = 'form_duplicated';
285 + $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) );
286 + $message = 'form_duplicated';
394 287 }
395 288
396 289 $url .= '&message=' . $message;
397 290
@@ -399,42 +292,27 @@
399 292 exit();
400 293 }
401 294
402 295 /**
403 - * @return string|null
296 + * @return string
404 297 */
405 298 public static function page_preview() {
406 299 $params = FrmForm::list_page_params();
407 - if ( ! $params['form'] || is_numeric( $params['form'] ) ) {
408 - return null;
300 + if ( ! $params['form'] ) {
301 + return;
409 302 }
410 303
411 - self::maybe_block_preview( $params['form'] );
412 -
413 304 $form = FrmForm::getOne( $params['form'] );
414 - if ( ! $form ) {
415 - return null;
305 + if ( $form ) {
306 + return self::show_form( $form->id, '', 'auto', 'auto' );
416 307 }
417 -
418 - return self::show_form( $form->id, '', 'auto', 'auto' );
419 308 }
420 309
421 310 /**
422 311 * @since 3.0
423 - *
424 - * @return void
425 312 */
426 313 public static function show_page_preview() {
427 - $preview = self::page_preview();
428 - if ( is_null( $preview ) ) {
429 - wp_die(
430 - '<h1>' . esc_html__( 'Form key is invalid', 'formidable' ) . '</h1>',
431 - '<p>' . esc_html__( 'Form key is invalid', 'formidable' ) . '</p>',
432 - 404
433 - );
434 - }
435 -
436 - echo $preview; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
314 + echo self::page_preview(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
437 315 }
438 316
439 317 /**
440 318 * @return void
@@ -445,17 +323,8 @@
445 323
446 324 global $frm_vars;
447 325 $frm_vars['preview'] = true;
448 326
449 - // print_emoji_styles is deprecated.
450 - remove_action( 'wp_print_styles', 'print_emoji_styles' );
451 -
452 - if ( FrmTestModeController::should_add_test_mode_container() ) {
453 - do_action( 'frm_test_mode_init' );
454 - add_action( 'wp_enqueue_scripts', 'FrmTestModeController::register_and_enqueue_required_scripts' );
455 - add_filter( 'frm_filter_final_form', 'FrmTestModeController::maybe_add_test_mode_container', 99 );
456 - }
457 -
458 327 $include_theme = FrmAppHelper::get_param( 'theme', '', 'get', 'absint' );
459 328 if ( $include_theme ) {
460 329 self::set_preview_query();
461 330 self::load_theme_preview();
@@ -490,13 +359,8 @@
490 359 return;
491 360 }
492 361
493 362 $random_page = reset( $random_page );
494 - if ( ! is_a( $random_page, 'WP_Post' ) ) {
495 - // The return type can also be int.
496 - return;
497 - }
498 -
499 363 query_posts(
500 364 array(
501 365 'post_type' => 'page',
502 366 'page_id' => $random_page->ID,
@@ -512,9 +376,9 @@
512 376 * Set the WP $post global object. Used for in-theme preview when defining a page.
513 377 *
514 378 * @since 5.5.2
515 379 *
516 - * @param WP_Post $page The page object.
380 + * @param WP_Post $post
517 381 * @return void
518 382 */
519 383 private static function set_post_global( $page ) {
520 384 global $post;
@@ -522,10 +386,8 @@
522 386 }
523 387
524 388 /**
525 389 * @since 3.0
526 - *
527 - * @return void
528 390 */
529 391 private static function load_theme_preview() {
530 392 add_filter( 'wp_title', 'FrmFormsController::preview_title', 9999 );
531 393 add_filter( 'the_title', 'FrmFormsController::preview_page_title', 9999 );
@@ -534,39 +396,20 @@
534 396 add_filter( 'is_active_sidebar', '__return_false' );
535 397 FrmStylesController::enqueue_css( 'enqueue', true );
536 398
537 399 if ( false === get_template_part( 'page' ) ) {
538 - if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) {
539 - add_filter( 'body_class', 'FrmFormsController::preview_block_theme_body_classnames' );
540 - }
541 400 self::fallback_when_page_template_part_is_not_supported_by_theme();
542 401 }
543 402 }
544 403
545 404 /**
546 - * Add padding to the body for block themes.
547 - *
548 - * @since 6.5.2
549 - *
550 - * @param array $classes The body classes list.
551 - * @return array
552 - */
553 - public static function preview_block_theme_body_classnames( $classes ) {
554 - $classes[] = 'has-global-padding';
555 - return $classes;
556 - }
557 -
558 - /**
559 405 * Not every theme supports get_template_part( 'page' ).
560 406 * When this is not supported, false is returned, and we can handle a fallback.
561 - *
562 - * @return void
563 407 */
564 408 private static function fallback_when_page_template_part_is_not_supported_by_theme() {
565 409 if ( have_posts() ) {
566 410 the_post();
567 - self::get_template( 'header' );
568 -
411 + get_header( '' );
569 412 // add some generic class names to the container to add some natural padding to the content.
570 413 // .entry-content catches the WordPress TwentyTwenty theme.
571 414 // .container catches Customizr content.
572 415 echo '<div class="container entry-content">';
@@ -571,58 +414,13 @@
571 414 // .container catches Customizr content.
572 415 echo '<div class="container entry-content">';
573 416 the_content();
574 417 echo '</div>';
575 -
576 - // Prevent extra unexpected forms in the footer.
577 - // For some reason this happens in the Twenty Twenty Five theme.
578 - add_filter( 'frm_filter_final_form', '__return_empty_string' );
579 -
580 - self::get_template( 'footer' );
418 + get_footer();
581 419 }
582 420 }
583 421
584 422 /**
585 - * Calls core function to get a template part if it doesn't cause deprecation warnings. Otherwise skips the deprecation function call
586 - * and renders required html fragments calling required functions.
587 - *
588 - * @since 6.7.1
589 - * @param string $template
590 - * @return void
591 - */
592 - private static function get_template( $template ) {
593 - if ( self::should_try_getting_template( $template ) ) {
594 - call_user_func( 'get_' . $template );
595 - return;
596 - }
597 -
598 - if ( 'header' === $template ) {
599 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/header.php';
600 - return;
601 - }
602 -
603 - if ( 'footer' === $template ) {
604 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/footer.php';
605 - }
606 - }
607 -
608 - /**
609 - * Returns true if calling a template function doesn't trigger deprecation warnings.
610 - *
611 - * @since 6.7.1
612 - * @param string $template
613 - * @return bool
614 - */
615 - private static function should_try_getting_template( $template ) {
616 - $stylesheet_path = get_stylesheet_directory();
617 - $template_path = get_template_directory();
618 - $is_child_theme = $stylesheet_path !== $template_path;
619 - $template_name = $template . '.php';
620 -
621 - return file_exists( $stylesheet_path . '/' . $template_name ) || $is_child_theme && file_exists( $template_path . '/' . $template_name );
622 - }
623 -
624 - /**
625 423 * Set the page title for the theme preview page
626 424 *
627 425 * @since 3.0
628 426 */
@@ -634,14 +432,11 @@
634 432 return $title;
635 433 }
636 434
637 435 /**
638 - * Set the page title for the theme preview page.
436 + * Set the page title for the theme preview page
639 437 *
640 438 * @since 3.0
641 - *
642 - * @param string $title
643 - * @return string
644 439 */
645 440 public static function preview_title( $title ) {
646 441 return __( 'Form Preview', 'formidable' );
647 442 }
@@ -646,20 +441,15 @@
646 441 return __( 'Form Preview', 'formidable' );
647 442 }
648 443
649 444 /**
650 - * Set the page content for the theme preview page.
445 + * Set the page content for the theme preview page
651 446 *
652 447 * @since 3.0
653 - *
654 - * @param string $content
655 - * @return string
656 448 */
657 449 public static function preview_content( $content ) {
658 450 if ( in_the_loop() ) {
659 - self::show_page_preview();
660 - // Clear the content for the page we're using.
661 - $content = '';
451 + $content = self::show_page_preview();
662 452 }
663 453
664 454 return $content;
665 455 }
@@ -667,88 +457,23 @@
667 457 /**
668 458 * @since 3.0
669 459 */
670 460 private static function load_direct_preview() {
461 + header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
462 +
671 463 $key = FrmAppHelper::simple_get( 'form', 'sanitize_title' );
672 464 if ( $key == '' ) {
673 465 $key = FrmAppHelper::get_post_param( 'form', '', 'sanitize_title' );
674 466 }
675 467
676 - if ( ! $key ) {
677 - $error = __( 'Form key is missing', 'formidable' );
678 - wp_die(
679 - '<h1>' . esc_html( $error ) . '</h1>',
680 - '<p>' . esc_html( $error ) . '</p>',
681 - 404
682 - );
683 - }
684 -
685 - self::maybe_block_preview( $key );
686 -
687 468 $form = FrmForm::getAll( array( 'form_key' => $key ), '', 1 );
688 - if ( ! $form ) {
689 - $error = __( 'Form does not exist', 'formidable' );
690 - wp_die(
691 - '<h1>' . esc_html( $error ) . '</h1>',
692 - '<p>' . esc_html( $error ) . '</p>',
693 - 404
694 - );
469 + if ( empty( $form ) ) {
470 + $form = FrmForm::getAll( array(), '', 1 );
695 471 }
696 472
697 - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
698 -
699 - self::fix_deprecated_null_param_warning();
700 -
701 - require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php';
473 + require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php' );
702 474 }
703 475
704 - /**
705 - * Block the form preview for the contact form by default if the user cannot view forms.
706 - * This is to prevent the contact form being exploited.
707 - * Since this form is added by default and every site uses the same key, it is too easy
708 - * to guess this form.
709 - *
710 - * @since 6.20
711 - *
712 - * @param string $form_key Form key.
713 - * @return void
714 - */
715 - public static function maybe_block_preview( $form_key ) {
716 - if ( FrmFormsHelper::should_block_preview( $form_key ) ) {
717 - $error = __( 'You do not have permission to view this form', 'formidable' );
718 - wp_die(
719 - '<h1>' . esc_html( $error ) . '</h1>',
720 - '<p>' . esc_html( $error ) . '</p>',
721 - 403
722 - );
723 - }
724 - }
725 -
726 - /**
727 - * Some themes have a null $src value.
728 - * This function adds a filter to ensure that $src is not null.
729 - * WP will call str_starts_with with the null value triggering a deprecated message otherwise.
730 - *
731 - * @since 6.10
732 - *
733 - * @return void
734 - */
735 - private static function fix_deprecated_null_param_warning() {
736 - add_filter(
737 - 'script_loader_src',
738 - /**
739 - * @param string|null $src
740 - * @return string
741 - */
742 - function ( $src ) {
743 - if ( is_null( $src ) ) {
744 - $src = '';
745 - }
746 - return $src;
747 - }
748 - );
749 - }
750 -
751 476 public static function untrash() {
752 477 self::change_form_status( 'untrash' );
753 478 }
754 479
@@ -811,14 +536,14 @@
811 536 FrmAppHelper::permission_check( $available_status[ $status ]['permission'] );
812 537
813 538 $params = FrmForm::list_page_params();
814 539
815 - // Check nonce url.
540 + //check nonce url
816 541 check_admin_referer( $status . '_form_' . $params['id'] );
817 542
818 543 $count = 0;
819 544 if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) {
820 - ++$count;
545 + $count ++;
821 546 }
822 547
823 548 $form_type = FrmAppHelper::get_simple_request(
824 549 array(
@@ -830,9 +555,9 @@
830 555 /* translators: %1$s: Number of forms */
831 556 $available_status['untrash']['message'] = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
832 557
833 558 /* translators: %1$s: Number of forms, %2$s: Start link HTML, %3$s: End link HTML */
834 - $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>' );
835 560
836 561 $message = $available_status[ $status ]['message'];
837 562
838 563 self::display_forms_list( $params, $message );
@@ -837,12 +562,8 @@
837 562
838 563 self::display_forms_list( $params, $message );
839 564 }
840 565
841 - /**
842 - * @param array $ids
843 - * @return string
844 - */
845 566 public static function bulk_trash( $ids ) {
846 567 FrmAppHelper::permission_check( 'frm_delete_forms' );
847 568
848 569 $count = 0;
@@ -847,16 +568,12 @@
847 568
848 569 $count = 0;
849 570 foreach ( $ids as $id ) {
850 571 if ( FrmForm::trash( $id ) ) {
851 - ++$count;
572 + $count ++;
852 573 }
853 574 }
854 575
855 - if ( ! $count ) {
856 - return '';
857 - }
858 -
859 576 $current_page = FrmAppHelper::get_simple_request(
860 577 array(
861 578 'param' => 'form_type',
862 579 'type' => 'request',
@@ -882,9 +599,9 @@
882 599 check_admin_referer( 'destroy_form_' . $params['id'] );
883 600
884 601 $count = 0;
885 602 if ( FrmForm::destroy( $params['id'] ) ) {
886 - ++$count;
603 + $count ++;
887 604 }
888 605
889 606 /* translators: %1$s: Number of forms */
890 607 $message = sprintf( _n( '%1$s Form Permanently Deleted', '%1$s Forms Permanently Deleted', $count, 'formidable' ), $count );
@@ -891,12 +608,8 @@
891 608
892 609 self::display_forms_list( $params, $message );
893 610 }
894 611
895 - /**
896 - * @param array $ids
897 - * @return string
898 - */
899 612 public static function bulk_destroy( $ids ) {
900 613 FrmAppHelper::permission_check( 'frm_delete_forms' );
901 614
902 615 $count = 0;
@@ -902,24 +615,19 @@
902 615 $count = 0;
903 616 foreach ( $ids as $id ) {
904 617 $d = FrmForm::destroy( $id );
905 618 if ( $d ) {
906 - ++$count;
619 + $count ++;
907 620 }
908 621 }
909 622
910 - if ( $count ) {
911 - /* translators: %1$s: Number of forms */
912 - return sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
913 - }
623 + /* translators: %1$s: Number of forms */
624 + $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
914 625
915 - return '';
626 + return $message;
916 627 }
917 628
918 - /**
919 - * @since 6.7.1 Function went from private to public.
920 - */
921 - public static function delete_all() {
629 + private static function delete_all() {
922 630 // Check nonce url.
923 631 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' );
924 632 if ( $permission_error !== false ) {
925 633 self::display_forms_list( array(), '', array( $permission_error ) );
@@ -926,15 +634,14 @@
926 634
927 635 return;
928 636 }
929 637
930 - $count = FrmForm::scheduled_delete( time() );
931 - $url = remove_query_arg( array( 'delete_all' ) );
638 + $count = FrmForm::scheduled_delete( time() );
932 639
933 - $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 );
934 642
935 - wp_safe_redirect( $url );
936 - die();
643 + self::display_forms_list( array(), $message );
937 644 }
938 645
939 646 /**
940 647 * Create a new form from the modal.
@@ -947,9 +654,9 @@
947 654
948 655 $new_values = self::get_modal_values();
949 656 $new_values['form_key'] = $new_values['name'];
950 657 $new_values['options'] = array(
951 - 'antispam' => 1,
658 + 'antispam' => 1,
952 659 'on_submit_migrated' => 1,
953 660 );
954 661
955 662 /**
@@ -968,14 +675,13 @@
968 675 * @param int $form_id
969 676 */
970 677 do_action( 'frm_build_new_form', $form_id );
971 678
972 - self::create_submit_button_field( $form_id );
973 679 self::create_default_on_submit_action( $form_id );
974 680 self::create_default_email_action( $form_id );
975 681
976 682 $response = array(
977 - 'redirect' => FrmForm::get_edit_link( $form_id ) . '&new_template=true',
683 + 'redirect' => FrmForm::get_edit_link( $form_id ),
978 684 );
979 685
980 686 echo wp_json_encode( $response );
981 687 wp_die();
@@ -981,15 +687,46 @@
981 687 wp_die();
982 688 }
983 689
984 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 + /**
985 724 * Before creating a new form, get the name and description from the modal.
986 725 *
987 726 * @since 4.0
988 - *
989 - * @return array<string,string>
990 727 */
991 - public static function get_modal_values() {
728 + private static function get_modal_values() {
992 729 $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' );
993 730 $desc = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' );
994 731
995 732 return array(
@@ -1002,24 +739,17 @@
1002 739 * Inserts Formidable button
1003 740 * Hook exists since 2.5.0
1004 741 *
1005 742 * @since 2.0.15
1006 - *
1007 - * @return void
1008 743 */
1009 744 public static function insert_form_button() {
1010 745 if ( current_user_can( 'frm_view_forms' ) ) {
1011 - // Store the result in memory and re-use it when this function is called multiple times.
1012 - // This helps speed up the form builder when there are a lot of HTML fields, where this
1013 - // button is inserted once per HTML field.
1014 - // In a form with 66 HTML fields, this saves 0.5 seconds on page load time, tested locally.
1015 - if ( ! isset( self::$formidable_tinymce_button ) ) {
1016 - FrmAppHelper::load_admin_wide_js();
1017 - $menu_name = FrmAppHelper::get_menu_name();
1018 - $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() );
1019 - 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>';
1020 - }
1021 - 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>';
1022 752 }
1023 753 }
1024 754
1025 755 /**
@@ -1107,9 +837,9 @@
1107 837 $form_id = $opts['form_id'];
1108 838 unset( $opts['form_id'] );
1109 839 }
1110 840
1111 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php';
841 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php' );
1112 842
1113 843 echo '</div>';
1114 844
1115 845 wp_die();
@@ -1149,14 +879,8 @@
1149 879 wp_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) );
1150 880 die();
1151 881 }
1152 882
1153 - $inbox = new FrmInbox();
1154 - $error = $inbox->check_for_error();
1155 - if ( $error ) {
1156 - $show_messages = array( $error['subject'] . '. ' . $error['message'] );
1157 - }
1158 -
1159 883 require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/list.php';
1160 884 }
1161 885
1162 886 /**
@@ -1163,17 +887,15 @@
1163 887 * @param array<string,string> $columns
1164 888 * @return array<string,string>
1165 889 */
1166 890 public static function get_columns( $columns ) {
1167 - $columns['cb'] = '<input type="checkbox" />';
1168 - $columns['name'] = esc_html__( 'Form Title', 'formidable' );
1169 - $columns['entries'] = esc_html__( 'Entries', 'formidable' );
1170 - $columns['id'] = 'ID';
1171 - $columns['form_key'] = esc_html__( 'Key', 'formidable' );
1172 - if ( 'trash' !== FrmAppHelper::simple_get( 'form_type' ) ) {
1173 - $columns['shortcode'] = esc_html__( 'Actions', 'formidable' );
1174 - }
1175 - $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' );
1176 898
1177 899 add_screen_option(
1178 900 'per_page',
1179 901 array(
@@ -1185,11 +907,8 @@
1185 907
1186 908 return $columns;
1187 909 }
1188 910
1189 - /**
1190 - * @return array<string,string>
1191 - */
1192 911 public static function get_sortable_columns() {
1193 912 return array(
1194 913 'id' => 'id',
1195 914 'name' => 'name',
@@ -1223,9 +942,9 @@
1223 942 return $hidden_columns;
1224 943 }
1225 944
1226 945 public static function save_per_page( $save, $option, $value ) {
1227 - if ( $option === 'formidable_page_formidable_per_page' ) {
946 + if ( $option == 'formidable_page_formidable_per_page' ) {
1228 947 $save = (int) $value;
1229 948 }
1230 949
1231 950 return $save;
@@ -1231,49 +950,146 @@
1231 950 return $save;
1232 951 }
1233 952
1234 953 /**
1235 - * @param int|string $id
1236 - * @param array $errors
1237 - * @param string $message
1238 - * @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 + *
1239 964 * @return void
1240 965 */
1241 - private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
1242 - global $frm_vars;
966 + public static function before_list_templates() {
967 + global $frm_templates;
968 + global $frm_expired;
969 + global $frm_license_type;
1243 970
1244 - $form = FrmForm::getOne( $id );
1245 - $error_args = array(
1246 - 'title' => __( 'You can\'t edit the form', 'formidable' ),
1247 - 'body' => __( 'You are trying to edit a form that does not exist', 'formidable' ),
1248 - 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
1249 - 'continue_url' => add_query_arg(
1250 - array(
1251 - 'page' => 'formidable',
1252 - )
1253 - ),
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 + }
1254 1028 );
1255 - if ( ! $form ) {
1256 - FrmAppController::show_error_modal( $error_args );
1257 - 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 + }
1258 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 + }
1259 1062
1260 - if ( 'trash' === $form->status ) {
1261 - $error_args['body'] = __( 'The form you\'re trying to edit is in trash. You must restore it first before you can make changes', 'formidable' );
1262 - $error_args['continue_url'] = add_query_arg(
1263 - array(
1264 - 'page' => 'formidable',
1265 - '_wpnonce' => wp_create_nonce( 'untrash_form_' . $id ),
1266 - 'form_type' => 'trash',
1267 - 'frm_action' => 'untrash',
1268 - 'id' => $id,
1269 - )
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,
1270 1078 );
1271 - $error_args['continue_text'] = __( 'Restore form', 'formidable' );
1272 - FrmAppController::show_error_modal( $error_args );
1273 - return;
1079 + array_unshift( $templates, $template );
1080 + unset( $template );
1274 1081 }
1082 + }
1275 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 +
1276 1092 if ( $form->parent_form_id ) {
1277 1093 /* translators: %1$s: Start link HTML, %2$s: End link HTML */
1278 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>' ) );
1279 1095 }
@@ -1284,9 +1100,8 @@
1284 1100
1285 1101 // Automatically add end section fields if they don't exist (2.0 migration).
1286 1102 $reset_fields = false;
1287 1103 FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields );
1288 - FrmSubmitHelper::maybe_create_submit_field( $form, $fields, $reset_fields );
1289 1104
1290 1105 if ( $reset_fields ) {
1291 1106 $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' );
1292 1107 }
@@ -1312,21 +1127,18 @@
1312 1127 }
1313 1128
1314 1129 self::maybe_update_form_builder_message( $message );
1315 1130
1316 - $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'] );
1317 1133
1318 1134 if ( defined( 'DOING_AJAX' ) ) {
1319 1135 wp_die();
1136 + } else {
1137 + require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' );
1320 1138 }
1321 -
1322 - require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php';
1323 1139 }
1324 1140
1325 - /**
1326 - * @param array $fields
1327 - * @return array
1328 - */
1329 1141 public static function update_form_builder_fields( $fields, $form ) {
1330 1142 foreach ( $fields as $field ) {
1331 1143 $field->do_not_include_icons = true;
1332 1144 }
@@ -1338,21 +1150,13 @@
1338 1150 $message = __( 'Form was Successfully Copied', 'formidable' );
1339 1151 }
1340 1152 }
1341 1153
1342 - /**
1343 - * @param int|string $id
1344 - * @param array $errors
1345 - * @param array|string $args
1346 - * @return void
1347 - */
1348 1154 public static function get_settings_vars( $id, $errors = array(), $args = array() ) {
1349 1155 FrmAppHelper::permission_check( 'frm_edit_forms' );
1350 1156
1351 1157 global $frm_vars;
1352 1158
1353 - self::maybe_print_media_templates();
1354 -
1355 1159 if ( ! is_array( $args ) ) {
1356 1160 // For reverse compatibility.
1357 1161 $args = array(
1358 1162 'message' => $args,
@@ -1385,38 +1189,17 @@
1385 1189
1386 1190 $sections = self::get_settings_tabs( $values );
1387 1191 $current = FrmAppHelper::simple_get( 't', 'sanitize_title', 'advanced_settings' );
1388 1192
1389 - require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php';
1193 + require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php' );
1390 1194 }
1391 1195
1392 1196 /**
1393 - * 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.
1394 - *
1395 - * @since 6.10
1396 - *
1397 - * @return void
1398 - */
1399 - private static function maybe_print_media_templates() {
1400 - if ( FrmAppHelper::pro_is_included() ) {
1401 - // This issue does not exist when Pro is active so exit early.
1402 - return;
1403 - }
1404 -
1405 - add_action(
1406 - 'wp_enqueue_editor',
1407 - function () {
1408 - wp_print_media_templates();
1409 - }
1410 - );
1411 - }
1412 -
1413 - /**
1414 1197 * @since 4.0
1415 1198 */
1416 1199 public static function form_publish_button( $atts ) {
1417 1200 $values = $atts['values'];
1418 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php';
1201 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php' );
1419 1202 }
1420 1203
1421 1204 /**
1422 1205 * Get a list of all the settings tabs for the form settings page.
@@ -1430,9 +1213,9 @@
1430 1213 $sections = array(
1431 1214 'advanced' => array(
1432 1215 'name' => __( 'General', 'formidable' ),
1433 1216 'title' => __( 'General Form Settings', 'formidable' ),
1434 - 'function' => array( self::class, 'advanced_settings' ),
1217 + 'function' => array( __CLASS__, 'advanced_settings' ),
1435 1218 'icon' => 'frm_icon_font frm_settings_icon',
1436 1219 ),
1437 1220 'email' => array(
1438 1221 'name' => __( 'Actions & Notifications', 'formidable' ),
@@ -1441,9 +1224,9 @@
1441 1224 'icon' => 'frm_icon_font frm_mail_bulk_icon',
1442 1225 ),
1443 1226 'permissions' => array(
1444 1227 'name' => __( 'Form Permissions', 'formidable' ),
1445 - 'icon' => 'frm_icon_font frm_lock_closed_icon',
1228 + 'icon' => 'frm_icon_font frm_lock_icon',
1446 1229 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1447 1230 'data' => array(
1448 1231 'medium' => 'permissions',
1449 1232 'upgrade' => __( 'Form Permissions', 'formidable' ),
@@ -1450,9 +1233,9 @@
1450 1233 'message' => __( 'Allow editing, protect forms and files, limit entries, and save drafts. Upgrade to get form and entry permissions.', 'formidable' ),
1451 1234 'screenshot' => 'permissions.png',
1452 1235 ),
1453 1236 ),
1454 - 'scheduling' => array(
1237 + 'scheduling' => array(
1455 1238 'name' => __( 'Form Scheduling', 'formidable' ),
1456 1239 'icon' => 'frm_icon_font frm_calendar_icon',
1457 1240 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1458 1241 'data' => array(
@@ -1462,9 +1245,9 @@
1462 1245 ),
1463 1246 ),
1464 1247 'buttons' => array(
1465 1248 'name' => __( 'Buttons', 'formidable' ),
1466 - 'class' => self::class,
1249 + 'class' => __CLASS__,
1467 1250 'function' => 'buttons_settings',
1468 1251 'icon' => 'frm_icon_font frm_button_icon',
1469 1252 ),
1470 1253 'landing' => array(
@@ -1485,34 +1268,17 @@
1485 1268 'screenshot' => 'chat.png',
1486 1269 )
1487 1270 ),
1488 1271 ),
1489 - 'abandonment' => array(
1490 - 'name' => __( 'Form Abandonment', 'formidable' ),
1491 - 'icon' => 'frm_icon_font frm_abandoned_icon',
1492 - 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1493 - 'data' => FrmAppHelper::get_upgrade_data_params(
1494 - 'abandonment',
1495 - array(
1496 - 'upgrade' => __( 'Form abandonment settings', 'formidable' ),
1497 - 'message' => __( 'Unlock the power of data capture to boost lead generation and master the art of form optimization.', 'formidable' ),
1498 - 'screenshot' => 'abandonment.png',
1499 - )
1500 - ),
1501 - ),
1502 1272 'html' => array(
1503 1273 'name' => __( 'Customize HTML', 'formidable' ),
1504 - 'class' => self::class,
1274 + 'class' => __CLASS__,
1505 1275 'function' => 'html_settings',
1506 1276 'icon' => 'frm_icon_font frm_code_icon',
1507 1277 ),
1508 1278 );
1509 1279
1510 - if ( ! has_action( 'frm_add_form_style_tab_options' ) && ! has_action( 'frm_add_form_button_options' ) ) {
1511 - unset( $sections['buttons'] );
1512 - }
1513 -
1514 - foreach ( array( 'landing', 'chat', 'abandonment' ) as $feature ) {
1280 + foreach ( array( 'landing', 'chat' ) as $feature ) {
1515 1281 if ( ! FrmAppHelper::show_new_feature( $feature ) ) {
1516 1282 unset( $sections[ $feature ] );
1517 1283 }
1518 1284 }
@@ -1518,8 +1284,13 @@
1518 1284 }
1519 1285
1520 1286 $sections = apply_filters( 'frm_add_form_settings_section', $sections, $values );
1521 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 +
1522 1293 foreach ( $sections as $key => $section ) {
1523 1294 $defaults = array(
1524 1295 'html_class' => '',
1525 1296 'name' => ucfirst( $key ),
@@ -1541,9 +1312,9 @@
1541 1312 $section['id'] = $section['anchor'];
1542 1313 }
1543 1314
1544 1315 $sections[ $key ] = $section;
1545 - }//end foreach
1316 + }
1546 1317
1547 1318 return $sections;
1548 1319 }
1549 1320
@@ -1550,9 +1321,8 @@
1550 1321 /**
1551 1322 * @since 4.0
1552 1323 *
1553 1324 * @param array $values
1554 - * @return void
1555 1325 */
1556 1326 public static function advanced_settings( $values ) {
1557 1327 $first_h3 = 'frm_first_h3';
1558 1328
@@ -1560,15 +1330,14 @@
1560 1330 }
1561 1331
1562 1332 /**
1563 1333 * @param array $values
1564 - * @return void
1565 1334 */
1566 1335 public static function render_spam_settings( $values ) {
1567 1336 if ( function_exists( 'akismet_http_post' ) ) {
1568 1337 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/akismet.php';
1569 1338 }
1570 - 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';
1571 1340 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/antispam.php';
1572 1341 }
1573 1342
1574 1343 /**
@@ -1574,12 +1343,16 @@
1574 1343 /**
1575 1344 * @since 4.0
1576 1345 *
1577 1346 * @param array $values
1578 - * @return void
1579 1347 */
1580 1348 public static function buttons_settings( $values ) {
1581 - 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' );
1582 1355 }
1583 1356
1584 1357 /**
1585 1358 * @since 4.0
@@ -1584,12 +1357,11 @@
1584 1357 /**
1585 1358 * @since 4.0
1586 1359 *
1587 1360 * @param array $values
1588 - * @return void
1589 1361 */
1590 1362 public static function html_settings( $values ) {
1591 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php';
1363 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php' );
1592 1364 }
1593 1365
1594 1366 /**
1595 1367 * Replace old Submit Button href with new href to avoid errors in Chrome
@@ -1595,10 +1367,9 @@
1595 1367 * Replace old Submit Button href with new href to avoid errors in Chrome
1596 1368 *
1597 1369 * @since 2.03.08
1598 1370 *
1599 - * @param array|bool $values
1600 - * @return void
1371 + * @param array|boolean $values
1601 1372 */
1602 1373 private static function clean_submit_html( &$values ) {
1603 1374 if ( is_array( $values ) && isset( $values['submit_html'] ) ) {
1604 1375 $values['submit_html'] = str_replace( 'javascript:void(0)', '#', $values['submit_html'] );
@@ -1619,13 +1390,8 @@
1619 1390
1620 1391 return $classes;
1621 1392 }
1622 1393
1623 - /**
1624 - * @param int|string $form_id
1625 - * @param string $class
1626 - * @return void
1627 - */
1628 1394 public static function mb_tags_box( $form_id, $class = '' ) {
1629 1395 $fields = FrmField::get_all_for_form( $form_id, '', 'include' );
1630 1396
1631 1397 /**
@@ -1638,9 +1404,9 @@
1638 1404 */
1639 1405 $fields = apply_filters( 'frm_fields_in_tags_box', $fields, compact( 'form_id' ) );
1640 1406 $linked_forms = array();
1641 1407 $col = 'one';
1642 - $settings_tab = FrmAppHelper::is_admin_page( 'formidable' );
1408 + $settings_tab = FrmAppHelper::is_admin_page( 'formidable' ) ? true : false;
1643 1409
1644 1410 $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() );
1645 1411 $entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
1646 1412
@@ -1645,9 +1411,9 @@
1645 1411 $entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
1646 1412
1647 1413 $advanced_helpers = self::advanced_helpers( compact( 'fields', 'form_id' ) );
1648 1414
1649 - include FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php';
1415 + include( FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php' );
1650 1416 }
1651 1417
1652 1418 /**
1653 1419 * @since 3.04.01
@@ -1660,9 +1426,9 @@
1660 1426 ),
1661 1427 );
1662 1428
1663 1429 $user_fields = self::user_shortcodes();
1664 - if ( $user_fields ) {
1430 + if ( ! empty( $user_fields ) ) {
1665 1431 $user_helpers = array();
1666 1432 foreach ( $user_fields as $uk => $uf ) {
1667 1433 $user_helpers[ '|user_id| show="' . $uk . '"' ] = $uf;
1668 1434 unset( $uk, $uf );
@@ -1668,9 +1434,9 @@
1668 1434 unset( $uk, $uf );
1669 1435 }
1670 1436
1671 1437 $advanced_helpers['user_id'] = array(
1672 - 'codes' => $user_helpers,
1438 + 'codes' => $user_helpers,
1673 1439 );
1674 1440 }
1675 1441
1676 1442 /**
@@ -1747,16 +1513,21 @@
1747 1513 'updated-at' => __( 'Entry updated', 'formidable' ),
1748 1514 '' => '',
1749 1515 'siteurl' => __( 'Site URL', 'formidable' ),
1750 1516 'sitename' => __( 'Site Name', 'formidable' ),
1751 - 'form_name' => __( 'Form Name', 'formidable' ),
1752 1517 );
1753 1518
1754 - $entry_shortcodes = array_merge( FrmShortcodeHelper::get_contextual_shortcode_values(), $entry_shortcodes );
1755 1519 if ( ! FrmAppHelper::pro_is_installed() ) {
1756 1520 unset( $entry_shortcodes['post_id'] );
1757 1521 }
1758 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 +
1759 1530 /**
1760 1531 * Use this hook to add or remove buttons in the helpers section
1761 1532 * in the customization panel
1762 1533 *
@@ -1782,9 +1553,9 @@
1782 1553 echo ' frm_js_validate ';
1783 1554 self::add_js_validate_form_to_global_vars( $form );
1784 1555 }
1785 1556
1786 - if ( FrmForm::is_ajax_on( $form ) ) {
1557 + if ( ! FrmFormsHelper::should_use_pro_for_ajax_submit() && FrmForm::is_ajax_on( $form ) ) {
1787 1558 echo ' frm_ajax_submit ';
1788 1559 }
1789 1560 }
1790 1561
@@ -1806,11 +1577,11 @@
1806 1577 check_ajax_referer( 'frm_ajax', 'nonce' );
1807 1578
1808 1579 echo FrmEntriesController::show_entry_shortcode( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1809 1580 array(
1810 - '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' ),
1811 1582 'default_email' => true,
1812 - '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' ),
1813 1584 )
1814 1585 );
1815 1586 wp_die();
1816 1587 }
@@ -1816,10 +1587,10 @@
1816 1587 }
1817 1588
1818 1589 /**
1819 1590 * @param string $content
1820 - * @param int|stdClass|string $form
1821 - * @param false|int|stdClass|string $entry
1591 + * @param stdClass|string|int $form
1592 + * @param stdClass|string|int|false $entry
1822 1593 * @return string
1823 1594 */
1824 1595 public static function filter_content( $content, $form, $entry = false ) {
1825 1596 $content = self::replace_form_name_shortcodes( $content, $form );
@@ -1832,16 +1603,8 @@
1832 1603 if ( is_object( $form ) ) {
1833 1604 $form = $form->id;
1834 1605 }
1835 1606
1836 - /*
1837 - * Repeater actions adds `parent_entry` to `$entry` store the parent entry data. If `parent_entry` is not empty,
1838 - * use the parent form ID instead of repeater form ID to fix the parent form field shortcodes doesn't work.
1839 - */
1840 - if ( ! empty( $entry->parent_entry ) ) {
1841 - $form = $entry->parent_entry->form_id;
1842 - }
1843 -
1844 1607 $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form );
1845 1608 $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
1846 1609
1847 1610 return $content;
@@ -1851,17 +1614,13 @@
1851 1614 * Replace any [form_name] shortcodes in a string.
1852 1615 *
1853 1616 * @since 5.5
1854 1617 *
1855 - * @param array|string $string
1856 - * @param int|stdClass|string $form
1857 - * @return array|string
1618 + * @param string $string
1619 + * @param stdClass|string|int $form
1620 + * @return string
1858 1621 */
1859 1622 public static function replace_form_name_shortcodes( $string, $form ) {
1860 - if ( ! is_string( $string ) ) {
1861 - return $string;
1862 - }
1863 -
1864 1623 if ( false === strpos( $string, '[form_name]' ) ) {
1865 1624 return $string;
1866 1625 }
1867 1626
@@ -1873,9 +1632,9 @@
1873 1632 return str_replace( '[form_name]', $form_name, $string );
1874 1633 }
1875 1634
1876 1635 /**
1877 - * @param false|int|stdClass|string $entry
1636 + * @param stdClass|string|int|false $entry
1878 1637 * @return void
1879 1638 */
1880 1639 private static function get_entry_by_param( &$entry ) {
1881 1640 if ( ! $entry || ! is_object( $entry ) ) {
@@ -1890,12 +1649,8 @@
1890 1649 public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
1891 1650 return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes );
1892 1651 }
1893 1652
1894 - /**
1895 - * @param array $errors
1896 - * @return array
1897 - */
1898 1653 public static function process_bulk_form_actions( $errors ) {
1899 1654 if ( ! $_REQUEST ) {
1900 1655 return $errors;
1901 1656 }
@@ -1939,9 +1694,9 @@
1939 1694 case 'untrash':
1940 1695 $message = self::bulk_untrash( $ids );
1941 1696 }
1942 1697
1943 - if ( ! empty( $message ) ) {
1698 + if ( isset( $message ) && ! empty( $message ) ) {
1944 1699 $errors['message'] = $message;
1945 1700 }
1946 1701
1947 1702 return $errors;
@@ -1946,26 +1701,13 @@
1946 1701
1947 1702 return $errors;
1948 1703 }
1949 1704
1950 - /**
1951 - * Includes html that shows a message when the device is too small to use Formidable Forms admin pages.
1952 - *
1953 - * @since 6.20
1954 - * @return void
1955 - */
1956 - public static function include_device_too_small_message() {
1957 - if ( ! FrmAppHelper::is_formidable_admin() ) {
1958 - return;
1959 - }
1960 -
1961 - include FrmAppHelper::plugin_path() . '/classes/views/shared/small-device-message.php';
1962 - }
1963 -
1964 1705 public static function route() {
1965 1706 $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
1966 1707 $vars = array();
1967 1708 FrmAppHelper::include_svg();
1709 +
1968 1710 if ( isset( $_POST['frm_compact_fields'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
1969 1711 FrmAppHelper::permission_check( 'frm_edit_forms' );
1970 1712
1971 1713 // Javascript needs to be allowed in some field settings.
@@ -1974,9 +1716,9 @@
1974 1716 $json_vars = json_decode( $json_vars, true );
1975 1717 if ( empty( $json_vars ) ) {
1976 1718 // json decoding failed so we should return an error message.
1977 1719 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
1978 - if ( 'edit' === $action ) {
1720 + if ( 'edit' == $action ) {
1979 1721 $action = 'update';
1980 1722 }
1981 1723
1982 1724 add_filter( 'frm_validate_form', 'FrmFormsController::json_error' );
@@ -1992,14 +1734,16 @@
1992 1734 if ( isset( $_REQUEST['delete_all'] ) ) {
1993 1735 // Override the action for this page.
1994 1736 $action = 'delete_all';
1995 1737 }
1996 - }//end if
1738 + }
1997 1739
1998 1740 add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
1999 1741 FrmAppHelper::trigger_hook_load( 'form' );
2000 1742
2001 1743 switch ( $action ) {
1744 + case 'new':
1745 + return self::new_form( $vars );
2002 1746 case 'create':
2003 1747 case 'edit':
2004 1748 case 'update':
2005 1749 case 'trash':
@@ -2004,17 +1748,16 @@
2004 1748 case 'update':
2005 1749 case 'trash':
2006 1750 case 'untrash':
2007 1751 case 'destroy':
1752 + case 'delete_all':
2008 1753 case 'settings':
2009 1754 case 'update_settings':
2010 1755 return self::$action( $vars );
2011 1756 case 'lite-reports':
2012 - self::no_reports( $vars );
2013 - return;
1757 + return self::no_reports( $vars );
2014 1758 case 'views':
2015 - self::no_views( $vars );
2016 - return;
1759 + return self::no_views( $vars );
2017 1760 default:
2018 1761 do_action( 'frm_form_action_' . $action );
2019 1762 if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) {
2020 1763 return;
@@ -2037,65 +1780,12 @@
2037 1780 self::display_forms_list( array(), '', array( __( 'There was a problem duplicating the form', 'formidable' ) ) );
2038 1781 return;
2039 1782 }
2040 1783
2041 - if ( 'forms_permanently_deleted' === $message ) {
2042 - $count = FrmAppHelper::get_param( 'forms_deleted', 0, 'get', 'absint' );
2043 - /* translators: %1$s: Number of forms */
2044 - $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
2045 - self::display_forms_list( array(), $message, '' );
2046 - return;
2047 - }
2048 -
2049 1784 self::display_forms_list();
2050 1785
2051 1786 return;
2052 - }//end switch
2053 - }
2054 -
2055 - /**
2056 - * Rename a form.
2057 - *
2058 - * Handles the AJAX request for renaming a form.
2059 - *
2060 - * @since 6.7
2061 - *
2062 - * @return void
2063 - */
2064 - public static function rename_form() {
2065 - // Check permission and nonce
2066 - FrmAppHelper::permission_check( 'frm_edit_forms' );
2067 - check_ajax_referer( 'frm_ajax', 'nonce' );
2068 -
2069 - // Get posted data
2070 - $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
2071 - $name = FrmAppHelper::get_post_param( 'form_name', '', 'sanitize_text_field' );
2072 -
2073 - $form = FrmForm::getOne( $form_id );
2074 - if ( ! $form ) {
2075 - wp_send_json_error( __( 'Form not found', 'formidable' ) );
2076 1787 }
2077 -
2078 - if ( $name === $form->name ) {
2079 - // Nothing to change so exit early.
2080 - wp_send_json_success();
2081 - }
2082 -
2083 - $to_update = array(
2084 - 'name' => $name,
2085 - );
2086 -
2087 - if ( '' !== $name ) {
2088 - // Only update form_key if name is not empty.
2089 - $form_key = FrmAppHelper::get_unique_key( sanitize_title( $name ), 'frm_forms', 'form_key' );
2090 - $to_update['form_key'] = $form_key;
2091 - } else {
2092 - $form_key = $form->form_key;
2093 - }
2094 -
2095 - FrmForm::update( $form_id, $to_update );
2096 -
2097 - wp_send_json_success( compact( 'form_key' ) );
2098 1788 }
2099 1789
2100 1790 public static function json_error( $errors ) {
2101 1791 $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
@@ -2103,13 +1793,20 @@
2103 1793 return $errors;
2104 1794 }
2105 1795
2106 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 + /**
2107 1806 * Add education about views.
2108 1807 *
2109 1808 * @since 4.07
2110 - *
2111 - * @return void
2112 1809 */
2113 1810 public static function no_views( $values = array() ) {
2114 1811 FrmAppHelper::include_svg();
2115 1812 $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
@@ -2121,10 +1818,8 @@
2121 1818 /**
2122 1819 * Add education about reports.
2123 1820 *
2124 1821 * @since 4.07
2125 - *
2126 - * @return void
2127 1822 */
2128 1823 public static function no_reports( $values = array() ) {
2129 1824 $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
2130 1825 $form = $id ? FrmForm::getOne( $id ) : false;
@@ -2131,11 +1826,9 @@
2131 1826
2132 1827 include FrmAppHelper::plugin_path() . '/classes/views/shared/reports-info.php';
2133 1828 }
2134 1829
2135 - /**
2136 - * FRONT-END FORMS.
2137 - */
1830 + /* FRONT-END FORMS */
2138 1831 public static function admin_bar_css() {
2139 1832 if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
2140 1833 return;
2141 1834 }
@@ -2209,9 +1902,9 @@
2209 1902 $wp_admin_bar->add_node(
2210 1903 array(
2211 1904 'parent' => 'frm-forms',
2212 1905 'id' => 'edit_form_' . $form_id,
2213 - 'title' => empty( $name ) ? FrmFormsHelper::get_no_title_text() : $name,
1906 + 'title' => empty( $name ) ? __( '(no title)', 'formidable' ) : $name,
2214 1907 'href' => FrmForm::get_edit_link( $form_id ),
2215 1908 )
2216 1909 );
2217 1910 }
@@ -2224,10 +1917,10 @@
2224 1917 * @return string
2225 1918 */
2226 1919 public static function get_form_shortcode( $atts ) {
2227 1920 global $frm_vars;
2228 - if ( ! empty( $frm_vars['skip_shortcode'] ) ) {
2229 - $sc = '[formidable';
1921 + if ( isset( $frm_vars['skip_shortcode'] ) && $frm_vars['skip_shortcode'] ) {
1922 + $sc = '[formidable';
2230 1923 $sc .= FrmAppHelper::array_to_html_params( $atts );
2231 1924 return $sc . ']';
2232 1925 }
2233 1926
@@ -2252,11 +1945,11 @@
2252 1945
2253 1946 /**
2254 1947 * @since 5.2.01
2255 1948 *
2256 - * @param false|int|string $id
2257 - * @param false|string $key
2258 - * @return false|stdClass
1949 + * @param string|int|false $id
1950 + * @param string|false $key
1951 + * @return stdClass|false
2259 1952 */
2260 1953 private static function maybe_get_form_by_id_or_key( $id, $key ) {
2261 1954 if ( ! $id ) {
2262 1955 $id = $key;
@@ -2264,12 +1957,12 @@
2264 1957 return self::maybe_get_form_to_show( $id );
2265 1958 }
2266 1959
2267 1960 /**
2268 - * @param false|int|string $id
2269 - * @param false|string $key
2270 - * @param bool|int|string $title may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
2271 - * @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.
2272 1965 * @param array $atts
2273 1966 * @return string
2274 1967 */
2275 1968 public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) {
@@ -2317,16 +2010,15 @@
2317 2010 return $form;
2318 2011 }
2319 2012
2320 2013 /**
2321 - * @param false|int|string $id
2322 - * @return false|stdClass
2014 + * @param string|int|false $id
2015 + * @return stdClass|false
2323 2016 */
2324 2017 private static function maybe_get_form_to_show( $id ) {
2325 2018 $form = false;
2326 2019
2327 - if ( ! empty( $id ) ) {
2328 - // Form id or key is set.
2020 + if ( ! empty( $id ) ) { // form id or key is set
2329 2021 $form = FrmForm::getOne( $id );
2330 2022 if ( ! $form || $form->parent_form_id || $form->status === 'trash' ) {
2331 2023 $form = false;
2332 2024 }
@@ -2384,11 +2076,11 @@
2384 2076
2385 2077 do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description );
2386 2078
2387 2079 if ( apply_filters( 'frm_continue_to_create', true, $form->id ) ) {
2388 - $entry_id = self::just_created_entry( $form->id );
2389 - $pass_args['entry_id'] = $entry_id;
2390 - $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;
2391 2083
2392 2084 self::run_on_submit_actions( $pass_args );
2393 2085
2394 2086 do_action(
@@ -2398,9 +2090,9 @@
2398 2090 'form' => $form,
2399 2091 )
2400 2092 );
2401 2093 }
2402 - }//end if
2094 + }
2403 2095 }
2404 2096
2405 2097 /**
2406 2098 * If the form was processed earlier (init), get the generated errors
@@ -2432,9 +2124,9 @@
2432 2124 */
2433 2125 public static function just_created_entry( $form_id ) {
2434 2126 global $frm_vars;
2435 2127
2436 - 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;
2437 2129 }
2438 2130
2439 2131 /**
2440 2132 * Gets confirmation method.
@@ -2447,14 +2139,14 @@
2447 2139 *
2448 2140 * @type object $form Form object.
2449 2141 * @type int $entry_id Entry ID.
2450 2142 * }
2451 - * @return array|string
2143 + * @return string|array
2452 2144 */
2453 2145 private static function get_confirmation_method( $atts ) {
2454 2146 $action = FrmOnSubmitHelper::current_event( $atts );
2455 2147 $opt = 'update' === $action ? 'edit_action' : 'success_action';
2456 - $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';
2457 2149
2458 2150 if ( ! empty( $atts['entry_id'] ) ) {
2459 2151 $met_actions = self::get_met_on_submit_actions( $atts, $action );
2460 2152 if ( $met_actions ) {
@@ -2463,9 +2155,9 @@
2463 2155 }
2464 2156
2465 2157 $method = apply_filters( 'frm_success_filter', $method, $atts['form'], $action );
2466 2158
2467 - if ( $method !== 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
2159 + if ( $method != 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
2468 2160 $method = 'message';
2469 2161 }
2470 2162
2471 2163 return $method;
@@ -2499,9 +2191,9 @@
2499 2191 * @param array $args See {@see FrmFormsController::maybe_trigger_redirect()}.
2500 2192 */
2501 2193 public static function maybe_trigger_redirect_with_action( $conf_method, $form, $params, $args ) {
2502 2194 if ( is_array( $conf_method ) && 1 === count( $conf_method ) ) {
2503 - 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] ) ) {
2504 2196 $event = FrmOnSubmitHelper::current_event( $params );
2505 2197 FrmOnSubmitHelper::populate_on_submit_data( $form->options, $conf_method[0], $event );
2506 2198 $conf_method = 'redirect';
2507 2199 }
@@ -2550,9 +2242,9 @@
2550 2242 unset( $extra_args['form'] );
2551 2243
2552 2244 do_action( 'frm_success_action', $args['conf_method'], $args['form'], $args['form']->options, $args['entry_id'], $extra_args );
2553 2245
2554 - $opt = ! isset( $args['action'] ) || $args['action'] === 'create' ? 'success' : 'edit';
2246 + $opt = ( ! isset( $args['action'] ) || $args['action'] === 'create' ) ? 'success' : 'edit';
2555 2247
2556 2248 $args['success_opt'] = $opt;
2557 2249 $args['ajax'] = ! empty( $frm_vars['ajax'] );
2558 2250
@@ -2578,16 +2270,11 @@
2578 2270 if ( ! FrmOnSubmitHelper::form_has_migrated( $args['form'] ) ) {
2579 2271 return array();
2580 2272 }
2581 2273
2582 - // If a redirect action has already opened the URL in a new tab, we show the default message in the current tab.
2583 - if ( ! empty( self::$redirected_in_new_tab[ $args['form']->id ] ) ) {
2584 - return array( FrmOnSubmitHelper::get_fallback_action_after_open_in_new_tab( $event ) );
2585 - }
2586 -
2587 - $entry = FrmEntry::getOne( $args['entry_id'], true );
2588 - $actions = FrmOnSubmitHelper::get_actions( $args['form']->id );
2589 - $met_actions = array();
2274 + $entry = FrmEntry::getOne( $args['entry_id'], true );
2275 + $actions = FrmOnSubmitHelper::get_actions( $args['form']->id );
2276 + $met_actions = array();
2590 2277 $has_redirect = false;
2591 2278
2592 2279 foreach ( $actions as $action ) {
2593 2280 if ( ! in_array( $event, $action->post_content['event'], true ) ) {
@@ -2600,15 +2287,21 @@
2600 2287
2601 2288 $action_type = FrmOnSubmitHelper::get_action_type( $action );
2602 2289
2603 2290 if ( 'redirect' === $action_type ) {
2604 - if ( $has_redirect ) {
2605 - // 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.
2606 2292 continue;
2607 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 + );
2608 2301 }
2609 2302
2610 - if ( ! self::is_valid_on_submit_action( $action, $args, $event ) ) {
2303 + if ( ! self::is_valid_on_submit_action( $action ) ) {
2611 2304 continue;
2612 2305 }
2613 2306
2614 2307 if ( 'redirect' === $action_type ) {
@@ -2616,9 +2309,9 @@
2616 2309 }
2617 2310
2618 2311 $met_actions[] = $action;
2619 2312 unset( $action );
2620 - }//end foreach
2313 + }
2621 2314
2622 2315 $args['event'] = $event;
2623 2316
2624 2317 /**
@@ -2638,30 +2331,45 @@
2638 2331 return $met_actions;
2639 2332 }
2640 2333
2641 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 + /**
2642 2360 * Checks if a Confirmation action has the valid data.
2643 2361 *
2644 2362 * @since 6.1.2
2645 2363 *
2646 2364 * @param object $action Form action object.
2647 - * @param array $args See {@see FrmFormsController::run_success_action()}.
2648 - * @param string $event Form event. Default is `create`.
2649 2365 * @return bool
2650 2366 */
2651 - private static function is_valid_on_submit_action( $action, $args, $event = 'create' ) {
2367 + private static function is_valid_on_submit_action( $action ) {
2652 2368 $action_type = FrmOnSubmitHelper::get_action_type( $action );
2653 2369
2654 - if ( 'redirect' === $action_type ) {
2655 - // Run through frm_redirect_url filter. This is used for the valid action check.
2656 - $action->post_content['success_url'] = apply_filters(
2657 - 'frm_redirect_url',
2658 - $action->post_content['success_url'],
2659 - $args['form'],
2660 - $args + array( 'action' => $event )
2661 - );
2662 -
2663 - return ! empty( $action->post_content['success_url'] );
2370 + if ( 'redirect' === $action_type && empty( $action->post_content['success_url'] ) ) {
2371 + return false;
2664 2372 }
2665 2373
2666 2374 if ( 'page' === $action_type ) {
2667 2375 if ( empty( $action->post_content['success_page_id'] ) ) {
@@ -2807,9 +2515,9 @@
2807 2515 add_filter( 'the_content', 'FrmFormsController::preview_content', 9999 );
2808 2516 }
2809 2517
2810 2518 $post = $old_post;
2811 - }//end if
2519 + }
2812 2520 }
2813 2521
2814 2522 /**
2815 2523 * @since 3.0
@@ -2825,30 +2533,20 @@
2825 2533
2826 2534 $args['id'] = $args['entry_id'];
2827 2535 FrmEntriesController::delete_entry_before_redirect( $success_url, $args['form'], $args );
2828 2536
2829 - add_filter( 'frm_redirect_url', 'FrmEntriesController::prepare_redirect_url' );
2830 - $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 );
2831 2538
2832 2539 $doing_ajax = FrmAppHelper::doing_ajax();
2833 2540
2834 - if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) {
2835 - // Is AJAX submit and there is just one Redirect action runs.
2836 - 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 ) );
2837 2543 wp_die();
2838 2544 }
2839 2545
2840 - if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) && empty( $args['form']->options['redirect_delay'] ) ) {
2841 - // Not AJAX submit, no headers sent, and there is just one Redirect action runs.
2842 - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2843 - self::print_open_in_new_tab_js_with_fallback_handler( $success_url, $args );
2844 - self::$redirected_in_new_tab[ $args['form']->id ] = 1;
2845 - return;
2846 - }
2847 -
2546 + if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) ) { // Not AJAX submit, no headers sent, and there is just one Redirect action runs.
2848 2547 wp_redirect( esc_url_raw( $success_url ) );
2849 - // Do not use wp_die or redirect fails.
2850 - die();
2548 + die(); // do not use wp_die or redirect fails
2851 2549 }
2852 2550
2853 2551 // Redirect with a delay.
2854 2552 self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) );
@@ -2854,81 +2552,8 @@
2854 2552 self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) );
2855 2553 }
2856 2554
2857 2555 /**
2858 - * Prints open in new tab js with fallback handler.
2859 - *
2860 - * @since 6.3.1
2861 - *
2862 - * @param string $success_url Success URL.
2863 - * @param array $args See {@see FrmFormsController::redirect_after_submit()}.
2864 - */
2865 - private static function print_open_in_new_tab_js_with_fallback_handler( $success_url, $args ) {
2866 - echo '<script>var newTab = window.open("' . esc_url_raw( $success_url ) . '", "_blank");';
2867 - echo 'if ( ! newTab ) {';
2868 -
2869 - $data = array(
2870 - 'formId' => intval( $args['form']->id ),
2871 - 'message' => self::get_redirect_fallback_message( $success_url, $args ),
2872 - );
2873 - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2874 - echo 'frmShowNewTabFallback = ' . FrmAppHelper::maybe_json_encode( $data ) . ';';
2875 - echo '}</script>';
2876 - }
2877 -
2878 - /**
2879 - * Gets response data for redirect action when AJAX submitting.
2880 - *
2881 - * @since 6.3.1
2882 - *
2883 - * @param array $args See {@see FrmFormsController::run_success_action()}.
2884 - * @return array
2885 - */
2886 - private static function get_ajax_redirect_response_data( $args ) {
2887 - $response_data = array(
2888 - 'redirect' => $args['success_url'],
2889 - 'content' => '',
2890 - );
2891 - $unset_content = true;
2892 -
2893 - if ( ! empty( $args['form']->options['redirect_delay'] ) ) {
2894 - $response_data['delay'] = $args['form']->options['redirect_delay_time'];
2895 - $response_data['content'] .= self::get_redirect_message( $args['success_url'], $args['form']->options['redirect_delay_msg'], $args );
2896 - $unset_content = false;
2897 - }
2898 -
2899 - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2900 - $response_data['openInNewTab'] = 1;
2901 -
2902 - // Only show open in new tab text if there is no delay.
2903 - if ( empty( $response_data['content'] ) ) {
2904 - $args['message'] = FrmOnSubmitHelper::get_default_new_tab_msg();
2905 -
2906 - $args['form']->options['success_msg'] = $args['message'];
2907 - $args['form']->options['edit_msg'] = $args['message'];
2908 - if ( ! isset( $args['fields'] ) ) {
2909 - $args['fields'] = FrmField::get_all_for_form( $args['form']->id );
2910 - }
2911 -
2912 - $args['message'] = self::prepare_submit_message( $args['form'], $args['entry_id'], $args );
2913 -
2914 - ob_start();
2915 - self::show_lone_success_message( $args );
2916 - $response_data['content'] .= ob_get_clean();
2917 - $unset_content = false;
2918 - }//end if
2919 -
2920 - $response_data['fallbackMsg'] = self::get_redirect_fallback_message( $args['success_url'], $args );
2921 - }//end if
2922 -
2923 - if ( $unset_content && '' === $response_data['content'] ) {
2924 - unset( $response_data['content'] );
2925 - }
2926 -
2927 - return $response_data;
2928 - }
2929 -
2930 - /**
2931 2556 * Redirects after submitting using JS. This is used when showing message before redirecting.
2932 2557 *
2933 2558 * @since 6.0
2934 2559 *
@@ -2934,11 +2559,10 @@
2934 2559 *
2935 2560 * @param array $args See {@see FrmFormsController::run_success_action()}.
2936 2561 */
2937 2562 private static function redirect_after_submit_using_js( $args ) {
2938 - $success_msg = $args['form']->options['redirect_delay_msg'];
2563 + $success_msg = FrmOnSubmitHelper::get_default_redirect_msg();
2939 2564 $redirect_msg = self::get_redirect_message( $args['success_url'], $success_msg, $args );
2940 - $success_url = esc_url_raw( $args['success_url'] );
2941 2565
2942 2566 /**
2943 2567 * Filters the delay time before redirecting when On Submit Redirect action is delayed.
2944 2568 *
@@ -2943,27 +2567,20 @@
2943 2567 * Filters the delay time before redirecting when On Submit Redirect action is delayed.
2944 2568 *
2945 2569 * @since 6.0
2946 2570 *
2947 - * @param int $delay_time Delay time in milliseconds.
2571 + * @param int $delay_time Delay time in miliseconds.
2948 2572 */
2949 - $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 );
2950 2574
2951 - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2952 - $redirect_js = 'window.open("' . $success_url . '", "_blank")';
2953 - } else {
2954 - $redirect_js = 'window.location="' . $success_url . '";';
2955 - }
2956 -
2957 2575 add_filter( 'frm_use_wpautop', '__return_true' );
2958 2576
2959 2577 echo FrmAppHelper::maybe_kses( $redirect_msg ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2960 2578 echo '<script>';
2961 - if ( empty( $args['doing_ajax'] ) ) {
2962 - // Not AJAX submit, delay JS until window.load.
2579 + if ( empty( $args['doing_ajax'] ) ) { // Not AJAX submit, delay JS until window.load.
2963 2580 echo 'window.onload=function(){';
2964 2581 }
2965 - 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 ) . ');';
2966 2583 if ( empty( $args['doing_ajax'] ) ) {
2967 2584 echo '};';
2968 2585 }
2969 2586 echo '</script>';
@@ -2973,15 +2590,14 @@
2973 2590 * @since 3.0
2974 2591 *
2975 2592 * @param string $success_url
2976 2593 * @param string $success_msg
2977 - * @param array $args
2594 + * @param array $args
2978 2595 */
2979 2596 private static function get_redirect_message( $success_url, $success_msg, $args ) {
2980 - $success_msg = apply_filters( 'frm_content', $success_msg, $args['form'], $args['entry_id'] );
2981 - $success_msg = do_shortcode( FrmAppHelper::use_wpautop( $success_msg ) );
2982 2597 $redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg" role="status">' . $success_msg . '<br/>' .
2983 - 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>' ) .
2984 2600 '</div></div>';
2985 2601
2986 2602 $redirect_args = array(
2987 2603 'entry_id' => $args['entry_id'],
@@ -2992,31 +2608,8 @@
2992 2608 return apply_filters( 'frm_redirect_msg', $redirect_msg, $redirect_args );
2993 2609 }
2994 2610
2995 2611 /**
2996 - * Gets fallback message when redirecting failed.
2997 - *
2998 - * @since 6.3.1
2999 - *
3000 - * @param string $success_url Redirect URL.
3001 - * @param array $args Contains `form` object.
3002 - * @return string
3003 - */
3004 - private static function get_redirect_fallback_message( $success_url, $args ) {
3005 - $target = '';
3006 - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
3007 - $target = ' target="_blank"';
3008 - }
3009 -
3010 - return sprintf(
3011 - /* translators: %1$s: Start link HTML, %2$s: End link HTML */
3012 - __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ),
3013 - '<a href="' . esc_url( $success_url ) . '"' . $target . '>',
3014 - '</a>'
3015 - );
3016 - }
3017 -
3018 - /**
3019 2612 * Prepare to show the success message and empty form after submit
3020 2613 *
3021 2614 * @since 2.05
3022 2615 */
@@ -3035,9 +2628,9 @@
3035 2628 } else {
3036 2629 self::show_form_after_submit( $atts );
3037 2630 }
3038 2631 } else {
3039 - self::show_lone_success_message( $atts );
2632 + self::show_lone_success_messsage( $atts );
3040 2633 }
3041 2634 }
3042 2635
3043 2636 /**
@@ -3065,9 +2658,9 @@
3065 2658
3066 2659 $include_form_tag = apply_filters( 'frm_include_form_tag', true, $form );
3067 2660
3068 2661 $frm_settings = FrmAppHelper::get_settings();
3069 - $submit = $form->options['submit_value'] ?? $frm_settings->submit_value;
2662 + $submit = isset( $form->options['submit_value'] ) ? $form->options['submit_value'] : $frm_settings->submit_value;
3070 2663
3071 2664 global $frm_vars;
3072 2665 self::maybe_load_css( $form, $values['custom_style'], $frm_vars['load_css'] );
3073 2666
@@ -3076,10 +2669,11 @@
3076 2669 include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php';
3077 2670 }
3078 2671
3079 2672 /**
2673 + * @return string - 'before', 'after', or 'submit'
2674 + *
3080 2675 * @since 4.05.02
3081 - * @return string - 'before', 'after', or 'submit'
3082 2676 */
3083 2677 private static function message_placement( $form, $message ) {
3084 2678 $place = 'before';
3085 2679
@@ -3091,10 +2685,11 @@
3091 2685 }
3092 2686 }
3093 2687
3094 2688 /**
2689 + * @return string - 'before' or 'after'
2690 + *
3095 2691 * @since 4.05.02
3096 - * @return string - 'before' or 'after'
3097 2692 */
3098 2693 return apply_filters( 'frm_message_placement', $place, compact( 'form', 'message' ) );
3099 2694 }
3100 2695
@@ -3128,9 +2723,9 @@
3128 2723 * Show the success message without the form
3129 2724 *
3130 2725 * @since 2.05
3131 2726 */
3132 - private static function show_lone_success_message( $atts ) {
2727 + private static function show_lone_success_messsage( $atts ) {
3133 2728 global $frm_vars;
3134 2729 $values = FrmEntriesHelper::setup_new_vars( $atts['fields'], $atts['form'], true );
3135 2730 self::maybe_load_css( $atts['form'], $values['custom_style'], $frm_vars['load_css'] );
3136 2731
@@ -3139,9 +2734,9 @@
3139 2734 $errors = array();
3140 2735 $form = $atts['form'];
3141 2736 $message = $atts['message'];
3142 2737
3143 - include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php';
2738 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php' );
3144 2739 }
3145 2740
3146 2741 /**
3147 2742 * Prepare the success message before it's shown
@@ -3155,12 +2750,12 @@
3155 2750 * @return string
3156 2751 */
3157 2752 private static function prepare_submit_message( $form, $entry_id, $args = array() ) {
3158 2753 $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) );
3159 - $opt = $args['success_opt'] ?? 'success';
2754 + $opt = isset( $args['success_opt'] ) ? $args['success_opt'] : 'success';
3160 2755
3161 2756 if ( $entry_id && is_numeric( $entry_id ) ) {
3162 - $message = $form->options[ $opt . '_msg' ] ?? $frm_settings->success_msg;
2757 + $message = isset( $form->options[ $opt . '_msg' ] ) ? $form->options[ $opt . '_msg' ] : $frm_settings->success_msg;
3163 2758 $class = 'frm_message';
3164 2759 } else {
3165 2760 $message = $frm_settings->failed_msg;
3166 2761 $class = FrmFormsHelper::form_error_class();
@@ -3261,13 +2856,11 @@
3261 2856 global $frm_vars;
3262 2857
3263 2858 FrmStylesController::enqueue_css();
3264 2859
3265 - if ( ! FrmAppHelper::is_admin() && $location !== 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
2860 + if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
3266 2861 // load formidable js
3267 2862 wp_enqueue_script( 'formidable' );
3268 -
3269 - FrmHoneypot::maybe_print_honeypot_js();
3270 2863 }
3271 2864 }
3272 2865
3273 2866 /**
@@ -3281,12 +2874,12 @@
3281 2874 }
3282 2875
3283 2876 /**
3284 2877 * @since 2.0.8
3285 - * @return bool
2878 + * @return boolean
3286 2879 */
3287 2880 private static function is_minification_on( $atts ) {
3288 - return ! empty( $atts['minimize'] );
2881 + return isset( $atts['minimize'] ) && ! empty( $atts['minimize'] );
3289 2882 }
3290 2883
3291 2884 /**
3292 2885 * @since 5.0.16
@@ -3314,9 +2907,9 @@
3314 2907 * Create a page with an embedded formidable Gutenberg block.
3315 2908 *
3316 2909 * @since 5.2
3317 2910 *
3318 - * @return void
2911 + * @return never
3319 2912 */
3320 2913 public static function create_page_with_shortcode() {
3321 2914 if ( ! current_user_can( 'publish_posts' ) ) {
3322 2915 die( 0 );
@@ -3361,9 +2954,10 @@
3361 2954
3362 2955 /**
3363 2956 * @since 5.3
3364 2957 *
3365 - * @param int $form_id
2958 + * @param string $content
2959 + * @param int $form_id
3366 2960 * @return string
3367 2961 */
3368 2962 private static function get_page_shortcode_content_for_form( $form_id ) {
3369 2963 $shortcode = '[formidable id="' . $form_id . '"]';
@@ -3374,9 +2968,9 @@
3374 2968
3375 2969 /**
3376 2970 * Get page dropdown for AJAX request for embedding form in an existing page.
3377 2971 *
3378 - * @return void
2972 + * @return never
3379 2973 */
3380 2974 public static function get_page_dropdown() {
3381 2975 if ( ! current_user_can( 'publish_posts' ) ) {
3382 2976 die( 0 );
@@ -3384,9 +2978,9 @@
3384 2978
3385 2979 check_ajax_referer( 'frm_ajax', 'nonce' );
3386 2980
3387 2981 $html = FrmAppHelper::clip(
3388 - function () {
2982 + function() {
3389 2983 FrmAppHelper::maybe_autocomplete_pages_options(
3390 2984 array(
3391 2985 'field_name' => 'frm_page_dropdown',
3392 2986 'page_id' => '',
@@ -3406,8 +3000,15 @@
3406 3000
3407 3001 /**
3408 3002 * @deprecated 4.0
3409 3003 */
3004 + public static function new_form( $values = array() ) {
3005 + FrmDeprecated::new_form( $values );
3006 + }
3007 +
3008 + /**
3009 + * @deprecated 4.0
3010 + */
3410 3011 public static function create( $values = array() ) {
3411 3012 _deprecated_function( __METHOD__, '4.0', 'FrmFormsController::update' );
3412 3013 self::update( $values );
3413 3014 }
@@ -3412,16 +3013,35 @@
3412 3013 self::update( $values );
3413 3014 }
3414 3015
3415 3016 /**
3416 - * Education for premium features.
3417 - *
3418 - * @since 4.05
3419 - * @deprecated 6.16.3
3420 - *
3421 - * @return void
3017 + * @deprecated 3.0
3018 + * @codeCoverageIgnore
3422 3019 */
3423 - public static function add_form_style_tab_options() {
3424 - _deprecated_function( __METHOD__, '6.16.3' );
3425 - 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' );
3426 3046 }
3427 3047 }