PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.10.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.10.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 / Core / Hooks / Hooks.php

Hooks.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.10.1, at includes/Core/Hooks/Hooks.php

156 lines 5.7 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\Core\Hooks;
4
5 use BitCode\BitForm\Admin\Admin_Bar;
6 use BitCode\BitForm\API\Route\Routes;
7 use BitCode\BitForm\Core\Ajax\AjaxService;
8 use BitCode\BitForm\Core\Capability\Request;
9 use BitCode\BitForm\Core\Database\FormModel;
10 use BitCode\BitForm\Core\Fallback\FormFallback;
11 use BitCode\BitForm\Core\Form\FormHandler;
12 use BitCode\BitForm\Core\Integration\Integrations;
13 use BitCode\BitForm\Core\Util\FileDownloadProvider;
14 use BitCode\BitForm\Core\Util\GutenBlockProvider;
15 use BitCode\BitForm\Core\Util\Utilities;
16 use BitCode\BitForm\Frontend\ConversationalFormView;
17 use BitCode\BitForm\Frontend\StandaloneFormView;
18
19 class Hooks
20 {
21 public static function init_hooks()
22 {
23 add_action('init', [PostType::class, 'registerBitformsPostType']);
24 add_action('init', [PostType::class, 'registerCustomPostType']);
25 add_action('bitforms_exec_integrations', [Integrations::class, 'integrationExecutionHelper'], 1, 5);
26 add_action('init', [Hooks::class, 'localization_setup']);
27 add_action('init', [Hooks::class, 'init_classes']);
28 add_action('init', [Hooks::class, 'versionUpdateRunFallbacks']);
29 add_action('rest_api_init', [Hooks::class, 'registerRoutes']);
30 add_filter('plugin_action_links_' . plugin_basename(BITFORMS_PLUGIN_MAIN_FILE), [Hooks::class, 'plugin_action_links']);
31 add_action('bitform_dequeue_scripts', [Hooks::class, 'dequeueScripts'], 1000, 100);
32 add_action('bitform_dequeue_styles', [Hooks::class, 'dequeueStyles'], 1000, 100);
33 add_action('init', [ConversationalFormView::class, 'conversationalFormView']);
34 add_action('init', [StandaloneFormView::class, 'standaloneFormView']);
35 // add_action('wp_footer', [Hooks::class, 'updateBitFormVersion'], 9999, 0);
36 }
37
38 public static function updateBitFormVersion()
39 {
40 $currentBitFormVersion = BITFORMS_VERSION;
41 $installedBitFormVersion = get_option('bitforms_version');
42 if ($currentBitFormVersion !== $installedBitFormVersion) {
43 (new FormFallback())->resetJsGeneratedPageIds();
44 update_option('bitforms_version', $currentBitFormVersion);
45 }
46 }
47
48 public static function registerRoutes()
49 {
50 $routes = new Routes();
51 $routes->register_routes();
52 }
53
54 public static function isGeneratedScript($postId, $oldPost, $updatedPost)
55 {
56 $oldContent = $oldPost->post_content;
57 $updatedContent = $updatedPost->post_content;
58 $oldShortCodeMatch = \preg_match_all("/\[bitform\s+id\s*=\s*('|\")\s*(\d+)\s*('|\")\]/", $oldContent, $oldShortCodes);
59 $updatedShortCodeMatch = \preg_match_all("/\[bitform\s+id\s*=\s*('|\")\s*(\d+)\s*('|\")\]/", $updatedContent, $updatedShortCodes);
60
61 if ($oldShortCodeMatch && $updatedShortCodeMatch) {
62 $oldShortCodes = $oldShortCodes[2];
63 $updatedShortCodes = $updatedShortCodes[2];
64
65 $checkEqualArray = array_diff($oldShortCodes, $updatedShortCodes);
66
67 if (!empty($checkEqualArray)) {
68 $formModel = new FormModel();
69 $value = "%$postId%";
70 $condtions = [
71 'generated_script_page_ids' => ['operator' => 'LIKE', 'value' => $value],
72 ];
73 $forms = $formModel->get('generated_script_page_ids,id', $condtions);
74 foreach ($forms as $form) {
75 $pageIds = json_decode($form->generated_script_page_ids);
76 if (property_exists($pageIds, $postId)) {
77 unset($pageIds->{$postId});
78 $formModel->update(['generated_script_page_ids' => \wp_json_encode($pageIds)], ['id' => $form->id]);
79 }
80 }
81 }
82 }
83 }
84
85 public static function localization_setup()
86 {
87 load_plugin_textdomain('bit-form', false, dirname(BITFORMS_PLUGIN_BASENAME) . '/languages');
88 }
89
90 public static function init_classes()
91 {
92 if (Request::Check('admin')) {
93 (new Admin_Bar())->register();
94 }
95 if (Request::Check('ajax')) {
96 new AjaxService();
97 }
98 if (Request::Check('frontend')) {
99 $formHandler = new FormHandler();
100 $formHandler->frontend;
101 }
102 if (Request::isPluginPage()) {
103 (new FileDownloadProvider())->register();
104 }
105 if (current_user_can('edit_posts')) {
106 (new GutenBlockProvider())->register();
107 }
108 include BITFORMS_PLUGIN_DIR_PATH . 'includes' . DIRECTORY_SEPARATOR . 'Frontend' . DIRECTORY_SEPARATOR . 'InitRoutes.php';
109 }
110
111 public static function versionUpdateRunFallbacks()
112 {
113 $dir = BITFORMS_PLUGIN_DIR_PATH . 'includes' . DIRECTORY_SEPARATOR . 'Core' . DIRECTORY_SEPARATOR . 'Fallback';
114 if (is_dir($dir) && is_file($dir . DIRECTORY_SEPARATOR . 'Init.php')) {
115 include $dir . DIRECTORY_SEPARATOR . 'Init.php';
116 }
117 }
118
119 public static function plugin_action_links($links)
120 {
121 $links[] = '<a href="https://docs.form.bitapps.pro" target="_blank">' . __('Docs') . '</a>';
122 if (!Utilities::isPro()) {
123 $links[] = '<a href="https://www.bitapps.pro/bit-form" target="_blank">' . __('Upgrade to Pro') . '</a>';
124 }
125 return $links;
126 }
127
128 public static function dequeueScripts(...$formIds)
129 {
130 foreach ($formIds as $formId) {
131 wp_deregister_script("bitform-script-{$formId}");
132 wp_dequeue_script("bitform-script-{$formId}");
133 }
134 global $bitform_dequeued_scripts;
135 if (!is_array($bitform_dequeued_scripts)) {
136 $bitform_dequeued_scripts = [];
137 }
138 $bitform_dequeued_scripts = array_merge($bitform_dequeued_scripts, $formIds);
139 }
140
141 public static function dequeueStyles(...$formIds)
142 {
143 foreach ($formIds as $formId) {
144 wp_deregister_style("bitform-style-{$formId}");
145 wp_dequeue_style("bitform-style-{$formId}");
146 wp_deregister_style("bitform-style-{$formId}-formid");
147 wp_dequeue_style("bitform-style-{$formId}-formid");
148 }
149 global $bitform_dequeued_styles;
150 if (!is_array($bitform_dequeued_styles)) {
151 $bitform_dequeued_styles = [];
152 }
153 $bitform_dequeued_styles = array_merge($bitform_dequeued_styles, $formIds);
154 }
155 }
156