PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.07.01
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.07.01
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
formidable / classes / controllers / FrmFormsController.php

FrmFormsController.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 4.07.01, at classes/controllers/FrmFormsController.php

2,147 lines 60.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 class FrmFormsController {
7
8 public static function menu() {
9 $menu_label = __( 'Forms', 'formidable' );
10 if ( ! FrmAppHelper::pro_is_installed() ) {
11 $menu_label .= ' (Lite)';
12 }
13 add_submenu_page( 'formidable', 'Formidable | ' . $menu_label, $menu_label, 'frm_view_forms', 'formidable', 'FrmFormsController::route' );
14
15 self::maybe_load_listing_hooks();
16 }
17
18 public static function maybe_load_listing_hooks() {
19 $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
20 if ( ! empty( $action ) && ! in_array( $action, array( 'list', 'trash', 'untrash', 'destroy' ) ) ) {
21 return;
22 }
23
24 add_filter( 'get_user_option_managetoplevel_page_formidablecolumnshidden', 'FrmFormsController::hidden_columns' );
25
26 add_filter( 'manage_toplevel_page_formidable_columns', 'FrmFormsController::get_columns', 0 );
27 add_filter( 'manage_toplevel_page_formidable_sortable_columns', 'FrmFormsController::get_sortable_columns' );
28 }
29
30 public static function head() {
31 if ( wp_is_mobile() ) {
32 wp_enqueue_script( 'jquery-touch-punch' );
33 }
34 }
35
36 public static function register_widgets() {
37 require_once( FrmAppHelper::plugin_path() . '/classes/widgets/FrmShowForm.php' );
38 register_widget( 'FrmShowForm' );
39 }
40
41 /**
42 * Show a message about conditional logic
43 *
44 * @since 4.06.03
45 */
46 public static function logic_tip() {
47 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__( 'Only show the fields you need and create branching forms. Upgrade to get conditional logic and question branching.', 'formidable' ) . esc_attr( ' <img src="https://cdn.formidableforms.com/wp-content/themes/fp2015git/images/survey/survey-logic.png" srcset="https://cdn.formidableforms.com/wp-content/themes/fp2015git/images/survey/survey-logic@2x.png 2x" alt="Conditional Logic options"/>' ) . '" data-medium="builder" data-content="logic">';
48 FrmAppHelper::icon_by_class( 'frmfont frm_swap_icon' );
49 esc_html_e( 'Add Conditional Logic', 'formidable' );
50 echo '</a>';
51 }
52
53 /**
54 * By default, Divi processes form shortcodes on the edit post page.
55 * Now that won't do.
56 *
57 * @since 3.01
58 */
59 public static function prevent_divi_conflict( $shortcodes ) {
60 $shortcodes[] = 'formidable';
61
62 return $shortcodes;
63 }
64
65 public static function list_form() {
66 FrmAppHelper::permission_check( 'frm_view_forms' );
67
68 $message = '';
69 $params = FrmForm::list_page_params();
70 $errors = self::process_bulk_form_actions( array() );
71 if ( isset( $errors['message'] ) ) {
72 $message = $errors['message'];
73 unset( $errors['message'] );
74 }
75 $errors = apply_filters( 'frm_admin_list_form_action', $errors );
76
77 return self::display_forms_list( $params, $message, $errors );
78 }
79
80 /**
81 * Choose which type of form to create
82 *
83 * @since 3.06
84 */
85 public static function add_new() {
86 self::list_templates();
87 }
88
89 /**
90 * Load the scripts before a modal can be triggered.
91 *
92 * @since 4.0
93 */
94 private static function init_modal() {
95 wp_enqueue_script( 'jquery-ui-dialog' );
96 wp_enqueue_style( 'jquery-ui-dialog' );
97 }
98
99 /**
100 * Create the default email action
101 *
102 * @since 2.02.11
103 *
104 * @param object $form
105 */
106 private static function create_default_email_action( $form ) {
107 FrmForm::maybe_get_form( $form );
108 $create_email = apply_filters( 'frm_create_default_email_action', true, $form );
109
110 if ( $create_email ) {
111 $action_control = FrmFormActionsController::get_form_actions( 'email' );
112 $action_control->create( $form->id );
113 }
114 }
115
116 public static function edit( $values = false ) {
117 FrmAppHelper::permission_check( 'frm_edit_forms' );
118
119 $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
120
121 return self::get_edit_vars( $id );
122 }
123
124 public static function settings( $id = false, $message = '' ) {
125 FrmAppHelper::permission_check( 'frm_edit_forms' );
126
127 if ( ! $id || ! is_numeric( $id ) ) {
128 $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
129 }
130
131 return self::get_settings_vars( $id, array(), $message );
132 }
133
134 public static function update_settings() {
135 FrmAppHelper::permission_check( 'frm_edit_forms' );
136
137 $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
138
139 $errors = FrmForm::validate( $_POST );
140 $warnings = FrmFormsHelper::check_for_warnings( $_POST );
141
142 if ( count( $errors ) > 0 ) {
143 return self::get_settings_vars( $id, $errors, compact( 'warnings' ) );
144 }
145
146 do_action( 'frm_before_update_form_settings', $id );
147
148 FrmForm::update( $id, $_POST );
149
150 $message = __( 'Settings Successfully Updated', 'formidable' );
151
152 return self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) );
153 }
154
155 public static function update( $values = array() ) {
156 if ( empty( $values ) ) {
157 $values = $_POST;
158 }
159
160 // Set radio button and checkbox meta equal to "other" value.
161 if ( FrmAppHelper::pro_is_installed() ) {
162 $values = FrmProEntry::mod_other_vals( $values, 'back' );
163 }
164
165 $errors = FrmForm::validate( $values );
166 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form', 'frm_save_form_nonce' );
167 if ( $permission_error !== false ) {
168 $errors['form'] = $permission_error;
169 }
170
171 $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
172
173 if ( count( $errors ) > 0 ) {
174 return self::get_edit_vars( $id, $errors );
175 } else {
176 FrmForm::update( $id, $values );
177 $message = __( 'Form was successfully updated.', 'formidable' );
178
179 if ( self::is_too_long( $values ) ) {
180 $message .= '<br/> ' . sprintf(
181 /* translators: %1$s: Start link HTML, %2$s: end link HTML */
182 __( 'However, your form is very long and may be %1$sreaching server limits%2$s.', 'formidable' ),
183 '<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">',
184 '</a>'
185 );
186 }
187
188 if ( defined( 'DOING_AJAX' ) ) {
189 wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // WPCS: XSS ok.
190 }
191
192 return self::get_edit_vars( $id, array(), $message );
193 }
194 }
195
196 /**
197 * Check if the value at the end of the form was included.
198 * If it's missing, it means other values at the end of the form
199 * were likely not saved either.
200 *
201 * @since 3.06.01
202 */
203 private static function is_too_long( $values ) {
204 return ( ! isset( $values['frm_end'] ) ) || empty( $values['frm_end'] );
205 }
206
207 /**
208 * Redirect to the url for creating from a template
209 * Also delete the current form
210 *
211 * @since 2.0
212 * @deprecated 3.06
213 */
214 public static function _create_from_template() {
215 _deprecated_function( __FUNCTION__, '3.06' );
216
217 FrmAppHelper::permission_check( 'frm_edit_forms' );
218 check_ajax_referer( 'frm_ajax', 'nonce' );
219
220 $current_form = FrmAppHelper::get_param( 'this_form', '', 'get', 'absint' );
221 $template_id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
222
223 if ( $current_form ) {
224 FrmForm::destroy( $current_form );
225 }
226
227 echo esc_url_raw( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template_id ) ) );
228 wp_die();
229 }
230
231 public static function duplicate() {
232 FrmAppHelper::permission_check( 'frm_edit_forms' );
233
234 $params = FrmForm::list_page_params();
235 $form = FrmForm::duplicate( $params['id'], $params['template'], true );
236 $message = $params['template'] ? __( 'Form template was Successfully Created', 'formidable' ) : __( 'Form was Successfully Copied', 'formidable' );
237 if ( $form ) {
238 return self::get_edit_vars( $form, array(), $message, true );
239 } else {
240 return self::display_forms_list( $params, __( 'There was a problem creating the new template.', 'formidable' ) );
241 }
242 }
243
244 public static function page_preview() {
245 $params = FrmForm::list_page_params();
246 if ( ! $params['form'] ) {
247 return;
248 }
249
250 $form = FrmForm::getOne( $params['form'] );
251 if ( $form ) {
252 return self::show_form( $form->id, '', true, true );
253 }
254 }
255
256 /**
257 * @since 3.0
258 */
259 public static function show_page_preview() {
260 echo self::page_preview(); // WPCS: XSS ok.
261 }
262
263 public static function preview() {
264 do_action( 'frm_wp' );
265
266 global $frm_vars;
267 $frm_vars['preview'] = true;
268
269 self::load_wp();
270
271 $include_theme = FrmAppHelper::get_param( 'theme', '', 'get', 'absint' );
272 if ( $include_theme ) {
273 self::set_preview_query();
274 self::load_theme_preview();
275 } else {
276 self::load_direct_preview();
277 }
278
279 wp_die();
280 }
281
282 /**
283 * @since 3.0
284 */
285 private static function load_wp() {
286 if ( ! defined( 'ABSPATH' ) && ! defined( 'XMLRPC_REQUEST' ) ) {
287 global $wp;
288 $root = dirname( dirname( dirname( dirname( __FILE__ ) ) ) );
289 include_once( $root . '/wp-config.php' );
290 $wp->init();
291 $wp->register_globals();
292 }
293 }
294
295 private static function set_preview_query() {
296 $random_page = get_posts(
297 array(
298 'numberposts' => 1,
299 'orderby' => 'date',
300 'order' => 'ASC',
301 'post_type' => 'page',
302 )
303 );
304
305 if ( ! empty( $random_page ) ) {
306 $random_page = reset( $random_page );
307 query_posts(
308 array(
309 'post_type' => 'page',
310 'page_id' => $random_page->ID,
311 )
312 );
313 }
314 }
315
316 /**
317 * @since 3.0
318 */
319 private static function load_theme_preview() {
320 add_filter( 'wp_title', 'FrmFormsController::preview_title', 9999 );
321 add_filter( 'the_title', 'FrmFormsController::preview_page_title', 9999 );
322 add_filter( 'the_content', 'FrmFormsController::preview_content', 9999 );
323 add_action( 'loop_no_results', 'FrmFormsController::show_page_preview' );
324 add_filter( 'is_active_sidebar', '__return_false' );
325 FrmStylesController::enqueue_css( 'enqueue', true );
326 get_template_part( 'page' );
327 }
328
329 /**
330 * Set the page title for the theme preview page
331 *
332 * @since 3.0
333 */
334 public static function preview_page_title( $title ) {
335 if ( in_the_loop() ) {
336 $title = self::preview_title( $title );
337 }
338
339 return $title;
340 }
341
342 /**
343 * Set the page title for the theme preview page
344 *
345 * @since 3.0
346 */
347 public static function preview_title( $title ) {
348 return __( 'Form Preview', 'formidable' );
349 }
350
351 /**
352 * Set the page content for the theme preview page
353 *
354 * @since 3.0
355 */
356 public static function preview_content( $content ) {
357 if ( in_the_loop() ) {
358 $content = self::show_page_preview();
359 }
360
361 return $content;
362 }
363
364 /**
365 * @since 3.0
366 */
367 private static function load_direct_preview() {
368 header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
369
370 $key = FrmAppHelper::simple_get( 'form', 'sanitize_title' );
371 if ( $key == '' ) {
372 $key = FrmAppHelper::get_post_param( 'form', '', 'sanitize_title' );
373 }
374
375 $form = FrmForm::getAll( array( 'form_key' => $key ), '', 1 );
376 if ( empty( $form ) ) {
377 $form = FrmForm::getAll( array(), '', 1 );
378 }
379
380 require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php' );
381 }
382
383 public static function untrash() {
384 self::change_form_status( 'untrash' );
385 }
386
387 public static function bulk_untrash( $ids ) {
388 FrmAppHelper::permission_check( 'frm_edit_forms' );
389
390 $count = FrmForm::set_status( $ids, 'published' );
391
392 /* translators: %1$s: Number of forms */
393 $message = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), 1 );
394
395 return $message;
396 }
397
398 /**
399 * @since 3.06
400 */
401 public static function ajax_trash() {
402 FrmAppHelper::permission_check( 'frm_delete_forms' );
403 check_ajax_referer( 'frm_ajax', 'nonce' );
404 $form_id = FrmAppHelper::get_param( 'id', '', 'post', 'absint' );
405 FrmForm::set_status( $form_id, 'trash' );
406 wp_die();
407 }
408
409 public static function trash() {
410 self::change_form_status( 'trash' );
411 }
412
413 /**
414 * @param string $status
415 *
416 * @return int The number of forms changed
417 */
418 public static function change_form_status( $status ) {
419 $available_status = array(
420 'untrash' => array(
421 'permission' => 'frm_edit_forms',
422 'new_status' => 'published',
423 ),
424 'trash' => array(
425 'permission' => 'frm_delete_forms',
426 'new_status' => 'trash',
427 ),
428 );
429
430 if ( ! isset( $available_status[ $status ] ) ) {
431 return;
432 }
433
434 FrmAppHelper::permission_check( $available_status[ $status ]['permission'] );
435
436 $params = FrmForm::list_page_params();
437
438 //check nonce url
439 check_admin_referer( $status . '_form_' . $params['id'] );
440
441 $count = 0;
442 if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) {
443 $count ++;
444 }
445
446 $form_type = FrmAppHelper::get_simple_request(
447 array(
448 'param' => 'form_type',
449 'type' => 'request',
450 )
451 );
452
453 /* translators: %1$s: Number of forms */
454 $available_status['untrash']['message'] = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
455
456 /* translators: %1$s: Number of forms, %2$s: Start link HTML, %3$s: End link HTML */
457 $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>' );
458
459 $message = $available_status[ $status ]['message'];
460
461 self::display_forms_list( $params, $message );
462 }
463
464 public static function bulk_trash( $ids ) {
465 FrmAppHelper::permission_check( 'frm_delete_forms' );
466
467 $count = 0;
468 foreach ( $ids as $id ) {
469 if ( FrmForm::trash( $id ) ) {
470 $count ++;
471 }
472 }
473
474 $current_page = FrmAppHelper::get_simple_request(
475 array(
476 'param' => 'form_type',
477 'type' => 'request',
478 )
479 );
480 $message = sprintf(
481 /* translators: %1$s: Number of forms, %2$s: Start link HTML, %3$s: End link HTML */
482 _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' ),
483 $count,
484 '<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=list&action=bulk_untrash&form_type=' . $current_page . '&item-action=' . implode( ',', $ids ), 'bulk-toplevel_page_formidable' ) ) . '">',
485 '</a>'
486 );
487
488 return $message;
489 }
490
491 public static function destroy() {
492 FrmAppHelper::permission_check( 'frm_delete_forms' );
493
494 $params = FrmForm::list_page_params();
495
496 // Check nonce url.
497 check_admin_referer( 'destroy_form_' . $params['id'] );
498
499 $count = 0;
500 if ( FrmForm::destroy( $params['id'] ) ) {
501 $count ++;
502 }
503
504 /* translators: %1$s: Number of forms */
505 $message = sprintf( _n( '%1$s Form Permanently Deleted', '%1$s Forms Permanently Deleted', $count, 'formidable' ), $count );
506
507 self::display_forms_list( $params, $message );
508 }
509
510 public static function bulk_destroy( $ids ) {
511 FrmAppHelper::permission_check( 'frm_delete_forms' );
512
513 $count = 0;
514 foreach ( $ids as $id ) {
515 $d = FrmForm::destroy( $id );
516 if ( $d ) {
517 $count ++;
518 }
519 }
520
521 /* translators: %1$s: Number of forms */
522 $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
523
524 return $message;
525 }
526
527 private static function delete_all() {
528 // Check nonce url.
529 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' );
530 if ( $permission_error !== false ) {
531 self::display_forms_list( array(), '', array( $permission_error ) );
532
533 return;
534 }
535
536 $count = FrmForm::scheduled_delete( time() );
537
538 /* translators: %1$s: Number of forms */
539 $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
540
541 self::display_forms_list( array(), $message );
542 }
543
544 /**
545 * Create a new form from the modal.
546 *
547 * @since 4.0
548 */
549 public static function build_new_form() {
550 global $wpdb;
551
552 FrmAppHelper::permission_check( 'frm_edit_forms' );
553 check_ajax_referer( 'frm_ajax', 'nonce' );
554
555 $new_values = self::get_modal_values();
556 $new_values['form_key'] = $new_values['name'];
557
558 $form_id = FrmForm::create( $new_values );
559
560 self::create_default_email_action( $form_id );
561
562 $response = array(
563 'redirect' => FrmForm::get_edit_link( $form_id ),
564 );
565
566 echo wp_json_encode( $response );
567 wp_die();
568 }
569
570 /**
571 * Create a custom template from a form
572 *
573 * @since 3.06
574 */
575 public static function build_template() {
576 global $wpdb;
577
578 FrmAppHelper::permission_check( 'frm_edit_forms' );
579 check_ajax_referer( 'frm_ajax', 'nonce' );
580
581 $form_id = FrmAppHelper::get_param( 'xml', '', 'post', 'absint' );
582 $new_form_id = FrmForm::duplicate( $form_id, 1, true );
583 if ( empty( $new_form_id ) ) {
584 $response = array(
585 'message' => __( 'There was an error creating a template.', 'formidable' ),
586 );
587 } else {
588 $new_values = self::get_modal_values();
589 $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $new_form_id ) );
590 if ( $query_results ) {
591 FrmForm::clear_form_cache();
592 }
593
594 $response = array(
595 'redirect' => admin_url( 'admin.php?page=formidable&frm_action=list_templates' ),
596 );
597 }
598
599 echo wp_json_encode( $response );
600 wp_die();
601 }
602
603 /**
604 * Before creating a new form, get the name and description from the modal.
605 *
606 * @since 4.0
607 */
608 private static function get_modal_values() {
609 $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' );
610 $desc = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' );
611
612 return array(
613 'name' => $name,
614 'description' => $desc,
615 );
616 }
617
618 /**
619 * Inserts Formidable button
620 * Hook exists since 2.5.0
621 *
622 * @since 2.0.15
623 */
624 public static function insert_form_button() {
625 if ( current_user_can( 'frm_view_forms' ) ) {
626 FrmAppHelper::load_admin_wide_js();
627 $menu_name = FrmAppHelper::get_menu_name();
628 $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() );
629 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' ) . '">' .
630 FrmAppHelper::kses( $icon, 'all' ) .
631 ' ' . esc_html( $menu_name ) . '</a>'; // WPCS: XSS ok.
632 }
633 }
634
635 public static function insert_form_popup() {
636 $page = basename( FrmAppHelper::get_server_value( 'PHP_SELF' ) );
637 if ( ! in_array( $page, array( 'post.php', 'page.php', 'page-new.php', 'post-new.php' ) ) ) {
638 return;
639 }
640
641 FrmAppHelper::load_admin_wide_js();
642
643 $shortcodes = array(
644 'formidable' => array(
645 'name' => __( 'Form', 'formidable' ),
646 'label' => __( 'Insert a Form', 'formidable' ),
647 ),
648 );
649
650 $shortcodes = apply_filters( 'frm_popup_shortcodes', $shortcodes );
651
652 include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/insert_form_popup.php' );
653 }
654
655 public static function get_shortcode_opts() {
656 FrmAppHelper::permission_check( 'frm_view_forms' );
657 check_ajax_referer( 'frm_ajax', 'nonce' );
658
659 $shortcode = FrmAppHelper::get_post_param( 'shortcode', '', 'sanitize_text_field' );
660 if ( empty( $shortcode ) ) {
661 wp_die();
662 }
663
664 echo '<div id="sc-opts-' . esc_attr( $shortcode ) . '" class="frm_shortcode_option">';
665 echo '<input type="radio" name="frmsc" value="' . esc_attr( $shortcode ) . '" id="sc-' . esc_attr( $shortcode ) . '" class="frm_hidden" />';
666
667 $form_id = '';
668 $opts = array();
669 switch ( $shortcode ) {
670 case 'formidable':
671 $opts = array(
672 'form_id' => 'id',
673 'title' => array(
674 'val' => 1,
675 'label' => __( 'Display form title', 'formidable' ),
676 ),
677 'description' => array(
678 'val' => 1,
679 'label' => __( 'Display form description', 'formidable' ),
680 ),
681 'minimize' => array(
682 'val' => 1,
683 'label' => __( 'Minimize form HTML', 'formidable' ),
684 ),
685 );
686 }
687 $opts = apply_filters( 'frm_sc_popup_opts', $opts, $shortcode );
688
689 if ( isset( $opts['form_id'] ) && is_string( $opts['form_id'] ) ) {
690 // allow other shortcodes to use the required form id option
691 $form_id = $opts['form_id'];
692 unset( $opts['form_id'] );
693 }
694
695 include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php' );
696
697 echo '</div>';
698
699 wp_die();
700 }
701
702 public static function display_forms_list( $params = array(), $message = '', $errors = array() ) {
703 FrmAppHelper::permission_check( 'frm_view_forms' );
704
705 global $wpdb, $frm_vars;
706
707 if ( empty( $params ) ) {
708 $params = FrmForm::list_page_params();
709 }
710
711 $wp_list_table = new FrmFormsListHelper( compact( 'params' ) );
712
713 $pagenum = $wp_list_table->get_pagenum();
714
715 $wp_list_table->prepare_items();
716
717 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
718 if ( $pagenum > $total_pages && $total_pages > 0 ) {
719 wp_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) );
720 die();
721 }
722
723 require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/list.php' );
724 }
725
726 public static function get_columns( $columns ) {
727 $columns['cb'] = '<input type="checkbox" />';
728 $columns['id'] = 'ID';
729
730 $type = FrmAppHelper::get_simple_request(
731 array(
732 'param' => 'form_type',
733 'type' => 'request',
734 'default' => 'published',
735 )
736 );
737
738 if ( 'template' == $type ) {
739 $columns['name'] = __( 'Template Name', 'formidable' );
740 $columns['type'] = __( 'Type', 'formidable' );
741 $columns['form_key'] = __( 'Key', 'formidable' );
742 } else {
743 $columns['name'] = __( 'Form Title', 'formidable' );
744 $columns['entries'] = __( 'Entries', 'formidable' );
745 $columns['form_key'] = __( 'Key', 'formidable' );
746 $columns['shortcode'] = __( 'Shortcodes', 'formidable' );
747 }
748
749 $columns['created_at'] = __( 'Date', 'formidable' );
750
751 add_screen_option(
752 'per_page',
753 array(
754 'label' => __( 'Forms', 'formidable' ),
755 'default' => 20,
756 'option' => 'formidable_page_formidable_per_page',
757 )
758 );
759
760 return $columns;
761 }
762
763 public static function get_sortable_columns() {
764 return array(
765 'id' => 'id',
766 'name' => 'name',
767 'description' => 'description',
768 'form_key' => 'form_key',
769 'created_at' => 'created_at',
770 );
771 }
772
773 public static function hidden_columns( $hidden_columns ) {
774 $type = FrmAppHelper::get_simple_request(
775 array(
776 'param' => 'form_type',
777 'type' => 'request',
778 )
779 );
780
781 if ( $type === 'template' ) {
782 $hidden_columns[] = 'id';
783 $hidden_columns[] = 'form_key';
784 }
785
786 return $hidden_columns;
787 }
788
789 public static function save_per_page( $save, $option, $value ) {
790 if ( $option == 'formidable_page_formidable_per_page' ) {
791 $save = (int) $value;
792 }
793
794 return $save;
795 }
796
797 /**
798 * Show the template listing page
799 *
800 * @since 3.06
801 */
802 private static function list_templates() {
803 self::init_modal();
804
805 $where = apply_filters( 'frm_forms_dropdown', array(), '' );
806 $forms = FrmForm::get_published_forms( $where );
807
808 $api = new FrmFormTemplateApi();
809 $templates = $api->get_api_info();
810
811 $custom_templates = array();
812 self::add_user_templates( $custom_templates );
813
814 $error = '';
815 $expired = false;
816 $license_type = '';
817 if ( isset( $templates['error'] ) ) {
818 $error = $templates['error']['message'];
819 $error = str_replace( 'utm_medium=addons', 'utm_medium=form-templates', $error );
820 $expired = ( $templates['error']['code'] === 'expired' );
821
822 $license_type = isset( $templates['error']['type'] ) ? $templates['error']['type'] : '';
823 unset( $templates['error'] );
824 }
825
826 $pricing = FrmAppHelper::admin_upgrade_link( 'form-templates' );
827
828 $categories = self::get_template_categories( $templates );
829
830 require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/list-templates.php' );
831 }
832
833 /**
834 * @since 4.03.01
835 */
836 private static function get_template_categories( $templates ) {
837 $categories = array();
838 foreach ( $templates as $template ) {
839 if ( isset( $template['categories'] ) ) {
840 $categories = array_merge( $categories, $template['categories'] );
841 }
842 }
843 $exclude_cats = FrmFormsHelper::ignore_template_categories();
844 $categories = array_unique( $categories );
845 $categories = array_diff( $categories, $exclude_cats );
846 sort( $categories );
847 return $categories;
848 }
849
850 private static function add_user_templates( &$templates ) {
851 $user_templates = array(
852 'is_template' => 1,
853 'default_template' => 0,
854 );
855 $user_templates = FrmForm::getAll( $user_templates, 'name' );
856 foreach ( $user_templates as $template ) {
857 $template = array(
858 'id' => $template->id,
859 'name' => $template->name,
860 'key' => $template->form_key,
861 'description' => $template->description,
862 'url' => admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template->id ) ),
863 'released' => $template->created_at,
864 'installed' => 1,
865 );
866 array_unshift( $templates, $template );
867 unset( $template );
868 }
869 }
870
871 private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
872 global $frm_vars;
873
874 $form = FrmForm::getOne( $id );
875 if ( ! $form ) {
876 wp_die( esc_html__( 'You are trying to edit a form that does not exist.', 'formidable' ) );
877 }
878
879 if ( $form->parent_form_id ) {
880 /* translators: %1$s: Start link HTML, %2$s: End link HTML */
881 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>' ) );
882 }
883
884 $frm_field_selection = FrmField::field_selection();
885
886 $fields = FrmField::get_all_for_form( $form->id );
887
888 // Automatically add end section fields if they don't exist (2.0 migration).
889 $reset_fields = false;
890 FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields );
891
892 if ( $reset_fields ) {
893 $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' );
894 }
895
896 unset( $end_section_values, $last_order, $open, $reset_fields );
897
898 $args = array( 'parent_form_id' => $form->id );
899 $values = FrmAppHelper::setup_edit_vars( $form, 'forms', '', true, array(), $args );
900 $values['fields'] = $fields;
901
902 $edit_message = __( 'Form was successfully updated.', 'formidable' );
903 if ( $form->is_template && $message == $edit_message ) {
904 $message = __( 'Template was successfully updated.', 'formidable' );
905 }
906
907 $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
908 $has_fields = isset( $values['fields'] ) && ! empty( $values['fields'] );
909
910 if ( defined( 'DOING_AJAX' ) ) {
911 wp_die();
912 } else {
913 require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' );
914 }
915 }
916
917 public static function get_settings_vars( $id, $errors = array(), $args = array() ) {
918 FrmAppHelper::permission_check( 'frm_edit_forms' );
919
920 global $frm_vars;
921
922 if ( ! is_array( $args ) ) {
923 // For reverse compatibility.
924 $args = array(
925 'message' => $args,
926 );
927 }
928
929 $defaults = array(
930 'message' => '',
931 'warnings' => array(),
932 );
933 $args = array_merge( $defaults, $args );
934 $message = $args['message'];
935 $warnings = $args['warnings'];
936
937 $form = FrmForm::getOne( $id );
938 $fields = FrmField::get_all_for_form( $id );
939 $values = FrmAppHelper::setup_edit_vars( $form, 'forms', $fields, true );
940
941 self::clean_submit_html( $values );
942
943 $sections = self::get_settings_tabs( $values );
944 $current = FrmAppHelper::simple_get( 't', 'sanitize_title', 'advanced_settings' );
945
946 require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php' );
947 }
948
949 /**
950 * @since 4.0
951 */
952 public static function form_publish_button( $atts ) {
953 $values = $atts['values'];
954 include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php' );
955 }
956
957 /**
958 * Get a list of all the settings tabs for the form settings page.
959 *
960 * @since 4.0
961 *
962 * @param array $values
963 * @return array
964 */
965 private static function get_settings_tabs( $values ) {
966 $sections = array(
967 'advanced' => array(
968 'name' => __( 'General', 'formidable' ),
969 'title' => __( 'General Form Settings', 'formidable' ),
970 'function' => array( __CLASS__, 'advanced_settings' ),
971 'icon' => 'frm_icon_font frm_settings_icon',
972 ),
973 'email' => array(
974 'name' => __( 'Actions & Notifications', 'formidable' ),
975 'function' => array( 'FrmFormActionsController', 'email_settings' ),
976 'id' => 'frm_notification_settings',
977 'icon' => 'frm_icon_font frm_mail_bulk_icon',
978 ),
979 'permissions' => array(
980 'name' => __( 'Form Permissions', 'formidable' ),
981 'icon' => 'frm_icon_font frm_lock_icon',
982 'html_class' => 'frm_show_upgrade frm_noallow',
983 'data' => array(
984 'medium' => 'permissions',
985 'upgrade' => __( 'Form Permissions', 'formidable' ),
986 ),
987 ),
988 'scheduling' => array(
989 'name' => __( 'Form Scheduling', 'formidable' ),
990 'icon' => 'frm_icon_font frm_calendar_icon',
991 'html_class' => 'frm_show_upgrade frm_noallow',
992 'data' => array(
993 'medium' => 'scheduling',
994 'upgrade' => __( 'Form scheduling settings', 'formidable' ),
995 ),
996 ),
997 'buttons' => array(
998 'name' => __( 'Styling & Buttons', 'formidable' ),
999 'class' => __CLASS__,
1000 'function' => 'buttons_settings',
1001 'icon' => 'frm_icon_font frm_pallet_icon',
1002 ),
1003 'html' => array(
1004 'name' => __( 'Customize HTML', 'formidable' ),
1005 'class' => __CLASS__,
1006 'function' => 'html_settings',
1007 'icon' => 'frm_icon_font frm_code_icon',
1008 ),
1009 );
1010
1011 $sections = apply_filters( 'frm_add_form_settings_section', $sections, $values );
1012
1013 if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) {
1014 // Prevent settings from showing in 2 spots.
1015 unset( $sections['permissions'], $sections['scheduling'] );
1016 }
1017
1018 foreach ( $sections as $key => $section ) {
1019 $defaults = array(
1020 'html_class' => '',
1021 'name' => ucfirst( $key ),
1022 'icon' => 'frm_icon_font frm_settings_icon',
1023 );
1024
1025 $section = array_merge( $defaults, $section );
1026
1027 if ( ! isset( $section['anchor'] ) ) {
1028 $section['anchor'] = $key;
1029 }
1030 $section['anchor'] .= '_settings';
1031
1032 if ( ! isset( $section['title'] ) ) {
1033 $section['title'] = $section['name'];
1034 }
1035
1036 if ( ! isset( $section['id'] ) ) {
1037 $section['id'] = $section['anchor'];
1038 }
1039
1040 $sections[ $key ] = $section;
1041 }
1042
1043 return $sections;
1044 }
1045
1046 /**
1047 * @since 4.0
1048 *
1049 * @param array $values
1050 */
1051 public static function advanced_settings( $values ) {
1052 $first_h3 = 'frm_first_h3';
1053
1054 include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-advanced.php' );
1055 }
1056
1057 /**
1058 * @since 4.0
1059 *
1060 * @param array $values
1061 */
1062 public static function buttons_settings( $values ) {
1063 $styles = apply_filters( 'frm_get_style_opts', array() );
1064
1065 $frm_settings = FrmAppHelper::get_settings();
1066 $no_global_style = $frm_settings->load_style === 'none';
1067
1068 include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php' );
1069 }
1070
1071 /**
1072 * @since 4.0
1073 *
1074 * @param array $values
1075 */
1076 public static function html_settings( $values ) {
1077 include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php' );
1078 }
1079
1080 /**
1081 * Replace old Submit Button href with new href to avoid errors in Chrome
1082 *
1083 * @since 2.03.08
1084 *
1085 * @param array|boolean $values
1086 */
1087 private static function clean_submit_html( &$values ) {
1088 if ( is_array( $values ) && isset( $values['submit_html'] ) ) {
1089 $values['submit_html'] = str_replace( 'javascript:void(0)', '#', $values['submit_html'] );
1090 }
1091 }
1092
1093 public static function mb_tags_box( $form_id, $class = '' ) {
1094 $fields = FrmField::get_all_for_form( $form_id, '', 'include' );
1095 $linked_forms = array();
1096 $col = 'one';
1097 $settings_tab = FrmAppHelper::is_admin_page( 'formidable' ) ? true : false;
1098
1099 $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() );
1100 $entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
1101
1102 $advanced_helpers = self::advanced_helpers( compact( 'fields', 'form_id' ) );
1103
1104 include( FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php' );
1105 }
1106
1107 /**
1108 * @since 3.04.01
1109 */
1110 private static function advanced_helpers( $atts ) {
1111 $advanced_helpers = array(
1112 'default' => array(
1113 'heading' => __( 'Customize field values with the following parameters.', 'formidable' ),
1114 'codes' => self::get_advanced_shortcodes(),
1115 ),
1116 );
1117
1118 $user_fields = self::user_shortcodes();
1119 if ( ! empty( $user_fields ) ) {
1120 $user_helpers = array();
1121 foreach ( $user_fields as $uk => $uf ) {
1122 $user_helpers[ '|user_id| show="' . $uk . '"' ] = $uf;
1123 unset( $uk, $uf );
1124 }
1125
1126 $advanced_helpers['user_id'] = array(
1127 'codes' => $user_helpers,
1128 );
1129 }
1130
1131 /**
1132 * Add extra helper shortcodes on the Advanced tab in form settings and views
1133 *
1134 * @since 3.04.01
1135 *
1136 * @param array $atts - Includes fields and form_id
1137 */
1138 return apply_filters( 'frm_advanced_helpers', $advanced_helpers, $atts );
1139 }
1140
1141 /**
1142 * Get an array of the options to display in the advanced tab
1143 * of the customization panel
1144 *
1145 * @since 2.0.6
1146 */
1147 private static function get_advanced_shortcodes() {
1148 $adv_shortcodes = array(
1149 'x sep=", "' => array(
1150 'label' => __( 'Separator', 'formidable' ),
1151 'title' => __( 'Use a different separator for checkbox fields', 'formidable' ),
1152 ),
1153 'x format="d-m-Y"' => array(
1154 'label' => __( 'Date Format', 'formidable' ),
1155 ),
1156 'x show="field_label"' => array(
1157 'label' => __( 'Field Label', 'formidable' ),
1158 ),
1159 'x wpautop=0' => array(
1160 'label' => __( 'No Auto P', 'formidable' ),
1161 'title' => __( 'Do not automatically add any paragraphs or line breaks', 'formidable' ),
1162 ),
1163 );
1164 $adv_shortcodes = apply_filters( 'frm_advanced_shortcodes', $adv_shortcodes );
1165
1166 // __( 'Leave blank instead of defaulting to User Login', 'formidable' ) : blank=1
1167
1168 return $adv_shortcodes;
1169 }
1170
1171 /**
1172 * @since 3.04.01
1173 */
1174 private static function user_shortcodes() {
1175 $options = array(
1176 'ID' => __( 'User ID', 'formidable' ),
1177 'first_name' => __( 'First Name', 'formidable' ),
1178 'last_name' => __( 'Last Name', 'formidable' ),
1179 'display_name' => __( 'Display Name', 'formidable' ),
1180 'user_login' => __( 'User Login', 'formidable' ),
1181 'user_email' => __( 'Email', 'formidable' ),
1182 'avatar' => __( 'Avatar', 'formidable' ),
1183 'author_link' => __( 'Author Link', 'formidable' ),
1184 );
1185
1186 return apply_filters( 'frm_user_shortcodes', $options );
1187 }
1188
1189 /**
1190 * Get an array of the helper shortcodes to display in the customization panel
1191 *
1192 * @since 2.0.6
1193 */
1194 private static function get_shortcode_helpers( $settings_tab ) {
1195 $entry_shortcodes = array(
1196 'id' => __( 'Entry ID', 'formidable' ),
1197 'key' => __( 'Entry Key', 'formidable' ),
1198 'post_id' => __( 'Post ID', 'formidable' ),
1199 'ip' => __( 'User IP', 'formidable' ),
1200 'created-at' => __( 'Entry created', 'formidable' ),
1201 'updated-at' => __( 'Entry updated', 'formidable' ),
1202 '' => '',
1203 'siteurl' => __( 'Site URL', 'formidable' ),
1204 'sitename' => __( 'Site Name', 'formidable' ),
1205 );
1206
1207 if ( ! FrmAppHelper::pro_is_installed() ) {
1208 unset( $entry_shortcodes['post_id'] );
1209 }
1210
1211 if ( $settings_tab ) {
1212 $entry_shortcodes['default-message'] = __( 'Default Msg', 'formidable' );
1213 $entry_shortcodes['default-html'] = __( 'Default HTML', 'formidable' );
1214 $entry_shortcodes['default-plain'] = __( 'Default Plain', 'formidable' );
1215 }
1216
1217 /**
1218 * Use this hook to add or remove buttons in the helpers section
1219 * in the customization panel
1220 *
1221 * @since 2.0.6
1222 */
1223 $entry_shortcodes = apply_filters( 'frm_helper_shortcodes', $entry_shortcodes, $settings_tab );
1224
1225 return $entry_shortcodes;
1226 }
1227
1228 /**
1229 * Insert the form class setting into the form
1230 */
1231 public static function form_classes( $form ) {
1232 if ( isset( $form->options['form_class'] ) ) {
1233 echo esc_attr( sanitize_text_field( $form->options['form_class'] ) );
1234 }
1235
1236 if ( isset( $form->options['js_validate'] ) && $form->options['js_validate'] ) {
1237 echo ' frm_js_validate ';
1238 }
1239 }
1240
1241 public static function get_email_html() {
1242 FrmAppHelper::permission_check( 'frm_view_forms' );
1243 check_ajax_referer( 'frm_ajax', 'nonce' );
1244
1245 echo FrmEntriesController::show_entry_shortcode( // WPCS: XSS ok.
1246 array(
1247 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ),
1248 'default_email' => true,
1249 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ),
1250 )
1251 );
1252 wp_die();
1253 }
1254
1255 public static function filter_content( $content, $form, $entry = false ) {
1256 self::get_entry_by_param( $entry );
1257 if ( ! $entry ) {
1258 return $content;
1259 }
1260
1261 if ( is_object( $form ) ) {
1262 $form = $form->id;
1263 }
1264
1265 $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form );
1266 $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
1267
1268 return $content;
1269 }
1270
1271 private static function get_entry_by_param( &$entry ) {
1272 if ( ! $entry || ! is_object( $entry ) ) {
1273 if ( ! $entry || ! is_numeric( $entry ) ) {
1274 $entry = FrmAppHelper::get_post_param( 'id', false, 'sanitize_title' );
1275 }
1276
1277 FrmEntry::maybe_get_entry( $entry );
1278 }
1279 }
1280
1281 public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
1282 return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes );
1283 }
1284
1285 public static function process_bulk_form_actions( $errors ) {
1286 if ( ! $_REQUEST ) {
1287 return $errors;
1288 }
1289
1290 $bulkaction = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
1291 if ( $bulkaction == - 1 ) {
1292 $bulkaction = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
1293 }
1294
1295 if ( ! empty( $bulkaction ) && strpos( $bulkaction, 'bulk_' ) === 0 ) {
1296 FrmAppHelper::remove_get_action();
1297
1298 $bulkaction = str_replace( 'bulk_', '', $bulkaction );
1299 }
1300
1301 $ids = FrmAppHelper::get_param( 'item-action', '', 'get', 'sanitize_text_field' );
1302 if ( empty( $ids ) ) {
1303 $errors[] = __( 'No forms were specified', 'formidable' );
1304
1305 return $errors;
1306 }
1307
1308 $permission_error = FrmAppHelper::permission_nonce_error( '', '_wpnonce', 'bulk-toplevel_page_formidable' );
1309 if ( $permission_error !== false ) {
1310 $errors[] = $permission_error;
1311
1312 return $errors;
1313 }
1314
1315 if ( ! is_array( $ids ) ) {
1316 $ids = explode( ',', $ids );
1317 }
1318
1319 switch ( $bulkaction ) {
1320 case 'delete':
1321 $message = self::bulk_destroy( $ids );
1322 break;
1323 case 'trash':
1324 $message = self::bulk_trash( $ids );
1325 break;
1326 case 'untrash':
1327 $message = self::bulk_untrash( $ids );
1328 }
1329
1330 if ( isset( $message ) && ! empty( $message ) ) {
1331 $errors['message'] = $message;
1332 }
1333
1334 return $errors;
1335 }
1336
1337 public static function route() {
1338 $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
1339 $vars = array();
1340 FrmAppHelper::include_svg();
1341
1342 if ( isset( $_POST['frm_compact_fields'] ) ) {
1343 FrmAppHelper::permission_check( 'frm_edit_forms' );
1344
1345 // Javascript needs to be allowed in some field settings.
1346 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1347 $json_vars = htmlspecialchars_decode( nl2br( str_replace( '&quot;', '"', wp_unslash( $_POST['frm_compact_fields'] ) ) ) );
1348 $json_vars = json_decode( $json_vars, true );
1349 if ( empty( $json_vars ) ) {
1350 // json decoding failed so we should return an error message.
1351 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
1352 if ( 'edit' == $action ) {
1353 $action = 'update';
1354 }
1355
1356 add_filter( 'frm_validate_form', 'FrmFormsController::json_error' );
1357 } else {
1358 $vars = FrmAppHelper::json_to_array( $json_vars );
1359 $action = $vars[ $action ];
1360 unset( $_REQUEST['frm_compact_fields'], $_POST['frm_compact_fields'] );
1361 $_REQUEST = array_merge( $_REQUEST, $vars );
1362 $_POST = array_merge( $_POST, $_REQUEST );
1363 }
1364 } else {
1365 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
1366 if ( isset( $_REQUEST['delete_all'] ) ) {
1367 // Override the action for this page.
1368 $action = 'delete_all';
1369 }
1370 }
1371
1372 add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
1373 FrmAppHelper::trigger_hook_load( 'form' );
1374
1375 switch ( $action ) {
1376 case 'new':
1377 return self::new_form( $vars );
1378 case 'add_new':
1379 case 'list_templates':
1380 return self::list_templates();
1381 case 'create':
1382 case 'edit':
1383 case 'update':
1384 case 'duplicate':
1385 case 'trash':
1386 case 'untrash':
1387 case 'destroy':
1388 case 'delete_all':
1389 case 'settings':
1390 case 'update_settings':
1391 return self::$action( $vars );
1392 case 'lite-reports':
1393 return self::no_reports( $vars );
1394 case 'views':
1395 return self::no_views( $vars );
1396 default:
1397 do_action( 'frm_form_action_' . $action );
1398 if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) {
1399 return;
1400 }
1401
1402 $action = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
1403 if ( $action == - 1 ) {
1404 $action = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
1405 }
1406
1407 if ( strpos( $action, 'bulk_' ) === 0 ) {
1408 FrmAppHelper::remove_get_action();
1409
1410 return self::list_form();
1411 }
1412
1413 return self::display_forms_list();
1414 }
1415 }
1416
1417 public static function json_error( $errors ) {
1418 $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
1419
1420 return $errors;
1421 }
1422
1423 /**
1424 * Education for premium features.
1425 *
1426 * @since 4.05
1427 */
1428 public static function add_form_style_tab_options() {
1429 include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php' );
1430 }
1431
1432 /**
1433 * Add education about views.
1434 *
1435 * @since 4.07
1436 */
1437 public static function no_views( $values = array() ) {
1438 FrmAppHelper::include_svg();
1439 $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
1440 $form = $id ? FrmForm::getOne( $id ) : false;
1441
1442 include FrmAppHelper::plugin_path() . '/classes/views/shared/views-info.php';
1443 }
1444
1445 /**
1446 * Add education about reports.
1447 *
1448 * @since 4.07
1449 */
1450 public static function no_reports( $values = array() ) {
1451 $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
1452 $form = $id ? FrmForm::getOne( $id ) : false;
1453
1454 include FrmAppHelper::plugin_path() . '/classes/views/shared/reports-info.php';
1455 }
1456
1457 /* FRONT-END FORMS */
1458 public static function admin_bar_css() {
1459 if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
1460 return;
1461 }
1462
1463 self::move_menu_to_footer();
1464
1465 add_action( 'wp_before_admin_bar_render', 'FrmFormsController::admin_bar_configure' );
1466 FrmAppHelper::load_font_style();
1467 }
1468
1469 /**
1470 * @since 4.05.02
1471 */
1472 private static function move_menu_to_footer() {
1473 $settings = FrmAppHelper::get_settings();
1474 if ( empty( $settings->admin_bar ) ) {
1475 remove_action( 'wp_body_open', 'wp_admin_bar_render', 0 );
1476 }
1477 }
1478
1479 public static function admin_bar_configure() {
1480 global $frm_vars;
1481 if ( empty( $frm_vars['forms_loaded'] ) ) {
1482 return;
1483 }
1484
1485 $actions = array();
1486 foreach ( $frm_vars['forms_loaded'] as $form ) {
1487 if ( is_object( $form ) ) {
1488 $actions[ $form->id ] = $form->name;
1489 }
1490 unset( $form );
1491 }
1492
1493 if ( empty( $actions ) ) {
1494 return;
1495 }
1496
1497 self::add_menu_to_admin_bar();
1498 self::add_forms_to_admin_bar( $actions );
1499 }
1500
1501 /**
1502 * @since 2.05.07
1503 */
1504 public static function add_menu_to_admin_bar() {
1505 global $wp_admin_bar;
1506
1507 $wp_admin_bar->add_node(
1508 array(
1509 'id' => 'frm-forms',
1510 'title' => '<span class="ab-icon"></span><span class="ab-label">' . FrmAppHelper::get_menu_name() . '</span>',
1511 'href' => admin_url( 'admin.php?page=formidable' ),
1512 'meta' => array(
1513 'title' => FrmAppHelper::get_menu_name(),
1514 ),
1515 )
1516 );
1517 }
1518
1519 /**
1520 * @since 2.05.07
1521 */
1522 private static function add_forms_to_admin_bar( $actions ) {
1523 global $wp_admin_bar;
1524
1525 asort( $actions );
1526
1527 foreach ( $actions as $form_id => $name ) {
1528
1529 $wp_admin_bar->add_node(
1530 array(
1531 'parent' => 'frm-forms',
1532 'id' => 'edit_form_' . $form_id,
1533 'title' => empty( $name ) ? __( '(no title)', 'formidable' ) : $name,
1534 'href' => FrmForm::get_edit_link( $form_id ),
1535 )
1536 );
1537 }
1538 }
1539
1540 /**
1541 * The formidable shortcode
1542 *
1543 * @param array $atts The params from the shortcode.
1544 */
1545 public static function get_form_shortcode( $atts ) {
1546 global $frm_vars;
1547 if ( isset( $frm_vars['skip_shortcode'] ) && $frm_vars['skip_shortcode'] ) {
1548 $sc = '[formidable';
1549 $sc .= FrmAppHelper::array_to_html_params( $atts );
1550 return $sc . ']';
1551 }
1552
1553 $shortcode_atts = shortcode_atts(
1554 array(
1555 'id' => '',
1556 'key' => '',
1557 'title' => false,
1558 'description' => false,
1559 'readonly' => false,
1560 'entry_id' => false,
1561 'fields' => array(),
1562 'exclude_fields' => array(),
1563 'minimize' => false,
1564 ),
1565 $atts
1566 );
1567 do_action( 'formidable_shortcode_atts', $shortcode_atts, $atts );
1568
1569 return self::show_form( $shortcode_atts['id'], $shortcode_atts['key'], $shortcode_atts['title'], $shortcode_atts['description'], $atts );
1570 }
1571
1572 public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) {
1573 if ( empty( $id ) ) {
1574 $id = $key;
1575 }
1576
1577 $form = self::maybe_get_form_to_show( $id );
1578 if ( ! $form ) {
1579 return __( 'Please select a valid form', 'formidable' );
1580 }
1581
1582 FrmAppController::maybe_update_styles();
1583
1584 add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
1585 FrmAppHelper::trigger_hook_load( 'form', $form );
1586
1587 $form = apply_filters( 'frm_pre_display_form', $form );
1588
1589 $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) );
1590
1591 if ( self::is_viewable_draft_form( $form ) ) {
1592 // don't show a draft form on a page
1593 $form = __( 'Please select a valid form', 'formidable' );
1594 } elseif ( ! FrmForm::is_visible_to_user( $form ) ) {
1595 $form = do_shortcode( $frm_settings->login_msg );
1596 } else {
1597 do_action( 'frm_pre_get_form', $form );
1598 $form = self::get_form( $form, $title, $description, $atts );
1599
1600 /**
1601 * Use this shortcode to check for external shortcodes that may span
1602 * across multiple fields in the customizable HTML
1603 *
1604 * @since 2.0.8
1605 */
1606 $form = apply_filters( 'frm_filter_final_form', $form );
1607 }
1608
1609 return $form;
1610 }
1611
1612 private static function maybe_get_form_to_show( $id ) {
1613 $form = false;
1614
1615 if ( ! empty( $id ) ) { // no form id or key set
1616 $form = FrmForm::getOne( $id );
1617 if ( ! $form || $form->parent_form_id || $form->status == 'trash' ) {
1618 $form = false;
1619 }
1620 }
1621
1622 return $form;
1623 }
1624
1625 private static function is_viewable_draft_form( $form ) {
1626 return $form->status == 'draft' && current_user_can( 'frm_edit_forms' ) && ! FrmAppHelper::is_preview_page();
1627 }
1628
1629 public static function get_form( $form, $title, $description, $atts = array() ) {
1630 ob_start();
1631
1632 do_action( 'frm_before_get_form', $atts );
1633
1634 self::get_form_contents( $form, $title, $description, $atts );
1635 self::enqueue_scripts( FrmForm::get_params( $form ) );
1636
1637 $contents = ob_get_contents();
1638 ob_end_clean();
1639
1640 self::maybe_minimize_form( $atts, $contents );
1641
1642 return $contents;
1643 }
1644
1645 public static function enqueue_scripts( $params ) {
1646 do_action( 'frm_enqueue_form_scripts', $params );
1647 }
1648
1649 public static function get_form_contents( $form, $title, $description, $atts ) {
1650 $params = FrmForm::get_params( $form );
1651 $errors = self::get_saved_errors( $form, $params );
1652 $fields = FrmFieldsHelper::get_form_fields( $form->id, $errors );
1653 $reset = false;
1654 $pass_args = compact( 'form', 'fields', 'errors', 'title', 'description', 'reset' );
1655
1656 $handle_process_here = $params['action'] == 'create' && $params['posted_form_id'] == $form->id && $_POST;
1657
1658 if ( ! $handle_process_here ) {
1659 do_action( 'frm_display_form_action', $params, $fields, $form, $title, $description );
1660 if ( apply_filters( 'frm_continue_to_new', true, $form->id, $params['action'] ) ) {
1661 self::show_form_after_submit( $pass_args );
1662 }
1663 } elseif ( ! empty( $errors ) ) {
1664 self::show_form_after_submit( $pass_args );
1665
1666 } else {
1667
1668 do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description );
1669
1670 if ( apply_filters( 'frm_continue_to_create', true, $form->id ) ) {
1671 $entry_id = self::just_created_entry( $form->id );
1672 $pass_args['entry_id'] = $entry_id;
1673 $pass_args['reset'] = true;
1674 $pass_args['conf_method'] = self::get_confirmation_method( compact( 'form', 'entry_id' ) );
1675
1676 self::run_success_action( $pass_args );
1677
1678 do_action(
1679 'frm_after_entry_processed',
1680 array(
1681 'entry_id' => $entry_id,
1682 'form' => $form,
1683 )
1684 );
1685 }
1686 }
1687 }
1688
1689 /**
1690 * If the form was processed earlier (init), get the generated errors
1691 *
1692 * @since 2.05
1693 */
1694 private static function get_saved_errors( $form, $params ) {
1695 global $frm_vars;
1696
1697 if ( $params['posted_form_id'] == $form->id && $_POST && isset( $frm_vars['created_entries'][ $form->id ] ) ) {
1698 $errors = $frm_vars['created_entries'][ $form->id ]['errors'];
1699 } else {
1700 $errors = array();
1701 }
1702
1703 return $errors;
1704 }
1705
1706 /**
1707 * @since 2.2.7
1708 */
1709 public static function just_created_entry( $form_id ) {
1710 global $frm_vars;
1711
1712 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;
1713 }
1714
1715 /**
1716 * @since 3.0
1717 */
1718 private static function get_confirmation_method( $atts ) {
1719 $opt = 'success_action';
1720 $method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message';
1721 $method = apply_filters( 'frm_success_filter', $method, $atts['form'], 'create' );
1722
1723 if ( $method != 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
1724 $method = 'message';
1725 }
1726
1727 return $method;
1728 }
1729
1730 public static function maybe_trigger_redirect( $form, $params, $args ) {
1731 if ( ! isset( $params['id'] ) ) {
1732 global $frm_vars;
1733 $params['id'] = $frm_vars['created_entries'][ $form->id ]['entry_id'];
1734 }
1735
1736 $conf_method = self::get_confirmation_method(
1737 array(
1738 'form' => $form,
1739 'entry_id' => $params['id'],
1740 )
1741 );
1742
1743 if ( 'redirect' === $conf_method ) {
1744 self::trigger_redirect( $form, $params, $args );
1745 }
1746 }
1747
1748 public static function trigger_redirect( $form, $params, $args ) {
1749 $success_args = array(
1750 'action' => $params['action'],
1751 'conf_method' => 'redirect',
1752 'form' => $form,
1753 'entry_id' => $params['id'],
1754 );
1755
1756 if ( isset( $args['ajax'] ) ) {
1757 $success_args['ajax'] = $args['ajax'];
1758 }
1759
1760 self::run_success_action( $success_args );
1761 }
1762
1763 /**
1764 * Used when the success action is not 'message'
1765 *
1766 * @since 2.05
1767 */
1768 public static function run_success_action( $args ) {
1769 $extra_args = $args;
1770 unset( $extra_args['form'] );
1771
1772 do_action( 'frm_success_action', $args['conf_method'], $args['form'], $args['form']->options, $args['entry_id'], $extra_args );
1773
1774 $opt = ( ! isset( $args['action'] ) || $args['action'] == 'create' ) ? 'success' : 'edit';
1775
1776 $args['success_opt'] = $opt;
1777 if ( $args['conf_method'] == 'page' && is_numeric( $args['form']->options[ $opt . '_page_id' ] ) ) {
1778 self::load_page_after_submit( $args );
1779 } elseif ( $args['conf_method'] == 'redirect' ) {
1780 self::redirect_after_submit( $args );
1781 } else {
1782 self::show_message_after_save( $args );
1783 }
1784 }
1785
1786 /**
1787 * @since 3.0
1788 */
1789 private static function load_page_after_submit( $args ) {
1790 global $post;
1791 $opt = $args['success_opt'];
1792 if ( ! $post || $args['form']->options[ $opt . '_page_id' ] != $post->ID ) {
1793 $page = get_post( $args['form']->options[ $opt . '_page_id' ] );
1794 $old_post = $post;
1795 $post = $page;
1796 $content = apply_filters( 'frm_content', $page->post_content, $args['form'], $args['entry_id'] );
1797 echo apply_filters( 'the_content', $content ); // WPCS: XSS ok.
1798 $post = $old_post;
1799 }
1800 }
1801
1802 /**
1803 * @since 3.0
1804 */
1805 private static function redirect_after_submit( $args ) {
1806 global $frm_vars;
1807
1808 add_filter( 'frm_use_wpautop', '__return_false' );
1809
1810 $opt = $args['success_opt'];
1811 $success_url = trim( $args['form']->options[ $opt . '_url' ] );
1812 $success_url = apply_filters( 'frm_content', $success_url, $args['form'], $args['entry_id'] );
1813 $success_url = do_shortcode( $success_url );
1814
1815 $success_msg = isset( $args['form']->options[ $opt . '_msg' ] ) ? $args['form']->options[ $opt . '_msg' ] : __( 'Please wait while you are redirected.', 'formidable' );
1816
1817 $redirect_msg = self::get_redirect_message( $success_url, $success_msg, $args );
1818
1819 $args['id'] = $args['entry_id'];
1820 FrmEntriesController::delete_entry_before_redirect( $success_url, $args['form'], $args );
1821
1822 add_filter( 'frm_redirect_url', 'FrmEntriesController::prepare_redirect_url' );
1823 $success_url = apply_filters( 'frm_redirect_url', $success_url, $args['form'], $args );
1824
1825 $doing_ajax = FrmAppHelper::doing_ajax();
1826
1827 if ( isset( $args['ajax'] ) && $args['ajax'] && $doing_ajax ) {
1828 echo json_encode( array( 'redirect' => $success_url ) );
1829 wp_die();
1830 } elseif ( ! headers_sent() ) {
1831 wp_redirect( esc_url_raw( $success_url ) );
1832 die(); // do not use wp_die or redirect fails
1833 } else {
1834 add_filter( 'frm_use_wpautop', '__return_true' );
1835
1836 echo $redirect_msg; // WPCS: XSS ok.
1837 echo "<script type='text/javascript'>window.onload = function(){setTimeout(window.location='" . esc_url_raw( $success_url ) . "', 8000);}</script>";
1838 }
1839 }
1840
1841 /**
1842 * @since 3.0
1843 *
1844 * @param string $success_url
1845 * @param string $success_msg
1846 * @param array $args
1847 */
1848 private static function get_redirect_message( $success_url, $success_msg, $args ) {
1849 $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/>' .
1850 /* translators: %1$s: Start link HTML, %2$s: End link HTML */
1851 sprintf( __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ), '<a href="' . esc_url( $success_url ) . '">', '</a>' ) .
1852 '</div></div>';
1853
1854 $redirect_args = array(
1855 'entry_id' => $args['entry_id'],
1856 'form_id' => $args['form']->id,
1857 'form' => $args['form'],
1858 );
1859
1860 return apply_filters( 'frm_redirect_msg', $redirect_msg, $redirect_args );
1861 }
1862
1863 /**
1864 * Prepare to show the success message and empty form after submit
1865 *
1866 * @since 2.05
1867 */
1868 public static function show_message_after_save( $atts ) {
1869 $atts['message'] = self::prepare_submit_message( $atts['form'], $atts['entry_id'] );
1870
1871 if ( ! isset( $atts['form']->options['show_form'] ) || $atts['form']->options['show_form'] ) {
1872 self::show_form_after_submit( $atts );
1873 } else {
1874 self::show_lone_success_messsage( $atts );
1875 }
1876 }
1877
1878 /**
1879 * Show an empty form
1880 *
1881 * @since 2.05
1882 */
1883 private static function show_form_after_submit( $args ) {
1884 self::fill_atts_for_form_display( $args );
1885
1886 $errors = $args['errors'];
1887 $message = $args['message'];
1888 $form = $args['form'];
1889 $title = $args['title'];
1890 $description = $args['description'];
1891
1892 if ( empty( $args['fields'] ) ) {
1893 $values = array();
1894 } else {
1895 $values = FrmEntriesHelper::setup_new_vars( $args['fields'], $form, $args['reset'] );
1896 }
1897 unset( $args );
1898
1899 $include_form_tag = apply_filters( 'frm_include_form_tag', true, $form );
1900
1901 $frm_settings = FrmAppHelper::get_settings();
1902 $submit = isset( $form->options['submit_value'] ) ? $form->options['submit_value'] : $frm_settings->submit_value;
1903
1904 global $frm_vars;
1905 self::maybe_load_css( $form, $values['custom_style'], $frm_vars['load_css'] );
1906
1907 $message_placement = self::message_placement( $form, $message );
1908
1909 include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php' );
1910 }
1911
1912 /**
1913 * @return string - 'before', 'after', or 'submit'
1914 *
1915 * @since 4.05.02
1916 */
1917 private static function message_placement( $form, $message ) {
1918 $place = 'before';
1919
1920 if ( $message && isset( $form->options['form_class'] ) ) {
1921 if ( strpos( $form->options['form_class'], 'frm_below_success' ) !== false ) {
1922 $place = 'after';
1923 } elseif ( strpos( $form->options['form_class'], 'frm_inline_success' ) !== false ) {
1924 $place = 'submit';
1925 }
1926 }
1927
1928 /**
1929 * @return string - 'before' or 'after'
1930 *
1931 * @since 4.05.02
1932 */
1933 return apply_filters( 'frm_message_placement', $place, compact( 'form', 'message' ) );
1934 }
1935
1936 /**
1937 * Get all the values needed on the new.php entry page
1938 *
1939 * @since 2.05
1940 */
1941 private static function fill_atts_for_form_display( &$args ) {
1942 $defaults = array(
1943 'errors' => array(),
1944 'message' => '',
1945 'fields' => array(),
1946 'form' => array(),
1947 'title' => true,
1948 'description' => false,
1949 'reset' => false,
1950 );
1951 $args = wp_parse_args( $args, $defaults );
1952 }
1953
1954 /**
1955 * Show the success message without the form
1956 *
1957 * @since 2.05
1958 */
1959 private static function show_lone_success_messsage( $atts ) {
1960 global $frm_vars;
1961 $values = FrmEntriesHelper::setup_new_vars( $atts['fields'], $atts['form'], true );
1962 self::maybe_load_css( $atts['form'], $values['custom_style'], $frm_vars['load_css'] );
1963
1964 $include_extra_container = 'frm_forms' . FrmFormsHelper::get_form_style_class( $values );
1965
1966 $errors = array();
1967 $form = $atts['form'];
1968 $message = $atts['message'];
1969
1970 include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php' );
1971 }
1972
1973 /**
1974 * Prepare the success message before it's shown
1975 *
1976 * @since 2.05
1977 */
1978 private static function prepare_submit_message( $form, $entry_id ) {
1979 $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) );
1980
1981 if ( $entry_id && is_numeric( $entry_id ) ) {
1982 $message = isset( $form->options['success_msg'] ) ? $form->options['success_msg'] : $frm_settings->success_msg;
1983 $class = 'frm_message';
1984 } else {
1985 $message = $frm_settings->failed_msg;
1986 $class = FrmFormsHelper::form_error_class();
1987 }
1988
1989 $message = FrmFormsHelper::get_success_message( compact( 'message', 'form', 'entry_id', 'class' ) );
1990
1991 return apply_filters( 'frm_main_feedback', $message, $form, $entry_id );
1992 }
1993
1994 public static function front_head() {
1995 $version = FrmAppHelper::plugin_version();
1996 $suffix = FrmAppHelper::js_suffix();
1997
1998 if ( ! empty( $suffix ) && self::has_combo_js_file() ) {
1999 wp_register_script( 'formidable', FrmAppHelper::plugin_url() . '/js/frm.min.js', array( 'jquery' ), $version, true );
2000 } else {
2001 wp_register_script( 'formidable', FrmAppHelper::plugin_url() . "/js/formidable{$suffix}.js", array( 'jquery' ), $version, true );
2002 }
2003
2004 add_filter( 'script_loader_tag', 'FrmFormsController::defer_script_loading', 10, 2 );
2005
2006 if ( FrmAppHelper::is_admin() ) {
2007 // don't load this in back-end
2008 return;
2009 }
2010
2011 FrmAppHelper::localize_script( 'front' );
2012 FrmStylesController::enqueue_css( 'register' );
2013 }
2014
2015 /**
2016 * @since 3.0
2017 */
2018 public static function has_combo_js_file() {
2019 return is_readable( FrmAppHelper::plugin_path() . '/js/frm.min.js' );
2020 }
2021
2022 public static function maybe_load_css( $form, $this_load, $global_load ) {
2023 $load_css = FrmForm::is_form_loaded( $form, $this_load, $global_load );
2024
2025 if ( ! $load_css ) {
2026 return;
2027 }
2028
2029 global $frm_vars;
2030 self::footer_js( 'header' );
2031 $frm_vars['css_loaded'] = true;
2032
2033 self::load_late_css();
2034 }
2035
2036 /**
2037 * If css is loaded only on applicable pages, include it before the form loads
2038 * to prevent a flash of unstyled form.
2039 *
2040 * @since 4.01
2041 */
2042 private static function load_late_css() {
2043 $frm_settings = FrmAppHelper::get_settings();
2044 $late_css = $frm_settings->load_style === 'dynamic';
2045 if ( ! $late_css ) {
2046 return;
2047 }
2048
2049 global $wp_styles;
2050 if ( is_array( $wp_styles->queue ) && in_array( 'formidable', $wp_styles->queue ) ) {
2051 wp_print_styles( 'formidable' );
2052 }
2053 }
2054
2055 public static function defer_script_loading( $tag, $handle ) {
2056 if ( 'recaptcha-api' == $handle && ! strpos( $tag, 'defer' ) ) {
2057 $tag = str_replace( ' src', ' defer="defer" async="async" src', $tag );
2058 }
2059
2060 return $tag;
2061 }
2062
2063 public static function footer_js( $location = 'footer' ) {
2064 global $frm_vars;
2065
2066 FrmStylesController::enqueue_css();
2067
2068 if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
2069 // load formidable js
2070 wp_enqueue_script( 'formidable' );
2071 }
2072 }
2073
2074 /**
2075 * @since 2.0.8
2076 */
2077 private static function maybe_minimize_form( $atts, &$content ) {
2078 // check if minimizing is turned on
2079 if ( self::is_minification_on( $atts ) ) {
2080 $content = str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', $content );
2081 }
2082 }
2083
2084 /**
2085 * @since 2.0.8
2086 * @return boolean
2087 */
2088 private static function is_minification_on( $atts ) {
2089 return isset( $atts['minimize'] ) && ! empty( $atts['minimize'] );
2090 }
2091
2092 /**
2093 * @deprecated 4.0
2094 */
2095 public static function new_form( $values = array() ) {
2096 FrmDeprecated::new_form( $values );
2097 }
2098
2099 /**
2100 * @deprecated 4.0
2101 */
2102 public static function create( $values = array() ) {
2103 _deprecated_function( __METHOD__, '4.0', 'FrmFormsController::update' );
2104 self::update( $values );
2105 }
2106
2107 /**
2108 * @deprecated 1.07.05
2109 * @codeCoverageIgnore
2110 */
2111 public static function add_default_templates( $path, $default = true, $template = true ) {
2112 FrmDeprecated::add_default_templates( $path, $default, $template );
2113 }
2114
2115 /**
2116 * @deprecated 3.0
2117 * @codeCoverageIgnore
2118 */
2119 public static function bulk_create_template( $ids ) {
2120 return FrmDeprecated::bulk_create_template( $ids );
2121 }
2122
2123 /**
2124 * @deprecated 2.03
2125 * @codeCoverageIgnore
2126 */
2127 public static function register_pro_scripts() {
2128 FrmDeprecated::register_pro_scripts();
2129 }
2130
2131 /**
2132 * @deprecated 3.0
2133 * @codeCoverageIgnore
2134 */
2135 public static function edit_key() {
2136 FrmDeprecated::edit_key();
2137 }
2138
2139 /**
2140 * @deprecated 3.0
2141 * @codeCoverageIgnore
2142 */
2143 public static function edit_description() {
2144 FrmDeprecated::edit_description();
2145 }
2146 }
2147