From b45e379d214240be1c572db0b1078f5d39b7ea71 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Thu, 27 Feb 2025 03:37:22 +0000 Subject: [PATCH] REST API: Add the site reading options to the index. Exposes `page_for_posts`, `page_on_front` and `show_on_front` reading settings via REST API index. Props mamaduka, audrasjb, spacedmonkey, timothyblynjacobs. Fixes #63023. git-svn-id: https://develop.svn.wordpress.org/trunk@59880 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/rest-api/class-wp-rest-server.php | 3 +++ tests/phpunit/tests/rest-api/rest-server.php | 3 +++ tests/qunit/fixtures/wp-api-generated.js | 3 +++ 3 files changed, 9 insertions(+) diff --git a/src/wp-includes/rest-api/class-wp-rest-server.php b/src/wp-includes/rest-api/class-wp-rest-server.php index 17d620f6fb..8fe9834a8d 100644 --- a/src/wp-includes/rest-api/class-wp-rest-server.php +++ b/src/wp-includes/rest-api/class-wp-rest-server.php @@ -1371,6 +1371,9 @@ class WP_REST_Server { 'home' => home_url(), 'gmt_offset' => get_option( 'gmt_offset' ), 'timezone_string' => get_option( 'timezone_string' ), + 'page_for_posts' => (int) get_option( 'page_for_posts' ), + 'page_on_front' => (int) get_option( 'page_on_front' ), + 'show_on_front' => get_option( 'show_on_front' ), 'namespaces' => array_keys( $this->namespaces ), 'authentication' => array(), 'routes' => $this->get_data_for_routes( $this->get_routes(), $request['context'] ), diff --git a/tests/phpunit/tests/rest-api/rest-server.php b/tests/phpunit/tests/rest-api/rest-server.php index 378b51f606..dc991eb672 100644 --- a/tests/phpunit/tests/rest-api/rest-server.php +++ b/tests/phpunit/tests/rest-api/rest-server.php @@ -1137,6 +1137,9 @@ class Tests_REST_Server extends WP_Test_REST_TestCase { $this->assertArrayHasKey( 'home', $data ); $this->assertArrayHasKey( 'gmt_offset', $data ); $this->assertArrayHasKey( 'timezone_string', $data ); + $this->assertArrayHasKey( 'page_for_posts', $data ); + $this->assertArrayHasKey( 'page_on_front', $data ); + $this->assertArrayHasKey( 'show_on_front', $data ); $this->assertArrayHasKey( 'namespaces', $data ); $this->assertArrayHasKey( 'authentication', $data ); $this->assertArrayHasKey( 'routes', $data ); diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index f3a1f21e48..47b272c1bd 100644 --- a/tests/qunit/fixtures/wp-api-generated.js +++ b/tests/qunit/fixtures/wp-api-generated.js @@ -12,6 +12,9 @@ mockedApiResponse.Schema = { "home": "http://example.org", "gmt_offset": "0", "timezone_string": "", + "page_for_posts": 0, + "page_on_front": 0, + "show_on_front": "posts", "namespaces": [ "oembed/1.0", "wp/v2",