PluginProbe
WindPress – Tailwind CSS integration for WordPress / 3.2.89
WindPress – Tailwind CSS integration for WordPress v3.2.89
3.2.89 3.2.88 3.2.87 3.2.86 3.2.85 3.2.84 3.2.83 3.2.82 3.2.81 trunk 3.0.0 3.0.1 3.0.10 3.0.11 3.0.12 3.0.13 3.0.14 3.0.15 3.0.16 3.0.17 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 All 143 releases
← All changes | src/Utils/Common.php +217 -24 3.0.33.2.89 View file →
@@ -12,8 +12,9 @@
12 12 namespace WindPress\WindPress\Utils;
13 13
14 14 use Exception;
15 15 use WIND_PRESS;
16 +use WindPress\WindPress\Plugin;
16 17 /**
17 18 * Common utility functions for the plugin.
18 19 *
19 20 * @since 3.0.0
@@ -24,27 +25,27 @@
24 25 * Check the type of the current request.
25 26 *
26 27 * @param string $type The type of the request. Available values: `admin`, `ajax`, `frontend`, `rest`, `cron`.
27 28 */
28 - public static function is_request(string $type) : bool
29 + public static function is_request(string $type): bool
29 30 {
30 31 switch ($type) {
31 32 case 'admin':
32 - return \is_admin();
33 + return is_admin();
33 34 case 'ajax':
34 - return \wp_doing_ajax();
35 + return wp_doing_ajax();
35 36 case 'rest':
36 - return \defined('REST_REQUEST') && \REST_REQUEST;
37 + return defined('REST_REQUEST') && \REST_REQUEST;
37 38 case 'cron':
38 - return \wp_doing_cron();
39 + return wp_doing_cron();
39 40 case 'json':
40 - return \wp_is_json_request();
41 + return wp_is_json_request();
41 42 case 'xmlrpc':
42 - return \defined('XMLRPC_REQUEST') && \XMLRPC_REQUEST;
43 + return defined('XMLRPC_REQUEST') && \XMLRPC_REQUEST;
43 44 case 'xml':
44 - return \wp_is_xml_request();
45 + return wp_is_xml_request();
45 46 case 'frontend':
46 - return (!\is_admin() || \wp_doing_ajax()) && !\wp_doing_cron();
47 + return (!is_admin() || wp_doing_ajax()) && !wp_doing_cron();
47 48 default:
48 49 return \false;
49 50 }
50 51 }
@@ -55,22 +56,31 @@
55 56 * @return mixed
56 57 */
57 58 public static function plugin_data(?string $key = null)
58 59 {
59 - if (!\function_exists('get_plugin_data')) {
60 + if (!function_exists('get_plugin_data')) {
60 61 require_once \ABSPATH . 'wp-admin/includes/plugin.php';
61 62 }
62 - $plugin_data = \wp_cache_get('plugin_data', WIND_PRESS::WP_OPTION);
63 + $plugin_data = wp_cache_get('plugin_data', WIND_PRESS::WP_OPTION);
63 64 if (!$plugin_data) {
64 - $plugin_data = \get_plugin_data(WIND_PRESS::FILE);
65 - \wp_cache_set('plugin_data', $plugin_data, WIND_PRESS::WP_OPTION);
65 + $plugin_data = get_plugin_data(WIND_PRESS::FILE);
66 + wp_cache_set('plugin_data', $plugin_data, WIND_PRESS::WP_OPTION);
66 67 }
67 68 return $key ? $plugin_data[$key] : $plugin_data;
68 69 }
69 - public static function random_slug(int $length = 21) : string
70 + public static function is_updater_library_available(): bool
70 71 {
71 - return (new \WindPressPackages\Hidehalo\Nanoid\Client())->generateId($length, \WindPressPackages\Hidehalo\Nanoid\Client::MODE_DYNAMIC);
72 + if (method_exists(Plugin::class, 'is_pro_edition')) {
73 + return Plugin::is_pro_edition();
74 + }
75 + // WordPress can run the old Plugin class against the newly installed files during an upgrade.
76 + $plugin_directory = dirname(WIND_PRESS::FILE);
77 + return is_file($plugin_directory . '/vendor/easy-digital-downloads/edd-sl-sdk/edd-sl-sdk.php') || is_file($plugin_directory . '/vendor/rosua/edd-sl-plugin-updater/src/PluginUpdater.php');
72 78 }
79 + public static function random_slug(int $length = 21): string
80 + {
81 + return (new \WindPressDeps\Hidehalo\Nanoid\Client())->generateId($length, \WindPressDeps\Hidehalo\Nanoid\Client::MODE_DYNAMIC);
82 + }
73 83 /**
74 84 * Redirect to the given location. If headers are already sent, use a meta refresh.
75 85 *
76 86 * @param string $location The location to redirect to.
@@ -77,16 +87,16 @@
77 87 * @param bool $safe Whether to use wp_safe_redirect() or not.
78 88 */
79 89 public static function redirect(string $location, bool $safe = \false, int $status = 302, string $x_redirect_by = 'WordPress')
80 90 {
81 - if (!\headers_sent()) {
91 + if (!headers_sent()) {
82 92 if ($safe) {
83 - \wp_safe_redirect($location, $status, $x_redirect_by);
93 + wp_safe_redirect($location, $status, $x_redirect_by);
84 94 } else {
85 - \wp_redirect($location, $status, $x_redirect_by);
95 + wp_redirect($location, $status, $x_redirect_by);
86 96 }
87 97 } else {
88 - echo '<meta http-equiv="refresh" content="0;url=' . \esc_url($location) . '">';
98 + echo '<meta http-equiv="refresh" content="0;url=' . esc_url($location) . '">';
89 99 }
90 100 exit;
91 101 }
92 102 /**
@@ -96,20 +106,20 @@
96 106 * @param string $file_path The file path.
97 107 * @param int $flags The flags to pass to the file_put_contents() function.
98 108 * @throws Exception
99 109 */
100 - public static function save_file($content, string $file_path, int $flags = 0) : void
110 + public static function save_file($content, string $file_path, int $flags = 0): void
101 111 {
102 112 /**
103 113 * @var \WP_Filesystem_Base $wp_filesystem
104 114 */
105 115 global $wp_filesystem;
106 - if (!\file_exists($file_path)) {
107 - \wp_mkdir_p(\dirname($file_path));
116 + if (!file_exists($file_path)) {
117 + wp_mkdir_p(dirname($file_path));
108 118 }
109 119 if (!$wp_filesystem) {
110 120 require_once \ABSPATH . 'wp-admin/includes/file.php';
111 - \WP_Filesystem();
121 + WP_Filesystem();
112 122 }
113 123 $result = $wp_filesystem->put_contents($file_path, $content, $flags);
114 124 if ($result === \false) {
115 125 throw new Exception('Failed to save to file.', 500);
@@ -115,11 +125,194 @@
115 125 throw new Exception('Failed to save to file.', 500);
116 126 }
117 127 // if write is successful continue
118 128 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Local file
119 - $saved_content = \file_get_contents($file_path);
129 + $saved_content = $wp_filesystem->get_contents($file_path);
120 130 // if read is successful continue
121 131 if ($saved_content === \false) {
122 132 throw new Exception('The saved file is not readable.', 500);
123 133 }
134 + }
135 + /**
136 + * Deletes a file or directory.
137 + *
138 + * @param string $file_path Path to the file or directory.
139 + * @param bool $recursive Optional. If set to true, deletes files and folders recursively.
140 + * Default false.
141 + * @param string|false $type Type of resource. 'f' for file, 'd' for directory.
142 + * Default false.
143 + */
144 + public static function delete_file($file_path, $recursive = \false, $type = \false): void
145 + {
146 + /**
147 + * @var \WP_Filesystem_Base $wp_filesystem
148 + */
149 + global $wp_filesystem;
150 + if (!$wp_filesystem) {
151 + require_once \ABSPATH . 'wp-admin/includes/file.php';
152 + WP_Filesystem();
153 + }
154 + $result = $wp_filesystem->delete($file_path, $recursive, $type);
155 + if ($result === \false) {
156 + throw new Exception('Failed to delete the file.', 500);
157 + }
158 + }
159 + /**
160 + * Get all installed plugins
161 + *
162 + * @return array Array of installed plugins
163 + */
164 + public static function get_all_plugins()
165 + {
166 + require_once \ABSPATH . 'wp-admin/includes/plugin.php';
167 + return get_plugins();
168 + }
169 + /**
170 + * Check if a plugin is installed by name or slug
171 + * Supports wildcard patterns (e.g., "GreenShift*") and regex patterns (e.g., "/^GreenShift/i")
172 + *
173 + * @param string|array $plugin_name The name, slug, or array of aliases of the plugin to check. Can be:
174 + * - Exact match: "GreenShift" or "greenshift/greenshift.php"
175 + * - Wildcard: "GreenShift*" or "greenshift/*"
176 + * - Regex: "/^GreenShift/i" or "/^greenshift\//i"
177 + * - Array: ['GreenShift', 'greenshift/*', '/^GreenShift/i']
178 + * @return bool True if the plugin is installed, false otherwise
179 + */
180 + public static function is_plugin_installed($plugin_name)
181 + {
182 + // Handle array input - check if any alias matches
183 + if (is_array($plugin_name)) {
184 + foreach ($plugin_name as $alias) {
185 + if (self::is_plugin_installed($alias)) {
186 + return \true;
187 + }
188 + }
189 + return \false;
190 + }
191 + $all_plugins = self::get_all_plugins();
192 + // Check if it's a regex pattern (starts and ends with /)
193 + $is_regex = preg_match('/^\/.*\/[imsxeADSUXJu]*$/', $plugin_name);
194 + if ($is_regex) {
195 + // Use regex pattern directly - check both name and slug
196 + foreach ($all_plugins as $plugin_path => $plugin_data) {
197 + if (preg_match($plugin_name, $plugin_data['Name']) || preg_match($plugin_name, $plugin_path)) {
198 + return \true;
199 + }
200 + }
201 + } else {
202 + // Check if contains wildcards (* or ?)
203 + $has_wildcards = strpos($plugin_name, '*') !== \false || strpos($plugin_name, '?') !== \false;
204 + if ($has_wildcards) {
205 + // Convert wildcard pattern to regex
206 + // First replace wildcards with placeholders, then escape, then convert placeholders to regex
207 + $pattern = str_replace(['*', '?'], ['__WILDCARD_ASTERISK__', '__WILDCARD_QUESTION__'], $plugin_name);
208 + $pattern = preg_quote($pattern, '/');
209 + $pattern = str_replace(['__WILDCARD_ASTERISK__', '__WILDCARD_QUESTION__'], ['.*', '.'], $pattern);
210 + $pattern = '/^' . $pattern . '$/i';
211 + foreach ($all_plugins as $plugin_path => $plugin_data) {
212 + if (preg_match($pattern, $plugin_data['Name']) || preg_match($pattern, $plugin_path)) {
213 + return \true;
214 + }
215 + }
216 + } else {
217 + // Exact match - check both name and slug
218 + foreach ($all_plugins as $plugin_path => $plugin_data) {
219 + if ($plugin_data['Name'] == $plugin_name || $plugin_path == $plugin_name) {
220 + return \true;
221 + }
222 + }
223 + }
224 + }
225 + return \false;
226 + }
227 + /**
228 + * Check if a plugin is active by name or slug
229 + * Supports wildcard patterns (e.g., "GreenShift*") and regex patterns (e.g., "/^GreenShift/i")
230 + *
231 + * @param string|array $plugin_name The name, slug, or array of aliases of the plugin to check. Can be:
232 + * - Exact match: "GreenShift" or "greenshift/greenshift.php"
233 + * - Wildcard: "GreenShift*" or "greenshift/*"
234 + * - Regex: "/^GreenShift/i" or "/^greenshift\//i"
235 + * - Array: ['GreenShift', 'greenshift/*', '/^GreenShift/i']
236 + * @return bool True if the plugin is active, false otherwise
237 + */
238 + public static function is_plugin_active_by_name($plugin_name)
239 + {
240 + // Handle array input - check if any alias matches
241 + if (is_array($plugin_name)) {
242 + foreach ($plugin_name as $alias) {
243 + if (self::is_plugin_active_by_name($alias)) {
244 + return \true;
245 + }
246 + }
247 + return \false;
248 + }
249 + $all_plugins = self::get_all_plugins();
250 + // Check if it's a regex pattern (starts and ends with /)
251 + $is_regex = preg_match('/^\/.*\/[imsxeADSUXJu]*$/', $plugin_name);
252 + if ($is_regex) {
253 + // Use regex pattern directly - check both name and slug
254 + foreach ($all_plugins as $plugin_path => $plugin_data) {
255 + if ((preg_match($plugin_name, $plugin_data['Name']) || preg_match($plugin_name, $plugin_path)) && is_plugin_active($plugin_path)) {
256 + return \true;
257 + }
258 + }
259 + } else {
260 + // Check if contains wildcards (* or ?)
261 + $has_wildcards = strpos($plugin_name, '*') !== \false || strpos($plugin_name, '?') !== \false;
262 + if ($has_wildcards) {
263 + // Convert wildcard pattern to regex
264 + // First replace wildcards with placeholders, then escape, then convert placeholders to regex
265 + $pattern = str_replace(['*', '?'], ['__WILDCARD_ASTERISK__', '__WILDCARD_QUESTION__'], $plugin_name);
266 + $pattern = preg_quote($pattern, '/');
267 + $pattern = str_replace(['__WILDCARD_ASTERISK__', '__WILDCARD_QUESTION__'], ['.*', '.'], $pattern);
268 + $pattern = '/^' . $pattern . '$/i';
269 + foreach ($all_plugins as $plugin_path => $plugin_data) {
270 + if ((preg_match($pattern, $plugin_data['Name']) || preg_match($pattern, $plugin_path)) && is_plugin_active($plugin_path)) {
271 + return \true;
272 + }
273 + }
274 + } else {
275 + // Exact match - check both name and slug
276 + foreach ($all_plugins as $plugin_path => $plugin_data) {
277 + if (($plugin_data['Name'] == $plugin_name || $plugin_path == $plugin_name) && is_plugin_active($plugin_path)) {
278 + return \true;
279 + }
280 + }
281 + }
282 + }
283 + return \false;
284 + }
285 + /**
286 + * Check if a theme is installed by name
287 + *
288 + * @param string $theme_name The name of the theme to check
289 + * @return bool True if the theme is installed, false otherwise
290 + */
291 + public static function is_theme_installed($theme_name)
292 + {
293 + $all_themes = wp_get_themes();
294 + foreach ($all_themes as $theme) {
295 + if ($theme->get('Name') == $theme_name) {
296 + return \true;
297 + }
298 + }
299 + return \false;
300 + }
301 + /**
302 + * Check if a theme is active by name
303 + *
304 + * @param string $theme_name The name of the theme or parent theme to check
305 + * @return bool True if the theme is active, false otherwise
306 + */
307 + public static function is_theme_active_by_name($theme_name)
308 + {
309 + $current_theme = wp_get_theme();
310 + if ($current_theme->get('Name') == $theme_name) {
311 + return \true;
312 + }
313 + if ($current_theme->parent() && $current_theme->parent()->get('Name') == $theme_name) {
314 + return \true;
315 + }
316 + return \false;
124 317 }
125 318 }