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

871 lines 24.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 class 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 self::register_popper1();
463 wp_register_script( 'formidable_admin', FrmAppHelper::plugin_url() . '/js/formidable_admin.js', $dependecies, $version, true );
464 wp_register_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css', array(), $version );
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 self::maybe_deregister_popper2();
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 self::maybe_deregister_popper2();
524 wp_enqueue_script( 'formidable_admin' );
525 wp_enqueue_style( 'formidable-admin' );
526 FrmAppHelper::localize_script( 'admin' );
527 self::include_info_overlay();
528 }
529 }
530
531 self::maybe_force_formidable_block_on_gutenberg_page();
532 }
533
534 /**
535 * Fix a Duplicator Pro conflict because it uses Popper 2. See issue #3459.
536 *
537 * @since 5.2.02.01
538 *
539 * @return void
540 */
541 private static function maybe_deregister_popper2() {
542 global $wp_scripts;
543
544 if ( ! array_key_exists( 'popper', $wp_scripts->registered ) ) {
545 return;
546 }
547
548 $popper = $wp_scripts->registered['popper'];
549 if ( version_compare( $popper->ver, '2.0', '>=' ) ) {
550 wp_deregister_script( 'popper' );
551 self::register_popper1();
552 }
553 }
554
555 /**
556 * Register Popper required for Bootstrap 4.
557 *
558 * @since 5.2.02.01
559 *
560 * @return void
561 */
562 private static function register_popper1() {
563 wp_register_script( 'popper', FrmAppHelper::plugin_url() . '/js/popper.min.js', array( 'jquery' ), '1.16.0', true );
564 }
565
566 /**
567 * Automatically insert a Formidable block when loading Gutenberg with a $_GET['frmForm'] value set.
568 *
569 * @since 5.2
570 *
571 * @return void
572 */
573 private static function maybe_force_formidable_block_on_gutenberg_page() {
574 global $pagenow;
575 if ( 'post.php' !== $pagenow ) {
576 return;
577 }
578
579 $form_id = FrmAppHelper::simple_get( 'frmForm', 'absint' );
580 if ( ! $form_id ) {
581 return;
582 }
583
584 ?>
585 <script>
586 ( function() {
587 const handleDomReady = () => {
588 if ( 'undefined' === typeof wp || 'undefined' === typeof wp.data || 'function' !== typeof wp.data.subscribe ) {
589 return;
590 }
591
592 const closeListener = wp.data.subscribe(
593 () => {
594 const editor = wp.data.select( 'core/editor' );
595
596 if ( 'function' !== typeof editor.__unstableIsEditorReady ) {
597 closeListener();
598 return;
599 }
600
601 const isReady = editor.__unstableIsEditorReady();
602 if ( isReady ) {
603 closeListener();
604 requestAnimationFrame( () => injectFormidableBlock() );
605 }
606 }
607 );
608 }
609
610 document.addEventListener( 'DOMContentLoaded', handleDomReady );
611
612 const injectFormidableBlock = () => {
613 insertedBlock = wp.blocks.createBlock(
614 'formidable/simple-form',
615 {
616 formId: '<?php echo absint( $form_id ); ?>'
617 }
618 );
619
620 const getBlocks = () => wp.data.select( 'core/editor' ).getBlocks();
621 const blockList = getBlocks();
622
623 const closeListener = wp.data.subscribe(
624 () => {
625 const currentBlocks = getBlocks();
626 if ( currentBlocks === blockList ) {
627 return;
628 }
629
630 closeListener();
631 const block = currentBlocks[ currentBlocks.length - 1 ];
632 const interval = setInterval(
633 () => {
634 const scrollTarget = document.getElementById( 'block-' + block.clientId );
635 const form = scrollTarget.querySelector( 'form' );
636 if ( form ) {
637 scrollTarget.scrollIntoView({ behavior: 'smooth' });
638 clearInterval( interval );
639 }
640 },
641 50
642 );
643 }
644 );
645
646 wp.data.dispatch( 'core/block-editor' ).insertBlocks( insertedBlock );
647 };
648 }() );
649 </script>
650 <?php
651 }
652
653 public static function load_lang() {
654 load_plugin_textdomain( 'formidable', false, FrmAppHelper::plugin_folder() . '/languages/' );
655 }
656
657 /**
658 * Check if the styles are updated when a form is loaded on the front-end
659 *
660 * @since 3.0.1
661 */
662 public static function maybe_update_styles() {
663 if ( self::needs_update() ) {
664 self::network_upgrade_site();
665 }
666 }
667
668 /**
669 * @since 3.0
670 */
671 public static function create_rest_routes() {
672 $args = array(
673 'methods' => 'GET',
674 'callback' => 'FrmAppController::api_install',
675 'permission_callback' => __CLASS__ . '::can_update_db',
676 );
677
678 register_rest_route( 'frm-admin/v1', '/install', $args );
679
680 $args = array(
681 'methods' => 'GET',
682 'callback' => 'FrmAddonsController::install_addon_api',
683 'permission_callback' => 'FrmAddonsController::can_install_addon_api',
684 );
685
686 register_rest_route( 'frm-admin/v1', '/install-addon', $args );
687 }
688
689 /**
690 * Make sure the install is only being run when we tell it to.
691 * We don't want to run manually by people calling the API.
692 *
693 * @since 4.06.02
694 */
695 public static function can_update_db() {
696 return get_transient( 'frm_updating_api' );
697 }
698
699 /**
700 * Run silent upgrade on each site in the network during a network upgrade.
701 * Update database settings for all sites in a network during network upgrade process.
702 *
703 * @since 2.0.1
704 *
705 * @param int $blog_id Blog ID.
706 */
707 public static function network_upgrade_site( $blog_id = 0 ) {
708 // Flag to check if install is happening as intended.
709 set_transient( 'frm_updating_api', true, MINUTE_IN_SECONDS );
710 $request = new WP_REST_Request( 'GET', '/frm-admin/v1/install' );
711
712 self::maybe_add_wp_site_health();
713
714 if ( $blog_id ) {
715 switch_to_blog( $blog_id );
716 $response = rest_do_request( $request );
717 restore_current_blog();
718 } else {
719 $response = rest_do_request( $request );
720 }
721
722 if ( $response->is_error() ) {
723 // if the remove post fails, use javascript instead
724 add_action( 'admin_notices', 'FrmAppController::install_js_fallback' );
725 }
726 }
727
728 /**
729 * Make sure WP_Site_Health has been included because it is required when calling rest_do_request.
730 * Check first that the file exists because WP_Site_Health was only introduced in WordPress 5.2.
731 */
732 private static function maybe_add_wp_site_health() {
733 if ( ! class_exists( 'WP_Site_Health' ) ) {
734 $wp_site_health_path = ABSPATH . 'wp-admin/includes/class-wp-site-health.php';
735 if ( file_exists( $wp_site_health_path ) ) {
736 require_once $wp_site_health_path;
737 }
738 }
739 }
740
741 /**
742 * @since 3.0
743 */
744 public static function api_install() {
745 delete_transient( 'frm_updating_api' );
746 if ( self::needs_update() ) {
747 $running = get_option( 'frm_install_running' );
748 if ( false === $running || $running < strtotime( '-5 minutes' ) ) {
749 update_option( 'frm_install_running', time(), 'no' );
750 self::install();
751 delete_option( 'frm_install_running' );
752 }
753 }
754
755 return true;
756 }
757
758 /**
759 * Silent database upgrade (no redirect).
760 * Called via ajax request during network upgrade process.
761 *
762 * @since 2.0.1
763 */
764 public static function ajax_install() {
765 self::api_install();
766 wp_die();
767 }
768
769 public static function install() {
770 $frmdb = new FrmMigrate();
771 $frmdb->upgrade();
772 }
773
774 public static function uninstall() {
775 FrmAppHelper::permission_check( 'administrator' );
776 check_ajax_referer( 'frm_ajax', 'nonce' );
777
778 $frmdb = new FrmMigrate();
779 $frmdb->uninstall();
780
781 //disable the plugin and redirect after uninstall so the tables don't get added right back
782 $plugins = array( FrmAppHelper::plugin_folder() . '/formidable.php', 'formidable-pro/formidable-pro.php' );
783 deactivate_plugins( $plugins, false, false );
784 echo esc_url_raw( admin_url( 'plugins.php?deactivate=true' ) );
785
786 wp_die();
787 }
788
789 public static function drop_tables( $tables ) {
790 global $wpdb;
791 $tables[] = $wpdb->prefix . 'frm_fields';
792 $tables[] = $wpdb->prefix . 'frm_forms';
793 $tables[] = $wpdb->prefix . 'frm_items';
794 $tables[] = $wpdb->prefix . 'frm_item_metas';
795
796 return $tables;
797 }
798
799 public static function deauthorize() {
800 FrmAppHelper::permission_check( 'frm_change_settings' );
801 check_ajax_referer( 'frm_ajax', 'nonce' );
802
803 delete_option( 'frmpro-credentials' );
804 delete_option( 'frmpro-authorized' );
805 delete_site_option( 'frmpro-credentials' );
806 delete_site_option( 'frmpro-authorized' );
807 wp_die();
808 }
809
810 public static function set_footer_text( $text ) {
811 if ( FrmAppHelper::is_formidable_admin() ) {
812 $text = '';
813 }
814
815 return $text;
816 }
817
818 /**
819 * Include icons on page for Embed Form modal.
820 *
821 * @since 5.2
822 *
823 * @return void
824 */
825 public static function include_embed_form_icons() {
826 require_once FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_embed_form_icons.php';
827 }
828
829 /**
830 * @deprecated 1.07.05
831 * @codeCoverageIgnore
832 */
833 public static function get_form_shortcode( $atts ) {
834 return FrmDeprecated::get_form_shortcode( $atts );
835 }
836
837 /**
838 * @deprecated 2.5.4
839 * @codeCoverageIgnore
840 */
841 public static function widget_text_filter( $content ) {
842 return FrmDeprecated::widget_text_filter( $content );
843 }
844
845 /**
846 * Deprecated in favor of wpmu_upgrade_site
847 *
848 * @deprecated 2.3
849 * @codeCoverageIgnore
850 */
851 public static function front_head() {
852 FrmDeprecated::front_head();
853 }
854
855 /**
856 * @deprecated 3.0.04
857 * @codeCoverageIgnore
858 */
859 public static function activation_install() {
860 FrmDeprecated::activation_install();
861 }
862
863 /**
864 * @deprecated 3.0
865 * @codeCoverageIgnore
866 */
867 public static function page_route( $content ) {
868 return FrmDeprecated::page_route( $content );
869 }
870 }
871