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

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