| 1 |
<?php |
| 2 |
/** |
| 3 |
* Shared setting-key declarations for the settings abilities. |
| 4 |
* |
| 5 |
* @package ThinkRank\Abilities\Settings |
| 6 |
* @since 2.1.1 |
| 7 |
*/ |
| 8 |
|
| 9 |
declare(strict_types=1); |
| 10 |
|
| 11 |
namespace ThinkRank\Abilities\Settings; |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* The keys each settings category exposes over the abilities layer, and their |
| 19 |
* JSON types. |
| 20 |
* |
| 21 |
* Declared once and shared by the get/update pair for each category, because |
| 22 |
* two hand-maintained allowlists per category is how the gap opened in the |
| 23 |
* first place: site identity exposed 13 of its 54 keys and sitemap 8 of its 20, |
| 24 |
* so an MCP agent could neither read nor set any title template, the whole |
| 25 |
* business/Local SEO block, or the sitemap index toggle — and, since the read |
| 26 |
* ability omitted them silently, had no way to tell its picture was incomplete |
| 27 |
* (#518). |
| 28 |
* |
| 29 |
* AbilitySettingsCoverageTest walks each manager's get_known_setting_keys() |
| 30 |
* against these maps and fails when a category gains a key that is neither |
| 31 |
* exposed here nor listed as deliberately excluded, so the drift cannot recur |
| 32 |
* unnoticed. |
| 33 |
* |
| 34 |
* @since 2.1.1 |
| 35 |
*/ |
| 36 |
final class Settings_Key_Map { |
| 37 |
|
| 38 |
/** |
| 39 |
* `site_identity` keys that belong to another ability. |
| 40 |
* |
| 41 |
* Not gaps: each is already reachable, and exposing it twice would give an |
| 42 |
* agent two ways to write the same row. |
| 43 |
* |
| 44 |
* @var array<string,string> Key => the ability that owns it. |
| 45 |
*/ |
| 46 |
public const SITE_IDENTITY_ELSEWHERE = [ |
| 47 |
'robots_txt_content' => 'thinkrank/update-robots-txt', |
| 48 |
'custom_robots_rules' => 'thinkrank/update-robots-txt', |
| 49 |
'knowledge_graph' => 'thinkrank/update-schema-settings', |
| 50 |
'organization_schema' => 'thinkrank/update-schema-settings', |
| 51 |
'post_title' => 'thinkrank/update-global-settings', |
| 52 |
'page_title' => 'thinkrank/update-global-settings', |
| 53 |
]; |
| 54 |
|
| 55 |
/** |
| 56 |
* `sitemap` keys that are derived state rather than settings. |
| 57 |
* |
| 58 |
* @var array<string,string> Key => why it is not exposed. |
| 59 |
*/ |
| 60 |
public const SITEMAP_ELSEWHERE = [ |
| 61 |
'last_generated' => 'written by the generator, not a setting', |
| 62 |
'sitemap_urls' => 'written by the generator, not a setting', |
| 63 |
'selected_preset' => 'UI marker the settings screen maintains for itself', |
| 64 |
]; |
| 65 |
|
| 66 |
/** |
| 67 |
* JSON schema properties for every exposed `site_identity` key. |
| 68 |
* |
| 69 |
* @return array<string, array<string, mixed>> |
| 70 |
*/ |
| 71 |
public static function site_identity(): array { |
| 72 |
return [ |
| 73 |
// Core. |
| 74 |
'enabled' => self::boolean( __( 'Whether site identity management is active.', 'thinkrank' ) ), |
| 75 |
'site_name' => self::string( __( 'Official name of the site, used in titles and schema.', 'thinkrank' ) ), |
| 76 |
'site_description' => self::string( __( 'Short description of the site.', 'thinkrank' ) ), |
| 77 |
'tagline' => self::string( __( 'Site tagline.', 'thinkrank' ) ), |
| 78 |
'alternate_name' => self::alternate_name(), |
| 79 |
'identity_type' => self::string( __( 'What the site is, e.g. "blog", "business", "portfolio".', 'thinkrank' ) ), |
| 80 |
'represents' => self::string( __( 'Whether the site represents a "person" or an "organization".', 'thinkrank' ) ), |
| 81 |
'default_meta_description' => self::string( __( 'Meta description used where no more specific one is set.', 'thinkrank' ) ), |
| 82 |
'default_social_image' => self::string( __( 'URL of the fallback social sharing image.', 'thinkrank' ) ), |
| 83 |
'social_media_accounts' => [ |
| 84 |
'type' => 'array', |
| 85 |
'description' => __( 'Profile URLs for the site\'s social accounts.', 'thinkrank' ), |
| 86 |
'items' => [ 'type' => 'string' ], |
| 87 |
], |
| 88 |
|
| 89 |
// Titles. These are %token% templates; the manager sanitizes them |
| 90 |
// without stripping their tokens. |
| 91 |
'title_template' => self::string( __( 'Named title layout, e.g. "default", "reverse", "category".', 'thinkrank' ) ), |
| 92 |
'title_separator' => self::string( __( 'Separator between title parts, e.g. "pipe", "dash".', 'thinkrank' ) ), |
| 93 |
'homepage_title' => self::template( __( 'the homepage', 'thinkrank' ), '' ), |
| 94 |
'category_title' => self::template( __( 'category archives', 'thinkrank' ), '%category_title%, %category%' ), |
| 95 |
'tag_title' => self::template( __( 'tag archives', 'thinkrank' ), '%tag_title%' ), |
| 96 |
'author_title' => self::template( __( 'author archives', 'thinkrank' ), '%author_name%' ), |
| 97 |
'search_title' => self::template( __( 'search results pages', 'thinkrank' ), '%search_term%' ), |
| 98 |
'archive_title' => self::template( __( 'date and other archives', 'thinkrank' ), '%archive_title%' ), |
| 99 |
|
| 100 |
// Breadcrumbs. |
| 101 |
'breadcrumbs_enabled' => self::boolean( __( 'Whether breadcrumb markup is generated.', 'thinkrank' ) ), |
| 102 |
'breadcrumb_type' => self::string( __( 'Breadcrumb structure, e.g. "hierarchical".', 'thinkrank' ) ), |
| 103 |
'breadcrumb_home_text' => self::string( __( 'Label for the home link in breadcrumbs.', 'thinkrank' ) ), |
| 104 |
'breadcrumb_separator' => self::string( __( 'Separator drawn between breadcrumb items.', 'thinkrank' ) ), |
| 105 |
'breadcrumb_prefix' => self::string( __( 'Text shown before the breadcrumb trail.', 'thinkrank' ) ), |
| 106 |
'show_current_page' => self::boolean( __( 'Whether the current page appears in its own breadcrumb trail.', 'thinkrank' ) ), |
| 107 |
'breadcrumb_use_seo_title' => self::boolean( __( 'Whether breadcrumb labels use the SEO title of a post or term when one is set, instead of its raw title.', 'thinkrank' ) ), |
| 108 |
|
| 109 |
// Brand imagery. |
| 110 |
'logo_url' => self::string( __( 'URL of the site logo.', 'thinkrank' ) ), |
| 111 |
'favicon_url' => self::string( __( 'URL of the site favicon.', 'thinkrank' ) ), |
| 112 |
'apple_touch_icon_url' => self::string( __( 'URL of the Apple touch icon.', 'thinkrank' ) ), |
| 113 |
|
| 114 |
// Homepage hero. |
| 115 |
'hero_title' => self::string( __( 'Homepage hero heading.', 'thinkrank' ) ), |
| 116 |
'hero_subtitle' => self::string( __( 'Homepage hero subheading.', 'thinkrank' ) ), |
| 117 |
'hero_cta_text' => self::string( __( 'Label on the homepage hero call to action.', 'thinkrank' ) ), |
| 118 |
'hero_cta_url' => self::string( __( 'URL the homepage hero call to action points at.', 'thinkrank' ) ), |
| 119 |
'hero_background_image' => self::string( __( 'URL of the homepage hero background image.', 'thinkrank' ) ), |
| 120 |
|
| 121 |
// Business / Local SEO. Feeds LocalBusiness schema. |
| 122 |
'local_seo_enabled' => self::boolean( __( 'Whether Local SEO output and LocalBusiness schema are enabled.', 'thinkrank' ) ), |
| 123 |
'business_name' => self::string( __( 'Registered business name.', 'thinkrank' ) ), |
| 124 |
'business_type' => self::string( __( 'schema.org business type, e.g. "Restaurant", "Store".', 'thinkrank' ) ), |
| 125 |
'business_email' => self::string( __( 'Public contact email address.', 'thinkrank' ) ), |
| 126 |
'business_phone' => self::string( __( 'Public contact telephone number.', 'thinkrank' ) ), |
| 127 |
'business_address' => self::string( __( 'Street address.', 'thinkrank' ) ), |
| 128 |
'business_city' => self::string( __( 'City or locality.', 'thinkrank' ) ), |
| 129 |
'business_state' => self::string( __( 'State, province or region.', 'thinkrank' ) ), |
| 130 |
'business_country' => self::string( __( 'Country.', 'thinkrank' ) ), |
| 131 |
'business_postal_code' => self::string( __( 'Postal or ZIP code.', 'thinkrank' ) ), |
| 132 |
'business_latitude' => self::string( __( 'Latitude of the business location, in decimal degrees.', 'thinkrank' ) ), |
| 133 |
'business_longitude' => self::string( __( 'Longitude of the business location, in decimal degrees.', 'thinkrank' ) ), |
| 134 |
'business_price_range' => self::string( __( 'Price range indicator, e.g. "$$".', 'thinkrank' ) ), |
| 135 |
'business_hours' => self::business_hours(), |
| 136 |
|
| 137 |
// Indexing. |
| 138 |
'allow_search_engines' => self::boolean( __( 'Whether search engines are allowed to index the site.', 'thinkrank' ) ), |
| 139 |
'query_protection' => self::boolean( __( 'Whether a URL whose content selector resolved to nothing (for example ?post_type=nosuchtype) answers 404 instead of serving the blog listing at 200.', 'thinkrank' ) ), |
| 140 |
'canonical_scheme' => [ |
| 141 |
'type' => 'string', |
| 142 |
'description' => __( 'Scheme for canonical URLs, og:url, schema @ids and sitemap entries. "automatic" follows WordPress; the other two override it, for a site behind a proxy that terminates TLS and leaves WordPress reporting the wrong scheme.', 'thinkrank' ), |
| 143 |
'enum' => \ThinkRank\SEO\Url_Scheme::MODES, |
| 144 |
], |
| 145 |
'robots_txt_enabled' => self::boolean( __( 'Whether ThinkRank manages robots.txt. Its contents are set with thinkrank/update-robots-txt.', 'thinkrank' ) ), |
| 146 |
|
| 147 |
// RSS feeds. |
| 148 |
'feed_excerpt_only' => self::boolean( __( 'Whether feed entries are shortened to an excerpt instead of carrying the full post.', 'thinkrank' ) ), |
| 149 |
'feed_source_link' => self::boolean( __( 'Whether each feed entry is signed with a link back to the original post and the site.', 'thinkrank' ) ), |
| 150 |
'feed_noindex' => self::boolean( __( 'Whether feeds are served with X-Robots-Tag: noindex. Leave off for a podcast feed, which needs to be indexable.', 'thinkrank' ) ), |
| 151 |
'ai_crawler_rules' => self::ai_crawler_rules(), |
| 152 |
]; |
| 153 |
} |
| 154 |
|
| 155 |
/** |
| 156 |
* JSON schema properties for every exposed `sitemap` key. |
| 157 |
* |
| 158 |
* @return array<string, array<string, mixed>> |
| 159 |
*/ |
| 160 |
public static function sitemap(): array { |
| 161 |
return [ |
| 162 |
'enabled' => self::boolean( __( 'Whether XML sitemap generation is active.', 'thinkrank' ) ), |
| 163 |
'delivery_mode' => [ |
| 164 |
'type' => 'string', |
| 165 |
'enum' => \ThinkRank\SEO\Sitemap_Generator::DELIVERY_MODES, |
| 166 |
'description' => __( 'How the sitemap reaches crawlers. "auto" writes files when the WordPress root is writable and serves the sitemap from WordPress when it is not. "static" always writes files, and fails where that is not possible. "dynamic" always serves from WordPress and writes nothing.', 'thinkrank' ), |
| 167 |
], |
| 168 |
'auto_generate' => self::boolean( __( 'Whether the sitemap regenerates automatically when content changes.', 'thinkrank' ) ), |
| 169 |
'use_sitemap_index' => self::boolean( __( 'Whether to publish a sitemap index that links per-type sitemaps, rather than one flat file.', 'thinkrank' ) ), |
| 170 |
'links_per_sitemap' => [ |
| 171 |
'type' => 'integer', |
| 172 |
'description' => __( 'Maximum URLs per sitemap file before it is split.', 'thinkrank' ), |
| 173 |
'minimum' => 1, |
| 174 |
'maximum' => 50000, |
| 175 |
], |
| 176 |
'custom_url_pattern' => self::string( __( 'Filename pattern for generated sitemaps, e.g. "sitemap-{type}.xml".', 'thinkrank' ) ), |
| 177 |
'enable_styling' => self::boolean( __( 'Whether an XSL stylesheet is attached so the sitemap is readable in a browser.', 'thinkrank' ) ), |
| 178 |
'ping_search_engines' => self::boolean( __( 'Whether search engines are notified after the sitemap is regenerated.', 'thinkrank' ) ), |
| 179 |
|
| 180 |
// How the styled sitemap looks. All four need enable_styling on. |
| 181 |
'styling_logo' => self::boolean( __( 'Whether a logo is shown above the sitemap heading. Requires enable_styling.', 'thinkrank' ) ), |
| 182 |
'styling_logo_url' => self::string( __( 'URL of the sitemap logo image. Empty falls back to the site icon.', 'thinkrank' ) ), |
| 183 |
'styling_color_main' => self::string( __( 'Hex colour ("#rrggbb") for the sitemap header, links and table head. Empty keeps the stock palette.', 'thinkrank' ) ), |
| 184 |
'styling_color_accent' => self::string( __( 'Hex colour ("#rrggbb") for the header gradient end and link hovers. Empty keeps the stock palette.', 'thinkrank' ) ), |
| 185 |
|
| 186 |
// What goes in. |
| 187 |
'include_posts' => self::boolean( __( 'Whether posts are included.', 'thinkrank' ) ), |
| 188 |
'include_pages' => self::boolean( __( 'Whether pages are included.', 'thinkrank' ) ), |
| 189 |
'include_categories' => self::boolean( __( 'Whether category archives are included.', 'thinkrank' ) ), |
| 190 |
'include_tags' => self::boolean( __( 'Whether tag archives are included.', 'thinkrank' ) ), |
| 191 |
'include_images' => self::boolean( __( 'Whether image entries are included for each URL.', 'thinkrank' ) ), |
| 192 |
'include_featured_images' => self::boolean( __( 'Whether featured images are included as image entries.', 'thinkrank' ) ), |
| 193 |
|
| 194 |
// What stays out. |
| 195 |
'exclude_posts' => self::string( __( 'Comma-separated post IDs to leave out.', 'thinkrank' ) ), |
| 196 |
'exclude_terms' => self::string( __( 'Comma-separated term IDs to leave out.', 'thinkrank' ) ), |
| 197 |
'exclude_private_posts' => self::boolean( __( 'Whether privately published posts are left out.', 'thinkrank' ) ), |
| 198 |
'exclude_password_protected' => self::boolean( __( 'Whether password-protected posts are left out.', 'thinkrank' ) ), |
| 199 |
]; |
| 200 |
} |
| 201 |
|
| 202 |
/** |
| 203 |
* Read the exposed keys out of a manager's stored settings. |
| 204 |
* |
| 205 |
* The store keeps everything as strings ("1"/""), so each value is coerced |
| 206 |
* back to the type the schema advertises before it reaches an agent. |
| 207 |
* |
| 208 |
* @param array<string, array<string, mixed>> $properties Schema properties for the category. |
| 209 |
* @param array<string, mixed> $stored Settings as the manager returns them. |
| 210 |
* @return array<string, mixed> Exposed settings, one entry per declared key. |
| 211 |
*/ |
| 212 |
public static function read( array $properties, array $stored ): array { |
| 213 |
$out = []; |
| 214 |
|
| 215 |
foreach ( $properties as $key => $property ) { |
| 216 |
$value = $stored[ $key ] ?? null; |
| 217 |
|
| 218 |
$type = $property['type'] ?? 'string'; |
| 219 |
|
| 220 |
// A union type ('string' or a list of them) keeps whichever shape |
| 221 |
// it arrived in: casting to string would flatten a list, and |
| 222 |
// casting to array would replace a name with [] (#692). |
| 223 |
if ( is_array( $type ) ) { |
| 224 |
$out[ $key ] = is_array( $value ) |
| 225 |
? array_values( array_map( 'strval', $value ) ) |
| 226 |
: (string) ( $value ?? '' ); |
| 227 |
continue; |
| 228 |
} |
| 229 |
|
| 230 |
switch ( $type ) { |
| 231 |
case 'boolean': |
| 232 |
$out[ $key ] = (bool) $value; |
| 233 |
break; |
| 234 |
case 'integer': |
| 235 |
$out[ $key ] = (int) $value; |
| 236 |
break; |
| 237 |
case 'array': |
| 238 |
case 'object': |
| 239 |
$out[ $key ] = is_array( $value ) ? $value : []; |
| 240 |
break; |
| 241 |
default: |
| 242 |
$out[ $key ] = (string) ( $value ?? '' ); |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
return $out; |
| 247 |
} |
| 248 |
|
| 249 |
/** |
| 250 |
* Coerce an incoming patch to the declared types, dropping unknown keys. |
| 251 |
* |
| 252 |
* Strings are passed through rather than sanitized here: the manager's own |
| 253 |
* save path already picks the right sanitizer per key, and running |
| 254 |
* sanitize_text_field() first would strip %date% and %category% out of the |
| 255 |
* title templates as percent-encoding before it ever got the chance (#521). |
| 256 |
* |
| 257 |
* @param array<string, array<string, mixed>> $properties Schema properties for the category. |
| 258 |
* @param array<string, mixed> $incoming Caller-supplied settings. |
| 259 |
* @return array<string, mixed> Recognized keys only, coerced to type. |
| 260 |
*/ |
| 261 |
public static function coerce( array $properties, array $incoming ): array { |
| 262 |
$out = []; |
| 263 |
|
| 264 |
foreach ( $properties as $key => $property ) { |
| 265 |
if ( ! array_key_exists( $key, $incoming ) ) { |
| 266 |
continue; |
| 267 |
} |
| 268 |
|
| 269 |
$value = $incoming[ $key ]; |
| 270 |
|
| 271 |
$type = $property['type'] ?? 'string'; |
| 272 |
|
| 273 |
// A union type ('string' or a list of them) keeps whichever shape |
| 274 |
// it arrived in: casting to string would flatten a list, and |
| 275 |
// casting to array would replace a name with [] (#692). |
| 276 |
if ( is_array( $type ) ) { |
| 277 |
$out[ $key ] = is_array( $value ) |
| 278 |
? array_values( array_map( 'strval', $value ) ) |
| 279 |
: (string) ( $value ?? '' ); |
| 280 |
continue; |
| 281 |
} |
| 282 |
|
| 283 |
switch ( $type ) { |
| 284 |
case 'boolean': |
| 285 |
$out[ $key ] = (bool) $value; |
| 286 |
break; |
| 287 |
case 'integer': |
| 288 |
$number = (int) $value; |
| 289 |
if ( isset( $property['minimum'] ) ) { |
| 290 |
$number = max( (int) $property['minimum'], $number ); |
| 291 |
} |
| 292 |
if ( isset( $property['maximum'] ) ) { |
| 293 |
$number = min( (int) $property['maximum'], $number ); |
| 294 |
} |
| 295 |
$out[ $key ] = $number; |
| 296 |
break; |
| 297 |
case 'array': |
| 298 |
case 'object': |
| 299 |
if ( ! is_array( $value ) ) { |
| 300 |
// A structured key given a scalar is a caller error, not |
| 301 |
// something to flatten into a string and store. |
| 302 |
continue 2; |
| 303 |
} |
| 304 |
$out[ $key ] = $value; |
| 305 |
break; |
| 306 |
default: |
| 307 |
if ( is_array( $value ) ) { |
| 308 |
continue 2; |
| 309 |
} |
| 310 |
$out[ $key ] = (string) $value; |
| 311 |
} |
| 312 |
} |
| 313 |
|
| 314 |
return $out; |
| 315 |
} |
| 316 |
|
| 317 |
/** |
| 318 |
* The opening hours object, one entry per day. |
| 319 |
* |
| 320 |
* A real sub-schema rather than string coercion: the value is a map of day |
| 321 |
* name to {open, close, closed}, and flattening it to a string would make |
| 322 |
* it unwritable over MCP. |
| 323 |
* |
| 324 |
* @return array<string, mixed> |
| 325 |
*/ |
| 326 |
private static function business_hours(): array { |
| 327 |
$day = [ |
| 328 |
'type' => 'object', |
| 329 |
'additionalProperties' => false, |
| 330 |
'properties' => [ |
| 331 |
'open' => [ |
| 332 |
'type' => 'string', |
| 333 |
'description' => __( 'Opening time as 24-hour HH:MM, or "" when closed.', 'thinkrank' ), |
| 334 |
], |
| 335 |
'close' => [ |
| 336 |
'type' => 'string', |
| 337 |
'description' => __( 'Closing time as 24-hour HH:MM, or "" when closed.', 'thinkrank' ), |
| 338 |
], |
| 339 |
'closed' => [ |
| 340 |
'type' => 'boolean', |
| 341 |
'description' => __( 'Whether the business is closed all day.', 'thinkrank' ), |
| 342 |
], |
| 343 |
], |
| 344 |
]; |
| 345 |
|
| 346 |
$properties = []; |
| 347 |
foreach ( [ 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday' ] as $name ) { |
| 348 |
$properties[ $name ] = $day; |
| 349 |
} |
| 350 |
|
| 351 |
return [ |
| 352 |
'type' => 'object', |
| 353 |
'description' => __( 'Opening hours per day of the week.', 'thinkrank' ), |
| 354 |
'additionalProperties' => false, |
| 355 |
'properties' => $properties, |
| 356 |
]; |
| 357 |
} |
| 358 |
|
| 359 |
/** |
| 360 |
* The per-agent AI crawler allow/block map. |
| 361 |
* |
| 362 |
* Enumerating the known slugs rather than accepting a free-form object is |
| 363 |
* what makes this usable by an agent: the alternative is a caller guessing |
| 364 |
* `chatgpt` for a crawler registered as `chatgpt-user`, having the key |
| 365 |
* dropped as unknown, and being told the save succeeded — because it did, |
| 366 |
* with nothing in it. |
| 367 |
* |
| 368 |
* @return array<string, mixed> |
| 369 |
*/ |
| 370 |
private static function ai_crawler_rules(): array { |
| 371 |
$properties = []; |
| 372 |
|
| 373 |
foreach ( \ThinkRank\SEO\AI_Crawlers::for_display() as $agent ) { |
| 374 |
$properties[ $agent['slug'] ] = [ |
| 375 |
'type' => 'string', |
| 376 |
'enum' => [ 'allow', 'block' ], |
| 377 |
/* translators: 1: crawler user-agent token, e.g. GPTBot. 2: what that crawler is for. */ |
| 378 |
'description' => sprintf( __( '%1$s — %2$s', 'thinkrank' ), $agent['token'], $agent['purpose'] ), |
| 379 |
]; |
| 380 |
} |
| 381 |
|
| 382 |
return [ |
| 383 |
'type' => 'object', |
| 384 |
'description' => __( 'Per-agent AI crawler rules. "block" writes a User-agent/Disallow pair for that crawler into robots.txt; "allow" (the default for any crawler not listed) writes nothing. Blocking Google-Extended does not affect normal Google Search indexing.', 'thinkrank' ), |
| 385 |
'additionalProperties' => false, |
| 386 |
'properties' => $properties, |
| 387 |
]; |
| 388 |
} |
| 389 |
|
| 390 |
/** |
| 391 |
* A boolean property. |
| 392 |
* |
| 393 |
* @param string $description Translated text describing what the toggle does. |
| 394 |
* @return array<string, mixed> |
| 395 |
*/ |
| 396 |
/** |
| 397 |
* The site's alternate name, as one value or several. |
| 398 |
* |
| 399 |
* schema.org and Google both allow `alternateName` to carry a list, and the |
| 400 |
* store already round-trips either shape, so the schema says so rather than |
| 401 |
* forcing a caller to pick one name and drop the rest (#692). |
| 402 |
* |
| 403 |
* @since 2.7.0 |
| 404 |
* @return array<string, mixed> |
| 405 |
*/ |
| 406 |
private static function alternate_name(): array { |
| 407 |
return [ |
| 408 |
// A union rather than anyOf: read() and coerce() switch on `type`, |
| 409 |
// and an entry without one is dropped as unrecognised. WordPress's |
| 410 |
// schema validator accepts a type list, so this is both valid JSON |
| 411 |
// Schema and legible to this file's own consumers. |
| 412 |
'type' => [ 'string', 'array' ], |
| 413 |
'items' => [ 'type' => 'string' ], |
| 414 |
'description' => __( 'Alternate or former name of the site, published as schema alternateName on the homepage WebSite node. Send a string for one name, or an array for several. Blank entries and duplicates are dropped, and a single surviving name is published as a string.', 'thinkrank' ), |
| 415 |
]; |
| 416 |
} |
| 417 |
|
| 418 |
private static function boolean( string $description ): array { |
| 419 |
return [ |
| 420 |
'type' => 'boolean', |
| 421 |
'description' => $description, |
| 422 |
]; |
| 423 |
} |
| 424 |
|
| 425 |
/** |
| 426 |
* A string property. |
| 427 |
* |
| 428 |
* @param string $description Translated text describing the value. |
| 429 |
* @return array<string, mixed> |
| 430 |
*/ |
| 431 |
private static function string( string $description ): array { |
| 432 |
return [ |
| 433 |
'type' => 'string', |
| 434 |
'description' => $description, |
| 435 |
]; |
| 436 |
} |
| 437 |
|
| 438 |
/** |
| 439 |
* A %token% title template property. |
| 440 |
* |
| 441 |
* The vocabulary here is Site Identity's, which is not the one the Global |
| 442 |
* SEO per-post-type templates use — %site_title% rather than %title%, |
| 443 |
* %site_name% rather than %sitename% — so the description spells it out |
| 444 |
* instead of leaving an agent to guess between the two. |
| 445 |
* |
| 446 |
* @param string $what Translated name of the pages the template titles. |
| 447 |
* @param string $extra Comma-separated tags available only on those pages, or ''. |
| 448 |
* @return array<string, mixed> |
| 449 |
*/ |
| 450 |
private static function template( string $what, string $extra ): array { |
| 451 |
$shared = '%site_title%, %site_name%, %site_description%, %tagline%, %sep%, %separator%, %date%'; |
| 452 |
|
| 453 |
$description = '' === $extra |
| 454 |
/* translators: 1: the pages a title template applies to. 2: the list of available variable tags. */ |
| 455 |
? sprintf( __( 'Title template for %1$s. Available tags: %2$s.', 'thinkrank' ), $what, $shared ) |
| 456 |
/* translators: 1: the pages a title template applies to. 2: tags available everywhere. 3: tags available only on those pages. */ |
| 457 |
: sprintf( __( 'Title template for %1$s. Available tags: %2$s, and on these pages also %3$s.', 'thinkrank' ), $what, $shared, $extra ); |
| 458 |
|
| 459 |
return [ |
| 460 |
'type' => 'string', |
| 461 |
'description' => $description, |
| 462 |
]; |
| 463 |
} |
| 464 |
} |
| 465 |
|