← All changes
|
includes/setup-wizard/class-remote-data-handler.php
+68
-4
4.5.3
→
4.5.6
View file →
| @@ -26,8 +26,61 @@ | ||
| 26 | 26 | */ |
| 27 | 27 | const CACHE_KEY = 'bdt_remote_plugins_data'; |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | + * Bundled logo file name for each plugin slug. | |
| 31 | + * | |
| 32 | + * These ship with the plugin (assets/images/others-plugin-logo/) so the plugin | |
| 33 | + * cards render our own branded artwork instead of the wordpress.org icon, and | |
| 34 | + * still show something for plugins whose .org listing has no icon at all. | |
| 35 | + * The key is the wordpress.org slug; the value is the file base name. | |
| 36 | + * | |
| 37 | + * @var array<string, string> | |
| 38 | + */ | |
| 39 | + const LOCAL_PLUGIN_LOGOS = [ | |
| 40 | + 'bdthemes-element-pack-lite' => 'element-pack', | |
| 41 | + 'bdthemes-prime-slider-lite' => 'prime-slider', | |
| 42 | + 'ultimate-post-kit' => 'ultimate-post-kit', | |
| 43 | + 'ultimate-store-kit' => 'ultimate-store-kit', | |
| 44 | + 'zoloblocks' => 'zoloblocks', | |
| 45 | + 'pixel-gallery' => 'pixel-gallery', | |
| 46 | + 'live-copy-paste' => 'live-copy-paste', | |
| 47 | + 'spin-wheel' => 'spin-wheel', | |
| 48 | + 'ai-image' => 'ai-image', | |
| 49 | + 'dark-reader' => 'dark-reader', | |
| 50 | + 'ar-viewer' => 'ar-viewer', | |
| 51 | + 'smart-admin-assistant' => 'smart-admin-assistant', | |
| 52 | + 'website-accessibility' => 'one-accessibility', | |
| 53 | + 'launch-guard' => 'launch-guard', | |
| 54 | + 'sigma-forms' => 'sigma-forms', | |
| 55 | + 'sigma-media-manager' => 'sigma-media-manager', | |
| 56 | + 'sigma-store-locator' => 'sigma-store-locator', | |
| 57 | + 'swift-checkout' => 'swift-checkout', | |
| 58 | + ]; | |
| 59 | + | |
| 60 | + /** | |
| 61 | + * Resolve the bundled logo URL for a plugin slug. | |
| 62 | + * | |
| 63 | + * @param string $slug Plugin slug. | |
| 64 | + * @return string Logo URL, or an empty string when the slug has no bundled logo. | |
| 65 | + */ | |
| 66 | + public static function get_local_plugin_logo( $slug ) { | |
| 67 | + if ( ! is_string( $slug ) || '' === $slug || ! isset( self::LOCAL_PLUGIN_LOGOS[ $slug ] ) ) { | |
| 68 | + return ''; | |
| 69 | + } | |
| 70 | + | |
| 71 | + $file = self::LOCAL_PLUGIN_LOGOS[ $slug ] . '.png'; | |
| 72 | + | |
| 73 | + // Only advertise the file if it actually shipped, so a trimmed build falls | |
| 74 | + // back to the remote icon rather than rendering a broken image. | |
| 75 | + if ( defined( 'BDTUPK_PATH' ) && ! file_exists( BDTUPK_PATH . 'assets/images/others-plugin-logo/' . $file ) ) { | |
| 76 | + return ''; | |
| 77 | + } | |
| 78 | + | |
| 79 | + return BDTUPK_ASSETS_URL . 'images/others-plugin-logo/' . $file; | |
| 80 | + } | |
| 81 | + | |
| 82 | + /** | |
| 30 | 83 | * Cron hook name for background fetch |
| 31 | 84 | */ |
| 32 | 85 | const CRON_HOOK = 'bdt_fetch_remote_plugins_cron'; |
| 33 | 86 | |
| @@ -438,11 +491,16 @@ | ||
| 438 | 491 | * @param array $raw_data Raw API data |
| 439 | 492 | * @return array Formatted plugin data |
| 440 | 493 | */ |
| 441 | 494 | private static function format_plugin_data($raw_data) { |
| 442 | - // Get the best available icon with validation | |
| 443 | - $icon_url = self::get_valid_plugin_icon($raw_data['icons'] ?? []); | |
| 495 | + // Prefer the logo bundled with this plugin so the cards show our own branded | |
| 496 | + // artwork; fall back to the wordpress.org icon for anything not bundled. | |
| 497 | + $icon_url = self::get_local_plugin_logo($raw_data['slug'] ?? ''); | |
| 444 | 498 | |
| 499 | + if ('' === $icon_url) { | |
| 500 | + $icon_url = self::get_valid_plugin_icon($raw_data['icons'] ?? []); | |
| 501 | + } | |
| 502 | + | |
| 445 | 503 | // Format active installs with null safety and real data |
| 446 | 504 | $active_installs_raw = $raw_data['active_installs'] ?? 0; |
| 447 | 505 | $active_installs = self::format_active_installs($active_installs_raw); |
| 448 | 506 | $active_installs_count = self::get_numeric_active_installs($active_installs_raw); |
| @@ -488,10 +546,16 @@ | ||
| 488 | 546 | * @return string Valid icon URL or empty string |
| 489 | 547 | */ |
| 490 | 548 | private static function get_valid_plugin_icon($icons) { |
| 491 | 549 | $valid_extensions = ['gif', 'png', 'jpg', 'jpeg', 'svg']; |
| 492 | - $icon_sizes = ['256', '128', 'default']; | |
| 493 | - | |
| 550 | + | |
| 551 | + // The wordpress.org plugin_information API returns its icon map keyed by | |
| 552 | + // '2x' / '1x' (and 'svg' or 'default' for the generated geopattern icon) -- | |
| 553 | + // never '256' / '128'. Looking only for the pixel keys meant no plugin icon | |
| 554 | + // ever resolved and every card fell back to the placeholder. Highest quality | |
| 555 | + // first, with the old pixel keys kept for any cached/legacy payload. | |
| 556 | + $icon_sizes = ['2x', '1x', 'svg', 'default', '256', '128']; | |
| 557 | + | |
| 494 | 558 | foreach ($icon_sizes as $size) { |
| 495 | 559 | if (!empty($icons[$size])) { |
| 496 | 560 | $icon_url = $icons[$size]; |
| 497 | 561 | |