class-admin-page.php
3 weeks ago
class-ai-crawlers.php
3 weeks ago
class-ai-seo-enhancer.php
3 days ago
class-author-schema-node.php
1 month ago
class-breadcrumb-schema-node.php
1 month ago
class-content-coverage.php
3 weeks ago
class-dashboard-data.php
2 weeks ago
class-initializer.php
3 days ago
class-llms-txt.php
3 weeks ago
class-local-business-schema-node.php
1 month ago
class-organization-schema-node.php
1 month ago
class-post-schema-node.php
1 month ago
class-post-types.php
3 weeks ago
class-schema-builder.php
1 month ago
class-schema-graph.php
1 month ago
class-schema-node-ids.php
1 month ago
class-schema-settings-controller.php
1 month ago
class-schema-settings.php
1 month ago
class-surface-visibility.php
2 weeks ago
class-website-schema-node.php
1 month ago
class-website-schema-node.php
70 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Site-level WebSite Schema.org node builder. |
| 4 | * |
| 5 | * Builds the WebSite JSON-LD node from existing site identity: Site Title, |
| 6 | * site URL, Tagline, site language, and core WordPress search. |
| 7 | * |
| 8 | * @package automattic/jetpack-seo-package |
| 9 | */ |
| 10 | |
| 11 | namespace Automattic\Jetpack\SEO; |
| 12 | |
| 13 | /** |
| 14 | * Builds the site-level WebSite node. |
| 15 | */ |
| 16 | class Website_Schema_Node { |
| 17 | |
| 18 | /** |
| 19 | * Build the WebSite node, or null when the site has no name to identify it. |
| 20 | * |
| 21 | * @return array|null |
| 22 | */ |
| 23 | public static function build() { |
| 24 | $name = self::text( get_bloginfo( 'name' ) ); |
| 25 | if ( '' === $name ) { |
| 26 | return null; |
| 27 | } |
| 28 | |
| 29 | $node = array( |
| 30 | '@type' => 'WebSite', |
| 31 | '@id' => Schema_Node_Ids::website(), |
| 32 | 'name' => $name, |
| 33 | 'url' => home_url( '/' ), |
| 34 | 'potentialAction' => array( |
| 35 | '@type' => 'SearchAction', |
| 36 | 'target' => array( |
| 37 | '@type' => 'EntryPoint', |
| 38 | 'urlTemplate' => home_url( '/?s={search_term_string}' ), |
| 39 | ), |
| 40 | 'query-input' => 'required name=search_term_string', |
| 41 | ), |
| 42 | ); |
| 43 | |
| 44 | $description = self::text( get_bloginfo( 'description' ) ); |
| 45 | if ( '' !== $description ) { |
| 46 | $node['description'] = $description; |
| 47 | } |
| 48 | |
| 49 | $language = self::text( get_bloginfo( 'language' ) ); |
| 50 | if ( '' !== $language ) { |
| 51 | $node['inLanguage'] = $language; |
| 52 | } |
| 53 | |
| 54 | return $node; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Normalize a scalar site value to trimmed plain text. |
| 59 | * |
| 60 | * @param mixed $value Raw value. |
| 61 | * @return string |
| 62 | */ |
| 63 | private static function text( $value ) { |
| 64 | if ( ! is_string( $value ) ) { |
| 65 | return ''; |
| 66 | } |
| 67 | return trim( wp_strip_all_tags( $value ) ); |
| 68 | } |
| 69 | } |
| 70 |