← All changes
|
includes/setup-wizard/class-plugin-integration-helper.php
+130
-17
4.0.9
→
4.5.6
View file →
| @@ -18,37 +18,48 @@ | ||
| 18 | 18 | * |
| 19 | 19 | * @return array Plugin configurations |
| 20 | 20 | */ |
| 21 | 21 | public static function get_predefined_plugins() { |
| 22 | - return [ | |
| 22 | + $plugins = [ | |
| 23 | 23 | 'bdthemes-element-pack-lite' => [ |
| 24 | 24 | 'recommended' => true, |
| 25 | 25 | 'fallback' => [ |
| 26 | 26 | 'name' => 'Element Pack', |
| 27 | - 'description' => 'Ultimate Elementor addon with 300+ widgets, templates, live copy paste, post grid, header footer, mega menu, dynamic builder, WooCommerce builder and more.', | |
| 28 | - 'logo' => 'https://ps.w.org/bdthemes-element-pack-lite/assets/icon-256x256.gif', | |
| 27 | + 'description' => 'Build your website with 100+ ready-made blocks and widgets for Elementor.', | |
| 28 | + 'logo' => '', | |
| 29 | 29 | 'rating' => 4.8, |
| 30 | 30 | 'num_ratings' => 1000, |
| 31 | - 'active_installs' => '100,000+' | |
| 31 | + 'active_installs' => '50,000+' | |
| 32 | 32 | ] |
| 33 | 33 | ], |
| 34 | - 'bdthemes-prime-slider-lite' => [ | |
| 34 | + 'bdthemes-prime-slider-lite/bdthemes-prime-slider.php' => [ | |
| 35 | 35 | 'recommended' => true, |
| 36 | 36 | 'fallback' => [ |
| 37 | 37 | 'name' => 'Prime Slider', |
| 38 | 38 | 'description' => 'Create eye-catching sliders for your website quickly and easily with 55+ modern Elementor slider widgets.', |
| 39 | - 'logo' => 'https://ps.w.org/bdthemes-prime-slider-lite/assets/icon-256x256.gif', | |
| 39 | + 'logo' => '', | |
| 40 | 40 | 'rating' => 4.7, |
| 41 | 41 | 'num_ratings' => 500, |
| 42 | 42 | 'active_installs' => '100,000+' |
| 43 | 43 | ] |
| 44 | 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 | + ], | |
| 45 | 56 | 'live-copy-paste' => [ |
| 46 | 57 | 'recommended' => false, |
| 47 | 58 | 'fallback' => [ |
| 48 | 59 | 'name' => 'Live Copy Paste', |
| 49 | 60 | 'description' => 'Copy and paste website elements between WordPress sites instantly.', |
| 50 | - 'logo' => 'https://ps.w.org/live-copy-paste/assets/icon-256x256.png', | |
| 61 | + 'logo' => '', | |
| 51 | 62 | 'rating' => 4.9, |
| 52 | 63 | 'num_ratings' => 200, |
| 53 | 64 | 'active_installs' => '10,000+' |
| 54 | 65 | ] |
| @@ -57,15 +68,102 @@ | ||
| 57 | 68 | 'recommended' => true, |
| 58 | 69 | 'fallback' => [ |
| 59 | 70 | 'name' => 'Ultimate Store Kit', |
| 60 | 71 | 'description' => 'Improve your online store with tools to display products better.', |
| 61 | - 'logo' => 'https://ps.w.org/ultimate-store-kit/assets/icon-256x256.gif', | |
| 72 | + 'logo' => '', | |
| 62 | 73 | 'rating' => 4.6, |
| 63 | 74 | 'num_ratings' => 300, |
| 64 | 75 | 'active_installs' => '20,000+' |
| 65 | 76 | ] |
| 66 | - ] | |
| 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 | + // ] | |
| 67 | 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; | |
| 68 | 166 | } |
| 69 | 167 | |
| 70 | 168 | /** |
| 71 | 169 | * Build plugin data array with API data and fallbacks |
| @@ -74,18 +172,30 @@ | ||
| 74 | 172 | * @return array Complete plugin data array |
| 75 | 173 | */ |
| 76 | 174 | public static function build_plugin_data($plugin_slugs = []) { |
| 77 | 175 | $predefined = self::get_predefined_plugins(); |
| 78 | - $fetched_data = Plugin_Api_Fetcher::get_multiple_plugins_data($plugin_slugs); | |
| 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 | + | |
| 79 | 183 | $plugins = []; |
| 80 | 184 | |
| 81 | 185 | foreach ($plugin_slugs as $slug) { |
| 82 | 186 | $config = $predefined[$slug] ?? ['recommended' => false, 'fallback' => []]; |
| 83 | - $api_data = $fetched_data[$slug] ?? null; | |
| 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; | |
| 84 | 191 | |
| 85 | - | |
| 86 | 192 | // Ensure api_data is a valid array with required fields |
| 87 | 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 | + | |
| 88 | 198 | // Use API data with fallbacks and proper null checking |
| 89 | 199 | $plugins[] = [ |
| 90 | 200 | 'logo' => $api_data['logo'] ?? ($config['fallback']['logo'] ?? ''), |
| 91 | 201 | 'rating' => $api_data['rating'] ?? 0, |
| @@ -91,9 +201,9 @@ | ||
| 91 | 201 | 'rating' => $api_data['rating'] ?? 0, |
| 92 | 202 | 'rating_percentage' => $api_data['rating_percentage'] ?? 0, |
| 93 | 203 | 'num_ratings' => $api_data['num_ratings'] ?? 0, |
| 94 | 204 | 'name' => $api_data['name'] ?? ($config['fallback']['name'] ?? $slug), |
| 95 | - 'slug' => $slug . '/' . $slug . '.php', | |
| 205 | + 'slug' => $plugin_slug, | |
| 96 | 206 | 'description' => $api_data['description'] ?? ($config['fallback']['description'] ?? ''), |
| 97 | 207 | 'active_installs' => $api_data['active_installs'] ?? ($config['fallback']['active_installs'] ?? '0'), |
| 98 | 208 | 'active_installs_count' => $api_data['active_installs_count'] ?? 0, |
| 99 | 209 | 'downloaded' => $api_data['downloaded'] ?? 0, |
| @@ -104,8 +214,12 @@ | ||
| 104 | 214 | 'last_updated' => $api_data['last_updated'] ?? '', |
| 105 | 215 | 'homepage' => $api_data['homepage'] ?? '' |
| 106 | 216 | ]; |
| 107 | 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 | + | |
| 108 | 222 | // Use fallback data with proper null checking |
| 109 | 223 | $fallback = $config['fallback'] ?? []; |
| 110 | 224 | $plugins[] = [ |
| 111 | 225 | 'logo' => $fallback['logo'] ?? '', |
| @@ -112,9 +226,9 @@ | ||
| 112 | 226 | 'rating' => $fallback['rating'] ?? 0, |
| 113 | 227 | 'rating_percentage' => 0, |
| 114 | 228 | 'num_ratings' => $fallback['num_ratings'] ?? 0, |
| 115 | 229 | 'name' => $fallback['name'] ?? $slug, |
| 116 | - 'slug' => $slug . '/' . $slug . '.php', | |
| 230 | + 'slug' => $plugin_slug, | |
| 117 | 231 | 'description' => $fallback['description'] ?? '', |
| 118 | 232 | 'active_installs' => $fallback['active_installs'] ?? '0', |
| 119 | 233 | 'active_installs_count' => 0, |
| 120 | 234 | 'downloaded' => 0, |
| @@ -169,9 +283,9 @@ | ||
| 169 | 283 | $predefined = self::get_predefined_plugins(); |
| 170 | 284 | $predefined[$slug] = $config; |
| 171 | 285 | |
| 172 | 286 | // In a real implementation, you'd save this to options |
| 173 | - // update_option('upk_predefined_plugins', $predefined); | |
| 287 | + // update_option('ultimate_post_kit_predefined_plugins', $predefined); | |
| 174 | 288 | } |
| 175 | 289 | |
| 176 | 290 | /** |
| 177 | 291 | * Check if a plugin is installed and active |
| @@ -222,6 +336,5 @@ | ||
| 222 | 336 | } |
| 223 | 337 | |
| 224 | 338 | return true; |
| 225 | 339 | } |
| 226 | - | |
| 227 | -} | |
| 340 | +} | |