Skip to content

Commit

Permalink
REST API: Add missing options to the settings endpoint.
Browse files Browse the repository at this point in the history
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:
* [WordPress/gutenberg#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
  • Loading branch information
SergeyBiryukov committed Jun 29, 2022
1 parent aaa4d1a commit a0b53ac
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/wp-includes/option.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit/tests/rest-api/rest-settings-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions tests/qunit/fixtures/wp-api-generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a0b53ac

Please sign in to comment.