Making WordPress.org


Ignore:
Timestamp:
08/27/2020 03:05:20 AM (6 years ago)
Author:
dd32
Message:

Plugin Directory: Prevent a PHP Notice in the JSON-LD output when a plugin has no icons/banners.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php

    r9862 r10211  
    7373
    7474                $num_ratings = array_sum( $ratings );
     75                $images      = [];
    7576                $banners     = self::get_plugin_banner( $plugin );
    7677                $icons       = self::get_plugin_icon( $plugin );
    7778
    78                 // Ignore the icons if we're relying upon the geopattern default.
    79                 if ( $icons['generated'] ) {
    80                         $icons = [ 'svg' => false, 'icon_2x' => false, 'icon' => false ];
     79                // First non-generated icon.
     80                if ( $icons && ! $icons['generated'] ) {
     81                        foreach ( [ 'svg', 'icon_2x', 'icon' ] as $field ) {
     82                                if ( !empty( $icons[ $field ] ) ) {
     83                                        $images[] = $icons[ $field ];
     84                                        break;
     85                                }
     86                        }
     87                }
     88                // Largest appropriate banner. rtl fields returned when is_rtl().
     89                if ( $banners ) {
     90                        foreach ( [ 'banner_2x_rtl', 'banner_rtl', 'banner_2x', 'banner' ] as $field ) {
     91                                if ( !empty( $banners[ $field ] ) ) {
     92                                        $images[] = $banners[ $field ];
     93                                        break;
     94                                }
     95                        }
    8196                }
    8297
    … …  
    112127                                "userInteractionCount" => self::get_downloads_count( $plugin ),
    113128                        ],
    114                         "image" => array_values( array_filter( [
    115                                 // RTL 2x Banner or RTL 1x Banner, otherwise 2x Banner or 1x Banner
    116                                 ( $banners['banner_2x_rtl'] ?: $banners['banner_rtl'] ) ?: ( $banners['banner_2x'] ?: $banners['banner'] ),
    117                                 // Plugin Icon, SVG is priority, otherwise 2x or 1x.
    118                                 ( $icons['svg'] ?: $icons['icon_2x'] ) ?: $icons['icon'],
    119                         ] ) ),
     129                        "image" => $images,
    120130                        "offers" => [
    121131                                "@type"         => "Offer",
Note: See TracChangeset for help on using the changeset viewer.