From 8c0d5292a22a0e53512bcfcfaa1fcc56e9a32b48 Mon Sep 17 00:00:00 2001 From: Rachel Baker Date: Wed, 26 Oct 2016 22:19:08 +0000 Subject: [PATCH] REST API: Add the `default_comment_status` and `default_ping_status` options to the setting endpoint. Props joehoyle. See #38490. git-svn-id: https://develop.svn.wordpress.org/trunk@38971 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/option.php | 21 +++++++++++++++++++ .../rest-api/rest-settings-controller.php | 12 +++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/wp-includes/option.php b/src/wp-includes/option.php index abc7b6f91d..866cbcc480 100644 --- a/src/wp-includes/option.php +++ b/src/wp-includes/option.php @@ -1819,6 +1819,27 @@ function register_initial_settings() { 'description' => __( 'Blog pages show at most.' ), 'default' => 10, ) ); + + register_setting( 'discussion', 'default_ping_status', array( + 'show_in_rest' => array( + 'schema' => array( + 'enum' => array( 'open', 'closed' ), + ), + ), + 'type' => 'string', + 'description' => __( 'Allow link notifications from other blogs (pingbacks and trackbacks) on new articles.' ), + ) ); + + register_setting( 'discussion', 'default_comment_status', array( + 'show_in_rest' => array( + 'schema' => array( + 'enum' => array( 'open', 'closed' ), + ), + ), + 'type' => 'string', + 'description' => __( 'Allow people to post comments on new articles.' ), + ) ); + } /** diff --git a/tests/phpunit/tests/rest-api/rest-settings-controller.php b/tests/phpunit/tests/rest-api/rest-settings-controller.php index 530a5398ff..f3d7b0a12c 100644 --- a/tests/phpunit/tests/rest-api/rest-settings-controller.php +++ b/tests/phpunit/tests/rest-api/rest-settings-controller.php @@ -57,6 +57,8 @@ class WP_Test_REST_Settings_Controller extends WP_Test_REST_Controller_Testcase 'default_category', 'default_post_format', 'posts_per_page', + 'default_ping_status', + 'default_comment_status', ), array_keys( $data ) ); } @@ -228,6 +230,16 @@ class WP_Test_REST_Settings_Controller extends WP_Test_REST_Controller_Testcase $this->assertEquals( 10, $data['posts_per_page'] ); } + public function test_update_item_with_invalid_enum() { + update_option( 'posts_per_page', 9 ); + + wp_set_current_user( $this->administrator ); + $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' ); + $request->set_param( 'default_ping_status', 'open&closed' ); + $response = $this->server->dispatch( $request ); + $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); + } + public function test_delete_item() { }