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
This commit is contained in:
John Blackbourn
2025-06-11 17:42:39 +00:00
parent ef6f590207
commit 56afb62f6b
2 changed files with 13 additions and 1 deletions

View File

@@ -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;

View File

@@ -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.