From a0b53ac1db23cb221460207f4bc11b28c2b83b39 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 29 Jun 2022 13:46:37 +0000 Subject: [PATCH] REST API: Add missing options to the settings endpoint. This adds the `show_on_front`, `page_on_front`, and `page_for_posts` options to the settings endpoint that were missed during WP 6.0 backports. Related PR from Gutenberg repository: * [https://github.com/WordPress/gutenberg/pull/38607 #38607 Page for Posts: Display notice in template panel] Props Mamaduka, spacedmonkey, gziolo, jameskoster. See #56058. git-svn-id: https://develop.svn.wordpress.org/trunk@53588 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/option.php | 31 +++++++++++++++++++ .../rest-api/rest-settings-controller.php | 3 ++ tests/qunit/fixtures/wp-api-generated.js | 18 +++++++++++ 3 files changed, 52 insertions(+) diff --git a/src/wp-includes/option.php b/src/wp-includes/option.php index 12f70fef047fc..def80ed18f329 100644 --- a/src/wp-includes/option.php +++ b/src/wp-includes/option.php @@ -2063,6 +2063,7 @@ function set_site_transient( $transient, $value, $expiration = 0 ) { * does not encompass all settings available in WordPress. * * @since 4.7.0 + * @since 6.1.0 The `show_on_front`, `page_on_front`, and `page_for_posts` options were added. */ function register_initial_settings() { register_setting( @@ -2220,6 +2221,36 @@ function register_initial_settings() { ) ); + register_setting( + 'reading', + 'show_on_front', + array( + 'show_in_rest' => true, + 'type' => 'string', + 'description' => __( 'What to show on the front page' ), + ) + ); + + register_setting( + 'reading', + 'page_on_front', + array( + 'show_in_rest' => true, + 'type' => 'number', + 'description' => __( 'The ID of the page that should be displayed on the front page' ), + ) + ); + + register_setting( + 'reading', + 'page_for_posts', + array( + 'show_in_rest' => true, + 'type' => 'number', + 'description' => __( 'The ID of the page that should display the latest posts' ), + ) + ); + register_setting( 'discussion', 'default_ping_status', diff --git a/tests/phpunit/tests/rest-api/rest-settings-controller.php b/tests/phpunit/tests/rest-api/rest-settings-controller.php index fe99fccfa8296..3c11935414af1 100644 --- a/tests/phpunit/tests/rest-api/rest-settings-controller.php +++ b/tests/phpunit/tests/rest-api/rest-settings-controller.php @@ -106,6 +106,9 @@ public function test_get_items() { 'default_category', 'default_post_format', 'posts_per_page', + 'show_on_front', + 'page_on_front', + 'page_for_posts', 'default_ping_status', 'default_comment_status', 'site_icon', // Registered in wp-includes/blocks/site-logo.php diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index 6161cf14fc137..654a0bee073ef 100644 --- a/tests/qunit/fixtures/wp-api-generated.js +++ b/tests/qunit/fixtures/wp-api-generated.js @@ -9628,6 +9628,21 @@ mockedApiResponse.Schema = { "type": "integer", "required": false }, + "show_on_front": { + "description": "What to show on the front page", + "type": "string", + "required": false + }, + "page_on_front": { + "description": "The ID of the page that should be displayed on the front page", + "type": "number", + "required": false + }, + "page_for_posts": { + "description": "The ID of the page that should display the latest posts", + "type": "number", + "required": false + }, "default_ping_status": { "description": "Allow link notifications from other blogs (pingbacks and trackbacks) on new articles.", "type": "string", @@ -12283,6 +12298,9 @@ mockedApiResponse.settings = { "default_category": 1, "default_post_format": "0", "posts_per_page": 10, + "show_on_front": "posts", + "page_on_front": 0, + "page_for_posts": 0, "default_ping_status": "open", "default_comment_status": "open", "site_logo": null,