Make WordPress Core


Ignore:
Timestamp:
06/11/2025 05:40:44 PM (8 months ago)
Author:
johnbillion
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php

    r58230 r60301  
    147147
    148148        $params = $request->get_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        }
    149161
    150162        foreach ( $options as $name => $args ) {
Note: See TracChangeset for help on using the changeset viewer.