PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.2.02
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.2.02
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.02, at classes/controllers/FrmAppController.php

837 lines 23.4 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( 'popper', FrmAppHelper::plugin_url() . '/js/popper.min.js', array( 'jquery' ), '1.16.0', true );
465 wp_register_script( 'bootstrap_tooltip', FrmAppHelper::plugin_url() . '/js/bootstrap.min.js', array( 'jquery', 'popper' ), '4.6.1', true );
466 wp_register_style( 'formidable-grids', FrmAppHelper::plugin_url() . '/css/frm_grids.css', array(), $version );
467
468 if ( 'formidable' === FrmAppHelper::simple_get( 'page', 'sanitize_title' ) ) {
469 $action = FrmAppHelper::get_param( 'frm_action', '', 'sanitize_title' );
470 $is_form_index = ! $action || in_array( $action, array( 'list', 'trash' ), true );
471 if ( $is_form_index ) {
472 // For the existing page dropdown in the Form embed modal.
473 wp_enqueue_script( 'jquery-ui-autocomplete' );
474 }
475 }
476
477 wp_register_script( 'bootstrap-multiselect', FrmAppHelper::plugin_url() . '/js/bootstrap-multiselect.js', array( 'jquery', 'bootstrap_tooltip', 'popper' ), '1.1.1', true );
478
479 $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
480 $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' );
481
482 global $pagenow;
483 if ( strpos( $page, 'formidable' ) === 0 || ( $pagenow === 'edit.php' && $post_type === 'frm_display' ) ) {
484
485 wp_enqueue_script( 'admin-widgets' );
486 wp_enqueue_style( 'widgets' );
487 wp_enqueue_script( 'formidable_admin' );
488 FrmAppHelper::localize_script( 'admin' );
489
490 wp_enqueue_style( 'formidable-admin' );
491 if ( 'formidable-styles' !== $page && 'formidable-styles2' !== $page ) {
492 wp_enqueue_style( 'formidable-grids' );
493 wp_enqueue_style( 'formidable-dropzone' );
494 } else {
495 wp_enqueue_style( 'formidable-grids' );
496 }
497
498 if ( 'formidable-entries' === $page ) {
499 // Load front end js for entries.
500 wp_enqueue_script( 'formidable' );
501 }
502
503 do_action( 'frm_enqueue_builder_scripts' );
504 self::include_upgrade_overlay();
505 self::include_info_overlay();
506 } elseif ( FrmAppHelper::is_view_builder_page() ) {
507 if ( isset( $_REQUEST['post_type'] ) ) {
508 $post_type = sanitize_title( wp_unslash( $_REQUEST['post_type'] ) );
509 } elseif ( isset( $_REQUEST['post'] ) && absint( $_REQUEST['post'] ) ) {
510 $post = get_post( absint( wp_unslash( $_REQUEST['post'] ) ) );
511 if ( ! $post ) {
512 return;
513 }
514 $post_type = $post->post_type;
515 } else {
516 return;
517 }
518
519 if ( $post_type === 'frm_display' ) {
520 wp_enqueue_style( 'formidable-grids' );
521 wp_enqueue_script( 'jquery-ui-draggable' );
522 wp_enqueue_script( 'formidable_admin' );
523 wp_enqueue_style( 'formidable-admin' );
524 FrmAppHelper::localize_script( 'admin' );
525 self::include_info_overlay();
526 }
527 }
528
529 self::maybe_force_formidable_block_on_gutenberg_page();
530 }
531
532 /**
533 * Automatically insert a Formidable block when loading Gutenberg with a $_GET['frmForm'] value set.
534 *
535 * @since 5.2
536 *
537 * @return void
538 */
539 private static function maybe_force_formidable_block_on_gutenberg_page() {
540 global $pagenow;
541 if ( 'post.php' !== $pagenow ) {
542 return;
543 }
544
545 $form_id = FrmAppHelper::simple_get( 'frmForm', 'absint' );
546 if ( ! $form_id ) {
547 return;
548 }
549
550 ?>
551 <script>
552 ( function() {
553 const handleDomReady = () => {
554 if ( 'undefined' === typeof wp || 'undefined' === typeof wp.data || 'function' !== typeof wp.data.subscribe ) {
555 return;
556 }
557
558 const closeListener = wp.data.subscribe(
559 () => {
560 const editor = wp.data.select( 'core/editor' );
561
562 if ( 'function' !== typeof editor.__unstableIsEditorReady ) {
563 closeListener();
564 return;
565 }
566
567 const isReady = editor.__unstableIsEditorReady();
568 if ( isReady ) {
569 closeListener();
570 requestAnimationFrame( () => injectFormidableBlock() );
571 }
572 }
573 );
574 }
575
576 document.addEventListener( 'DOMContentLoaded', handleDomReady );
577
578 const injectFormidableBlock = () => {
579 insertedBlock = wp.blocks.createBlock(
580 'formidable/simple-form',
581 {
582 formId: '<?php echo absint( $form_id ); ?>'
583 }
584 );
585
586 const getBlocks = () => wp.data.select( 'core/editor' ).getBlocks();
587 const blockList = getBlocks();
588
589 const closeListener = wp.data.subscribe(
590 () => {
591 const currentBlocks = getBlocks();
592 if ( currentBlocks === blockList ) {
593 return;
594 }
595
596 closeListener();
597 const block = currentBlocks[ currentBlocks.length - 1 ];
598 const interval = setInterval(
599 () => {
600 const scrollTarget = document.getElementById( 'block-' + block.clientId );
601 const form = scrollTarget.querySelector( 'form' );
602 if ( form ) {
603 scrollTarget.scrollIntoView({ behavior: 'smooth' });
604 clearInterval( interval );
605 }
606 },
607 50
608 );
609 }
610 );
611
612 wp.data.dispatch( 'core/block-editor' ).insertBlocks( insertedBlock );
613 };
614 }() );
615 </script>
616 <?php
617 }
618
619 public static function load_lang() {
620 load_plugin_textdomain( 'formidable', false, FrmAppHelper::plugin_folder() . '/languages/' );
621 }
622
623 /**
624 * Check if the styles are updated when a form is loaded on the front-end
625 *
626 * @since 3.0.1
627 */
628 public static function maybe_update_styles() {
629 if ( self::needs_update() ) {
630 self::network_upgrade_site();
631 }
632 }
633
634 /**
635 * @since 3.0
636 */
637 public static function create_rest_routes() {
638 $args = array(
639 'methods' => 'GET',
640 'callback' => 'FrmAppController::api_install',
641 'permission_callback' => __CLASS__ . '::can_update_db',
642 );
643
644 register_rest_route( 'frm-admin/v1', '/install', $args );
645
646 $args = array(
647 'methods' => 'GET',
648 'callback' => 'FrmAddonsController::install_addon_api',
649 'permission_callback' => 'FrmAddonsController::can_install_addon_api',
650 );
651
652 register_rest_route( 'frm-admin/v1', '/install-addon', $args );
653 }
654
655 /**
656 * Make sure the install is only being run when we tell it to.
657 * We don't want to run manually by people calling the API.
658 *
659 * @since 4.06.02
660 */
661 public static function can_update_db() {
662 return get_transient( 'frm_updating_api' );
663 }
664
665 /**
666 * Run silent upgrade on each site in the network during a network upgrade.
667 * Update database settings for all sites in a network during network upgrade process.
668 *
669 * @since 2.0.1
670 *
671 * @param int $blog_id Blog ID.
672 */
673 public static function network_upgrade_site( $blog_id = 0 ) {
674 // Flag to check if install is happening as intended.
675 set_transient( 'frm_updating_api', true, MINUTE_IN_SECONDS );
676 $request = new WP_REST_Request( 'GET', '/frm-admin/v1/install' );
677
678 self::maybe_add_wp_site_health();
679
680 if ( $blog_id ) {
681 switch_to_blog( $blog_id );
682 $response = rest_do_request( $request );
683 restore_current_blog();
684 } else {
685 $response = rest_do_request( $request );
686 }
687
688 if ( $response->is_error() ) {
689 // if the remove post fails, use javascript instead
690 add_action( 'admin_notices', 'FrmAppController::install_js_fallback' );
691 }
692 }
693
694 /**
695 * Make sure WP_Site_Health has been included because it is required when calling rest_do_request.
696 * Check first that the file exists because WP_Site_Health was only introduced in WordPress 5.2.
697 */
698 private static function maybe_add_wp_site_health() {
699 if ( ! class_exists( 'WP_Site_Health' ) ) {
700 $wp_site_health_path = ABSPATH . 'wp-admin/includes/class-wp-site-health.php';
701 if ( file_exists( $wp_site_health_path ) ) {
702 require_once $wp_site_health_path;
703 }
704 }
705 }
706
707 /**
708 * @since 3.0
709 */
710 public static function api_install() {
711 delete_transient( 'frm_updating_api' );
712 if ( self::needs_update() ) {
713 $running = get_option( 'frm_install_running' );
714 if ( false === $running || $running < strtotime( '-5 minutes' ) ) {
715 update_option( 'frm_install_running', time(), 'no' );
716 self::install();
717 delete_option( 'frm_install_running' );
718 }
719 }
720
721 return true;
722 }
723
724 /**
725 * Silent database upgrade (no redirect).
726 * Called via ajax request during network upgrade process.
727 *
728 * @since 2.0.1
729 */
730 public static function ajax_install() {
731 self::api_install();
732 wp_die();
733 }
734
735 public static function install() {
736 $frmdb = new FrmMigrate();
737 $frmdb->upgrade();
738 }
739
740 public static function uninstall() {
741 FrmAppHelper::permission_check( 'administrator' );
742 check_ajax_referer( 'frm_ajax', 'nonce' );
743
744 $frmdb = new FrmMigrate();
745 $frmdb->uninstall();
746
747 //disable the plugin and redirect after uninstall so the tables don't get added right back
748 $plugins = array( FrmAppHelper::plugin_folder() . '/formidable.php', 'formidable-pro/formidable-pro.php' );
749 deactivate_plugins( $plugins, false, false );
750 echo esc_url_raw( admin_url( 'plugins.php?deactivate=true' ) );
751
752 wp_die();
753 }
754
755 public static function drop_tables( $tables ) {
756 global $wpdb;
757 $tables[] = $wpdb->prefix . 'frm_fields';
758 $tables[] = $wpdb->prefix . 'frm_forms';
759 $tables[] = $wpdb->prefix . 'frm_items';
760 $tables[] = $wpdb->prefix . 'frm_item_metas';
761
762 return $tables;
763 }
764
765 public static function deauthorize() {
766 FrmAppHelper::permission_check( 'frm_change_settings' );
767 check_ajax_referer( 'frm_ajax', 'nonce' );
768
769 delete_option( 'frmpro-credentials' );
770 delete_option( 'frmpro-authorized' );
771 delete_site_option( 'frmpro-credentials' );
772 delete_site_option( 'frmpro-authorized' );
773 wp_die();
774 }
775
776 public static function set_footer_text( $text ) {
777 if ( FrmAppHelper::is_formidable_admin() ) {
778 $text = '';
779 }
780
781 return $text;
782 }
783
784 /**
785 * Include icons on page for Embed Form modal.
786 *
787 * @since 5.2
788 *
789 * @return void
790 */
791 public static function include_embed_form_icons() {
792 require_once FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_embed_form_icons.php';
793 }
794
795 /**
796 * @deprecated 1.07.05
797 * @codeCoverageIgnore
798 */
799 public static function get_form_shortcode( $atts ) {
800 return FrmDeprecated::get_form_shortcode( $atts );
801 }
802
803 /**
804 * @deprecated 2.5.4
805 * @codeCoverageIgnore
806 */
807 public static function widget_text_filter( $content ) {
808 return FrmDeprecated::widget_text_filter( $content );
809 }
810
811 /**
812 * Deprecated in favor of wpmu_upgrade_site
813 *
814 * @deprecated 2.3
815 * @codeCoverageIgnore
816 */
817 public static function front_head() {
818 FrmDeprecated::front_head();
819 }
820
821 /**
822 * @deprecated 3.0.04
823 * @codeCoverageIgnore
824 */
825 public static function activation_install() {
826 FrmDeprecated::activation_install();
827 }
828
829 /**
830 * @deprecated 3.0
831 * @codeCoverageIgnore
832 */
833 public static function page_route( $content ) {
834 return FrmDeprecated::page_route( $content );
835 }
836 }
837