PluginProbe
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets / 4.5.6
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets v4.5.6
4.5.6 4.5.5 4.5.4 4.2.1 4.2.2 4.2.3 4.5.0 4.5.2 4.5.3 4.2.0 4.1.18 4.1.17 4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.0.9 4.1.0 4.1.1 4.1.2 All 148 releases
ultimate-post-kit / includes / setup-wizard / class-plugin-integration-helper.php

class-plugin-integration-helper.php in Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets 4.5.6, at includes/setup-wizard/class-plugin-integration-helper.php

340 lines 13.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Integration Helper
4 *
5 * Helper functions for managing plugin integrations in setup wizard
6 */
7
8 namespace UltimatePostKit\SetupWizard;
9
10 if (!defined('ABSPATH')) {
11 exit;
12 }
13
14 class Plugin_Integration_Helper {
15
16 /**
17 * Get predefined plugin configurations
18 *
19 * @return array Plugin configurations
20 */
21 public static function get_predefined_plugins() {
22 $plugins = [
23 'bdthemes-element-pack-lite' => [
24 'recommended' => true,
25 'fallback' => [
26 'name' => 'Element Pack',
27 'description' => 'Build your website with 100+ ready-made blocks and widgets for Elementor.',
28 'logo' => '',
29 'rating' => 4.8,
30 'num_ratings' => 1000,
31 'active_installs' => '50,000+'
32 ]
33 ],
34 'bdthemes-prime-slider-lite/bdthemes-prime-slider.php' => [
35 'recommended' => true,
36 'fallback' => [
37 'name' => 'Prime Slider',
38 'description' => 'Create eye-catching sliders for your website quickly and easily with 55+ modern Elementor slider widgets.',
39 'logo' => '',
40 'rating' => 4.7,
41 'num_ratings' => 500,
42 'active_installs' => '100,000+'
43 ]
44 ],
45 'ultimate-post-kit' => [
46 'recommended' => true,
47 'fallback' => [
48 'name' => 'Ultimate Post Kit',
49 'description' => 'Design beautiful post layouts with simple, ready-made blocks.',
50 'logo' => '',
51 'rating' => 4.8,
52 'num_ratings' => 1000,
53 'active_installs' => '50,000+'
54 ]
55 ],
56 'live-copy-paste' => [
57 'recommended' => false,
58 'fallback' => [
59 'name' => 'Live Copy Paste',
60 'description' => 'Copy and paste website elements between WordPress sites instantly.',
61 'logo' => '',
62 'rating' => 4.9,
63 'num_ratings' => 200,
64 'active_installs' => '10,000+'
65 ]
66 ],
67 'ultimate-store-kit' => [
68 'recommended' => true,
69 'fallback' => [
70 'name' => 'Ultimate Store Kit',
71 'description' => 'Improve your online store with tools to display products better.',
72 'logo' => '',
73 'rating' => 4.6,
74 'num_ratings' => 300,
75 'active_installs' => '20,000+'
76 ]
77 ],
78 // 'pixel-gallery' => [
79 // 'recommended' => false,
80 // 'fallback' => [
81 // 'name' => 'Pixel Gallery',
82 // 'description' => 'Show off your photos in a stylish, responsive gallery.',
83 // 'logo' => '',
84 // 'rating' => 4.5,
85 // 'num_ratings' => 150,
86 // 'active_installs' => '5,000+'
87 // ]
88 // ],
89 // 'zoloblocks' => [
90 // 'recommended' => false,
91 // 'fallback' => [
92 // 'name' => 'ZoloBlocks',
93 // 'description' => 'Build amazing WordPress pages with helpful and flexible Gutenberg blocks.',
94 // 'logo' => '',
95 // 'rating' => 4.3,
96 // 'num_ratings' => 100,
97 // 'active_installs' => '3,000+'
98 // ]
99 // ],
100 // 'spin-wheel' => [
101 // 'recommended' => false,
102 // 'fallback' => [
103 // 'name' => 'Spin Wheel',
104 // 'description' => 'Add a fun, interactive spin wheel to offer instant coupons, boost engagement, and grow your email list.',
105 // 'logo' => '',
106 // 'rating' => 4.2,
107 // 'num_ratings' => 50,
108 // 'active_installs' => '1,000+'
109 // ]
110 // ],
111 // 'ai-image' => [
112 // 'recommended' => false,
113 // 'fallback' => [
114 // 'name' => 'Instant Image Generator',
115 // 'description' => 'Instant Image Generator (One Click Image Uploads from Pixabay, Pexels and OpenAI).',
116 // 'logo' => '',
117 // 'rating' => 4.0,
118 // 'num_ratings' => 25,
119 // 'active_installs' => '500+'
120 // ]
121 // ],
122 // 'dark-reader' => [
123 // 'recommended' => false,
124 // 'fallback' => [
125 // 'name' => 'Dark Reader',
126 // 'description' => 'Add beautiful dark mode to your WordPress site with customizable settings.',
127 // 'logo' => '',
128 // 'rating' => 4.1,
129 // 'num_ratings' => 30,
130 // 'active_installs' => '800+'
131 // ]
132 // ],
133 // 'ar-viewer' => [
134 // 'recommended' => false,
135 // 'fallback' => [
136 // 'name' => 'AR Viewer',
137 // 'description' => 'Augmented Reality Viewer – 3D Model Viewer.',
138 // 'logo' => '',
139 // 'rating' => 3.9,
140 // 'num_ratings' => 15,
141 // 'active_installs' => '200+'
142 // ]
143 // ]
144 ];
145
146 // Point every fallback at the logo bundled with this plugin. These entries are
147 // what render when the wordpress.org data is unavailable, so without this the
148 // cards would fall back to a placeholder instead of the real branding. Keys may
149 // be either a bare slug or "slug/file.php", so normalise to the directory first.
150 if ( class_exists( __NAMESPACE__ . '\\Remote_Data_Handler' ) ) {
151 foreach ( $plugins as $key => $config ) {
152 if ( ! empty( $config['fallback']['logo'] ) ) {
153 continue;
154 }
155
156 $slug = ( false !== strpos( $key, '/' ) ) ? dirname( $key ) : $key;
157 $logo = Remote_Data_Handler::get_local_plugin_logo( $slug );
158
159 if ( '' !== $logo ) {
160 $plugins[ $key ]['fallback']['logo'] = $logo;
161 }
162 }
163 }
164
165 return $plugins;
166 }
167
168 /**
169 * Build plugin data array with API data and fallbacks
170 *
171 * @param array $plugin_slugs Array of plugin slugs to include
172 * @return array Complete plugin data array
173 */
174 public static function build_plugin_data($plugin_slugs = []) {
175 $predefined = self::get_predefined_plugins();
176
177 // Use new non-blocking approach - get cached data only from Remote_Data_Handler
178 $fetched_data = [];
179 if (function_exists('upk_get_remote_plugins')) {
180 $fetched_data = upk_get_remote_plugins();
181 }
182
183 $plugins = [];
184
185 foreach ($plugin_slugs as $slug) {
186 $config = $predefined[$slug] ?? ['recommended' => false, 'fallback' => []];
187
188 // Try to get data from remote cache first
189 $api_slug = (strpos($slug, '/') !== false) ? dirname($slug) : $slug;
190 $api_data = $fetched_data[$api_slug] ?? null;
191
192 // Ensure api_data is a valid array with required fields
193 if ($api_data && self::validate_plugin_data($api_data)) {
194 // Determine the correct plugin slug format
195 // If slug already contains .php, use it as-is, otherwise append default format
196 $plugin_slug = (strpos($slug, '.php') !== false) ? $slug : $slug . '/' . $slug . '.php';
197
198 // Use API data with fallbacks and proper null checking
199 $plugins[] = [
200 'logo' => $api_data['logo'] ?? ($config['fallback']['logo'] ?? ''),
201 'rating' => $api_data['rating'] ?? 0,
202 'rating_percentage' => $api_data['rating_percentage'] ?? 0,
203 'num_ratings' => $api_data['num_ratings'] ?? 0,
204 'name' => $api_data['name'] ?? ($config['fallback']['name'] ?? $slug),
205 'slug' => $plugin_slug,
206 'description' => $api_data['description'] ?? ($config['fallback']['description'] ?? ''),
207 'active_installs' => $api_data['active_installs'] ?? ($config['fallback']['active_installs'] ?? '0'),
208 'active_installs_count' => $api_data['active_installs_count'] ?? 0,
209 'downloaded' => $api_data['downloaded'] ?? 0,
210 'downloaded_formatted' => $api_data['downloaded_formatted'] ?? '',
211 'recommended' => $config['recommended'],
212 'version' => $api_data['version'] ?? '',
213 'tested' => $api_data['tested'] ?? '',
214 'last_updated' => $api_data['last_updated'] ?? '',
215 'homepage' => $api_data['homepage'] ?? ''
216 ];
217 } else {
218 // Determine the correct plugin slug format
219 // If slug already contains .php, use it as-is, otherwise append default format
220 $plugin_slug = (strpos($slug, '.php') !== false) ? $slug : $slug . '/' . $slug . '.php';
221
222 // Use fallback data with proper null checking
223 $fallback = $config['fallback'] ?? [];
224 $plugins[] = [
225 'logo' => $fallback['logo'] ?? '',
226 'rating' => $fallback['rating'] ?? 0,
227 'rating_percentage' => 0,
228 'num_ratings' => $fallback['num_ratings'] ?? 0,
229 'name' => $fallback['name'] ?? $slug,
230 'slug' => $plugin_slug,
231 'description' => $fallback['description'] ?? '',
232 'active_installs' => $fallback['active_installs'] ?? '0',
233 'active_installs_count' => 0,
234 'downloaded' => 0,
235 'downloaded_formatted' => '',
236 'recommended' => $config['recommended'],
237 'version' => '',
238 'tested' => '',
239 'last_updated' => '',
240 'homepage' => ''
241 ];
242 }
243 }
244
245 return $plugins;
246 }
247
248 /**
249 * Get recommended plugins only
250 *
251 * @return array Recommended plugins data
252 */
253 public static function get_recommended_plugins() {
254 $predefined = self::get_predefined_plugins();
255 $recommended_slugs = array_keys(array_filter($predefined, function($config) {
256 return $config['recommended'];
257 }));
258
259 return self::build_plugin_data($recommended_slugs);
260 }
261
262 /**
263 * Get all available plugins
264 *
265 * @return array All plugins data
266 */
267 public static function get_all_plugins() {
268 $predefined = self::get_predefined_plugins();
269 $all_slugs = array_keys($predefined);
270
271 return self::build_plugin_data($all_slugs);
272 }
273
274 /**
275 * Add a new plugin to the predefined list
276 *
277 * @param string $slug Plugin slug
278 * @param array $config Plugin configuration
279 */
280 public static function add_plugin($slug, $config) {
281 // This would typically be stored in a database or options table
282 // For now, it's just a helper method
283 $predefined = self::get_predefined_plugins();
284 $predefined[$slug] = $config;
285
286 // In a real implementation, you'd save this to options
287 // update_option('ultimate_post_kit_predefined_plugins', $predefined);
288 }
289
290 /**
291 * Check if a plugin is installed and active
292 *
293 * @param string $plugin_file Plugin file path
294 * @return bool True if plugin is active
295 */
296 public static function is_plugin_active($plugin_file) {
297 return is_plugin_active($plugin_file);
298 }
299
300 /**
301 * Get plugin installation status
302 *
303 * @param string $plugin_file Plugin file path
304 * @return string Status: 'active', 'installed', 'not_installed'
305 */
306 public static function get_plugin_status($plugin_file) {
307 if (self::is_plugin_active($plugin_file)) {
308 return 'active';
309 }
310
311 $installed_plugins = get_plugins();
312 if (isset($installed_plugins[$plugin_file])) {
313 return 'installed';
314 }
315
316 return 'not_installed';
317 }
318
319 /**
320 * Validate plugin data structure
321 *
322 * @param array $plugin_data Plugin data to validate
323 * @return bool True if valid
324 */
325 public static function validate_plugin_data($plugin_data) {
326 if (!is_array($plugin_data)) {
327 return false;
328 }
329
330 $required_fields = ['name', 'slug', 'description', 'active_installs', 'rating', 'num_ratings'];
331
332 foreach ($required_fields as $field) {
333 if (!array_key_exists($field, $plugin_data)) {
334 return false;
335 }
336 }
337
338 return true;
339 }
340 }