Making WordPress.org

Changeset 9473


Ignore:
Timestamp:
02/06/2020 12:48:01 AM (5 years ago)
Author:
dd32
Message:

Plugin Directory: Schema: Enhance the plugins schema to provice richer data.

Props jonoaldersonwp.
Fixes #5010.

File:
1 edited

Legend:

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

    r9468 r9473  
    6767        $ratings     = get_post_meta( $plugin->ID, 'ratings', true ) ?: [];
    6868        $num_ratings = array_sum( $ratings );
     69        $banners     = self::get_plugin_banner( $plugin );
     70        $icons       = self::get_plugin_icon( $plugin );
     71
     72        // Ignore the icons if we're relying upon the geopattern default.
     73        if ( $icons['generated'] ) {
     74            $icons = [];
     75        }
    6976
    7077        $schema = [];
     
    7380        $software_application = [
    7481            "@context"            => "http://schema.org",
    75             "@type"               => "SoftwareApplication",
    76             "applicationCategory" => "http://schema.org/OtherApplication",
     82            "@type"               => [
     83                "SoftwareApplication",
     84                "Product"
     85            ],
     86            "applicationCategory" => "Plugin",
     87            "operatingSystem"     => "WordPress",
    7788            "name"                => get_the_title( $plugin ),
    7889            "url"                 => get_permalink( $plugin ),
     
    95106                "userInteractionCount" => self::get_downloads_count( $plugin ),
    96107            ],
     108            "image" => array_values( array_filter( [
     109                // RTL 2x Banner or RTL 1x Banner, otherwise 2x Banner or 1x Banner
     110                ( $banners['banner_2x_rtl'] ?: $banners['banner_rtl'] ) ?: ( $banners['banner_2x'] ?: $banners['banner'] ),
     111                // Plugin Icon, SVG is priority, otherwise 2x or 1x.
     112                ( $icons['svg'] ?: $icons['icon_2x'] ) ?: $icons['icon'],
     113            ] ) ),
    97114            "offers" => [
    98115                "@type"         => "Offer",
     116                "url"           => get_permalink( $plugin ),
    99117                "price"         => "0.00",
    100118                "priceCurrency" => "USD",
     
    107125        ];
    108126
     127        // Remove the aggregateRating node if there's no reviews.
    109128        if ( ! $software_application['aggregateRating']['ratingCount'] ) {
    110129            unset( $software_application['aggregateRating'] );
     130        }
     131
     132        // Remove the images property if no images exist.
     133        if ( ! $software_application['image'] ) {
     134            unset( $software_application['image'] );
    111135        }
    112136
Note: See TracChangeset for help on using the changeset viewer.