Changeset 9465
- Timestamp:
- 02/05/2020 05:12:50 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php
r9238 r9465 23 23 */ 24 24 public static function json_ld_schema() { 25 $schema = false; 26 25 27 // 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; 28 if ( is_front_page() ) { 29 $schema = [ 30 "@context" => "http://schema.org", 31 "@type" => "WebSite", 32 "name" => __( 'WordPress Plugins', 'wporg-plugins' ), 33 "url" => home_url( '/' ), 34 "potentialAction" => [ 35 [ 36 "@type" => "SearchAction", 37 "target" => home_url( '?s={search_term_string}' ), 38 "query-input" => "required name=search_term_string" 39 ] 40 ] 41 ]; 46 42 47 43 // Schema for plugin pages. 48 if ( is_singular( 'plugin' ) && 'publish' === get_post_status( get_queried_object_id() ) ) { 49 self::plugin_json_jd_schema( get_queried_object() ); 50 } 51 } 52 53 /** 54 * Prints JSON LD schema for a specific plugin. 44 } elseif ( is_singular( 'plugin' ) && 'publish' === get_post_status( get_queried_object_id() ) ) { 45 $schema = self::plugin_json_jd_schema( get_queried_object() ); 46 } 47 48 // Print the schema. 49 if ( $schema ) { 50 echo PHP_EOL, '<script type="application/ld+json">', PHP_EOL; 51 // Output URLs without escaping the slashes, and print it human readable. 52 echo wp_json_encode( $schema, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT ); 53 echo PHP_EOL, '</script>', PHP_EOL; 54 } 55 } 56 57 /** 58 * Fetches JSON LD schema for a specific plugin. 55 59 * 56 60 * @static 57 61 * 58 62 * @param \WP_Post $plugin Plugin to output JSON LD Schema for. 63 * @return array Schema object. 59 64 */ 60 65 protected static function plugin_json_jd_schema( $plugin ) { … … 63 68 $num_ratings = array_sum( $ratings ); 64 69 65 echo PHP_EOL; 66 ?> 67 <script type="application/ld+json"> 68 [ 69 { 70 "@context": "http://schema.org", 71 "@type": "BreadcrumbList", 72 "itemListElement": [ 73 { 74 "@type": "ListItem", 75 "position": 1, 76 "item": { 77 "@id": "https://wordpress.org/", 78 "name": "WordPress" 79 } 80 }, 81 { 82 "@type": "ListItem", 83 "position": 2, 84 "item": { 85 "@id": <?php echo wp_json_encode( home_url( '/' ) ); ?>, 86 "name": <?php echo wp_json_encode( __( 'WordPress Plugins', 'wporg-plugins' ) ) . PHP_EOL; ?> 87 } 88 } 70 $schema = []; 71 72 // Add the BreadcrumbList node. 73 $breadcrumb_list = [ 74 "@context" => "http://schema.org", 75 "@type" => "BreadcrumbList", 76 "itemListElement" => [ 77 [ 78 "@type" => "ListItem", 79 "position" => 1, 80 "item" => [ 81 "@id" => "https://wordpress.org/", 82 "name" => "WordPress" 83 ] 84 ], 85 [ 86 "@type" => "ListItem", 87 "position" => 2, 88 "item" => [ 89 "@id" => home_url( '/' ), 90 "name" => __( 'WordPress Plugins', 'wporg-plugins' ), 91 ] 92 ] 89 93 ] 90 }, 91 { 92 "@context": "http://schema.org", 93 "@type": "SoftwareApplication", 94 "applicationCategory": "http://schema.org/OtherApplication", 95 "name": <?php echo wp_json_encode( get_the_title( $plugin ) ); ?>, 96 "description": <?php echo wp_json_encode( get_the_excerpt( $plugin ) ); ?>, 97 "softwareVersion": <?php echo wp_json_encode( $plugin->version ); ?>, 98 "fileFormat": "application/zip", 99 "downloadUrl": <?php echo wp_json_encode( self::download_link( $plugin ) ); ?>, 100 "dateModified": <?php echo wp_json_encode( get_post_modified_time( 'c', false, $plugin ) ); ?>, 101 "aggregateRating": { 102 "@type": "AggregateRating", 103 "worstRating": 0, 104 "bestRating": 5, 105 "ratingValue": <?php echo wp_json_encode( $rating ); ?>, 106 "ratingCount": <?php echo wp_json_encode( $num_ratings ); ?>, 107 "reviewCount": <?php echo wp_json_encode( $num_ratings ) . PHP_EOL; ?> 108 }, 109 "interactionStatistic": { 110 "@type": "InteractionCounter", 111 "interactionType": "http://schema.org/DownloadAction", 112 "userInteractionCount": <?php echo wp_json_encode( self::get_downloads_count( $plugin ) ) . PHP_EOL; ?> 113 }, 114 "offers": { 115 "@type": "Offer", 116 "price": "0.00", 117 "priceCurrency": "USD", 118 "seller": { 119 "@type": "Organization", 120 "name": "WordPress.org", 121 "url": "https://wordpress.org" 122 } 123 } 124 } 125 ] 126 </script> 127 <?php 94 ]; 95 $schema[] = $breadcrumb_list; 96 97 // Add the Plugin 'SoftwareApplication' node. 98 $software_application = [ 99 "@context" => "http://schema.org", 100 "@type" => "SoftwareApplication", 101 "applicationCategory" => "http://schema.org/OtherApplication", 102 "name" => get_the_title( $plugin ), 103 "description" => get_the_excerpt( $plugin ), 104 "softwareVersion" => $plugin->version, 105 "fileFormat" => "application/zip", 106 "downloadUrl" => self::download_link( $plugin ), 107 "dateModified" => get_post_modified_time( 'c', false, $plugin ), 108 "aggregateRating" => [ 109 "@type" => "AggregateRating", 110 "worstRating" => 0, 111 "bestRating" => 5, 112 "ratingValue" => $rating, 113 "ratingCount" => $num_ratings, 114 "reviewCount" => $num_ratings, 115 ], 116 "interactionStatistic" => [ 117 "@type" => "InteractionCounter", 118 "interactionType" => "http://schema.org/DownloadAction", 119 "userInteractionCount" => self::get_downloads_count( $plugin ), 120 ], 121 "offers" => [ 122 "@type" => "Offer", 123 "price" => "0.00", 124 "priceCurrency" => "USD", 125 "seller" => [ 126 "@type" => "Organization", 127 "name" => "WordPress.org", 128 "url" => "https://wordpress.org" 129 ] 130 ] 131 ]; 132 $schema[] = $software_application; 133 134 return $schema; 128 135 } 129 136
Note: See TracChangeset
for help on using the changeset viewer.