The conditionals that must be met to load this. */ public static function get_conditionals() { return [ Schema_Aggregator_Conditional::class ]; } /** * Site_Schema_Aggregator_Route constructor. * * @param Schema_Map_Xml_Provider $schema_map_xml_provider The schema map XML provider. */ public function __construct( Schema_Map_Xml_Provider $schema_map_xml_provider ) { $this->schema_map_xml_provider = $schema_map_xml_provider; } /** * Registers routes with WordPress. * * @return void */ public function register_routes() { $schema_aggregator_xml_route = [ 'methods' => 'GET', 'callback' => [ $this, 'render_schema_xml' ], 'permission_callback' => [ $this, 'get_permission_callback' ], ]; \register_rest_route( Main::API_V1_NAMESPACE, self::GET_SCHEMA_ROUTE, $schema_aggregator_xml_route ); } /** * Permission callback for the route. * * @codeCoverageIgnore -- No sensible tests can be written for this. * * @return bool True if the user has permission, false otherwise. */ public function get_permission_callback(): bool { return true; } /** * Returns a XML representation of the post types that are used for schema. * * @return WP_REST_Response The response. */ public function render_schema_xml() { $response = new WP_REST_Response( $this->schema_map_xml_provider->get_xml(), 200 ); $response->header( 'Content-Type', 'application/xml; charset=UTF-8' ); $response->header( 'Cache-Control', 'public, max-age=300' ); return $response; } }