PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 1.1.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v1.1.1
V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 2.10.2 All 137 releases
bit-form / includes / Plugin.php

Plugin.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 1.1.1, at includes/Plugin.php

213 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm;
4
5 /**
6 * Main class for the plugin.
7 *
8 * @since 1.0.0-alpha
9 */
10
11 use BitCode\BitForm\Admin\Admin_Bar;
12 use BitCode\BitForm\Core\Database\DB;
13 use BitCode\BitForm\Core\Util\Activation;
14 use BitCode\BitForm\Core\Form\FormHandler;
15 use BitCode\BitForm\Core\Ajax\AjaxService;
16 use BitCode\BitForm\Core\Util\Deactivation;
17 use BitCode\BitForm\Core\Util\Uninstallation;
18 use BitCode\BitForm\Core\Capability\Request;
19 use BitCode\BitForm\Core\Util\GutenBlockProvider;
20 use BitCode\BitForm\Core\Integration\Integrations;
21 use BitCode\BitForm\Core\Util\FileDownloadProvider;
22 use BitCode\BitForm\Core\Fallback\FormEntryMetaChange;
23
24 final class Plugin
25 {
26
27 /**
28 * Main instance of the plugin.
29 *
30 * @since 1.0.0-alpha
31 * @var Plugin|null
32 */
33 private static $instance = null;
34
35
36 /**
37 * Registers the plugin with WordPress.
38 *
39 * @since 1.0.0-alpha
40 */
41 public function register()
42 {
43 add_action('plugins_loaded', array($this, 'init_plugin'));
44 (new Activation())->activate();
45 (new Deactivation())->register();
46 (new Uninstallation())->register();
47 }
48
49
50 /**
51 * Initialize the hooks
52 *
53 * @return void
54 */
55 public function init_hooks()
56 {
57 add_action('init', array($this, 'registerBitformsPostType'));
58 add_action("bitforms_exec_integrations", array(Integrations::class, 'integrationExecutionHelper'), 1, 5);
59 // Localize our plugin
60 add_action('init', array($this, 'localization_setup'));
61
62 // initialize the classes
63 add_action('init', array($this, 'init_classes'));
64
65 add_action('init', array($this, 'entryMetaKeyUpdate'));
66
67 add_filter('plugin_action_links_' . plugin_basename(BITFORMS_PLUGIN_MAIN_FILE), array($this, 'plugin_action_links'));
68 }
69
70 public function entryMetaKeyUpdate()
71 {
72 $installed = get_option('bitforms_installed');
73 $oldversion = null;
74 if ($installed) {
75 $oldversion = get_option('bitforms_version');
76 }
77 if ($oldversion && version_compare($oldversion, BITFORMS_VERSION, '!=')) {
78 update_option('bitforms_version', BITFORMS_VERSION);
79 if (version_compare('1.0.4', $oldversion, '>=')) {
80 // if version is lower or equal than 1.0.4
81 $formEntryMetaChange = new FormEntryMetaChange();
82 $formEntryMetaChange->changeMeta();
83 }
84 }
85 }
86
87 /**
88 * Updates bit form content tables on wp db
89 *
90 * @return void
91 */
92 public function update_tables()
93 {
94 if (!current_user_can('manage_options')) {
95 return;
96 }
97
98 global $bitforms_db_version;
99 $installed_db_version = get_site_option("bitforms_db_version");
100 if ($installed_db_version != $bitforms_db_version) {
101 DB::migrate();
102 }
103 }
104
105 /**
106 * Register post type for bitforms
107 *
108 * @return void
109 */
110 public function registerBitformsPostType()
111 {
112 $args = array(
113 'label' => __('Bitform Pages', 'bitform'),
114 'public' => true,
115 'show_ui' => true,
116 'show_in_menu' => false,
117 'capability_type' => 'page',
118 'hierarchical' => false,
119 'query_var' => false,
120 'supports' => array('title'),
121 'show_in_rest' => false
122 );
123 register_post_type('bitforms', $args);
124 }
125
126 /**
127 * Initialize plugin for localization
128 *
129 * @uses load_plugin_textdomain()
130 */
131 public function localization_setup()
132 {
133 load_plugin_textdomain('bitform', false, dirname(BITFORMS_PLUGIN_BASENAME) . '/languages');
134 }
135
136 /**
137 * Instantiate the required classes
138 *
139 * @return void
140 */
141 public function init_classes()
142 {
143 if (Request::Check('admin')) {
144 (new Admin_Bar())->register();
145 }
146 if (Request::Check('ajax')) {
147 new AjaxService();
148 }
149 if (Request::Check('frontend')) {
150 $formHandler = new FormHandler();
151 $formHandler->frontend;
152 }
153 if (Request::isPluginPage()) {
154 (new FileDownloadProvider())->register();
155 }
156 if (current_user_can('edit_posts')) {
157 (new GutenBlockProvider())->register();
158 }
159 }
160
161 /**
162 * Plugin action links
163 *
164 * @param array $links
165 *
166 * @return array
167 */
168 public function plugin_action_links($links)
169 {
170 $links[] = '<a href="https://www.bitpress.pro" target="_blank">' . __('Docs', 'bitform') . '</a>';
171
172 return $links;
173 }
174
175
176 public function init_plugin()
177 {
178 $this->init_hooks();
179 $this->update_tables();
180 do_action('bitform_loaded');
181 }
182
183 /**
184 * Retrieves the main instance of the plugin.
185 *
186 * @since 1.0.0-alpha
187 *
188 * @return BITFORM Plugin main instance.
189 */
190 public static function instance()
191 {
192 return static::$instance;
193 }
194
195 /**
196 * Loads the plugin main instance and initializes it.
197 *
198 * @param string $main_file Absolute path to the plugin main file.
199 *
200 * @return bool True if the plugin main instance could be loaded, false otherwise.
201 */
202 public static function load($main_file)
203 {
204 if (null !== static::$instance) {
205 return false;
206 }
207
208 static::$instance = new static($main_file);
209 static::$instance->register();
210 return true;
211 }
212 }
213