PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.6
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.6
28.6 28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 All 130 releases
wordpress-seo / src / schema-aggregator / user-interface / site-schema-aggregator-xml-route.php

site-schema-aggregator-xml-route.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.6, at src/schema-aggregator/user-interface/site-schema-aggregator-xml-route.php

95 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
3 namespace Yoast\WP\SEO\Schema_Aggregator\User_Interface;
4
5 use WP_REST_Response;
6 use Yoast\WP\SEO\Main;
7 use Yoast\WP\SEO\Routes\Route_Interface;
8 use Yoast\WP\SEO\Schema_Aggregator\Application\Schema_Map\Schema_Map_Xml_Provider;
9 use Yoast\WP\SEO\Schema_Aggregator\Infrastructure\Schema_Aggregator_Conditional;
10
11 /**
12 * Handles the route to represent all indexable post types as XML.
13 *
14 * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded
15 */
16 class Site_Schema_Aggregator_Xml_Route implements Route_Interface {
17 /**
18 * Represents the site schema prefix.
19 *
20 * @var string
21 */
22 public const ROUTE_PREFIX = 'schema-aggregator';
23
24 /**
25 * Represents route to view the schema.
26 *
27 * @var string
28 */
29 public const GET_SCHEMA_ROUTE = self::ROUTE_PREFIX . '/get-xml';
30
31 /**
32 * The schema map XML provider.
33 *
34 * @var Schema_Map_Xml_Provider
35 */
36 private $schema_map_xml_provider;
37
38 /**
39 * Returns the conditional for this route.
40 *
41 * @return array<string> The conditionals that must be met to load this.
42 */
43 public static function get_conditionals() {
44 return [ Schema_Aggregator_Conditional::class ];
45 }
46
47 /**
48 * Site_Schema_Aggregator_Route constructor.
49 *
50 * @param Schema_Map_Xml_Provider $schema_map_xml_provider The schema map XML provider.
51 */
52 public function __construct( Schema_Map_Xml_Provider $schema_map_xml_provider ) {
53 $this->schema_map_xml_provider = $schema_map_xml_provider;
54 }
55
56 /**
57 * Registers routes with WordPress.
58 *
59 * @return void
60 */
61 public function register_routes() {
62 $schema_aggregator_xml_route = [
63 'methods' => 'GET',
64 'callback' => [ $this, 'render_schema_xml' ],
65 'permission_callback' => [ $this, 'get_permission_callback' ],
66 ];
67
68 \register_rest_route( Main::API_V1_NAMESPACE, self::GET_SCHEMA_ROUTE, $schema_aggregator_xml_route );
69 }
70
71 /**
72 * Permission callback for the route.
73 *
74 * @codeCoverageIgnore -- No sensible tests can be written for this.
75 *
76 * @return bool True if the user has permission, false otherwise.
77 */
78 public function get_permission_callback(): bool {
79 return true;
80 }
81
82 /**
83 * Returns a XML representation of the post types that are used for schema.
84 *
85 * @return WP_REST_Response The response.
86 */
87 public function render_schema_xml() {
88 $response = new WP_REST_Response( $this->schema_map_xml_provider->get_xml(), 200 );
89 $response->header( 'Content-Type', 'application/xml; charset=UTF-8' );
90 $response->header( 'Cache-Control', 'public, max-age=300' );
91
92 return $response;
93 }
94 }
95