PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.3.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.3.1
3.3.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 All 138 releases
← All changes | includes/Admin/Admin_Bar.php +433 -143 1.23.3.1 View file →
@@ -1,179 +1,469 @@
1 1 <?php
2 2
3 3 namespace BitCode\BitForm\Admin;
4 4
5 +if (!defined('ABSPATH')) {
6 + exit;
7 +}
8 +
5 9 /**
6 10 * The admin menu and page handler class
7 11 */
8 12
9 -use BitCode\BitForm\Core\Util\IpTool;
10 13 use BitCode\BitForm\Core\Form\FormHandler;
14 +use BitCode\BitForm\Core\Integration\IntegrationHandler;
15 +use BitCode\BitForm\Core\Integration\Integrations;
16 +use BitCode\BitForm\Core\Util\DateTimeHelper;
11 17 use BitCode\BitForm\Core\Util\FileDownloadProvider;
12 -use BitCode\BitForm\Core\Integration\IntegrationHandler;
18 +use BitCode\BitForm\Core\Util\IpTool;
19 +use BitCode\BitForm\Core\Util\Utilities;
20 +use WP_Admin_Bar;
13 21
14 22 class Admin_Bar
15 23 {
16 - public function register()
17 - {
18 - add_action('in_admin_header', array($this, 'AdminNotices'));
19 - add_action('admin_menu', array($this, 'AdminMenu'));
20 - add_action('admin_enqueue_scripts', array($this, 'AdminAssets'));
24 + private static $fonts_url = [
25 + // 'https://fonts.googleapis.com/css2?family=Outfit:wght@100;300;400;500;600;700&display=swap&family=Roboto:wght@300;400;500&display=swap',
26 + 'https://fonts.googleapis.com/css2?family=DM+Sans:wght@100;200;300;400;500;600;700&display=swap',
27 + 'https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap',
28 + ];
29 +
30 + public function register()
31 + {
32 + add_action('in_admin_header', [$this, 'AdminNotices']);
33 + add_action('admin_menu', [$this, 'AdminMenu']);
34 + add_action('admin_enqueue_scripts', [$this, 'AdminAssets']);
35 + add_filter('style_loader_tag', [$this, 'linkTagFilter'], 0, 3);
36 + add_filter('script_loader_tag', [$this, 'scriptTagFilter'], 0, 3);
37 + add_action('admin_bar_menu', [$this, 'AdminTopMenu'], 999);
38 + add_action('admin_enqueue_scripts', [$this, 'bitforms_enqueue_admin_styles']);
39 + }
40 +
41 + /**
42 + * Register the admin menu
43 + *
44 + * @return void
45 + */
46 + public function AdminMenu()
47 + {
48 + global $submenu;
49 +
50 + $capability = apply_filters('bitforms_form_access_capability', 'manage_options');
51 + $menuTitle = Utilities::isProLicensed() ? 'Bit Form Pro' : 'Bit Form';
52 + add_menu_page(
53 + __('Bit Form - Most advanced form builder and entries management plugin', 'bit-form'),
54 + $menuTitle,
55 + $capability,
56 + 'bitform',
57 + [$this, 'RootPage'],
58 + 'data:image/svg+xml;base64,' . base64_encode('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 163 163"><path fill="#fff" d="M106 0H57A57 57 0 000 57v49a57 57 0 0057 57h49a57 57 0 0057-57V57a57 57 0 00-57-57zM51 60v3l-1 59v12c0 5-3 8-8 6-2-1-3-4-3-6v-21-55a29 29 0 011-4 5 5 0 015-4h33a4 4 0 004-2c2-3 8-2 10-1a9 9 0 015 9 9 9 0 01-7 8c-3 1-6 0-9-3a3 3 0 00-1-1H51zm73 74c-6 5-12 6-20 6H72a8 8 0 01-4-1 5 5 0 01-2-6 5 5 0 015-3h35c11-1 20-10 21-20 0-11-8-20-18-23a6 6 0 00-1 0H78h-1v14l1 2h18a4 4 0 003-1c4-4 8-3 11-1 4 2 5 7 3 12-2 4-9 6-13 2a6 6 0 00-5-1H71c-3 0-5-2-5-6V82c0-4 1-5 5-6h17a21 21 0 0021-24c-1-9-8-16-16-18a25 25 0 00-6 0H46c-4 0-7-3-7-6s3-5 7-5h42a33 33 0 0132 23c2 11 0 20-6 29l-1 2 5 2c11 4 17 12 19 23 3 12-2 24-13 32z"/></svg>'),
59 + 56
60 + );
61 + if (current_user_can($capability)) {
62 + $entriesCount = '';
63 + // if (self::countUnreadEntries()) {
64 + // $entriesCount = ' <span class="update-plugins">' . self::countUnreadEntries() . '</span>';
65 + // }
66 +
67 + $submenu['bitform'][] = [__('All Forms', 'bit-form') . $entriesCount, $capability, 'admin.php?page=bitform#/'];
68 + $submenu['bitform'][] = [__('Form Templates', 'bit-form') . '<span class="bf-template-new-badge">New</span>', $capability, 'admin.php?page=bitform#/form-templates'];
69 + $submenu['bitform'][] = [__('App Settings', 'bit-form'), $capability, 'admin.php?page=bitform#/app-settings/general'];
70 + $submenu['bitform'][] = [__('Integrations', 'bit-form'), $capability, 'admin.php?page=bitform#/app-settings/integrations'];
71 + $submenu['bitform'][] = [__('SMTP', 'bit-form'), $capability, 'admin.php?page=bitform#/app-settings/smtp'];
72 + $submenu['bitform'][] = [__('PDF Setting', 'bit-form'), $capability, 'admin.php?page=bitform#/app-settings/pdf'];
73 + $submenu['bitform'][] = [__('CPT', 'bit-form'), $capability, 'admin.php?page=bitform#/app-settings/cpt'];
74 + $submenu['bitform'][] = [__('Bit Form API', 'bit-form'), $capability, 'admin.php?page=bitform#/app-settings/api'];
75 + $submenu['bitform'][] = [__('Payments', 'bit-form'), $capability, 'admin.php?page=bitform#/app-settings/payments'];
76 + $submenu['bitform'][] = [__('Doc & Support', 'bit-form'), $capability, 'admin.php?page=bitform#/doc-support'];
77 + if (!Utilities::isPro()) {
78 + $submenu['bitform'][] = ['<span class="bf-pro-btn">' . __('Get 74% OFF', 'bit-form') . '</span>', $capability, 'https://bit-form.com/#pricing', '_blank'];
79 + }
21 80 }
81 + }
22 82
83 + public function AdminTopMenu(WP_Admin_Bar $wp_admin_bar)
84 + {
85 + if (!(current_user_can('manage_options') || current_user_can('manage_bitform'))) {
86 + return;
87 + }
88 + $indicator = '';
89 + // if (self::countUnreadEntries()) {
90 + // $indicator = ' <div class="wp-core-ui wp-ui-notification bf-indicator-badge">' . self::countUnreadEntries() . '</div>';
91 + // }
23 92
24 - /**
25 - * Register the admin menu
26 - *
27 - * @return void
28 - */
29 - public function AdminMenu()
30 - {
31 - global $submenu;
93 + $wp_admin_bar->add_node([
94 + 'id' => 'bitform',
95 + 'title' => 'Bit Form' . $indicator,
96 + 'href' => admin_url('admin.php?page=bitform'),
97 + 'meta' => [
98 + 'class' => 'bitform-admin-bar',
99 + ],
100 + ]);
101 + $wp_admin_bar->add_node([
102 + 'id' => 'bitform-all-forms',
103 + 'parent' => 'bitform',
104 + 'title' => __('All Forms', 'bit-form') . $indicator,
105 + 'href' => admin_url('admin.php?page=bitform#/'),
106 + ]);
107 + $wp_admin_bar->add_node([
108 + 'id' => 'bitform-form-templates',
109 + 'parent' => 'bitform',
110 + 'title' => __('Form Templates', 'bit-form'),
111 + 'href' => admin_url('admin.php?page=bitform#/form-templates'),
112 + ]);
113 + $wp_admin_bar->add_node([
114 + 'id' => 'bitform-app-settings',
115 + 'parent' => 'bitform',
116 + 'title' => __('App Settings', 'bit-form'),
117 + 'href' => admin_url('admin.php?page=bitform#/app-settings/general'),
118 + ]);
119 + $wp_admin_bar->add_node([
120 + 'id' => 'bitform-smtp',
121 + 'parent' => 'bitform',
122 + 'title' => __('SMTP', 'bit-form'),
123 + 'href' => admin_url('admin.php?page=bitform#/app-settings/smtp'),
124 + ]);
125 + $wp_admin_bar->add_node([
126 + 'id' => 'bitform-pdf-setting',
127 + 'parent' => 'bitform',
128 + 'title' => __('PDF Setting', 'bit-form'),
129 + 'href' => admin_url('admin.php?page=bitform#/app-settings/pdf'),
130 + ]);
131 + $wp_admin_bar->add_node([
132 + 'id' => 'bitform-cpt',
133 + 'parent' => 'bitform',
134 + 'title' => __('CPT', 'bit-form'),
135 + 'href' => admin_url('admin.php?page=bitform#/app-settings/cpt'),
136 + ]);
137 + $wp_admin_bar->add_node([
138 + 'id' => 'bitform-api',
139 + 'parent' => 'bitform',
140 + 'title' => __('Bit Form API', 'bit-form'),
141 + 'href' => admin_url('admin.php?page=bitform#/app-settings/api'),
142 + ]);
143 + $wp_admin_bar->add_node([
144 + 'id' => 'bitform-payments',
145 + 'parent' => 'bitform',
146 + 'title' => __('Payments', 'bit-form'),
147 + 'href' => admin_url('admin.php?page=bitform#/app-settings/payments'),
148 + ]);
149 + }
32 150
151 + public function getAllPages()
152 + {
153 + $pages = get_pages(['post_status' => 'publish', 'sort_column' => 'post_date', 'sort_order' => 'desc']);
154 + $allPages = [];
155 + foreach ($pages as $pageKey => $pageDetails) {
156 + $allPages[$pageKey]['title'] = $pageDetails->post_title;
157 + $allPages[$pageKey]['url'] = get_page_link($pageDetails->ID);
158 + }
159 + return $allPages;
160 + }
33 161
34 - $capability = apply_filters('bitforms_form_access_capability', 'manage_options');
35 - add_menu_page(__('Bit Form - wordpress form builder and database management system', 'bitform'), 'Bit Form', $capability, 'bitform', array($this, 'RootPage'), 'data:image/svg+xml;base64,' . base64_encode('<svg xmlns="http://www.w3.org/2000/svg" data-name="Layer 1" viewBox="0 0 163 163"><defs/><path fill="#13233c" d="M106 0H57A57 57 0 000 57v49a57 57 0 0057 57h49a57 57 0 0057-57V57a57 57 0 00-57-57zM51 60v3l-1 59v12c0 5-3 8-8 6-2-1-3-4-3-6v-21-55a29 29 0 011-4 5 5 0 015-4h33a4 4 0 004-2c2-3 8-2 10-1a9 9 0 015 9 9 9 0 01-7 8c-3 1-6 0-9-3a3 3 0 00-1-1H51zm73 74c-6 5-12 6-20 6H72a8 8 0 01-4-1 5 5 0 01-2-6 5 5 0 015-3h35c11-1 20-10 21-20 0-11-8-20-18-23a6 6 0 00-1 0H78h-1v14l1 2h18a4 4 0 003-1c4-4 8-3 11-1 4 2 5 7 3 12-2 4-9 6-13 2a6 6 0 00-5-1H71c-3 0-5-2-5-6V82c0-4 1-5 5-6h17a21 21 0 0021-24c-1-9-8-16-16-18a25 25 0 00-6 0H46c-4 0-7-3-7-6s3-5 7-5h42a33 33 0 0132 23c2 11 0 20-6 29l-1 2 5 2c11 4 17 12 19 23 3 12-2 24-13 32z"/></svg>'), 56);
162 + /**
163 + * Load the asset libraries
164 + *
165 + * @return void
166 + */
167 + public function AdminAssets($current_screen)
168 + {
169 + if (false === strpos($current_screen, 'bitform')) {
170 + return;
171 + }
172 + $parsed_url = wp_parse_url(get_admin_url());
173 + $site_url = $parsed_url['scheme'] . '://' . $parsed_url['host'];
174 + $site_url .= empty($parsed_url['port']) ? null : ':' . $parsed_url['port'];
175 + $base_path_admin = str_replace($site_url, '', get_admin_url());
176 + // loading google fonts
177 + wp_enqueue_style('googleapis-BITFORM-PRECONNECT', 'https://fonts.googleapis.com', [], BITFORMS_VERSION, false);
178 + wp_enqueue_style('gstatic-BITFORM-PRECONNECT-CROSSORIGIN', 'https://fonts.gstatic.com', [], BITFORMS_VERSION, false);
179 + foreach (self::$fonts_url as $i => $font_url) {
180 + wp_enqueue_style('bf-font-' . $i, $font_url, [], BITFORMS_VERSION);
181 + }
36 182
37 - if (current_user_can($capability)) {
38 - $submenu['bitform'][] = array(__('All Forms', 'bitform'), $capability, 'admin.php?page=bitform#/');
39 - }
183 + if (defined('BITAPPS_DEV') && BITAPPS_DEV) {
184 + // Vite dev server scripts; null version intentional (dev mode, no cache busting needed).
185 + wp_enqueue_script('vite-client-helper-BITFORM-MODULE', BIT_DEV_URL . '/config/devHotModule.js', [], null);
186 + wp_enqueue_script('vite-client-BITFORM-MODULE', BIT_DEV_URL . '/@vite/client', [], null);
187 + wp_enqueue_script('index-BITFORM-MODULE', BIT_DEV_URL . '/main.jsx', [], null);
40 188 }
41 189
42 - /**
43 - * Load the asset libraries
44 - *
45 - * @return void
46 - */
47 - public function AdminAssets($current_screen)
48 - {
49 - if (!strpos($current_screen, 'bitform')) {
50 - return;
190 + if (!defined('BITAPPS_DEV') || (defined('BITAPPS_DEV') && !BITAPPS_DEV)) {
191 + $build_hash = file_get_contents(BITFORMS_PLUGIN_DIR_PATH . '/build-hash.txt');
192 + wp_enqueue_script('index-BITFORM-MODULE', BITFORMS_ASSET_URI . "/main-{$build_hash}.js", [], null);
193 + wp_enqueue_style('bf-css', BITFORMS_ASSET_URI . "/main-{$build_hash}.css", [], $build_hash);
194 + }
195 +
196 + // if (defined('BITAPPS_DEV') && BITAPPS_DEV) {
197 + // wp_enqueue_script(
198 + // 'bitforms-vendors',
199 + // BITFORMS_ASSET_JS_URI . '/vendors-main.js',
200 + // null,
201 + // BITFORMS_VERSION,
202 + // true
203 + // );
204 + // wp_enqueue_script(
205 + // 'bitforms-runtime',
206 + // BITFORMS_ASSET_JS_URI . '/runtime.js',
207 + // null,
208 + // BITFORMS_VERSION,
209 + // true
210 + // );
211 + // wp_enqueue_script(
212 + // 'bitforms-file',
213 + // BITFORMS_ASSET_JS_URI . '/bitforms-file.js',
214 + // ['bitforms-vendors', 'bitforms-runtime'],
215 + // BITFORMS_VERSION,
216 + // true
217 + // );
218 + // }
219 +
220 + // if (wp_script_is('wp-i18n')) {
221 + // error_log('wp_script' . wp_script_is('wp-i18n'));
222 + // $deps = ['bitforms-vendors', 'bitforms-runtime', 'bitforms-file', 'wp-i18n'];
223 + // } else {
224 + // $deps = ['bitforms-vendors', 'bitforms-runtime', 'bitforms-file'];
225 + // }
226 + // if (!defined('BITAPPS_DEV')) {
227 + // wp_enqueue_script(
228 + // 'bitforms-admin-script',
229 + // BITFORMS_ASSET_JS_URI . '/index.js',
230 + // $deps,
231 + // BITFORMS_VERSION,
232 + // true
233 + // );
234 + // }
235 +
236 + wp_enqueue_script('tinymce_js', includes_url('js/tinymce/') . 'wp-tinymce.php', [], get_bloginfo('version'), true);
237 +
238 + if (!wp_script_is('media-upload')) {
239 + wp_enqueue_media();
240 + }
241 +
242 + // $plugin_path = BITFORMS_ASSET_URI;
243 +
244 + echo "<meta name='theme-color' content='#13233c' />";
245 +
246 + // if (defined('BITAPPS_DEV') && !BITAPPS_DEV) {
247 + // wp_enqueue_style(
248 + // 'bitforms-styles',
249 + // BITFORMS_ASSET_URI . '/css/bitforms.css',
250 + // null,
251 + // BITFORMS_VERSION,
252 + // 'screen'
253 + // );
254 +
255 + // wp_enqueue_style(
256 + // 'bitforms-components-styles',
257 + // BITFORMS_ASSET_URI . '/css/components.css',
258 + // null,
259 + // BITFORMS_VERSION,
260 + // 'screen'
261 + // );
262 + // }
263 +
264 + $formHandler = FormHandler::getInstance();
265 + $all_forms = $formHandler->admin->getAllForm();
266 + $urlQuery = wp_parse_url(FileDownloadProvider::getBaseDownloadURL(), PHP_URL_QUERY);
267 + $baseDLURL = FileDownloadProvider::getBaseDownloadURL();
268 + $baseDLURL = empty($urlQuery) ? $baseDLURL . '?' : $baseDLURL . '&';
269 + $ipTool = new IpTool();
270 + $user_details = $ipTool->getUserDetail();
271 + $integrationHandler = new IntegrationHandler(0, $user_details);
272 + $allFormIntegrations = $integrationHandler->getAllIntegration('app');
273 +
274 + $integraions = Integrations::getInstance();
275 + $connectedIntegrationApps = $integraions->getConnectedIntegrationApp();
276 +
277 + $allFormSettings = [];
278 + if (!is_wp_error($allFormIntegrations)) {
279 + $integCount = [];
280 + foreach ($allFormIntegrations as $integration) {
281 + $type = $integration->integration_type;
282 + if (!is_null($type)) {
283 + if (!isset($integCount[$type])) {
284 + $integCount[$type] = 1;
285 + } else {
286 + $integCount[$type] += 1;
287 + }
51 288 }
52 - $parsed_url = parse_url(get_admin_url());
53 - $site_url = $parsed_url['scheme'] . "://" . $parsed_url['host'];
54 - $site_url .= empty($parsed_url['port']) ? null : ':' . $parsed_url['port'];
55 - $base_path_admin = str_replace($site_url, null, get_admin_url());
56 - wp_enqueue_script(
57 - 'bitforms-vendors',
58 - BITFORMS_ASSET_URI . '/js/vendors-main.js',
59 - null,
60 - BITFORMS_VERSION,
61 - true
62 - );
63 - wp_enqueue_script(
64 - 'bitforms-runtime',
65 - BITFORMS_ASSET_URI . '/js/runtime.js',
66 - null,
67 - BITFORMS_VERSION,
68 - true
69 - );
70 - wp_enqueue_script(
71 - 'bitforms-file',
72 - BITFORMS_ASSET_URI . '/js/bitforms-file.js',
73 - array('bitforms-vendors', 'bitforms-runtime'),
74 - BITFORMS_VERSION,
75 - true
76 - );
77 - wp_enqueue_script(
78 - 'bitforms-admin-script',
79 - BITFORMS_ASSET_URI . '/js/index.js',
80 - array('bitforms-vendors', 'bitforms-runtime', 'bitforms-file', 'wp-i18n'),
81 - BITFORMS_VERSION,
82 - true
83 - );
84 - wp_enqueue_script('tinymce_js', includes_url('js/tinymce/') . 'wp-tinymce.php', null, false, true);
289 + }
290 + foreach ($allFormIntegrations as $integration) {
291 + $type = $integration->integration_type;
292 + if (!is_null($type)) {
293 + $integrationDetails = json_decode($integration->integration_details);
85 294
86 - if (!wp_script_is('media-upload')) {
87 - wp_enqueue_media();
295 + if (!is_object($integrationDetails) || is_null($integrationDetails)) {
296 + $integrationDetails = new \stdClass();
297 + }
298 + $integrationDetails->id = $integration->id;
299 + if ($integCount[$type] > 1) {
300 + if (!isset($allFormSettings[$type])) {
301 + $allFormSettings[$type] = [];
302 + }
303 + array_push($allFormSettings[$type], $integrationDetails);
304 + } else {
305 + $allFormSettings[$type] = $integrationDetails;
306 + }
88 307 }
308 + }
309 + }
89 310
90 - $plugin_path = BITFORMS_ASSET_URI;
311 + if (!is_wp_error($connectedIntegrationApps)) {
312 + $allFormSettings['connectedIntegrationApps'] = $connectedIntegrationApps;
313 + }
91 314
315 + $appSettings = get_option('bitform_app_settings', (object)[]);
316 + $bits = [
317 + 'configs' => ['bf_separator' => BITFORMS_BF_SEPARATOR],
318 + 'nonce' => wp_create_nonce('bitforms_save'),
319 + 'isPro' => false,
320 + 'siteURL' => site_url(),
321 + 'rootURL' => BITFORMS_ROOT_URI,
322 + 'assetsURL' => BITFORMS_ASSET_URI,
323 + 'baseURL' => $base_path_admin . 'admin.php?page=bitform#',
324 + 'baseDLURL' => $baseDLURL,
325 + 'styleURL' => BITFORMS_UPLOAD_BASE_URL . '/form-styles',
326 + 'iconURL' => BITFORMS_UPLOAD_BASE_URL . '/icons',
327 + 'ajaxURL' => admin_url('admin-ajax.php'),
328 + 'allForms' => is_wp_error($all_forms) ? null : $all_forms,
329 + 'allPages' => is_wp_error($this->getAllPages()) ? [] : $this->getAllPages(),
330 + 'allFormSettings' => count($allFormSettings) > 0 ? $allFormSettings : (object)[],
331 + 'appSettings' => $appSettings,
332 + 'dateFormat' => get_option('date_format'),
333 + 'timeFormat' => get_option('time_format'),
334 + 'timeZone' => DateTimeHelper::wp_timezone_string(),
335 + 'googleRedirectURL' => get_rest_url() . 'bitform/v1/google',
336 + 'oneDriveRedirectURL' => get_rest_url() . 'bitform/v1/oneDrive',
337 + 'zohoRedirectURL' => get_rest_url() . 'bitform/v1/zoho',
338 + 'oAuthRedirectURL' => get_rest_url() . 'bitform/v1/oauth-redirect',
339 + 'downloadedPdfFonts' => is_array(get_option('bitforms_pdf_fonts')) ? get_option('bitforms_pdf_fonts') : [],
340 + 'permission' => empty(get_option('bitforms_allow_tracking')) ? false : true,
341 + 'templatePath' => BITFORMS_ROOT_URI . '/static/templates',
342 + 'serverInfo' => ['php_version' => phpversion(), 'engine' => isset($_SERVER['SERVER_SOFTWARE']) ? sanitize_text_field(wp_unslash($_SERVER['SERVER_SOFTWARE'])) : '', 'wp_version' => get_bloginfo('version'), 'loaded_extensions' => get_loaded_extensions()],
343 + ];
92 344
93 - echo "<link rel='icon' type='image/svg+xml' href='{$plugin_path}/img/logo.svg' />
94 - <link rel='alternate icon' type='image/png' href='{$plugin_path}/img/logo-256.png' />
95 - <link rel='manifest' href='{$plugin_path}/js/manifest.json' />
96 - <link rel='stylesheet preload prefetch' type='text/css' crossorigin='anonymous' as='style' crossorigin='anonymous' href='https://fonts.googleapis.com/css2?family=Montserrat:wght@100;300;400;500;600;700;800&display=swap'>
97 - <link rel='apple-touch-icon' href='{$plugin_path}/img/logo-256.png' />
98 - <meta name='theme-color' content='#13233c' />
99 - <meta name='description' content='Bit Form | Fast Modern Form builder for Wordpress' />
100 - <meta name='keywords' content='Fast WP form, Bitform, Fast Modern Form builder for Wordpress'>";
345 + $isMigratingToV2 = get_option('bitforms_migrating_to_v2', false);
346 + if ($isMigratingToV2) {
347 + $bits['isMigratingToV2'] = $isMigratingToV2;
348 + }
101 349
102 - wp_enqueue_style(
103 - 'bitforms-styles',
104 - BITFORMS_ASSET_URI . '/css/bitforms.css',
105 - null,
106 - BITFORMS_VERSION,
107 - 'screen'
108 - );
350 + if (defined('BITFORMS_VERSION')) {
351 + $bits['version'] = BITFORMS_VERSION;
352 + }
109 353
110 - wp_enqueue_style(
111 - 'bitforms-components-styles',
112 - BITFORMS_ASSET_URI . '/css/components.css',
113 - null,
114 - BITFORMS_VERSION,
115 - 'screen'
116 - );
117 - $formHandler = FormHandler::getInstance();
118 - $all_forms = $formHandler->admin->getAllForm();
119 - $urlQuery = parse_url(FileDownloadProvider::getBaseDownloadURL(), PHP_URL_QUERY);
120 - $baseDLURL = FileDownloadProvider::getBaseDownloadURL();
121 - $baseDLURL = empty($urlQuery) ? $baseDLURL . '?' : $baseDLURL . '&';
122 - $ipTool = new IpTool();
123 - $user_details = $ipTool->getUserDetail();
124 - $integrationHandler = new IntegrationHandler(0, $user_details);
125 - $allFormIntegrations = $integrationHandler->getAllIntegration('app');
126 - $allFormSettings = array();
127 - if (!is_wp_error($allFormIntegrations)) {
128 - foreach ($allFormIntegrations as $integration) {
129 - if (!is_null($integration->integration_type)) {
130 - $integrationDetails = json_decode($integration->integration_details);
131 - $integrationDetails->id = $integration->id;
132 - $allFormSettings[$integration->integration_type] = $integrationDetails;
133 - }
134 - }
135 - }
354 + $changelogVersion = get_option('bitforms_changelog_version', '0.0.0');
355 + $bits['changelogVersion'] = $changelogVersion;
136 356
137 - $users = get_users(['fields' => ['user_nicename', 'user_email']]);
138 - $userMail = [];
139 - foreach ($users as $key => $value) {
140 - $userMail[$key]['label'] = !empty($value->user_nicename) ? $value->user_nicename : '';
141 - $userMail[$key]['value'] = !empty($value->user_email) ? $value->user_email : '';
142 - }
143 - $bitforms = apply_filters(
144 - 'bitforms_localized_script',
145 - array(
146 - 'nonce' => wp_create_nonce('bitforms_save'),
147 - 'isPro' => false,
148 - 'assetsURL' => BITFORMS_ASSET_URI,
149 - 'baseURL' => $base_path_admin . 'admin.php?page=bitform#',
150 - 'baseDLURL' => $baseDLURL,
151 - 'styleURL' => BITFORMS_UPLOAD_BASE_URL . '/form-styles',
152 - 'ajaxURL' => admin_url('admin-ajax.php'),
153 - 'allForms' => is_wp_error($all_forms) ? null : $all_forms,
154 - 'allFormSettings' => $allFormSettings,
155 - 'userMail' => !empty($userMail) ? $userMail : [],
156 - 'dateFormat' => get_option('date_format'),
157 - 'timeFormat' => get_option('time_format'),
158 - 'timeZone' => wp_timezone_string(),
159 - )
160 - );
161 - wp_localize_script('bitforms-admin-script', 'bits', $bitforms);
162 - wp_set_script_translations('bitforms-admin-script', 'bitform', BITFORMS_PLUGIN_DIR_PATH . 'languages');
357 + $hideAnnouncementModal = (bool) get_option('bitforms_hide_announcement', false);
358 + $bits['hideAnnouncementModal'] = $hideAnnouncementModal;
359 +
360 + $hideCashbackModal = (bool) get_option('bitforms_hide_cashback', false);
361 + $bits['hideCashbackModal'] = $hideCashbackModal;
362 +
363 + global $wpdb;
364 + // Direct query: table name interpolation only (no user input). $wpdb->prepare() cannot parameterize schema-check queries.
365 + $hasV1FormTable = $wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}bitforms_form_v1'");
366 + if ($hasV1FormTable) {
367 + $bits['canRollbackToV1'] = true;
163 368 }
164 369
165 - /**
166 - * Bitforms apps-root id provider
167 - * @return void
168 - */
169 - public function RootPage()
170 - {
171 - require_once BITFORMS_PLUGIN_DIR_PATH . '/views/view-root.php';
370 + $bitforms = apply_filters(
371 + 'bitforms_localized_script',
372 + $bits
373 + );
374 +
375 + $allowBitFormTranslation = apply_filters('bitform_filter_allow_translation', true);
376 + if ($allowBitFormTranslation && 'en_US' !== get_user_locale() && file_exists(BITFORMS_PLUGIN_DIR_PATH . '/languages/generatedString.php')) {
377 + include_once BITFORMS_PLUGIN_DIR_PATH . '/languages/generatedString.php';
378 + $bitforms['translations'] = $bitforms_i18n_strings;
379 +
380 + // Apply a filter to allow user/custom translations to modify the $bitforms translations
381 + $bitforms['translations'] = apply_filters('bitform_filter_translations', $bitforms['translations']);
172 382 }
383 + wp_localize_script('index-BITFORM-MODULE', 'bits', $bitforms);
384 + // !BIT_DEV && wp_localize_script('bitforms-admin-script', 'bits', $bitforms);
385 + // echo !BIT_DEV ? '' : "<script>console.log(window.bits=JSON.parse('" . str_replace("'", '', wp_json_encode($bitforms)) . "'))</script>";
386 + // if (\function_exists('wp_set_script_translations'))
387 + // wp_set_script_translations('bitforms-admin-script', 'bitform', BITFORMS_PLUGIN_DIR_PATH . 'languages');
388 + }
173 389
174 - public function AdminNotices()
175 - {
176 - remove_all_actions('admin_notices');
177 - remove_all_actions('all_admin_notices');
390 + public function bitforms_enqueue_admin_styles()
391 + {
392 + wp_enqueue_style(
393 + 'bitforms-admin-styles',
394 + BITFORMS_ROOT_URI . '/resources/admin.css',
395 + [],
396 + BITFORMS_VERSION,
397 + 'all'
398 + );
399 + }
400 +
401 + /**
402 + * Bitforms apps-root id provider
403 + * @return void
404 + */
405 + public function RootPage()
406 + {
407 + require_once BITFORMS_PLUGIN_DIR_PATH . '/views/view-root.php';
408 + }
409 +
410 + public function AdminNotices()
411 + {
412 + global $plugin_page;
413 + $plugin_page = null === $plugin_page ? '' : $plugin_page;
414 + if (false === strpos($plugin_page, 'bitform')) {
415 + return;
178 416 }
417 + remove_all_actions('admin_notices');
418 + remove_all_actions('all_admin_notices');
419 + }
420 +
421 + /**
422 + * Modify style tags
423 + *
424 + * @param string $html link tag
425 + *
426 + * @return string new link tag
427 + */
428 + public function linkTagFilter($html, $handle, $href)
429 + {
430 + $newTag = $html;
431 + if (preg_match('/BITFORM-PRECONNECT/', $handle)) {
432 + $newTag = preg_replace('/rel=("|\')stylesheet("|\')/', 'rel="preconnect"', $newTag);
433 + }
434 + if (preg_match('/BITFORM-PRELOAD/', $handle)) {
435 + $newTag = preg_replace('/rel=("|\')stylesheet("|\')/', 'rel="preload"', $newTag);
436 + }
437 + if (preg_match('/BITFORM-CROSSORIGIN/', $handle)) {
438 + $newTag = preg_replace('/<link /', '<link crossorigin ', $newTag);
439 + }
440 + if (preg_match('/BITFORM-SCRIPT/', $handle)) {
441 + $newTag = preg_replace('/<link /', '<link as="script" ', $newTag);
442 + }
443 + return $newTag;
444 + }
445 +
446 + /**
447 + * Modify script tags
448 + *
449 + * @param string $html script tag
450 + *
451 + * @return string new script tag
452 + */
453 + public function scriptTagFilter($html, $handle, $href)
454 + {
455 + $newTag = $html;
456 + if (preg_match('/BITFORM-MODULE/', $handle)) {
457 + $newTag = preg_replace('/<script /', '<script type="module" ', $newTag);
458 + }
459 + return $newTag;
460 + }
461 +
462 + private static function countUnreadEntries()
463 + {
464 + global $wpdb;
465 + // Direct query: table name interpolation only (no user input). status = 1 is a hardcoded literal.
466 + $unreadEntries = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}bitforms_form_entries WHERE status = 1");
467 + return $unreadEntries;
468 + }
179 469 }