Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Schema_Node_Ids | |
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| organization | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| site_anchor | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Stable Schema.org node `@id` helpers. |
| 4 | * |
| 5 | * Site-level nodes (Organization, WebSite, …) and page nodes (Article) live |
| 6 | * together in one `@graph` and cross-reference each other by `@id`. Those `@id`s |
| 7 | * must be stable URIs — the same across every page of the site — so references |
| 8 | * resolve and search engines can de-duplicate the entities. Centralizing them |
| 9 | * here keeps every node builder agreeing on the exact same strings. |
| 10 | * |
| 11 | * @package automattic/jetpack-seo-package |
| 12 | */ |
| 13 | |
| 14 | namespace Automattic\Jetpack\SEO; |
| 15 | |
| 16 | /** |
| 17 | * Builds the canonical `@id` URIs used across the schema graph. |
| 18 | */ |
| 19 | class Schema_Node_Ids { |
| 20 | |
| 21 | /** |
| 22 | * `@id` for the site-level Organization node. |
| 23 | * |
| 24 | * Anchored to the site root with a stable fragment, e.g. |
| 25 | * `https://example.com/#organization`, so the Article `publisher` |
| 26 | * reference resolves to the same entity on every page. |
| 27 | * |
| 28 | * @return string |
| 29 | */ |
| 30 | public static function organization() { |
| 31 | return self::site_anchor( 'organization' ); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Build a stable site-root `@id` from a fragment name. |
| 36 | * |
| 37 | * @param string $fragment Fragment identifier (without the leading `#`). |
| 38 | * @return string |
| 39 | */ |
| 40 | private static function site_anchor( $fragment ) { |
| 41 | // home_url( '/' ) is the canonical site root and already carries a trailing |
| 42 | // slash, giving fragments like `https://example.com/#organization`. |
| 43 | return home_url( '/' ) . '#' . $fragment; |
| 44 | } |
| 45 | } |