From 56afb62f6beb72c4e87a844e4662554fff00a970 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 11 Jun 2025 17:42:39 +0000 Subject: [PATCH] REST API: Return a more appropriate HTTP 400 response code when attempting to create or update a non-existent setting. This switches the response from a 200, which is not appropriate for invalid requests. Props sheldorofazeroth, johnbillion Fixes #41604 Built from https://develop.svn.wordpress.org/trunk@60301 git-svn-id: http://core.svn.wordpress.org/trunk@59637 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../endpoints/class-wp-rest-settings-controller.php | 12 ++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php index 004f5851a2..66cf8785e4 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php @@ -147,6 +147,18 @@ class WP_REST_Settings_Controller extends WP_REST_Controller { $params = $request->get_params(); + if ( empty( $params ) || ! empty( array_diff_key( $params, $options ) ) ) { + $message = empty( $params ) + ? __( 'Request body cannot be empty.' ) + : __( 'Invalid parameter(s) provided.' ); + + return new WP_Error( + 'rest_invalid_param', + $message, + array( 'status' => 400 ) + ); + } + foreach ( $options as $name => $args ) { if ( ! array_key_exists( $name, $params ) ) { continue; diff --git a/wp-includes/version.php b/wp-includes/version.php index 7884208867..30bdb96c2e 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.9-alpha-60300'; +$wp_version = '6.9-alpha-60301'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.