From 308f6a794a7b5a15f99a7b150509276715e9e994 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 4 Mar 2024 13:54:48 +0100 Subject: [PATCH] API: Fix #1531 This needs to load a local file path and no remote path. Reverts commit 751b26a3902cf67f1690775eb9dd95eac32c991f But leaves new exception for troubleshooting purposes, when file_get_contents returns false. --- src/API/BaseRoute.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/API/BaseRoute.php b/src/API/BaseRoute.php index d06fb5bbd..2db175d50 100644 --- a/src/API/BaseRoute.php +++ b/src/API/BaseRoute.php @@ -130,26 +130,26 @@ protected function getSchemaObject(): Schema { /** * Returns schema json for current route. * - * @return array|WP_Error + * @throws RuntimeException On missing schema files. + * @return string */ - protected function getSchemaJson() { - $schemaArray = wp_remote_get( $this->schemaUrl ); - if ( is_array( $schemaArray ) && ! is_wp_error( $schemaArray )) { + protected function getSchemaJson(): string { + $schemaArray = file_get_contents( $this->schemaUrl ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents + if ( $schemaArray ) { return $schemaArray; } else { - throw new RuntimeException("Could not retrieve schema json from " . $this->schemaUrl ); + throw new RuntimeException( 'Could not retrieve schema json from ' . esc_url( $this->schemaUrl ) ); } } /** * Adds schema-fields for output to current route. * - * @param array $schema - * + * @param array $schema Assoc array of schema json object. * @return array */ public function add_additional_fields_schema( $schema ): array { - $schemaArray = json_decode( $this->getSchemaJson(), true ); // TODO verify that this works and doesn't expects ['body'] from wp_remote_get? + $schemaArray = json_decode( $this->getSchemaJson(), true ); return array_merge( $schema, $schemaArray ); }