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