PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.7.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.7.0
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/Core/Util/Utilities.php +4 -141 3.2.12.7.0 View file →
@@ -1,46 +1,21 @@
1 1 <?php
2 2
3 3 namespace BitCode\BitForm\Core\Util;
4 4
5 -use BitCode\BitForm\Admin\Form\Helpers;
6 -
7 5 final class Utilities
8 6 {
9 7 public static function isPro()
10 8 {
11 - // IMPORTANT:
12 - // For wp.org (free) distribution we treat "Pro" as "Pro addon is installed/active".
13 - // License enforcement must live inside the Pro addon, not in the free plugin.
14 - return class_exists('BitCode\\BitFormPro\\Plugin');
15 - }
16 -
17 - /**
18 - * Kept for backward compatibility where the free plugin needs to know if a Pro
19 - * license is marked active. Prefer checking license inside the Pro addon.
20 - */
21 - public static function isProLicensed(): bool
22 - {
23 - if (!self::isPro()) {
24 - return false;
25 - }
26 - if (class_exists('BitCode\\BitFormPro\\Core\\Util\\LicenseHelper')) {
27 - return \BitCode\BitFormPro\Core\Util\LicenseHelper::hasValidLicense();
28 - }
29 9 $integrateData = get_option('bitformpro_integrate_key_data');
30 -
31 - return !empty($integrateData)
32 - && is_array($integrateData)
33 - && !empty($integrateData['status'])
34 - && 'success' === $integrateData['status'];
10 + $isProLicenseActivated = !empty($integrateData) && is_array($integrateData) && 'success' === $integrateData['status'];
11 + return class_exists('BitCode\\BitFormPro\\Plugin') && $isProLicenseActivated;
35 12 }
36 13
37 14 public static function getRealPath($dir, $name)
38 15 {
39 - if (!isset($dir)) {
40 - return false;
41 - }
42 - $directories = array_diff(scandir($dir), ['..', '.']);
16 + if (!isset($dir)) return false;
17 + $directories = array_diff(scandir($dir), array('..', '.'));
43 18 $name = strtolower($name);
44 19
45 20 foreach ($directories as $directory) {
46 21 $dirLower = strtolower($directory);
@@ -55,118 +30,6 @@
55 30 public static function getFileNameExceptExtension($filename)
56 31 {
57 32 $path_parts = pathinfo($filename);
58 33 return $path_parts['filename'];
59 - }
60 -
61 - public static function styleGenerator($styleObj, $important = false)
62 - {
63 - if (is_array($styleObj)) {
64 - $styleObj = json_decode(wp_json_encode($styleObj));
65 - }
66 - $important = $important ? '!important' : '';
67 - $classes = array_keys((array) $styleObj);
68 - $css = '';
69 - foreach ($classes as $class) {
70 - $css .= $class;
71 - $props = (array) $styleObj->{$class};
72 - $propsKeys = array_keys($props);
73 - $styleObject = '{';
74 - foreach ($propsKeys as $property) {
75 - $value = $props[$property];
76 - if (empty($value)) {
77 - continue;
78 - }
79 - if (is_object($value)) {
80 - continue;
81 - }
82 - $styleObject .= "{$property}:{$value}{$important};";
83 - }
84 - $styleObject = rtrim($styleObject, ';');
85 - $styleObject .= '}';
86 - $css .= $styleObject;
87 - }
88 -
89 - return $css;
90 - }
91 -
92 - public static function convertToCSS(array $styles): string
93 - {
94 - $css = '';
95 -
96 - foreach ($styles as $selector => $properties) {
97 - $css .= "$selector{";
98 -
99 - // Check if the properties are an array, meaning it's a nested rule (e.g., media queries, keyframes)
100 - if (is_array($properties)) {
101 - // If it's a nested array (media query or keyframe), recursively handle it
102 - foreach ($properties as $property => $value) {
103 - if (is_array($value)) {
104 - // Recursively process nested arrays (media queries, keyframes, etc.)
105 - $css .= self::convertToCSS([$property => $value]);
106 - } else {
107 - // Regular CSS property
108 - $css .= "$property:$value;";
109 - }
110 - }
111 - }
112 -
113 - $css .= '}';
114 - }
115 -
116 - return $css;
117 - }
118 -
119 - public static function appendCSS($formId, $css, $mode = 'a')
120 - {
121 - $fileName = '';
122 - $path = '';
123 - $path = 'form-styles';
124 - $fileName = "bitform-{$formId}.css";
125 - Helpers::saveFile($path, $fileName, $css, $mode);
126 - $fileName = "bitform-{$formId}-formid.css";
127 - Helpers::saveFile($path, $fileName, $css, $mode);
128 - }
129 -
130 - /**
131 - * First row of a Model/get() style result, or null when the lookup failed
132 - * (WP_Error), returned an empty set, or has no index 0. Prevents
133 - * "Attempt to read property on null" when dereferencing $result[0]->col.
134 - *
135 - * @param mixed $result
136 - * @return object|null
137 - */
138 - public static function firstRow($result)
139 - {
140 - if (is_wp_error($result) || empty($result) || !isset($result[0])) {
141 - return null;
142 - }
143 - return $result[0];
144 - }
145 -
146 - /**
147 - * Decode a JSON string to an object, guaranteed to return object|null so
148 - * downstream `$obj->prop ?? default` reads never emit an undefined-property
149 - * warning. Returns null for non-strings, empty strings and malformed JSON.
150 - *
151 - * @param mixed $json
152 - * @return object|null
153 - */
154 - public static function jsonObj($json)
155 - {
156 - if (!is_string($json) || '' === $json) {
157 - return null;
158 - }
159 - $decoded = json_decode($json);
160 - return is_object($decoded) ? $decoded : null;
161 - }
162 -
163 - public static function duplicateDbTable($oldTableName, $newTableName)
164 - {
165 - global $wpdb;
166 - $oldTable = "{$wpdb->prefix}bitforms_{$oldTableName}";
167 - $newTable = "{$wpdb->prefix}bitforms_{$newTableName}";
168 - // Schema operation: table name interpolation only (no user input). $wpdb->prepare() cannot parameterize DDL statements.
169 - $wpdb->query("CREATE TABLE IF NOT EXISTS `{$newTable}` LIKE `{$oldTable}`");
170 - $wpdb->query("INSERT INTO `{$newTable}` SELECT * FROM `{$oldTable}`");
171 34 }
172 35 }