Skip to content

Commit 2f9b1d2

Browse files
committed
Options, Meta APIs: Revert additional request validity handling that was added to the /wp/v2/settings REST API route. This change needs more work to account for URL query parameters used in place of body data.
This reverts [60357] and [60301]. See #41604 git-svn-id: https://develop.svn.wordpress.org/trunk@61324 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 3901a29 commit 2f9b1d2

File tree

2 files changed

+3
-82
lines changed

2 files changed

+3
-82
lines changed

src/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,7 @@ protected function prepare_value( $value, $schema ) {
145145
public function update_item( $request ) {
146146
$options = $this->get_registered_options();
147147

148-
$params = array_diff_key( $request->get_params(), $request->get_query_params() );
149-
150-
if ( empty( $params ) || ! empty( array_diff_key( $params, $options ) ) ) {
151-
$message = empty( $params )
152-
? __( 'Request body cannot be empty.' )
153-
: __( 'Invalid parameter(s) provided.' );
154-
155-
return new WP_Error(
156-
'rest_invalid_param',
157-
$message,
158-
array( 'status' => 400 )
159-
);
160-
}
148+
$params = $request->get_params();
161149

162150
foreach ( $options as $name => $args ) {
163151
if ( ! array_key_exists( $name, $params ) ) {

tests/phpunit/tests/rest-api/rest-settings-controller.php

Lines changed: 2 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -385,24 +385,14 @@ public function test_get_item_with_invalid_object_array_in_options() {
385385
}
386386

387387
/**
388-
* Settings can't be created
388+
* @doesNotPerformAssertions
389389
*/
390390
public function test_create_item() {
391-
wp_set_current_user( self::$administrator );
392-
393-
$request = new WP_REST_Request( 'POST', '/wp/v2/settings' );
394-
$request->set_param( 'new_setting', 'New value' );
395-
$response = rest_get_server()->dispatch( $request );
396-
397-
$this->assertSame( 400, $response->get_status() );
391+
// Controller does not implement create_item().
398392
}
399393

400-
/**
401-
* @ticket 41604
402-
*/
403394
public function test_update_item() {
404395
wp_set_current_user( self::$administrator );
405-
406396
$request = new WP_REST_Request( 'PUT', '/wp/v2/settings' );
407397
$request->set_param( 'title', 'The new title!' );
408398
$response = rest_get_server()->dispatch( $request );
@@ -413,63 +403,6 @@ public function test_update_item() {
413403
$this->assertSame( get_option( 'blogname' ), $data['title'] );
414404
}
415405

416-
/**
417-
* @ticket 41604
418-
*/
419-
public function test_update_item_with_global_parameters_present() {
420-
wp_set_current_user( self::$administrator );
421-
422-
$request = new WP_REST_Request( 'PUT', '/wp/v2/settings' );
423-
$request->set_param( 'title', 'The new title!' );
424-
$request->set_url_params( array( '_locale' => 'user' ) );
425-
$response = rest_get_server()->dispatch( $request );
426-
$data = $response->get_data();
427-
428-
$this->assertSame( 200, $response->get_status() );
429-
$this->assertSame( 'The new title!', $data['title'] );
430-
$this->assertSame( get_option( 'blogname' ), $data['title'] );
431-
}
432-
433-
/**
434-
* @ticket 41604
435-
*/
436-
public function test_update_item_with_empty_body() {
437-
wp_set_current_user( self::$administrator );
438-
439-
$request = new WP_REST_Request( 'PUT', '/wp/v2/settings' );
440-
$response = rest_get_server()->dispatch( $request );
441-
$data = $response->get_data();
442-
443-
$this->assertSame( 400, $response->get_status() );
444-
}
445-
446-
/**
447-
* @ticket 41604
448-
*/
449-
public function test_update_nonexistent_item() {
450-
wp_set_current_user( self::$administrator );
451-
452-
$request = new WP_REST_Request( 'PUT', '/wp/v2/settings' );
453-
$request->set_param( 'i_do_no_exist', 'New value' );
454-
$response = rest_get_server()->dispatch( $request );
455-
456-
$this->assertSame( 400, $response->get_status() );
457-
}
458-
459-
/**
460-
* @ticket 41604
461-
*/
462-
public function test_update_partially_valid_items() {
463-
wp_set_current_user( self::$administrator );
464-
465-
$request = new WP_REST_Request( 'PUT', '/wp/v2/settings' );
466-
$request->set_param( 'title', 'The new title!' );
467-
$request->set_param( 'i_do_no_exist', 'New value' );
468-
$response = rest_get_server()->dispatch( $request );
469-
470-
$this->assertSame( 400, $response->get_status() );
471-
}
472-
473406
public function update_setting_custom_callback( $result, $name, $value, $args ) {
474407
if ( 'title' === $name && 'The new title!' === $value ) {
475408
// Do not allow changing the title in this case.

0 commit comments

Comments
 (0)