PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 1.0.3
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v1.0.3
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.0.3, at includes/Plugin.php

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