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

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