PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.2
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / controllers / FrmAppController.php

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

838 lines 23.3 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 FrmAppController {
7
8 public static function menu() {
9 FrmAppHelper::maybe_add_permissions();
10 if ( ! current_user_can( 'frm_view_forms' ) ) {
11 return;
12 }
13
14 $menu_name = FrmAppHelper::get_menu_name();
15 add_menu_page( 'Formidable', $menu_name, 'frm_view_forms', 'formidable', 'FrmFormsController::route', self::menu_icon(), self::get_menu_position() );
16 }
17
18 /**
19 * @return int
20 */
21 private static function get_menu_position() {
22 return (int) apply_filters( 'frm_menu_position', 29 );
23 }
24
25 /**
26 * @since 3.05
27 */
28 private static function menu_icon() {
29 $icon = FrmAppHelper::svg_logo(
30 array(
31 'fill' => '#a0a5aa',
32 'orange' => '#a0a5aa',
33 )
34 );
35 $icon = 'data:image/svg+xml;base64,' . base64_encode( $icon );
36
37 return apply_filters( 'frm_icon', $icon );
38 }
39
40 /**
41 * @since 3.0
42 */
43 public static function add_admin_class( $classes ) {
44 if ( self::is_white_page() ) {
45 $classes .= ' frm-white-body ';
46 $classes .= self::get_os();
47
48 $page = str_replace( 'formidable-', '', FrmAppHelper::simple_get( 'page', 'sanitize_title' ) );
49 if ( empty( $page ) || $page === 'formidable' ) {
50 $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
51 if ( in_array( $action, array( 'settings', 'edit', 'list' ) ) ) {
52 $page .= $action;
53 } else {
54 $page = $action;
55 }
56 }
57 if ( ! empty( $page ) ) {
58 $classes .= ' frm-admin-page-' . $page;
59 }
60 }
61
62 if ( FrmAppHelper::is_full_screen() ) {
63 $classes .= apply_filters( 'frm_admin_full_screen_class', ' frm-full-screen folded' );
64 }
65
66 return $classes;
67 }
68
69 /**
70 * @since 4.0
71 */
72 private static function get_os() {
73 $agent = strtolower( FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' ) );
74 $os = '';
75 if ( strpos( $agent, 'mac' ) !== false ) {
76 $os = ' osx';
77 } elseif ( strpos( $agent, 'linux' ) !== false ) {
78 $os = ' linux';
79 } elseif ( strpos( $agent, 'windows' ) !== false ) {
80 $os = ' windows';
81 }
82 return $os;
83 }
84
85 /**
86 * @since 3.0
87 */
88 private static function is_white_page() {
89 $white_pages = array(
90 'formidable',
91 'formidable-entries',
92 'formidable-views',
93 'formidable-pro-upgrade',
94 'formidable-addons',
95 'formidable-import',
96 'formidable-settings',
97 'formidable-styles',
98 'formidable-styles2',
99 'formidable-inbox',
100 'formidable-welcome',
101 );
102
103 $get_page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
104 $is_white_page = in_array( $get_page, $white_pages );
105
106 if ( ! $is_white_page ) {
107 $screen = get_current_screen();
108 $is_white_page = ( $screen && strpos( $screen->id, 'frm_display' ) !== false );
109 }
110
111 return $is_white_page;
112 }
113
114 public static function load_wp_admin_style() {
115 FrmAppHelper::load_font_style();
116 }
117
118 public static function get_form_nav( $form, $show_nav = false, $title = 'show' ) {
119 $show_nav = FrmAppHelper::get_param( 'show_nav', $show_nav, 'get', 'absint' );
120 if ( empty( $show_nav ) || ! $form ) {
121 return;
122 }
123
124 FrmForm::maybe_get_form( $form );
125 if ( ! is_object( $form ) ) {
126 return;
127 }
128
129 $id = $form->id;
130 $current_page = self::get_current_page();
131 $nav_items = self::get_form_nav_items( $form );
132
133 include( FrmAppHelper::plugin_path() . '/classes/views/shared/form-nav.php' );
134 }
135
136 private static function get_current_page() {
137 $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
138 $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title', 'None' );
139 $current_page = isset( $_GET['page'] ) ? $page : $post_type;
140
141 if ( FrmAppHelper::is_view_builder_page() ) {
142 $current_page = 'frm_display';
143 }
144
145 return $current_page;
146 }
147
148 private static function get_form_nav_items( $form ) {
149 $id = $form->parent_form_id ? $form->parent_form_id : $form->id;
150
151 $nav_items = array(
152 array(
153 'link' => FrmForm::get_edit_link( $id ),
154 'label' => __( 'Build', 'formidable' ),
155 'current' => array( 'edit', 'new', 'duplicate' ),
156 'page' => 'formidable',
157 'permission' => 'frm_edit_forms',
158 ),
159 array(
160 'link' => admin_url( 'admin.php?page=formidable&frm_action=settings&id=' . absint( $id ) ),
161 'label' => __( 'Settings', 'formidable' ),
162 'current' => array( 'settings' ),
163 'page' => 'formidable',
164 'permission' => 'frm_edit_forms',
165 ),
166 array(
167 'link' => admin_url( 'admin.php?page=formidable-entries&frm-full=1&frm_action=list&form=' . absint( $id ) ),
168 'label' => __( 'Entries', 'formidable' ),
169 'current' => array(),
170 'page' => 'formidable-entries',
171 'permission' => 'frm_view_entries',
172 ),
173 );
174
175 $views_installed = is_callable( 'FrmProAppHelper::views_is_installed' ) ? FrmProAppHelper::views_is_installed() : FrmAppHelper::pro_is_installed();
176
177 if ( ! $views_installed ) {
178 $nav_items[] = array(
179 'link' => admin_url( 'admin.php?page=formidable-views&frm-full=1&form=' . absint( $id ) ),
180 'label' => __( 'Views', 'formidable' ),
181 'current' => array(),
182 'page' => 'formidable-views',
183 'permission' => 'frm_view_entries',
184 'atts' => array(
185 'class' => 'frm_noallow',
186 ),
187 );
188 }
189
190 // Let people know reports and views exist.
191 if ( ! FrmAppHelper::pro_is_installed() ) {
192 $nav_items[] = array(
193 'link' => admin_url( 'admin.php?page=formidable&frm_action=lite-reports&frm-full=1&form=' . absint( $id ) ),
194 'label' => __( 'Reports', 'formidable' ),
195 'current' => array( 'reports' ),
196 'page' => 'formidable',
197 'permission' => 'frm_view_entries',
198 'atts' => array(
199 'class' => 'frm_noallow',
200 ),
201 );
202 }
203
204 $nav_args = array(
205 'form_id' => $id,
206 'form' => $form,
207 );
208
209 return apply_filters( 'frm_form_nav_list', $nav_items, $nav_args );
210 }
211
212 // Adds a settings link to the plugins page
213 public static function settings_link( $links ) {
214 $settings = array();
215
216 if ( ! FrmAppHelper::pro_is_installed() ) {
217 $settings[] = '<a href="' . esc_url( FrmAppHelper::admin_upgrade_link( 'plugin-row' ) ) . '" target="_blank" rel="noopener"><b>' . esc_html__( 'Upgrade to Pro', 'formidable' ) . '</b></a>';
218 }
219
220 $settings[] = '<a href="' . esc_url( admin_url( 'admin.php?page=formidable' ) ) . '">' . __( 'Build a Form', 'formidable' ) . '</a>';
221
222 return array_merge( $settings, $links );
223 }
224
225 public static function pro_get_started_headline() {
226 self::review_request();
227 FrmAppHelper::min_pro_version_notice( '4.0' );
228 }
229
230 /**
231 * Add admin notices as needed for reviews
232 *
233 * @since 3.04.03
234 */
235 private static function review_request() {
236 $reviews = new FrmReviews();
237 $reviews->review_request();
238 }
239
240 /**
241 * Save the request to hide the review
242 *
243 * @since 3.04.03
244 */
245 public static function dismiss_review() {
246 FrmAppHelper::permission_check( 'frm_change_settings' );
247 check_ajax_referer( 'frm_ajax', 'nonce' );
248
249 $reviews = new FrmReviews();
250 $reviews->dismiss_review();
251 }
252
253 /**
254 * @since 3.04.02
255 */
256 public static function include_upgrade_overlay() {
257 wp_enqueue_script( 'jquery-ui-dialog' );
258 wp_enqueue_style( 'jquery-ui-dialog' );
259
260 add_action( 'admin_footer', 'FrmAppController::upgrade_overlay_html' );
261 }
262
263 /**
264 * @since 3.06.03
265 */
266 public static function upgrade_overlay_html() {
267 $is_pro = FrmAppHelper::pro_is_installed();
268 $upgrade_link = array(
269 'medium' => 'builder',
270 'content' => 'upgrade',
271 );
272 $default_link = FrmAppHelper::admin_upgrade_link( $upgrade_link );
273 $plugin_path = FrmAppHelper::plugin_path();
274 $shared_path = $plugin_path . '/classes/views/shared/';
275
276 include $shared_path . 'upgrade_overlay.php';
277 include $shared_path . 'confirm-overlay.php';
278
279 if ( ( FrmAppHelper::is_admin_page( 'formidable' ) || FrmAppHelper::is_admin_page( 'formidable-welcome' ) ) && in_array( FrmAppHelper::get_param( 'frm_action' ), array( '', 'list', 'trash' ), true ) ) {
280 self::new_form_overlay_html();
281 }
282 }
283
284 private static function new_form_overlay_html() {
285 FrmFormsController::before_list_templates();
286
287 $plugin_path = FrmAppHelper::plugin_path();
288 $path = $plugin_path . '/classes/views/frm-forms/';
289 $expired = FrmFormsController::expired();
290 $expiring = FrmAddonsController::is_license_expiring();
291 $user = wp_get_current_user(); // $user used in leave-email.php to determine a default value for field
292 $view_path = $path . 'new-form-overlay/';
293 $modal_class = '';
294 $upgrade_link = FrmAppHelper::admin_upgrade_link(
295 array(
296 'medium' => 'new-template',
297 'content' => 'upgrade',
298 )
299 );
300 $renew_link = FrmAppHelper::admin_upgrade_link(
301 array(
302 'medium' => 'new-template',
303 'content' => 'renew',
304 )
305 );
306 $blocks_to_render = array();
307
308 if ( ! FrmAppHelper::pro_is_installed() ) {
309 // avoid rendering the email and code blocks for users who have upgraded or have a free license already
310 $api = new FrmFormTemplateApi();
311 if ( ! $api->has_free_access() ) {
312 array_push( $blocks_to_render, 'email', 'code' );
313 }
314 }
315
316 // avoid rendering the upgrade block for users with elite
317 if ( 'elite' !== FrmAddonsController::license_type() ) {
318 $blocks_to_render[] = 'upgrade';
319 }
320
321 // avoid rendering the renew block for users who are not currently expired
322 if ( $expired ) {
323 $blocks_to_render[] = 'renew';
324 $modal_class = 'frm-expired';
325 } elseif ( $expiring ) {
326 $modal_class = 'frm-expiring';
327 }
328
329 include $path . 'new-form-overlay.php';
330 }
331
332 public static function include_info_overlay() {
333 wp_enqueue_script( 'jquery-ui-dialog' );
334 wp_enqueue_style( 'jquery-ui-dialog' );
335
336 add_action( 'admin_footer', 'FrmAppController::info_overlay_html' );
337 }
338
339 public static function info_overlay_html() {
340 include( FrmAppHelper::plugin_path() . '/classes/views/shared/info-overlay.php' );
341 }
342
343 /**
344 * @since 3.04.02
345 */
346 public static function remove_upsells() {
347 remove_action( 'frm_before_settings', 'FrmSettingsController::license_box' );
348 remove_action( 'frm_after_settings', 'FrmSettingsController::settings_cta' );
349 remove_action( 'frm_add_form_style_tab_options', 'FrmFormsController::add_form_style_tab_options' );
350 remove_action( 'frm_after_field_options', 'FrmFormsController::logic_tip' );
351
352 if ( is_callable( 'FrmProAddonsController::renewal_message' ) ) {
353 // These functions moved to Pro in 4.09.01
354 remove_action( 'frm_page_footer', 'FrmAppHelper::renewal_message' );
355 }
356 }
357
358 /**
359 * If there are CURL problems on this server, wp_remote_post won't work for installing
360 * Use a javascript fallback instead.
361 *
362 * @since 2.0.3
363 */
364 public static function install_js_fallback() {
365 FrmAppHelper::load_admin_wide_js();
366 echo '<div id="hidden frm_install_message"></div><script type="text/javascript">jQuery(document).ready(function(){frm_install_now();});</script>';
367 }
368
369 /**
370 * Check if the database is outdated
371 *
372 * @since 2.0.1
373 * @return boolean
374 */
375 public static function needs_update() {
376 $needs_upgrade = self::compare_for_update(
377 array(
378 'option' => 'frm_db_version',
379 'new_db_version' => FrmAppHelper::$db_version,
380 'new_plugin_version' => FrmAppHelper::plugin_version(),
381 )
382 );
383
384 if ( ! $needs_upgrade ) {
385 $needs_upgrade = apply_filters( 'frm_db_needs_upgrade', $needs_upgrade );
386 }
387
388 return $needs_upgrade;
389 }
390
391 /**
392 * Check both version number and DB number for changes
393 *
394 * @since 3.0.04
395 */
396 public static function compare_for_update( $atts ) {
397 $db_version = get_option( $atts['option'] );
398
399 if ( strpos( $db_version, '-' ) === false ) {
400 $needs_upgrade = true;
401 } else {
402 $last_upgrade = explode( '-', $db_version );
403 $needs_db_upgrade = (int) $last_upgrade[1] < (int) $atts['new_db_version'];
404 $new_version = version_compare( $last_upgrade[0], $atts['new_plugin_version'], '<' );
405 $needs_upgrade = $needs_db_upgrade || $new_version;
406 }
407
408 return $needs_upgrade;
409 }
410
411 /**
412 * Check for database update and trigger js loading
413 *
414 * @since 2.0.1
415 */
416 public static function admin_init() {
417 new FrmPersonalData(); // register personal data hooks
418
419 if ( ! FrmAppHelper::doing_ajax() && self::needs_update() ) {
420 self::network_upgrade_site();
421 }
422
423 if ( ! FrmAppHelper::doing_ajax() ) {
424 // don't continue during ajax calls
425 self::admin_js();
426 }
427
428 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
429 $action = FrmAppHelper::get_param( 'frm_action' );
430
431 if ( in_array( $action, array( 'add_new', 'list_templates' ), true ) ) {
432 wp_safe_redirect( admin_url( 'admin.php?page=formidable&triggerNewFormModal=1' ) );
433 exit;
434 }
435
436 FrmInbox::maybe_disable_screen_options();
437 }
438 }
439
440 /**
441 * @return void
442 */
443 public static function admin_js() {
444 $version = FrmAppHelper::plugin_version();
445 FrmAppHelper::load_admin_wide_js();
446
447 $dependecies = array(
448 'formidable_admin_global',
449 'jquery',
450 'jquery-ui-core',
451 'jquery-ui-draggable',
452 'jquery-ui-sortable',
453 'bootstrap_tooltip',
454 'bootstrap-multiselect',
455 'wp-i18n',
456 );
457
458 if ( FrmAppHelper::is_admin_page( 'formidable-styles' ) || FrmAppHelper::is_admin_page( 'formidable-styles2' ) ) {
459 $dependecies[] = 'wp-color-picker';
460 }
461
462 wp_register_script( 'formidable_admin', FrmAppHelper::plugin_url() . '/js/formidable_admin.js', $dependecies, $version, true );
463 wp_register_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css', array(), $version );
464 wp_register_script( 'bootstrap_tooltip', FrmAppHelper::plugin_url() . '/js/bootstrap.min.js', array( 'jquery' ), '3.4.1' );
465 wp_register_style( 'formidable-grids', FrmAppHelper::plugin_url() . '/css/frm_grids.css', array(), $version );
466
467 if ( 'formidable' === FrmAppHelper::simple_get( 'page', 'sanitize_title' ) ) {
468 $action = FrmAppHelper::get_param( 'frm_action', '', 'sanitize_title' );
469 $is_form_index = ! $action || in_array( $action, array( 'list', 'trash' ), true );
470 if ( $is_form_index ) {
471 // For the existing page dropdown in the Form embed modal.
472 wp_enqueue_script( 'jquery-ui-autocomplete' );
473 }
474 }
475
476 // load multselect js
477 $depends_on = array( 'jquery', 'bootstrap_tooltip' );
478 wp_register_script( 'bootstrap-multiselect', FrmAppHelper::plugin_url() . '/js/bootstrap-multiselect.js', $depends_on, '1.1.1', true );
479
480 $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
481 $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' );
482
483 global $pagenow;
484 if ( strpos( $page, 'formidable' ) === 0 || ( $pagenow === 'edit.php' && $post_type === 'frm_display' ) ) {
485
486 wp_enqueue_script( 'admin-widgets' );
487 wp_enqueue_style( 'widgets' );
488 wp_enqueue_script( 'formidable_admin' );
489 FrmAppHelper::localize_script( 'admin' );
490
491 wp_enqueue_style( 'formidable-admin' );
492 if ( 'formidable-styles' !== $page && 'formidable-styles2' !== $page ) {
493 wp_enqueue_style( 'formidable-grids' );
494 wp_enqueue_style( 'formidable-dropzone' );
495 } else {
496 wp_enqueue_style( 'formidable-grids' );
497 }
498
499 if ( 'formidable-entries' === $page ) {
500 // Load front end js for entries.
501 wp_enqueue_script( 'formidable' );
502 }
503
504 do_action( 'frm_enqueue_builder_scripts' );
505 self::include_upgrade_overlay();
506 self::include_info_overlay();
507 } elseif ( FrmAppHelper::is_view_builder_page() ) {
508 if ( isset( $_REQUEST['post_type'] ) ) {
509 $post_type = sanitize_title( wp_unslash( $_REQUEST['post_type'] ) );
510 } elseif ( isset( $_REQUEST['post'] ) && absint( $_REQUEST['post'] ) ) {
511 $post = get_post( absint( wp_unslash( $_REQUEST['post'] ) ) );
512 if ( ! $post ) {
513 return;
514 }
515 $post_type = $post->post_type;
516 } else {
517 return;
518 }
519
520 if ( $post_type === 'frm_display' ) {
521 wp_enqueue_style( 'formidable-grids' );
522 wp_enqueue_script( 'jquery-ui-draggable' );
523 wp_enqueue_script( 'formidable_admin' );
524 wp_enqueue_style( 'formidable-admin' );
525 FrmAppHelper::localize_script( 'admin' );
526 self::include_info_overlay();
527 }
528 }
529
530 self::maybe_force_formidable_block_on_gutenberg_page();
531 }
532
533 /**
534 * Automatically insert a Formidable block when loading Gutenberg with a $_GET['frmForm'] value set.
535 *
536 * @since 5.2
537 *
538 * @return void
539 */
540 private static function maybe_force_formidable_block_on_gutenberg_page() {
541 global $pagenow;
542 if ( 'post.php' !== $pagenow ) {
543 return;
544 }
545
546 $form_id = FrmAppHelper::simple_get( 'frmForm', 'absint' );
547 if ( ! $form_id ) {
548 return;
549 }
550
551 ?>
552 <script>
553 ( function() {
554 const handleDomReady = () => {
555 if ( 'undefined' === typeof wp || 'undefined' === typeof wp.data || 'function' !== typeof wp.data.subscribe ) {
556 return;
557 }
558
559 const closeListener = wp.data.subscribe(
560 () => {
561 const editor = wp.data.select( 'core/editor' );
562
563 if ( 'function' !== typeof editor.__unstableIsEditorReady ) {
564 closeListener();
565 return;
566 }
567
568 const isReady = editor.__unstableIsEditorReady();
569 if ( isReady ) {
570 closeListener();
571 requestAnimationFrame( () => injectFormidableBlock() );
572 }
573 }
574 );
575 }
576
577 document.addEventListener( 'DOMContentLoaded', handleDomReady );
578
579 const injectFormidableBlock = () => {
580 insertedBlock = wp.blocks.createBlock(
581 'formidable/simple-form',
582 {
583 formId: '<?php echo absint( $form_id ); ?>'
584 }
585 );
586
587 const getBlocks = () => wp.data.select( 'core/editor' ).getBlocks();
588 const blockList = getBlocks();
589
590 const closeListener = wp.data.subscribe(
591 () => {
592 const currentBlocks = getBlocks();
593 if ( currentBlocks === blockList ) {
594 return;
595 }
596
597 closeListener();
598 const block = currentBlocks[ currentBlocks.length - 1 ];
599 const interval = setInterval(
600 () => {
601 const scrollTarget = document.getElementById( 'block-' + block.clientId );
602 const form = scrollTarget.querySelector( 'form' );
603 if ( form ) {
604 scrollTarget.scrollIntoView({ behavior: 'smooth' });
605 clearInterval( interval );
606 }
607 },
608 50
609 );
610 }
611 );
612
613 wp.data.dispatch( 'core/block-editor' ).insertBlocks( insertedBlock );
614 };
615 }() );
616 </script>
617 <?php
618 }
619
620 public static function load_lang() {
621 load_plugin_textdomain( 'formidable', false, FrmAppHelper::plugin_folder() . '/languages/' );
622 }
623
624 /**
625 * Check if the styles are updated when a form is loaded on the front-end
626 *
627 * @since 3.0.1
628 */
629 public static function maybe_update_styles() {
630 if ( self::needs_update() ) {
631 self::network_upgrade_site();
632 }
633 }
634
635 /**
636 * @since 3.0
637 */
638 public static function create_rest_routes() {
639 $args = array(
640 'methods' => 'GET',
641 'callback' => 'FrmAppController::api_install',
642 'permission_callback' => __CLASS__ . '::can_update_db',
643 );
644
645 register_rest_route( 'frm-admin/v1', '/install', $args );
646
647 $args = array(
648 'methods' => 'GET',
649 'callback' => 'FrmAddonsController::install_addon_api',
650 'permission_callback' => 'FrmAddonsController::can_install_addon_api',
651 );
652
653 register_rest_route( 'frm-admin/v1', '/install-addon', $args );
654 }
655
656 /**
657 * Make sure the install is only being run when we tell it to.
658 * We don't want to run manually by people calling the API.
659 *
660 * @since 4.06.02
661 */
662 public static function can_update_db() {
663 return get_transient( 'frm_updating_api' );
664 }
665
666 /**
667 * Run silent upgrade on each site in the network during a network upgrade.
668 * Update database settings for all sites in a network during network upgrade process.
669 *
670 * @since 2.0.1
671 *
672 * @param int $blog_id Blog ID.
673 */
674 public static function network_upgrade_site( $blog_id = 0 ) {
675 // Flag to check if install is happening as intended.
676 set_transient( 'frm_updating_api', true, MINUTE_IN_SECONDS );
677 $request = new WP_REST_Request( 'GET', '/frm-admin/v1/install' );
678
679 self::maybe_add_wp_site_health();
680
681 if ( $blog_id ) {
682 switch_to_blog( $blog_id );
683 $response = rest_do_request( $request );
684 restore_current_blog();
685 } else {
686 $response = rest_do_request( $request );
687 }
688
689 if ( $response->is_error() ) {
690 // if the remove post fails, use javascript instead
691 add_action( 'admin_notices', 'FrmAppController::install_js_fallback' );
692 }
693 }
694
695 /**
696 * Make sure WP_Site_Health has been included because it is required when calling rest_do_request.
697 * Check first that the file exists because WP_Site_Health was only introduced in WordPress 5.2.
698 */
699 private static function maybe_add_wp_site_health() {
700 if ( ! class_exists( 'WP_Site_Health' ) ) {
701 $wp_site_health_path = ABSPATH . 'wp-admin/includes/class-wp-site-health.php';
702 if ( file_exists( $wp_site_health_path ) ) {
703 require_once $wp_site_health_path;
704 }
705 }
706 }
707
708 /**
709 * @since 3.0
710 */
711 public static function api_install() {
712 delete_transient( 'frm_updating_api' );
713 if ( self::needs_update() ) {
714 $running = get_option( 'frm_install_running' );
715 if ( false === $running || $running < strtotime( '-5 minutes' ) ) {
716 update_option( 'frm_install_running', time(), 'no' );
717 self::install();
718 delete_option( 'frm_install_running' );
719 }
720 }
721
722 return true;
723 }
724
725 /**
726 * Silent database upgrade (no redirect).
727 * Called via ajax request during network upgrade process.
728 *
729 * @since 2.0.1
730 */
731 public static function ajax_install() {
732 self::api_install();
733 wp_die();
734 }
735
736 public static function install() {
737 $frmdb = new FrmMigrate();
738 $frmdb->upgrade();
739 }
740
741 public static function uninstall() {
742 FrmAppHelper::permission_check( 'administrator' );
743 check_ajax_referer( 'frm_ajax', 'nonce' );
744
745 $frmdb = new FrmMigrate();
746 $frmdb->uninstall();
747
748 //disable the plugin and redirect after uninstall so the tables don't get added right back
749 $plugins = array( FrmAppHelper::plugin_folder() . '/formidable.php', 'formidable-pro/formidable-pro.php' );
750 deactivate_plugins( $plugins, false, false );
751 echo esc_url_raw( admin_url( 'plugins.php?deactivate=true' ) );
752
753 wp_die();
754 }
755
756 public static function drop_tables( $tables ) {
757 global $wpdb;
758 $tables[] = $wpdb->prefix . 'frm_fields';
759 $tables[] = $wpdb->prefix . 'frm_forms';
760 $tables[] = $wpdb->prefix . 'frm_items';
761 $tables[] = $wpdb->prefix . 'frm_item_metas';
762
763 return $tables;
764 }
765
766 public static function deauthorize() {
767 FrmAppHelper::permission_check( 'frm_change_settings' );
768 check_ajax_referer( 'frm_ajax', 'nonce' );
769
770 delete_option( 'frmpro-credentials' );
771 delete_option( 'frmpro-authorized' );
772 delete_site_option( 'frmpro-credentials' );
773 delete_site_option( 'frmpro-authorized' );
774 wp_die();
775 }
776
777 public static function set_footer_text( $text ) {
778 if ( FrmAppHelper::is_formidable_admin() ) {
779 $text = '';
780 }
781
782 return $text;
783 }
784
785 /**
786 * Include icons on page for Embed Form modal.
787 *
788 * @since 5.2
789 *
790 * @return void
791 */
792 public static function include_embed_form_icons() {
793 require_once FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_embed_form_icons.php';
794 }
795
796 /**
797 * @deprecated 1.07.05
798 * @codeCoverageIgnore
799 */
800 public static function get_form_shortcode( $atts ) {
801 return FrmDeprecated::get_form_shortcode( $atts );
802 }
803
804 /**
805 * @deprecated 2.5.4
806 * @codeCoverageIgnore
807 */
808 public static function widget_text_filter( $content ) {
809 return FrmDeprecated::widget_text_filter( $content );
810 }
811
812 /**
813 * Deprecated in favor of wpmu_upgrade_site
814 *
815 * @deprecated 2.3
816 * @codeCoverageIgnore
817 */
818 public static function front_head() {
819 FrmDeprecated::front_head();
820 }
821
822 /**
823 * @deprecated 3.0.04
824 * @codeCoverageIgnore
825 */
826 public static function activation_install() {
827 FrmDeprecated::activation_install();
828 }
829
830 /**
831 * @deprecated 3.0
832 * @codeCoverageIgnore
833 */
834 public static function page_route( $content ) {
835 return FrmDeprecated::page_route( $content );
836 }
837 }
838