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

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