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

2,148 lines 61.1 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 'message' => __( 'Allow editing, protect forms and files, limit entries, and save drafts. Upgrade to get form and entry permissions.', 'formidable' ),
987 ),
988 ),
989 'scheduling' => array(
990 'name' => __( 'Form Scheduling', 'formidable' ),
991 'icon' => 'frm_icon_font frm_calendar_icon',
992 'html_class' => 'frm_show_upgrade frm_noallow',
993 'data' => array(
994 'medium' => 'scheduling',
995 'upgrade' => __( 'Form scheduling settings', 'formidable' ),
996 ),
997 ),
998 'buttons' => array(
999 'name' => __( 'Styling & Buttons', 'formidable' ),
1000 'class' => __CLASS__,
1001 'function' => 'buttons_settings',
1002 'icon' => 'frm_icon_font frm_pallet_icon',
1003 ),
1004 'html' => array(
1005 'name' => __( 'Customize HTML', 'formidable' ),
1006 'class' => __CLASS__,
1007 'function' => 'html_settings',
1008 'icon' => 'frm_icon_font frm_code_icon',
1009 ),
1010 );
1011
1012 $sections = apply_filters( 'frm_add_form_settings_section', $sections, $values );
1013
1014 if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) {
1015 // Prevent settings from showing in 2 spots.
1016 unset( $sections['permissions'], $sections['scheduling'] );
1017 }
1018
1019 foreach ( $sections as $key => $section ) {
1020 $defaults = array(
1021 'html_class' => '',
1022 'name' => ucfirst( $key ),
1023 'icon' => 'frm_icon_font frm_settings_icon',
1024 );
1025
1026 $section = array_merge( $defaults, $section );
1027
1028 if ( ! isset( $section['anchor'] ) ) {
1029 $section['anchor'] = $key;
1030 }
1031 $section['anchor'] .= '_settings';
1032
1033 if ( ! isset( $section['title'] ) ) {
1034 $section['title'] = $section['name'];
1035 }
1036
1037 if ( ! isset( $section['id'] ) ) {
1038 $section['id'] = $section['anchor'];
1039 }
1040
1041 $sections[ $key ] = $section;
1042 }
1043
1044 return $sections;
1045 }
1046
1047 /**
1048 * @since 4.0
1049 *
1050 * @param array $values
1051 */
1052 public static function advanced_settings( $values ) {
1053 $first_h3 = 'frm_first_h3';
1054
1055 include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-advanced.php' );
1056 }
1057
1058 /**
1059 * @since 4.0
1060 *
1061 * @param array $values
1062 */
1063 public static function buttons_settings( $values ) {
1064 $styles = apply_filters( 'frm_get_style_opts', array() );
1065
1066 $frm_settings = FrmAppHelper::get_settings();
1067 $no_global_style = $frm_settings->load_style === 'none';
1068
1069 include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php' );
1070 }
1071
1072 /**
1073 * @since 4.0
1074 *
1075 * @param array $values
1076 */
1077 public static function html_settings( $values ) {
1078 include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php' );
1079 }
1080
1081 /**
1082 * Replace old Submit Button href with new href to avoid errors in Chrome
1083 *
1084 * @since 2.03.08
1085 *
1086 * @param array|boolean $values
1087 */
1088 private static function clean_submit_html( &$values ) {
1089 if ( is_array( $values ) && isset( $values['submit_html'] ) ) {
1090 $values['submit_html'] = str_replace( 'javascript:void(0)', '#', $values['submit_html'] );
1091 }
1092 }
1093
1094 public static function mb_tags_box( $form_id, $class = '' ) {
1095 $fields = FrmField::get_all_for_form( $form_id, '', 'include' );
1096 $linked_forms = array();
1097 $col = 'one';
1098 $settings_tab = FrmAppHelper::is_admin_page( 'formidable' ) ? true : false;
1099
1100 $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() );
1101 $entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
1102
1103 $advanced_helpers = self::advanced_helpers( compact( 'fields', 'form_id' ) );
1104
1105 include( FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php' );
1106 }
1107
1108 /**
1109 * @since 3.04.01
1110 */
1111 private static function advanced_helpers( $atts ) {
1112 $advanced_helpers = array(
1113 'default' => array(
1114 'heading' => __( 'Customize field values with the following parameters.', 'formidable' ),
1115 'codes' => self::get_advanced_shortcodes(),
1116 ),
1117 );
1118
1119 $user_fields = self::user_shortcodes();
1120 if ( ! empty( $user_fields ) ) {
1121 $user_helpers = array();
1122 foreach ( $user_fields as $uk => $uf ) {
1123 $user_helpers[ '|user_id| show="' . $uk . '"' ] = $uf;
1124 unset( $uk, $uf );
1125 }
1126
1127 $advanced_helpers['user_id'] = array(
1128 'codes' => $user_helpers,
1129 );
1130 }
1131
1132 /**
1133 * Add extra helper shortcodes on the Advanced tab in form settings and views
1134 *
1135 * @since 3.04.01
1136 *
1137 * @param array $atts - Includes fields and form_id
1138 */
1139 return apply_filters( 'frm_advanced_helpers', $advanced_helpers, $atts );
1140 }
1141
1142 /**
1143 * Get an array of the options to display in the advanced tab
1144 * of the customization panel
1145 *
1146 * @since 2.0.6
1147 */
1148 private static function get_advanced_shortcodes() {
1149 $adv_shortcodes = array(
1150 'x sep=", "' => array(
1151 'label' => __( 'Separator', 'formidable' ),
1152 'title' => __( 'Use a different separator for checkbox fields', 'formidable' ),
1153 ),
1154 'x format="d-m-Y"' => array(
1155 'label' => __( 'Date Format', 'formidable' ),
1156 ),
1157 'x show="field_label"' => array(
1158 'label' => __( 'Field Label', 'formidable' ),
1159 ),
1160 'x wpautop=0' => array(
1161 'label' => __( 'No Auto P', 'formidable' ),
1162 'title' => __( 'Do not automatically add any paragraphs or line breaks', 'formidable' ),
1163 ),
1164 );
1165 $adv_shortcodes = apply_filters( 'frm_advanced_shortcodes', $adv_shortcodes );
1166
1167 // __( 'Leave blank instead of defaulting to User Login', 'formidable' ) : blank=1
1168
1169 return $adv_shortcodes;
1170 }
1171
1172 /**
1173 * @since 3.04.01
1174 */
1175 private static function user_shortcodes() {
1176 $options = array(
1177 'ID' => __( 'User ID', 'formidable' ),
1178 'first_name' => __( 'First Name', 'formidable' ),
1179 'last_name' => __( 'Last Name', 'formidable' ),
1180 'display_name' => __( 'Display Name', 'formidable' ),
1181 'user_login' => __( 'User Login', 'formidable' ),
1182 'user_email' => __( 'Email', 'formidable' ),
1183 'avatar' => __( 'Avatar', 'formidable' ),
1184 'author_link' => __( 'Author Link', 'formidable' ),
1185 );
1186
1187 return apply_filters( 'frm_user_shortcodes', $options );
1188 }
1189
1190 /**
1191 * Get an array of the helper shortcodes to display in the customization panel
1192 *
1193 * @since 2.0.6
1194 */
1195 private static function get_shortcode_helpers( $settings_tab ) {
1196 $entry_shortcodes = array(
1197 'id' => __( 'Entry ID', 'formidable' ),
1198 'key' => __( 'Entry Key', 'formidable' ),
1199 'post_id' => __( 'Post ID', 'formidable' ),
1200 'ip' => __( 'User IP', 'formidable' ),
1201 'created-at' => __( 'Entry created', 'formidable' ),
1202 'updated-at' => __( 'Entry updated', 'formidable' ),
1203 '' => '',
1204 'siteurl' => __( 'Site URL', 'formidable' ),
1205 'sitename' => __( 'Site Name', 'formidable' ),
1206 );
1207
1208 if ( ! FrmAppHelper::pro_is_installed() ) {
1209 unset( $entry_shortcodes['post_id'] );
1210 }
1211
1212 if ( $settings_tab ) {
1213 $entry_shortcodes['default-message'] = __( 'Default Msg', 'formidable' );
1214 $entry_shortcodes['default-html'] = __( 'Default HTML', 'formidable' );
1215 $entry_shortcodes['default-plain'] = __( 'Default Plain', 'formidable' );
1216 }
1217
1218 /**
1219 * Use this hook to add or remove buttons in the helpers section
1220 * in the customization panel
1221 *
1222 * @since 2.0.6
1223 */
1224 $entry_shortcodes = apply_filters( 'frm_helper_shortcodes', $entry_shortcodes, $settings_tab );
1225
1226 return $entry_shortcodes;
1227 }
1228
1229 /**
1230 * Insert the form class setting into the form
1231 */
1232 public static function form_classes( $form ) {
1233 if ( isset( $form->options['form_class'] ) ) {
1234 echo esc_attr( sanitize_text_field( $form->options['form_class'] ) );
1235 }
1236
1237 if ( isset( $form->options['js_validate'] ) && $form->options['js_validate'] ) {
1238 echo ' frm_js_validate ';
1239 }
1240 }
1241
1242 public static function get_email_html() {
1243 FrmAppHelper::permission_check( 'frm_view_forms' );
1244 check_ajax_referer( 'frm_ajax', 'nonce' );
1245
1246 echo FrmEntriesController::show_entry_shortcode( // WPCS: XSS ok.
1247 array(
1248 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ),
1249 'default_email' => true,
1250 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ),
1251 )
1252 );
1253 wp_die();
1254 }
1255
1256 public static function filter_content( $content, $form, $entry = false ) {
1257 self::get_entry_by_param( $entry );
1258 if ( ! $entry ) {
1259 return $content;
1260 }
1261
1262 if ( is_object( $form ) ) {
1263 $form = $form->id;
1264 }
1265
1266 $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form );
1267 $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
1268
1269 return $content;
1270 }
1271
1272 private static function get_entry_by_param( &$entry ) {
1273 if ( ! $entry || ! is_object( $entry ) ) {
1274 if ( ! $entry || ! is_numeric( $entry ) ) {
1275 $entry = FrmAppHelper::get_post_param( 'id', false, 'sanitize_title' );
1276 }
1277
1278 FrmEntry::maybe_get_entry( $entry );
1279 }
1280 }
1281
1282 public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
1283 return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes );
1284 }
1285
1286 public static function process_bulk_form_actions( $errors ) {
1287 if ( ! $_REQUEST ) {
1288 return $errors;
1289 }
1290
1291 $bulkaction = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
1292 if ( $bulkaction == - 1 ) {
1293 $bulkaction = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
1294 }
1295
1296 if ( ! empty( $bulkaction ) && strpos( $bulkaction, 'bulk_' ) === 0 ) {
1297 FrmAppHelper::remove_get_action();
1298
1299 $bulkaction = str_replace( 'bulk_', '', $bulkaction );
1300 }
1301
1302 $ids = FrmAppHelper::get_param( 'item-action', '', 'get', 'sanitize_text_field' );
1303 if ( empty( $ids ) ) {
1304 $errors[] = __( 'No forms were specified', 'formidable' );
1305
1306 return $errors;
1307 }
1308
1309 $permission_error = FrmAppHelper::permission_nonce_error( '', '_wpnonce', 'bulk-toplevel_page_formidable' );
1310 if ( $permission_error !== false ) {
1311 $errors[] = $permission_error;
1312
1313 return $errors;
1314 }
1315
1316 if ( ! is_array( $ids ) ) {
1317 $ids = explode( ',', $ids );
1318 }
1319
1320 switch ( $bulkaction ) {
1321 case 'delete':
1322 $message = self::bulk_destroy( $ids );
1323 break;
1324 case 'trash':
1325 $message = self::bulk_trash( $ids );
1326 break;
1327 case 'untrash':
1328 $message = self::bulk_untrash( $ids );
1329 }
1330
1331 if ( isset( $message ) && ! empty( $message ) ) {
1332 $errors['message'] = $message;
1333 }
1334
1335 return $errors;
1336 }
1337
1338 public static function route() {
1339 $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
1340 $vars = array();
1341 FrmAppHelper::include_svg();
1342
1343 if ( isset( $_POST['frm_compact_fields'] ) ) {
1344 FrmAppHelper::permission_check( 'frm_edit_forms' );
1345
1346 // Javascript needs to be allowed in some field settings.
1347 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1348 $json_vars = htmlspecialchars_decode( nl2br( str_replace( '&quot;', '"', wp_unslash( $_POST['frm_compact_fields'] ) ) ) );
1349 $json_vars = json_decode( $json_vars, true );
1350 if ( empty( $json_vars ) ) {
1351 // json decoding failed so we should return an error message.
1352 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
1353 if ( 'edit' == $action ) {
1354 $action = 'update';
1355 }
1356
1357 add_filter( 'frm_validate_form', 'FrmFormsController::json_error' );
1358 } else {
1359 $vars = FrmAppHelper::json_to_array( $json_vars );
1360 $action = $vars[ $action ];
1361 unset( $_REQUEST['frm_compact_fields'], $_POST['frm_compact_fields'] );
1362 $_REQUEST = array_merge( $_REQUEST, $vars );
1363 $_POST = array_merge( $_POST, $_REQUEST );
1364 }
1365 } else {
1366 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
1367 if ( isset( $_REQUEST['delete_all'] ) ) {
1368 // Override the action for this page.
1369 $action = 'delete_all';
1370 }
1371 }
1372
1373 add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
1374 FrmAppHelper::trigger_hook_load( 'form' );
1375
1376 switch ( $action ) {
1377 case 'new':
1378 return self::new_form( $vars );
1379 case 'add_new':
1380 case 'list_templates':
1381 return self::list_templates();
1382 case 'create':
1383 case 'edit':
1384 case 'update':
1385 case 'duplicate':
1386 case 'trash':
1387 case 'untrash':
1388 case 'destroy':
1389 case 'delete_all':
1390 case 'settings':
1391 case 'update_settings':
1392 return self::$action( $vars );
1393 case 'lite-reports':
1394 return self::no_reports( $vars );
1395 case 'views':
1396 return self::no_views( $vars );
1397 default:
1398 do_action( 'frm_form_action_' . $action );
1399 if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) {
1400 return;
1401 }
1402
1403 $action = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
1404 if ( $action == - 1 ) {
1405 $action = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
1406 }
1407
1408 if ( strpos( $action, 'bulk_' ) === 0 ) {
1409 FrmAppHelper::remove_get_action();
1410
1411 return self::list_form();
1412 }
1413
1414 return self::display_forms_list();
1415 }
1416 }
1417
1418 public static function json_error( $errors ) {
1419 $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
1420
1421 return $errors;
1422 }
1423
1424 /**
1425 * Education for premium features.
1426 *
1427 * @since 4.05
1428 */
1429 public static function add_form_style_tab_options() {
1430 include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php' );
1431 }
1432
1433 /**
1434 * Add education about views.
1435 *
1436 * @since 4.07
1437 */
1438 public static function no_views( $values = array() ) {
1439 FrmAppHelper::include_svg();
1440 $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
1441 $form = $id ? FrmForm::getOne( $id ) : false;
1442
1443 include FrmAppHelper::plugin_path() . '/classes/views/shared/views-info.php';
1444 }
1445
1446 /**
1447 * Add education about reports.
1448 *
1449 * @since 4.07
1450 */
1451 public static function no_reports( $values = array() ) {
1452 $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
1453 $form = $id ? FrmForm::getOne( $id ) : false;
1454
1455 include FrmAppHelper::plugin_path() . '/classes/views/shared/reports-info.php';
1456 }
1457
1458 /* FRONT-END FORMS */
1459 public static function admin_bar_css() {
1460 if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
1461 return;
1462 }
1463
1464 self::move_menu_to_footer();
1465
1466 add_action( 'wp_before_admin_bar_render', 'FrmFormsController::admin_bar_configure' );
1467 FrmAppHelper::load_font_style();
1468 }
1469
1470 /**
1471 * @since 4.05.02
1472 */
1473 private static function move_menu_to_footer() {
1474 $settings = FrmAppHelper::get_settings();
1475 if ( empty( $settings->admin_bar ) ) {
1476 remove_action( 'wp_body_open', 'wp_admin_bar_render', 0 );
1477 }
1478 }
1479
1480 public static function admin_bar_configure() {
1481 global $frm_vars;
1482 if ( empty( $frm_vars['forms_loaded'] ) ) {
1483 return;
1484 }
1485
1486 $actions = array();
1487 foreach ( $frm_vars['forms_loaded'] as $form ) {
1488 if ( is_object( $form ) ) {
1489 $actions[ $form->id ] = $form->name;
1490 }
1491 unset( $form );
1492 }
1493
1494 if ( empty( $actions ) ) {
1495 return;
1496 }
1497
1498 self::add_menu_to_admin_bar();
1499 self::add_forms_to_admin_bar( $actions );
1500 }
1501
1502 /**
1503 * @since 2.05.07
1504 */
1505 public static function add_menu_to_admin_bar() {
1506 global $wp_admin_bar;
1507
1508 $wp_admin_bar->add_node(
1509 array(
1510 'id' => 'frm-forms',
1511 'title' => '<span class="ab-icon"></span><span class="ab-label">' . FrmAppHelper::get_menu_name() . '</span>',
1512 'href' => admin_url( 'admin.php?page=formidable' ),
1513 'meta' => array(
1514 'title' => FrmAppHelper::get_menu_name(),
1515 ),
1516 )
1517 );
1518 }
1519
1520 /**
1521 * @since 2.05.07
1522 */
1523 private static function add_forms_to_admin_bar( $actions ) {
1524 global $wp_admin_bar;
1525
1526 asort( $actions );
1527
1528 foreach ( $actions as $form_id => $name ) {
1529
1530 $wp_admin_bar->add_node(
1531 array(
1532 'parent' => 'frm-forms',
1533 'id' => 'edit_form_' . $form_id,
1534 'title' => empty( $name ) ? __( '(no title)', 'formidable' ) : $name,
1535 'href' => FrmForm::get_edit_link( $form_id ),
1536 )
1537 );
1538 }
1539 }
1540
1541 /**
1542 * The formidable shortcode
1543 *
1544 * @param array $atts The params from the shortcode.
1545 */
1546 public static function get_form_shortcode( $atts ) {
1547 global $frm_vars;
1548 if ( isset( $frm_vars['skip_shortcode'] ) && $frm_vars['skip_shortcode'] ) {
1549 $sc = '[formidable';
1550 $sc .= FrmAppHelper::array_to_html_params( $atts );
1551 return $sc . ']';
1552 }
1553
1554 $shortcode_atts = shortcode_atts(
1555 array(
1556 'id' => '',
1557 'key' => '',
1558 'title' => false,
1559 'description' => false,
1560 'readonly' => false,
1561 'entry_id' => false,
1562 'fields' => array(),
1563 'exclude_fields' => array(),
1564 'minimize' => false,
1565 ),
1566 $atts
1567 );
1568 do_action( 'formidable_shortcode_atts', $shortcode_atts, $atts );
1569
1570 return self::show_form( $shortcode_atts['id'], $shortcode_atts['key'], $shortcode_atts['title'], $shortcode_atts['description'], $atts );
1571 }
1572
1573 public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) {
1574 if ( empty( $id ) ) {
1575 $id = $key;
1576 }
1577
1578 $form = self::maybe_get_form_to_show( $id );
1579 if ( ! $form ) {
1580 return __( 'Please select a valid form', 'formidable' );
1581 }
1582
1583 FrmAppController::maybe_update_styles();
1584
1585 add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
1586 FrmAppHelper::trigger_hook_load( 'form', $form );
1587
1588 $form = apply_filters( 'frm_pre_display_form', $form );
1589
1590 $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) );
1591
1592 if ( self::is_viewable_draft_form( $form ) ) {
1593 // don't show a draft form on a page
1594 $form = __( 'Please select a valid form', 'formidable' );
1595 } elseif ( ! FrmForm::is_visible_to_user( $form ) ) {
1596 $form = do_shortcode( $frm_settings->login_msg );
1597 } else {
1598 do_action( 'frm_pre_get_form', $form );
1599 $form = self::get_form( $form, $title, $description, $atts );
1600
1601 /**
1602 * Use this shortcode to check for external shortcodes that may span
1603 * across multiple fields in the customizable HTML
1604 *
1605 * @since 2.0.8
1606 */
1607 $form = apply_filters( 'frm_filter_final_form', $form );
1608 }
1609
1610 return $form;
1611 }
1612
1613 private static function maybe_get_form_to_show( $id ) {
1614 $form = false;
1615
1616 if ( ! empty( $id ) ) { // no form id or key set
1617 $form = FrmForm::getOne( $id );
1618 if ( ! $form || $form->parent_form_id || $form->status == 'trash' ) {
1619 $form = false;
1620 }
1621 }
1622
1623 return $form;
1624 }
1625
1626 private static function is_viewable_draft_form( $form ) {
1627 return $form->status == 'draft' && current_user_can( 'frm_edit_forms' ) && ! FrmAppHelper::is_preview_page();
1628 }
1629
1630 public static function get_form( $form, $title, $description, $atts = array() ) {
1631 ob_start();
1632
1633 do_action( 'frm_before_get_form', $atts );
1634
1635 self::get_form_contents( $form, $title, $description, $atts );
1636 self::enqueue_scripts( FrmForm::get_params( $form ) );
1637
1638 $contents = ob_get_contents();
1639 ob_end_clean();
1640
1641 self::maybe_minimize_form( $atts, $contents );
1642
1643 return $contents;
1644 }
1645
1646 public static function enqueue_scripts( $params ) {
1647 do_action( 'frm_enqueue_form_scripts', $params );
1648 }
1649
1650 public static function get_form_contents( $form, $title, $description, $atts ) {
1651 $params = FrmForm::get_params( $form );
1652 $errors = self::get_saved_errors( $form, $params );
1653 $fields = FrmFieldsHelper::get_form_fields( $form->id, $errors );
1654 $reset = false;
1655 $pass_args = compact( 'form', 'fields', 'errors', 'title', 'description', 'reset' );
1656
1657 $handle_process_here = $params['action'] == 'create' && $params['posted_form_id'] == $form->id && $_POST;
1658
1659 if ( ! $handle_process_here ) {
1660 do_action( 'frm_display_form_action', $params, $fields, $form, $title, $description );
1661 if ( apply_filters( 'frm_continue_to_new', true, $form->id, $params['action'] ) ) {
1662 self::show_form_after_submit( $pass_args );
1663 }
1664 } elseif ( ! empty( $errors ) ) {
1665 self::show_form_after_submit( $pass_args );
1666
1667 } else {
1668
1669 do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description );
1670
1671 if ( apply_filters( 'frm_continue_to_create', true, $form->id ) ) {
1672 $entry_id = self::just_created_entry( $form->id );
1673 $pass_args['entry_id'] = $entry_id;
1674 $pass_args['reset'] = true;
1675 $pass_args['conf_method'] = self::get_confirmation_method( compact( 'form', 'entry_id' ) );
1676
1677 self::run_success_action( $pass_args );
1678
1679 do_action(
1680 'frm_after_entry_processed',
1681 array(
1682 'entry_id' => $entry_id,
1683 'form' => $form,
1684 )
1685 );
1686 }
1687 }
1688 }
1689
1690 /**
1691 * If the form was processed earlier (init), get the generated errors
1692 *
1693 * @since 2.05
1694 */
1695 private static function get_saved_errors( $form, $params ) {
1696 global $frm_vars;
1697
1698 if ( $params['posted_form_id'] == $form->id && $_POST && isset( $frm_vars['created_entries'][ $form->id ] ) ) {
1699 $errors = $frm_vars['created_entries'][ $form->id ]['errors'];
1700 } else {
1701 $errors = array();
1702 }
1703
1704 return $errors;
1705 }
1706
1707 /**
1708 * @since 2.2.7
1709 */
1710 public static function just_created_entry( $form_id ) {
1711 global $frm_vars;
1712
1713 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;
1714 }
1715
1716 /**
1717 * @since 3.0
1718 */
1719 private static function get_confirmation_method( $atts ) {
1720 $opt = 'success_action';
1721 $method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message';
1722 $method = apply_filters( 'frm_success_filter', $method, $atts['form'], 'create' );
1723
1724 if ( $method != 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
1725 $method = 'message';
1726 }
1727
1728 return $method;
1729 }
1730
1731 public static function maybe_trigger_redirect( $form, $params, $args ) {
1732 if ( ! isset( $params['id'] ) ) {
1733 global $frm_vars;
1734 $params['id'] = $frm_vars['created_entries'][ $form->id ]['entry_id'];
1735 }
1736
1737 $conf_method = self::get_confirmation_method(
1738 array(
1739 'form' => $form,
1740 'entry_id' => $params['id'],
1741 )
1742 );
1743
1744 if ( 'redirect' === $conf_method ) {
1745 self::trigger_redirect( $form, $params, $args );
1746 }
1747 }
1748
1749 public static function trigger_redirect( $form, $params, $args ) {
1750 $success_args = array(
1751 'action' => $params['action'],
1752 'conf_method' => 'redirect',
1753 'form' => $form,
1754 'entry_id' => $params['id'],
1755 );
1756
1757 if ( isset( $args['ajax'] ) ) {
1758 $success_args['ajax'] = $args['ajax'];
1759 }
1760
1761 self::run_success_action( $success_args );
1762 }
1763
1764 /**
1765 * Used when the success action is not 'message'
1766 *
1767 * @since 2.05
1768 */
1769 public static function run_success_action( $args ) {
1770 $extra_args = $args;
1771 unset( $extra_args['form'] );
1772
1773 do_action( 'frm_success_action', $args['conf_method'], $args['form'], $args['form']->options, $args['entry_id'], $extra_args );
1774
1775 $opt = ( ! isset( $args['action'] ) || $args['action'] == 'create' ) ? 'success' : 'edit';
1776
1777 $args['success_opt'] = $opt;
1778 if ( $args['conf_method'] == 'page' && is_numeric( $args['form']->options[ $opt . '_page_id' ] ) ) {
1779 self::load_page_after_submit( $args );
1780 } elseif ( $args['conf_method'] == 'redirect' ) {
1781 self::redirect_after_submit( $args );
1782 } else {
1783 self::show_message_after_save( $args );
1784 }
1785 }
1786
1787 /**
1788 * @since 3.0
1789 */
1790 private static function load_page_after_submit( $args ) {
1791 global $post;
1792 $opt = $args['success_opt'];
1793 if ( ! $post || $args['form']->options[ $opt . '_page_id' ] != $post->ID ) {
1794 $page = get_post( $args['form']->options[ $opt . '_page_id' ] );
1795 $old_post = $post;
1796 $post = $page;
1797 $content = apply_filters( 'frm_content', $page->post_content, $args['form'], $args['entry_id'] );
1798 echo apply_filters( 'the_content', $content ); // WPCS: XSS ok.
1799 $post = $old_post;
1800 }
1801 }
1802
1803 /**
1804 * @since 3.0
1805 */
1806 private static function redirect_after_submit( $args ) {
1807 global $frm_vars;
1808
1809 add_filter( 'frm_use_wpautop', '__return_false' );
1810
1811 $opt = $args['success_opt'];
1812 $success_url = trim( $args['form']->options[ $opt . '_url' ] );
1813 $success_url = apply_filters( 'frm_content', $success_url, $args['form'], $args['entry_id'] );
1814 $success_url = do_shortcode( $success_url );
1815
1816 $success_msg = isset( $args['form']->options[ $opt . '_msg' ] ) ? $args['form']->options[ $opt . '_msg' ] : __( 'Please wait while you are redirected.', 'formidable' );
1817
1818 $redirect_msg = self::get_redirect_message( $success_url, $success_msg, $args );
1819
1820 $args['id'] = $args['entry_id'];
1821 FrmEntriesController::delete_entry_before_redirect( $success_url, $args['form'], $args );
1822
1823 add_filter( 'frm_redirect_url', 'FrmEntriesController::prepare_redirect_url' );
1824 $success_url = apply_filters( 'frm_redirect_url', $success_url, $args['form'], $args );
1825
1826 $doing_ajax = FrmAppHelper::doing_ajax();
1827
1828 if ( isset( $args['ajax'] ) && $args['ajax'] && $doing_ajax ) {
1829 echo json_encode( array( 'redirect' => $success_url ) );
1830 wp_die();
1831 } elseif ( ! headers_sent() ) {
1832 wp_redirect( esc_url_raw( $success_url ) );
1833 die(); // do not use wp_die or redirect fails
1834 } else {
1835 add_filter( 'frm_use_wpautop', '__return_true' );
1836
1837 echo $redirect_msg; // WPCS: XSS ok.
1838 echo "<script type='text/javascript'>window.onload = function(){setTimeout(window.location='" . esc_url_raw( $success_url ) . "', 8000);}</script>";
1839 }
1840 }
1841
1842 /**
1843 * @since 3.0
1844 *
1845 * @param string $success_url
1846 * @param string $success_msg
1847 * @param array $args
1848 */
1849 private static function get_redirect_message( $success_url, $success_msg, $args ) {
1850 $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/>' .
1851 /* translators: %1$s: Start link HTML, %2$s: End link HTML */
1852 sprintf( __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ), '<a href="' . esc_url( $success_url ) . '">', '</a>' ) .
1853 '</div></div>';
1854
1855 $redirect_args = array(
1856 'entry_id' => $args['entry_id'],
1857 'form_id' => $args['form']->id,
1858 'form' => $args['form'],
1859 );
1860
1861 return apply_filters( 'frm_redirect_msg', $redirect_msg, $redirect_args );
1862 }
1863
1864 /**
1865 * Prepare to show the success message and empty form after submit
1866 *
1867 * @since 2.05
1868 */
1869 public static function show_message_after_save( $atts ) {
1870 $atts['message'] = self::prepare_submit_message( $atts['form'], $atts['entry_id'] );
1871
1872 if ( ! isset( $atts['form']->options['show_form'] ) || $atts['form']->options['show_form'] ) {
1873 self::show_form_after_submit( $atts );
1874 } else {
1875 self::show_lone_success_messsage( $atts );
1876 }
1877 }
1878
1879 /**
1880 * Show an empty form
1881 *
1882 * @since 2.05
1883 */
1884 private static function show_form_after_submit( $args ) {
1885 self::fill_atts_for_form_display( $args );
1886
1887 $errors = $args['errors'];
1888 $message = $args['message'];
1889 $form = $args['form'];
1890 $title = $args['title'];
1891 $description = $args['description'];
1892
1893 if ( empty( $args['fields'] ) ) {
1894 $values = array();
1895 } else {
1896 $values = FrmEntriesHelper::setup_new_vars( $args['fields'], $form, $args['reset'] );
1897 }
1898 unset( $args );
1899
1900 $include_form_tag = apply_filters( 'frm_include_form_tag', true, $form );
1901
1902 $frm_settings = FrmAppHelper::get_settings();
1903 $submit = isset( $form->options['submit_value'] ) ? $form->options['submit_value'] : $frm_settings->submit_value;
1904
1905 global $frm_vars;
1906 self::maybe_load_css( $form, $values['custom_style'], $frm_vars['load_css'] );
1907
1908 $message_placement = self::message_placement( $form, $message );
1909
1910 include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php' );
1911 }
1912
1913 /**
1914 * @return string - 'before', 'after', or 'submit'
1915 *
1916 * @since 4.05.02
1917 */
1918 private static function message_placement( $form, $message ) {
1919 $place = 'before';
1920
1921 if ( $message && isset( $form->options['form_class'] ) ) {
1922 if ( strpos( $form->options['form_class'], 'frm_below_success' ) !== false ) {
1923 $place = 'after';
1924 } elseif ( strpos( $form->options['form_class'], 'frm_inline_success' ) !== false ) {
1925 $place = 'submit';
1926 }
1927 }
1928
1929 /**
1930 * @return string - 'before' or 'after'
1931 *
1932 * @since 4.05.02
1933 */
1934 return apply_filters( 'frm_message_placement', $place, compact( 'form', 'message' ) );
1935 }
1936
1937 /**
1938 * Get all the values needed on the new.php entry page
1939 *
1940 * @since 2.05
1941 */
1942 private static function fill_atts_for_form_display( &$args ) {
1943 $defaults = array(
1944 'errors' => array(),
1945 'message' => '',
1946 'fields' => array(),
1947 'form' => array(),
1948 'title' => true,
1949 'description' => false,
1950 'reset' => false,
1951 );
1952 $args = wp_parse_args( $args, $defaults );
1953 }
1954
1955 /**
1956 * Show the success message without the form
1957 *
1958 * @since 2.05
1959 */
1960 private static function show_lone_success_messsage( $atts ) {
1961 global $frm_vars;
1962 $values = FrmEntriesHelper::setup_new_vars( $atts['fields'], $atts['form'], true );
1963 self::maybe_load_css( $atts['form'], $values['custom_style'], $frm_vars['load_css'] );
1964
1965 $include_extra_container = 'frm_forms' . FrmFormsHelper::get_form_style_class( $values );
1966
1967 $errors = array();
1968 $form = $atts['form'];
1969 $message = $atts['message'];
1970
1971 include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php' );
1972 }
1973
1974 /**
1975 * Prepare the success message before it's shown
1976 *
1977 * @since 2.05
1978 */
1979 private static function prepare_submit_message( $form, $entry_id ) {
1980 $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) );
1981
1982 if ( $entry_id && is_numeric( $entry_id ) ) {
1983 $message = isset( $form->options['success_msg'] ) ? $form->options['success_msg'] : $frm_settings->success_msg;
1984 $class = 'frm_message';
1985 } else {
1986 $message = $frm_settings->failed_msg;
1987 $class = FrmFormsHelper::form_error_class();
1988 }
1989
1990 $message = FrmFormsHelper::get_success_message( compact( 'message', 'form', 'entry_id', 'class' ) );
1991
1992 return apply_filters( 'frm_main_feedback', $message, $form, $entry_id );
1993 }
1994
1995 public static function front_head() {
1996 $version = FrmAppHelper::plugin_version();
1997 $suffix = FrmAppHelper::js_suffix();
1998
1999 if ( ! empty( $suffix ) && self::has_combo_js_file() ) {
2000 wp_register_script( 'formidable', FrmAppHelper::plugin_url() . '/js/frm.min.js', array( 'jquery' ), $version, true );
2001 } else {
2002 wp_register_script( 'formidable', FrmAppHelper::plugin_url() . "/js/formidable{$suffix}.js", array( 'jquery' ), $version, true );
2003 }
2004
2005 add_filter( 'script_loader_tag', 'FrmFormsController::defer_script_loading', 10, 2 );
2006
2007 if ( FrmAppHelper::is_admin() ) {
2008 // don't load this in back-end
2009 return;
2010 }
2011
2012 FrmAppHelper::localize_script( 'front' );
2013 FrmStylesController::enqueue_css( 'register' );
2014 }
2015
2016 /**
2017 * @since 3.0
2018 */
2019 public static function has_combo_js_file() {
2020 return is_readable( FrmAppHelper::plugin_path() . '/js/frm.min.js' );
2021 }
2022
2023 public static function maybe_load_css( $form, $this_load, $global_load ) {
2024 $load_css = FrmForm::is_form_loaded( $form, $this_load, $global_load );
2025
2026 if ( ! $load_css ) {
2027 return;
2028 }
2029
2030 global $frm_vars;
2031 self::footer_js( 'header' );
2032 $frm_vars['css_loaded'] = true;
2033
2034 self::load_late_css();
2035 }
2036
2037 /**
2038 * If css is loaded only on applicable pages, include it before the form loads
2039 * to prevent a flash of unstyled form.
2040 *
2041 * @since 4.01
2042 */
2043 private static function load_late_css() {
2044 $frm_settings = FrmAppHelper::get_settings();
2045 $late_css = $frm_settings->load_style === 'dynamic';
2046 if ( ! $late_css ) {
2047 return;
2048 }
2049
2050 global $wp_styles;
2051 if ( is_array( $wp_styles->queue ) && in_array( 'formidable', $wp_styles->queue ) ) {
2052 wp_print_styles( 'formidable' );
2053 }
2054 }
2055
2056 public static function defer_script_loading( $tag, $handle ) {
2057 if ( 'recaptcha-api' == $handle && ! strpos( $tag, 'defer' ) ) {
2058 $tag = str_replace( ' src', ' defer="defer" async="async" src', $tag );
2059 }
2060
2061 return $tag;
2062 }
2063
2064 public static function footer_js( $location = 'footer' ) {
2065 global $frm_vars;
2066
2067 FrmStylesController::enqueue_css();
2068
2069 if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
2070 // load formidable js
2071 wp_enqueue_script( 'formidable' );
2072 }
2073 }
2074
2075 /**
2076 * @since 2.0.8
2077 */
2078 private static function maybe_minimize_form( $atts, &$content ) {
2079 // check if minimizing is turned on
2080 if ( self::is_minification_on( $atts ) ) {
2081 $content = str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', $content );
2082 }
2083 }
2084
2085 /**
2086 * @since 2.0.8
2087 * @return boolean
2088 */
2089 private static function is_minification_on( $atts ) {
2090 return isset( $atts['minimize'] ) && ! empty( $atts['minimize'] );
2091 }
2092
2093 /**
2094 * @deprecated 4.0
2095 */
2096 public static function new_form( $values = array() ) {
2097 FrmDeprecated::new_form( $values );
2098 }
2099
2100 /**
2101 * @deprecated 4.0
2102 */
2103 public static function create( $values = array() ) {
2104 _deprecated_function( __METHOD__, '4.0', 'FrmFormsController::update' );
2105 self::update( $values );
2106 }
2107
2108 /**
2109 * @deprecated 1.07.05
2110 * @codeCoverageIgnore
2111 */
2112 public static function add_default_templates( $path, $default = true, $template = true ) {
2113 FrmDeprecated::add_default_templates( $path, $default, $template );
2114 }
2115
2116 /**
2117 * @deprecated 3.0
2118 * @codeCoverageIgnore
2119 */
2120 public static function bulk_create_template( $ids ) {
2121 return FrmDeprecated::bulk_create_template( $ids );
2122 }
2123
2124 /**
2125 * @deprecated 2.03
2126 * @codeCoverageIgnore
2127 */
2128 public static function register_pro_scripts() {
2129 FrmDeprecated::register_pro_scripts();
2130 }
2131
2132 /**
2133 * @deprecated 3.0
2134 * @codeCoverageIgnore
2135 */
2136 public static function edit_key() {
2137 FrmDeprecated::edit_key();
2138 }
2139
2140 /**
2141 * @deprecated 3.0
2142 * @codeCoverageIgnore
2143 */
2144 public static function edit_description() {
2145 FrmDeprecated::edit_description();
2146 }
2147 }
2148