Making WordPress.org

Changeset 5457


Ignore:
Timestamp:
05/01/2017 09:23:28 PM (8 years ago)
Author:
ocean90
Message:

Plugin Directory: Add markup information (JSON+LD) for front page and plugin pages.

See #2661.

Location:
sites/trunk/wordpress.org/public_html/wp-content
Files:
5 edited

Legend:

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

    r5340 r5457  
    4343        add_filter( 'single_term_title', array( $this, 'filter_single_term_title' ) );
    4444        add_filter( 'the_content', array( $this, 'filter_rel_nofollow' ) );
     45        add_action( 'wp_head', array( Template::class, 'json_ld_schema' ), 1 );
    4546
    4647        // Cron tasks.
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php

    r5404 r5457  
    1313 */
    1414class Template {
     15
     16    /**
     17     * Prints markup information in the head of a page.
     18     *
     19     * @link http://schema.org/SoftwareApplication
     20     * @link https://developers.google.com/search/docs/data-types/software-apps
     21     *
     22     * @static
     23     */
     24    public static function json_ld_schema() {
     25        // Schema for the front page.
     26        if ( is_front_page() ) :
     27            echo PHP_EOL;
     28            ?>
     29<script type="application/ld+json">
     30    {
     31        "@context": "http://schema.org",
     32        "@type": "WebSite",
     33        "name": <?php echo wp_json_encode( __( 'WordPress Plugins', 'wporg-plugins' ) ); ?>,
     34        "url": <?php echo wp_json_encode( home_url( '/' ) ); ?>,
     35        "potentialAction": [
     36            {
     37                "@type": "SearchAction",
     38                "target": <?php echo wp_json_encode( home_url( '?s={search_term_string}' ) ); ?>,
     39                "query-input": "required name=search_term_string"
     40            }
     41        ]
     42    }
     43</script>
     44            <?php
     45        endif;
     46
     47        // Schema for plugin pages.
     48        if ( is_singular( 'plugin' ) ) :
     49            $plugin = get_queried_object();
     50
     51            $rating      = get_post_meta( $plugin->ID, 'rating', true ) ?: 0;
     52            $ratings     = get_post_meta( $plugin->ID, 'ratings', true ) ?: [];
     53            $num_ratings = array_sum( $ratings );
     54
     55            echo PHP_EOL;
     56            ?>
     57<script type="application/ld+json">
     58    [
     59        {
     60            "@context": "http://schema.org",
     61            "@type": "BreadcrumbList",
     62            "itemListElement": [
     63                {
     64                    "@type": "ListItem",
     65                    "position": 1,
     66                    "item": {
     67                        "@id": "https://wordpress.org/",
     68                        "name": "WordPress"
     69                    }
     70                },
     71                {
     72                    "@type": "ListItem",
     73                    "position": 2,
     74                    "item": {
     75                        "@id": <?php echo wp_json_encode( home_url( '/' ) ); ?>,
     76                        "name": <?php echo wp_json_encode( __( 'WordPress Plugins', 'wporg-plugins' ) ) . PHP_EOL; ?>
     77                    }
     78                }
     79            ]
     80        },
     81        {
     82            "@context": "http://schema.org",
     83            "@type": "SoftwareApplication",
     84            "applicationCategory": "http://schema.org/OtherApplication",
     85            "name": <?php echo wp_json_encode( get_the_title( $plugin ) ); ?>,
     86            "description": <?php echo wp_json_encode( get_the_excerpt( $plugin ) ); ?>,
     87            "softwareVersion": <?php echo wp_json_encode( $plugin->version ); ?>,
     88            "fileFormat": "application/zip",
     89            "downloadUrl": <?php echo wp_json_encode( self::download_link( $plugin ) ); ?>,
     90            "dateModified": <?php echo wp_json_encode( get_post_modified_time( 'c', false, $plugin ) ); ?>,
     91            "aggregateRating": {
     92                "@type": "AggregateRating",
     93                "worstRating": 0,
     94                "bestRating": 5,
     95                "ratingValue": <?php echo wp_json_encode( $rating ); ?>,
     96                "ratingCount": <?php echo wp_json_encode( $num_ratings ); ?>,
     97                "reviewCount": <?php echo wp_json_encode( $num_ratings ) . PHP_EOL; ?>
     98            },
     99            "interactionStatistic": {
     100                "@type": "InteractionCounter",
     101                "interactionType": "http://schema.org/DownloadAction",
     102                "userInteractionCount": <?php echo wp_json_encode( self::get_downloads_count( $plugin ) ) . PHP_EOL; ?>
     103            },
     104            "offers": {
     105                "@type": "Offer",
     106                "price": "0.00",
     107                "priceCurrency": "USD",
     108                "seller": {
     109                    "@type": "Organization",
     110                    "name": "WordPress.org",
     111                    "url": "https://wordpress.org"
     112                }
     113            }
     114        }
     115    ]
     116</script>
     117            <?php
     118        endif;
     119    }
    15120
    16121    /**
     
    99204
    100205        return
    101             '<div class="plugin-rating" itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">' .
    102                 '<meta itemprop="ratingCount" content="' . esc_attr( $num_ratings ) . '"/>' .
    103                 '<meta itemprop="ratingValue" content="' . esc_attr( $rating ) . '"/>' .
     206            '<div class="plugin-rating">' .
    104207                Template::dashicons_stars( $rating ) .
    105208                '<span class="rating-count">(' .
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/widgets/class-meta.php

    r5248 r5457  
    3333
    3434        <h3 class="screen-reader-text"><?php echo apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Meta', 'wporg-plugins' ) : $instance['title'], $instance, $this->id_base ); ?></h3>
    35         <link itemprop="applicationCategory" href="http://schema.org/OtherApplication" />
    36         <span itemprop="offers" itemscope itemtype="http://schema.org/Offer">
    37             <meta itemprop="price" content="0.00" />
    38             <meta itemprop="priceCurrency" content="USD" />
    39             <span itemprop="seller" itemscope itemtype="http://schema.org/Organization">
    40                 <span itemprop="name" content="WordPress.org"></span>
    41             </span>
    42         </span>
    4335
    4436        <ul>
     
    5244                printf( __( 'Last updated: %s', 'wporg-plugins' ),
    5345                    /* Translators: Plugin modified time. */
    54                     '<strong>' . sprintf( __( '%s ago', 'wporg-plugins' ), '<span itemprop="dateModified" content="' . esc_attr( get_post_modified_time( 'c' ) ) . '">' . human_time_diff( get_post_modified_time() ) . '</span>' ) . '</strong>'
     46                    '<strong>' . sprintf( __( '%s ago', 'wporg-plugins' ), '<span>' . human_time_diff( get_post_modified_time() ) . '</span>' ) . '</strong>'
    5547                );
    5648                ?>
     
    7365            <?php endif; ?>
    7466
    75             <?php if ( ! get_query_var( 'plugin_advanced' ) ) : ?> 
     67            <?php if ( ! get_query_var( 'plugin_advanced' ) ) : ?>
    7668                <li class="hide-if-no-js">
    7769                    <?php
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/widgets/class-ratings.php

    r5001 r5457  
    3737        echo $args['before_title'] . $title . $args['after_title'];
    3838        ?>
    39         <meta itemprop="ratingCount" content="<?php echo esc_attr( $num_ratings ) ?>"/>
    4039
    4140        <?php if ( $rating ) : ?>
     
    4443            <div class="rating">
    4544                <?php echo Template::dashicons_stars( $rating ); ?>
    46                 <meta itemprop="ratingValue" content="<?php echo esc_attr( $rating ) ?>">
    4745            </div>
    4846
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/template-parts/plugin-single.php

    r5405 r5457  
    9696            <?php endif; ?>
    9797
    98             <a class="plugin-download button download-button button-large" href="<?php echo esc_url( Template::download_link() ); ?>" itemprop="downloadUrl"><?php _e( 'Download', 'wporg-plugins' ); ?></a>
    99             <meta itemprop="softwareVersion" content="<?php echo esc_attr( get_post_meta( get_the_ID(), 'version', true ) ); ?>">
    100             <meta itemprop="fileFormat" content="application/zip">
     98            <a class="plugin-download button download-button button-large" href="<?php echo esc_url( Template::download_link() ); ?>"><?php _e( 'Download', 'wporg-plugins' ); ?></a>
    10199        </div>
    102100
Note: See TracChangeset for help on using the changeset viewer.