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 / helpers / FrmFormMigratorsHelper.php

FrmFormMigratorsHelper.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 5.4, at classes/helpers/FrmFormMigratorsHelper.php

162 lines 4.9 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 FrmFormMigratorsHelper {
7
8 private static function is_dismissed( $form, $dismissed = null ) {
9 if ( $dismissed === null ) {
10 $dismissed = get_option( 'frm_dismissed' );
11 }
12
13 if ( ! empty( $dismissed ) && in_array( $form['class'], $dismissed ) ) {
14 return true;
15 }
16
17 return false;
18 }
19
20 public static function maybe_show_download_link() {
21 $forms = self::import_links();
22 foreach ( $forms as $form ) {
23 if ( ! self::is_dismissed( $form ) ) {
24 self::install_banner( $form );
25 } else {
26 echo '<span>';
27 self::install_button( $form, 'auto' );
28 echo '</span>';
29 }
30 }
31 }
32
33 /**
34 * @since 4.05
35 */
36 public static function maybe_add_to_inbox() {
37 $inbox = new FrmInbox();
38 $forms = self::import_links();
39
40 foreach ( $forms as $form ) {
41 $inbox->add_message(
42 array(
43 'key' => $form['class'],
44 'subject' => 'You have new importable forms',
45 'message' => 'Did you know you can import your forms created in ' . esc_html( $form['name'] ) . '?',
46 'cta' => '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-import' ) ) . '" class="button-primary frm-button-primary">' . esc_html__( 'Learn More', 'formidable' ) . '</a>',
47 'icon' => 'frm_cloud_upload_solid_icon',
48 'type' => 'news',
49 )
50 );
51 }
52 }
53
54 private static function import_links() {
55 if ( ! current_user_can( 'activate_plugins' ) ) {
56 return array();
57 }
58
59 $forms = array();
60 foreach ( self::importable_forms() as $form ) {
61 if ( class_exists( $form['class'] ) || ! is_plugin_active( $form['plugin'] ) ) {
62 // Either the importer is installed or the source plugin isn't.
63 continue;
64 }
65
66 $installer = new FrmInstallPlugin( array( 'plugin_file' => $form['importer'] ) );
67 $form['installed'] = $installer->is_installed();
68 $form['link'] = $installer->get_activate_link();
69
70 $forms[] = $form;
71 }
72 return $forms;
73 }
74
75 private static function importable_forms() {
76 return array(
77 'gf' => array(
78 'class' => 'FrmGravityImporter',
79 'plugin' => 'gravityforms/gravityforms.php',
80 'importer' => 'formidable-gravity-forms-importer/formidable-gravity-forms-importer.php',
81 'name' => 'Gravity Forms',
82 'package' => 'https://downloads.wordpress.org/plugin/formidable-gravity-forms-importer.zip',
83 ),
84 'pf' => array(
85 'class' => 'FrmPirateImporter',
86 'plugin' => 'pirate-forms/pirate-forms.php',
87 'importer' => 'formidable-import-pirate-forms/pf-to-frm.php',
88 'name' => 'Pirate Forms',
89 'package' => 'https://downloads.wordpress.org/plugin/formidable-import-pirate-forms.zip',
90 ),
91 );
92 }
93
94 private static function install_banner( $install ) {
95 if ( empty( $install['link'] ) ) {
96 return '';
97 }
98
99 ?>
100 <div class="frm-feature-banner">
101 <a href="#" class="dismiss alignright" id="<?php echo esc_attr( $install['class'] ); ?>" title="<?php esc_attr_e( 'Dismiss this message', 'formidable' ); ?>">
102 <?php FrmAppHelper::icon_by_class( 'frmfont frm_close_icon', array( 'aria-label' => 'Dismiss' ) ); ?>
103 </a>
104 <div class="frm-big-icon">
105 <?php FrmAppHelper::icon_by_class( 'frmfont frm_cloud_upload_solid_icon', array( 'aria-label' => 'Import' ) ); ?>
106 </div>
107 <p>Did you know you can import your forms created in <?php echo esc_html( $install['name'] ); ?>?</p>
108 <?php self::install_button( $install ); ?>
109 </div>
110 <?php
111 }
112
113 private static function install_button( $install, $label = '' ) {
114 $primary = 'button-secondary frm-button-secondary ';
115
116 if ( empty( $label ) ) {
117 $label = __( 'Get Started', 'formidable' );
118 $primary = 'button-primary frm-button-primary ';
119 }
120
121 if ( $install['installed'] ) {
122 ?>
123 <a rel="<?php echo esc_attr( $install['importer'] ); ?>" class="button frm-activate-addon <?php echo esc_attr( $primary . ( empty( $install['link'] ) ? 'frm_hidden' : '' ) ); ?>">
124 <?php
125 if ( $label === 'auto' ) {
126 /* translators: %s: Name of the plugin */
127 $label = sprintf( __( 'Activate %s', 'formidable' ), $install['name'] );
128 }
129 } else {
130 ?>
131 <a rel="<?php echo esc_attr( $install['package'] ); ?>" class="frm-install-addon button <?php echo esc_attr( $primary ); ?>" aria-label="<?php esc_attr_e( 'Install', 'formidable' ); ?>">
132 <?php
133 if ( $label === 'auto' ) {
134 /* translators: %s: Name of the plugin */
135 $label = sprintf( __( 'Install %s Importer', 'formidable' ), $install['name'] );
136 }
137 }
138 ?>
139 <?php echo esc_html( $label ); ?>
140 </a>
141 <?php
142 }
143
144 public static function dismiss_migrator() {
145 check_ajax_referer( 'frm_ajax', 'nonce' );
146 $dismissed = get_option( 'frm_dismissed' );
147 if ( empty( $dismissed ) ) {
148 $dismissed = array();
149 }
150 $dismissed[] = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
151 update_option( 'frm_dismissed', array_filter( $dismissed ), 'no' );
152 wp_die();
153 }
154
155 /**
156 * @deprecated 4.05
157 */
158 public static function notification_count() {
159 _deprecated_function( __METHOD__, '4.05' );
160 }
161 }
162